mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
composer.json - move tests-related classes to "autoload-dev" section (used for development purposes only and avoid polluting the autoloader in production)
This commit is contained in:
143
tests/Result/Collection/ParticipantsTest.php
Normal file
143
tests/Result/Collection/ParticipantsTest.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
|
||||
/**
|
||||
* Test case of the participants of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantsTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* An empty collection of participants
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsEmpty;
|
||||
|
||||
/**
|
||||
* Participants of 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsOfOneSurvey;
|
||||
|
||||
/**
|
||||
* Participants of more than 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsOfManySurvey;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Participants::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->expectException(DisabledMethodException::class);
|
||||
(new Participants())->add('');
|
||||
}
|
||||
|
||||
public function testAddMultiple()
|
||||
{
|
||||
$this->expectException(DisabledMethodException::class);
|
||||
(new Participants())->addMultiple([]);
|
||||
}
|
||||
|
||||
public function testAddParticipantsWithoutParticipants()
|
||||
{
|
||||
$surveyId = 1;
|
||||
|
||||
$participants = new Participants();
|
||||
$result = $participants->addParticipants(new Collection(), $surveyId);
|
||||
|
||||
static::assertFalse($participants->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($participants->hasParticipantsOfSurvey(2));
|
||||
|
||||
static::assertEquals($participants, $result);
|
||||
static::assertCount(0, $participants->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
public function testAddParticipantsFirstParticipants()
|
||||
{
|
||||
$surveyId = 1;
|
||||
|
||||
$participantsData = new Collection([
|
||||
new Participant(),
|
||||
new Participant(),
|
||||
]);
|
||||
|
||||
$result = $this
|
||||
->participantsEmpty
|
||||
->addParticipants($participantsData, $surveyId);
|
||||
|
||||
static::assertTrue($this->participantsEmpty->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($this->participantsEmpty->hasParticipantsOfSurvey(2));
|
||||
|
||||
static::assertEquals($this->participantsEmpty, $result);
|
||||
static::assertCount(2, $this->participantsEmpty->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
public function testAddParticipantsMoreParticipants()
|
||||
{
|
||||
$surveyId = 2;
|
||||
|
||||
$participantsData = new Collection([
|
||||
new Participant(),
|
||||
new Participant(),
|
||||
]);
|
||||
|
||||
$result = $this
|
||||
->participantsOfOneSurvey
|
||||
->addParticipants($participantsData, $surveyId);
|
||||
|
||||
static::assertTrue($this->participantsOfOneSurvey->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($this->participantsOfOneSurvey->hasParticipantsOfSurvey(3));
|
||||
|
||||
static::assertEquals($this->participantsOfOneSurvey, $result);
|
||||
static::assertCount(2, $this->participantsOfOneSurvey->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->participantsEmpty = new Participants();
|
||||
$this->participantsOfOneSurvey = new Participants();
|
||||
$this->participantsOfManySurvey = new Participants();
|
||||
|
||||
$participants1Survey = new Collection();
|
||||
$participants2Survey = new Collection();
|
||||
$participants3Survey = new Collection();
|
||||
|
||||
$this
|
||||
->participantsOfOneSurvey
|
||||
->addParticipants($participants1Survey, 1);
|
||||
|
||||
$this
|
||||
->participantsOfManySurvey
|
||||
->addParticipants($participants1Survey, 2)
|
||||
->addParticipants($participants2Survey, 3)
|
||||
->addParticipants($participants3Survey, 4);
|
||||
}
|
||||
}
|
||||
122
tests/Result/Item/ParticipantShortTest.php
Normal file
122
tests/Result/Item/ParticipantShortTest.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: short data of participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantShortTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* 1st instance of the participant created using the raw data
|
||||
*
|
||||
* @var ParticipantShort
|
||||
*/
|
||||
private $participant1stInstance;
|
||||
|
||||
/**
|
||||
* 2nd instance of the participant created using the raw data
|
||||
*
|
||||
* @var ParticipantShort
|
||||
*/
|
||||
private $participant2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(ParticipantShort::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_PARTICIPANTS, $this->rawData);
|
||||
|
||||
static::assertCount(2, $processed);
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
static::assertEquals(123, $this->participant1stInstance->getId());
|
||||
static::assertEquals(456, $this->participant2ndInstance->getId());
|
||||
}
|
||||
|
||||
public function testGetFirstName()
|
||||
{
|
||||
static::assertEquals('Lorem', $this->participant1stInstance->getFirstName());
|
||||
static::assertEquals('Dolor', $this->participant2ndInstance->getFirstName());
|
||||
}
|
||||
|
||||
public function testGetLastName()
|
||||
{
|
||||
static::assertEquals('Ipsum', $this->participant1stInstance->getLastName());
|
||||
static::assertEquals('Sit', $this->participant2ndInstance->getLastName());
|
||||
}
|
||||
|
||||
public function testGetEmail()
|
||||
{
|
||||
static::assertEquals('lorem@ipsum.com', $this->participant1stInstance->getEmail());
|
||||
static::assertEquals('dolor@sit.com', $this->participant2ndInstance->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getParticipantsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tid' => '123',
|
||||
'token' => uniqid(),
|
||||
'participant_info' => [
|
||||
'firstname' => 'Lorem',
|
||||
'lastname' => 'Ipsum',
|
||||
'email' => 'lorem@ipsum.com',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tid' => '456',
|
||||
'token' => uniqid(),
|
||||
'participant_info' => [
|
||||
'firstname' => 'Dolor',
|
||||
'lastname' => 'Sit',
|
||||
'email' => 'dolor@sit.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getParticipantsRawData();
|
||||
|
||||
$this->participant1stInstance = (new ParticipantShort())->setValues($this->rawData[0]);
|
||||
$this->participant2ndInstance = (new ParticipantShort())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
221
tests/Result/Item/ParticipantTest.php
Normal file
221
tests/Result/Item/ParticipantTest.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: full data of participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* 1st instance of the participant created using the raw data
|
||||
*
|
||||
* @var Participant
|
||||
*/
|
||||
private $participant1stInstance;
|
||||
|
||||
/**
|
||||
* 2nd instance of the participant created using the raw data
|
||||
*
|
||||
* @var Participant
|
||||
*/
|
||||
private $participant2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Participant::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::GET_PARTICIPANT_PROPERTIES, $this->rawData[0]);
|
||||
|
||||
static::assertInstanceOf(Participant::class, $processed);
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
static::assertEquals(123, $this->participant1stInstance->getId());
|
||||
static::assertEquals(456, $this->participant2ndInstance->getId());
|
||||
}
|
||||
|
||||
public function testGetParticipantId()
|
||||
{
|
||||
static::assertEquals(0, $this->participant1stInstance->getParticipantId());
|
||||
static::assertEquals(789, $this->participant2ndInstance->getParticipantId());
|
||||
}
|
||||
|
||||
public function testGetMpId()
|
||||
{
|
||||
static::assertEquals(0, $this->participant1stInstance->getMpId());
|
||||
static::assertEquals(1, $this->participant2ndInstance->getMpId());
|
||||
}
|
||||
|
||||
public function testGetFirstName()
|
||||
{
|
||||
static::assertEquals('Lorem', $this->participant1stInstance->getFirstName());
|
||||
static::assertEquals('Dolor', $this->participant2ndInstance->getFirstName());
|
||||
}
|
||||
|
||||
public function testGetLastName()
|
||||
{
|
||||
static::assertEquals('Ipsum', $this->participant1stInstance->getLastName());
|
||||
static::assertEquals('Sit', $this->participant2ndInstance->getLastName());
|
||||
}
|
||||
|
||||
public function testGetEmail()
|
||||
{
|
||||
static::assertEquals('lorem@ipsum.com', $this->participant1stInstance->getEmail());
|
||||
static::assertEquals('dolor@sit.com', $this->participant2ndInstance->getEmail());
|
||||
}
|
||||
|
||||
public function testGetEmailStatus()
|
||||
{
|
||||
static::assertEquals('OK', $this->participant1stInstance->getEmailStatus());
|
||||
static::assertEquals('OK', $this->participant2ndInstance->getEmailStatus());
|
||||
}
|
||||
|
||||
public function testGetToken()
|
||||
{
|
||||
static::assertEquals($this->rawData[0]['token'], $this->participant1stInstance->getToken());
|
||||
static::assertEquals($this->rawData[1]['token'], $this->participant2ndInstance->getToken());
|
||||
}
|
||||
|
||||
public function testGetLanguage()
|
||||
{
|
||||
static::assertEquals('pl', $this->participant1stInstance->getLanguage());
|
||||
static::assertEquals('en', $this->participant2ndInstance->getLanguage());
|
||||
}
|
||||
|
||||
public function testIsBlacklisted()
|
||||
{
|
||||
static::assertFalse($this->participant1stInstance->isBlacklisted());
|
||||
static::assertTrue($this->participant2ndInstance->isBlacklisted());
|
||||
}
|
||||
|
||||
public function testIsSent()
|
||||
{
|
||||
static::assertTrue($this->participant1stInstance->isSent());
|
||||
static::assertTrue($this->participant2ndInstance->isSent());
|
||||
}
|
||||
|
||||
public function testIsReminderSent()
|
||||
{
|
||||
static::assertFalse($this->participant1stInstance->isReminderSent());
|
||||
static::assertFalse($this->participant2ndInstance->isReminderSent());
|
||||
}
|
||||
|
||||
public function testGetReminderCount()
|
||||
{
|
||||
static::assertEquals(0, $this->participant1stInstance->getReminderCount());
|
||||
static::assertEquals(1, $this->participant2ndInstance->getReminderCount());
|
||||
}
|
||||
|
||||
public function testIsCompleted()
|
||||
{
|
||||
static::assertFalse($this->participant1stInstance->isCompleted());
|
||||
static::assertTrue($this->participant2ndInstance->isCompleted());
|
||||
}
|
||||
|
||||
public function testGetUsesLeft()
|
||||
{
|
||||
static::assertEquals(10, $this->participant1stInstance->getUsesLeft());
|
||||
static::assertEquals(5, $this->participant2ndInstance->getUsesLeft());
|
||||
}
|
||||
|
||||
public function testGetValidFrom()
|
||||
{
|
||||
static::assertNull($this->participant1stInstance->getValidFrom());
|
||||
static::assertEquals(new DateTime($this->rawData[1]['validfrom']), $this->participant2ndInstance->getValidFrom());
|
||||
}
|
||||
|
||||
public function testGetValidUntil()
|
||||
{
|
||||
static::assertEquals(new DateTime($this->rawData[0]['validuntil']), $this->participant1stInstance->getValidUntil());
|
||||
static::assertNull($this->participant2ndInstance->getValidUntil());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getParticipantsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tid' => '123',
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'Lorem',
|
||||
'lastname' => 'Ipsum',
|
||||
'email' => 'lorem@ipsum.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => 'N',
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
],
|
||||
[
|
||||
'tid' => '456',
|
||||
'participant_id' => '789',
|
||||
'mpid' => '001',
|
||||
'firstname' => 'Dolor',
|
||||
'lastname' => 'Sit',
|
||||
'email' => 'dolor@sit.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'en',
|
||||
'blacklisted' => 'Y',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 1,
|
||||
'completed' => 'Y',
|
||||
'usesleft' => 5,
|
||||
'validfrom' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'validuntil' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getParticipantsRawData();
|
||||
|
||||
$this->participant1stInstance = (new Participant())->setValues($this->rawData[0]);
|
||||
$this->participant2ndInstance = (new Participant())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
228
tests/Result/Item/QuestionShortTest.php
Normal file
228
tests/Result/Item/QuestionShortTest.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\QuestionShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: short data of one question of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class QuestionShortTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of questions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* 1st instance of the question created using the raw data
|
||||
*
|
||||
* @var QuestionShort
|
||||
*/
|
||||
private $question1stInstance;
|
||||
|
||||
/**
|
||||
* 2nd instance of the question created using the raw data
|
||||
*
|
||||
* @var QuestionShort
|
||||
*/
|
||||
private $question2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(QuestionShort::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_QUESTIONS, $this->rawData);
|
||||
|
||||
static::assertCount(2, $processed);
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
static::assertEquals(123, $this->question1stInstance->getId());
|
||||
static::assertEquals(456, $this->question2ndInstance->getId());
|
||||
}
|
||||
|
||||
public function testGetParentId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getParentId());
|
||||
static::assertEquals(789, $this->question2ndInstance->getParentId());
|
||||
}
|
||||
|
||||
public function testGetSurveyId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getSurveyId());
|
||||
static::assertEquals(1020, $this->question2ndInstance->getSurveyId());
|
||||
}
|
||||
|
||||
public function testGetGroupId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getGroupId());
|
||||
static::assertEquals(3040, $this->question2ndInstance->getGroupId());
|
||||
}
|
||||
|
||||
public function testGetScaleId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getScaleId());
|
||||
static::assertEquals(5060, $this->question2ndInstance->getScaleId());
|
||||
}
|
||||
|
||||
public function testGetType()
|
||||
{
|
||||
static::assertEquals('T', $this->question1stInstance->getType());
|
||||
static::assertEquals('N', $this->question2ndInstance->getType());
|
||||
}
|
||||
|
||||
public function testGetTitle()
|
||||
{
|
||||
static::assertEquals('Test', $this->question1stInstance->getTitle());
|
||||
static::assertEquals('Another Test', $this->question2ndInstance->getTitle());
|
||||
}
|
||||
|
||||
public function testGetContent()
|
||||
{
|
||||
static::assertEquals('Donec ullamcorper nulla non metus auctor fringilla?', $this->question1stInstance->getContent());
|
||||
static::assertEquals('Maecenas sed diam eget risus varius blandit sit amet non magna?', $this->question2ndInstance->getContent());
|
||||
}
|
||||
|
||||
public function testGetContentHelp()
|
||||
{
|
||||
static::assertEquals('Maecenas sed diam eget risus varius blandit sit amet non magna.', $this->question1stInstance->getContentHelp());
|
||||
static::assertEquals('Donec id elit non mi porta gravida at eget metus.', $this->question2ndInstance->getContentHelp());
|
||||
}
|
||||
|
||||
public function testGetRegularExpression()
|
||||
{
|
||||
static::assertNull($this->question1stInstance->getRegularExpression());
|
||||
static::assertEquals('\d+', $this->question2ndInstance->getRegularExpression());
|
||||
}
|
||||
|
||||
public function testIsOther()
|
||||
{
|
||||
static::assertFalse($this->question1stInstance->isOther());
|
||||
static::assertFalse($this->question2ndInstance->isOther());
|
||||
}
|
||||
|
||||
public function testIsMandatory()
|
||||
{
|
||||
static::assertTrue($this->question1stInstance->isMandatory());
|
||||
static::assertTrue($this->question2ndInstance->isMandatory());
|
||||
}
|
||||
|
||||
public function testGetPosition()
|
||||
{
|
||||
static::assertEquals(1, $this->question1stInstance->getPosition());
|
||||
static::assertEquals(2, $this->question2ndInstance->getPosition());
|
||||
}
|
||||
|
||||
public function testGetLanguage()
|
||||
{
|
||||
static::assertEquals('pl', $this->question1stInstance->getLanguage());
|
||||
static::assertEquals('pl', $this->question2ndInstance->getLanguage());
|
||||
}
|
||||
|
||||
public function testGetSameDefault()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getSameDefault());
|
||||
static::assertEquals(0, $this->question2ndInstance->getSameDefault());
|
||||
}
|
||||
|
||||
public function testGetRelevance()
|
||||
{
|
||||
static::assertEquals('', $this->question1stInstance->getRelevance());
|
||||
static::assertEquals('1', $this->question2ndInstance->getRelevance());
|
||||
}
|
||||
|
||||
public function testGetModuleName()
|
||||
{
|
||||
static::assertNull($this->question1stInstance->getModuleName());
|
||||
static::assertEquals('HR', $this->question2ndInstance->getModuleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of questions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getQuestionsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'id' => [
|
||||
'qid' => '123',
|
||||
'language' => 'pl',
|
||||
],
|
||||
'qid' => '123',
|
||||
'parent_qid' => null,
|
||||
'sid' => null,
|
||||
'gid' => null,
|
||||
'scale_id' => null,
|
||||
'type' => 'T',
|
||||
'title' => 'Test',
|
||||
'question' => 'Donec ullamcorper nulla non metus auctor fringilla?',
|
||||
'help' => 'Maecenas sed diam eget risus varius blandit sit amet non magna.',
|
||||
'preg' => null,
|
||||
'other' => 'N',
|
||||
'mandatory' => 'Y',
|
||||
'question_order' => '1',
|
||||
'language' => 'pl',
|
||||
'same_default' => '0',
|
||||
'relevance' => null,
|
||||
'modulename' => null,
|
||||
],
|
||||
[
|
||||
'id' => [
|
||||
'qid' => '456',
|
||||
'language' => 'pl',
|
||||
],
|
||||
'qid' => '456',
|
||||
'parent_qid' => '789',
|
||||
'sid' => '1020',
|
||||
'gid' => '3040',
|
||||
'scale_id' => '5060',
|
||||
'type' => 'N',
|
||||
'title' => 'Another Test',
|
||||
'question' => 'Maecenas sed diam eget risus varius blandit sit amet non magna?',
|
||||
'help' => 'Donec id elit non mi porta gravida at eget metus.',
|
||||
'preg' => '\d+',
|
||||
'other' => 'N',
|
||||
'mandatory' => 'Y',
|
||||
'question_order' => '2',
|
||||
'language' => 'pl',
|
||||
'same_default' => '0',
|
||||
'relevance' => '1',
|
||||
'modulename' => 'HR',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = (new QuestionShort())->setValues($this->rawData[0]);
|
||||
$this->question2ndInstance = (new QuestionShort())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
290
tests/Result/Item/QuestionTest.php
Normal file
290
tests/Result/Item/QuestionTest.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: full data of one question of survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class QuestionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of questions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* 1st instance of the question created using the raw data
|
||||
*
|
||||
* @var Question
|
||||
*/
|
||||
private $question1stInstance;
|
||||
|
||||
/**
|
||||
* 2nd instance of the question created using the raw data
|
||||
*
|
||||
* @var Question
|
||||
*/
|
||||
private $question2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Question::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::GET_QUESTION_PROPERTIES, $this->rawData);
|
||||
|
||||
static::assertInstanceOf(Question::class, $processed);
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
static::assertEquals(123, $this->question1stInstance->getId());
|
||||
static::assertEquals(456, $this->question2ndInstance->getId());
|
||||
}
|
||||
|
||||
public function testGetParentId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getParentId());
|
||||
static::assertEquals(789, $this->question2ndInstance->getParentId());
|
||||
}
|
||||
|
||||
public function testGetSurveyId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getSurveyId());
|
||||
static::assertEquals(1020, $this->question2ndInstance->getSurveyId());
|
||||
}
|
||||
|
||||
public function testGetGroupId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getGroupId());
|
||||
static::assertEquals(3040, $this->question2ndInstance->getGroupId());
|
||||
}
|
||||
|
||||
public function testGetScaleId()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getScaleId());
|
||||
static::assertEquals(5060, $this->question2ndInstance->getScaleId());
|
||||
}
|
||||
|
||||
public function testGetType()
|
||||
{
|
||||
static::assertEquals('T', $this->question1stInstance->getType());
|
||||
static::assertEquals('M', $this->question2ndInstance->getType());
|
||||
}
|
||||
|
||||
public function testGetTitle()
|
||||
{
|
||||
static::assertEquals('Test', $this->question1stInstance->getTitle());
|
||||
static::assertEquals('Another Test', $this->question2ndInstance->getTitle());
|
||||
}
|
||||
|
||||
public function testGetContent()
|
||||
{
|
||||
static::assertEquals('Donec ullamcorper nulla non metus auctor fringilla?', $this->question1stInstance->getContent());
|
||||
static::assertEquals('Maecenas sed diam eget risus varius blandit sit amet non magna?', $this->question2ndInstance->getContent());
|
||||
}
|
||||
|
||||
public function testGetContentHelp()
|
||||
{
|
||||
static::assertEquals('Maecenas sed diam eget risus varius blandit sit amet non magna.', $this->question1stInstance->getContentHelp());
|
||||
static::assertEquals('Donec id elit non mi porta gravida at eget metus.', $this->question2ndInstance->getContentHelp());
|
||||
}
|
||||
|
||||
public function testGetRegularExpression()
|
||||
{
|
||||
static::assertNull($this->question1stInstance->getRegularExpression());
|
||||
static::assertEquals('\d+', $this->question2ndInstance->getRegularExpression());
|
||||
}
|
||||
|
||||
public function testIsOther()
|
||||
{
|
||||
static::assertFalse($this->question1stInstance->isOther());
|
||||
static::assertFalse($this->question2ndInstance->isOther());
|
||||
}
|
||||
|
||||
public function testIsMandatory()
|
||||
{
|
||||
static::assertTrue($this->question1stInstance->isMandatory());
|
||||
static::assertTrue($this->question2ndInstance->isMandatory());
|
||||
}
|
||||
|
||||
public function testGetPosition()
|
||||
{
|
||||
static::assertEquals(1, $this->question1stInstance->getPosition());
|
||||
static::assertEquals(2, $this->question2ndInstance->getPosition());
|
||||
}
|
||||
|
||||
public function testGetLanguage()
|
||||
{
|
||||
static::assertEquals('pl', $this->question1stInstance->getLanguage());
|
||||
static::assertEquals('pl', $this->question2ndInstance->getLanguage());
|
||||
}
|
||||
|
||||
public function testGetSameDefault()
|
||||
{
|
||||
static::assertEquals(0, $this->question1stInstance->getSameDefault());
|
||||
static::assertEquals(0, $this->question2ndInstance->getSameDefault());
|
||||
}
|
||||
|
||||
public function testGetRelevance()
|
||||
{
|
||||
static::assertEquals('', $this->question1stInstance->getRelevance());
|
||||
static::assertEquals('1', $this->question2ndInstance->getRelevance());
|
||||
}
|
||||
|
||||
public function testGetModuleName()
|
||||
{
|
||||
static::assertNull($this->question1stInstance->getModuleName());
|
||||
static::assertEquals('HR', $this->question2ndInstance->getModuleName());
|
||||
}
|
||||
|
||||
public function testGetAvailableAnswers()
|
||||
{
|
||||
static::assertEquals('No available answers', $this->question1stInstance->getAvailableAnswers());
|
||||
static::assertEquals($this->rawData[1]['available_answers'], $this->question2ndInstance->getAvailableAnswers());
|
||||
}
|
||||
|
||||
public function testGetSubQuestions()
|
||||
{
|
||||
static::assertEquals('No available subquestions', $this->question1stInstance->getSubQuestions());
|
||||
static::assertEquals($this->rawData[1]['subquestions'], $this->question2ndInstance->getSubQuestions());
|
||||
}
|
||||
|
||||
public function testGetAttributes()
|
||||
{
|
||||
static::assertEquals('No available attributes', $this->question1stInstance->getAttributes());
|
||||
static::assertEquals('No available attributes', $this->question2ndInstance->getAttributes());
|
||||
}
|
||||
|
||||
public function testGetAttributesLanguages()
|
||||
{
|
||||
static::assertEquals('No available attributes', $this->question1stInstance->getAttributesLanguages());
|
||||
static::assertEquals('No available attributes', $this->question2ndInstance->getAttributesLanguages());
|
||||
}
|
||||
|
||||
public function testGetAnswerOptions()
|
||||
{
|
||||
static::assertEquals('No available answer options', $this->question1stInstance->getAnswerOptions());
|
||||
static::assertEquals('No available answer options', $this->question2ndInstance->getAnswerOptions());
|
||||
}
|
||||
|
||||
public function testGetDefaultValue()
|
||||
{
|
||||
static::assertNull($this->question1stInstance->getDefaultValue());
|
||||
static::assertNull($this->question2ndInstance->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of questions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getQuestionsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'id' => [
|
||||
'qid' => '123',
|
||||
'language' => 'pl',
|
||||
],
|
||||
'qid' => '123',
|
||||
'parent_qid' => null,
|
||||
'sid' => null,
|
||||
'gid' => null,
|
||||
'scale_id' => null,
|
||||
'type' => 'T',
|
||||
'title' => 'Test',
|
||||
'question' => 'Donec ullamcorper nulla non metus auctor fringilla?',
|
||||
'help' => 'Maecenas sed diam eget risus varius blandit sit amet non magna.',
|
||||
'preg' => null,
|
||||
'other' => 'N',
|
||||
'mandatory' => 'Y',
|
||||
'question_order' => '1',
|
||||
'language' => 'pl',
|
||||
'same_default' => '0',
|
||||
'relevance' => null,
|
||||
'modulename' => null,
|
||||
'available_answers' => 'No available answers',
|
||||
'subquestions' => 'No available subquestions',
|
||||
'attributes' => 'No available attributes',
|
||||
'attributes_lang' => 'No available attributes',
|
||||
'answeroptions' => 'No available answer options',
|
||||
'defaultvalue' => null,
|
||||
],
|
||||
[
|
||||
'id' => [
|
||||
'qid' => '456',
|
||||
'language' => 'pl',
|
||||
],
|
||||
'qid' => '456',
|
||||
'parent_qid' => '789',
|
||||
'sid' => '1020',
|
||||
'gid' => '3040',
|
||||
'scale_id' => '5060',
|
||||
'type' => 'M',
|
||||
'title' => 'Another Test',
|
||||
'question' => 'Maecenas sed diam eget risus varius blandit sit amet non magna?',
|
||||
'help' => 'Donec id elit non mi porta gravida at eget metus.',
|
||||
'preg' => '\d+',
|
||||
'other' => 'N',
|
||||
'mandatory' => 'Y',
|
||||
'question_order' => '2',
|
||||
'language' => 'pl',
|
||||
'same_default' => '0',
|
||||
'relevance' => '1',
|
||||
'modulename' => 'HR',
|
||||
'available_answers' => [
|
||||
'SQ001' => 'Sed posuere consectetur est at lobortis?',
|
||||
'SQ002' => 'Cum sociis natoque penatibus et magnis?',
|
||||
],
|
||||
'subquestions' => [
|
||||
1 => [
|
||||
'title' => 'SQ001',
|
||||
'question' => 'Cum sociis natoque penatibus et magnis?',
|
||||
'scale_id' => '0',
|
||||
],
|
||||
2 => [
|
||||
'title' => 'SQ002',
|
||||
'question' => 'Sed posuere consectetur est at lobortis?',
|
||||
'scale_id' => '0',
|
||||
],
|
||||
],
|
||||
'attributes' => 'No available attributes',
|
||||
'attributes_lang' => 'No available attributes',
|
||||
'answeroptions' => 'No available answer options',
|
||||
'defaultvalue' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = (new Question())->setValues($this->rawData[0]);
|
||||
$this->question2ndInstance = (new Question())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
125
tests/Result/Item/SurveyTest.php
Normal file
125
tests/Result/Item/SurveyTest.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of surveys
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $rawData;
|
||||
|
||||
/**
|
||||
* 1st instance of the survey created using the raw data
|
||||
*
|
||||
* @var Survey
|
||||
*/
|
||||
private $survey1stInstance;
|
||||
|
||||
/**
|
||||
* 2nd instance of the survey created using the raw data
|
||||
*
|
||||
* @var Survey
|
||||
*/
|
||||
private $survey2ndInstance;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Survey::class);
|
||||
}
|
||||
|
||||
public function testCreateOfTheSurvey()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, $this->rawData);
|
||||
|
||||
static::assertCount(2, $processed);
|
||||
}
|
||||
|
||||
public function testGetId()
|
||||
{
|
||||
static::assertEquals(123, $this->survey1stInstance->getId());
|
||||
static::assertEquals(456, $this->survey2ndInstance->getId());
|
||||
}
|
||||
|
||||
public function testGetTitle()
|
||||
{
|
||||
static::assertEquals('Test', $this->survey1stInstance->getTitle());
|
||||
static::assertEquals('Another Test', $this->survey2ndInstance->getTitle());
|
||||
}
|
||||
|
||||
public function testGetStartsAt()
|
||||
{
|
||||
static::assertNull($this->survey1stInstance->getStartsAt());
|
||||
static::assertEquals(new DateTime($this->rawData[1]['startdate']), $this->survey2ndInstance->getStartsAt());
|
||||
}
|
||||
|
||||
public function testGetExpiresAt()
|
||||
{
|
||||
static::assertEquals(new DateTime($this->rawData[0]['expires']), $this->survey1stInstance->getExpiresAt());
|
||||
static::assertNull($this->survey2ndInstance->getExpiresAt());
|
||||
}
|
||||
|
||||
public function testIsActive()
|
||||
{
|
||||
static::assertFalse($this->survey1stInstance->isActive());
|
||||
static::assertTrue($this->survey2ndInstance->isActive());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of surveys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSurveysRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'sid' => '123',
|
||||
'surveyls_title' => 'Test',
|
||||
'startdate' => null,
|
||||
'expires' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'active' => 'N',
|
||||
],
|
||||
[
|
||||
'sid' => '456',
|
||||
'surveyls_title' => 'Another Test',
|
||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'expires' => null,
|
||||
'active' => 'Y',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getSurveysRawData();
|
||||
|
||||
$this->survey1stInstance = (new Survey())->setValues($this->rawData[0]);
|
||||
$this->survey2ndInstance = (new Survey())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
95
tests/Result/Processor/ResultProcessorTest.php
Normal file
95
tests/Result/Processor/ResultProcessorTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Processor;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
|
||||
/**
|
||||
* Test case of the processor of the raw data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ResultProcessorTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(ResultProcessor::class);
|
||||
}
|
||||
|
||||
public function testProcessWithEmptyRawData()
|
||||
{
|
||||
$rawData = [];
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
static::assertNull($processor->process(MethodType::LIST_SURVEYS, $rawData));
|
||||
}
|
||||
|
||||
public function testProcessWithIterableData()
|
||||
{
|
||||
$surveysRawData = SurveyTest::getSurveysRawData();
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, $surveysRawData);
|
||||
|
||||
static::assertTrue(is_array($processed));
|
||||
static::assertCount(2, $processed);
|
||||
|
||||
/* @var Survey $firstSurvey */
|
||||
$firstSurvey = $processed[0];
|
||||
|
||||
/* @var Survey $secondSurvey */
|
||||
$secondSurvey = $processed[1];
|
||||
|
||||
static::assertEquals($surveysRawData[0]['sid'], $firstSurvey->getId());
|
||||
static::assertEquals($surveysRawData[1]['sid'], $secondSurvey->getId());
|
||||
|
||||
static::assertEquals($surveysRawData[0]['surveyls_title'], $firstSurvey->getTitle());
|
||||
static::assertEquals($surveysRawData[1]['surveyls_title'], $secondSurvey->getTitle());
|
||||
}
|
||||
|
||||
public function testProcessWithNotIterableData()
|
||||
{
|
||||
$rawData = [
|
||||
'lorem' => 'ipsum',
|
||||
'dolor' => 'sit',
|
||||
];
|
||||
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::GET_PARTICIPANT_PROPERTIES, $rawData);
|
||||
|
||||
static::assertNotEmpty($processed);
|
||||
static::assertFalse(is_array($processed));
|
||||
static::assertInstanceOf(BaseItem::class, $processed);
|
||||
}
|
||||
|
||||
public function testGetItemInstanceVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(ResultProcessor::class, 'getItemInstance', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunWithUnknownResultClass()
|
||||
{
|
||||
$this->expectException(UnknownInstanceOfResultItem::class);
|
||||
|
||||
$rawData = [
|
||||
'lorem' => 'ipsum',
|
||||
'dolor' => 'sit',
|
||||
];
|
||||
|
||||
$processor = new ResultProcessor();
|
||||
$processor->process(MethodType::LIST_USERS, $rawData);
|
||||
}
|
||||
}
|
||||
223
tests/Result/ResultTest.php
Normal file
223
tests/Result/ResultTest.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Result;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the result with data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ResultTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Empty data returned by the LimeSurvey's API
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $emptyData;
|
||||
|
||||
/**
|
||||
* Iterable, not empty data returned by the LimeSurvey's API
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $iterableData;
|
||||
|
||||
/**
|
||||
* Not iterable, not empty data returned by the LimeSurvey's API
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $notIterableData;
|
||||
|
||||
/**
|
||||
* Status provided instead of real data.
|
||||
* An array with one key: "status".
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $statusInsteadData;
|
||||
|
||||
/**
|
||||
* Result with empty data returned by the LimeSurvey's API.
|
||||
* Mock of the tested class.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $emptyDataResult;
|
||||
|
||||
/**
|
||||
* Result with iterable, not empty data.
|
||||
* Mock of the tested class.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $iterableDataResult;
|
||||
|
||||
/**
|
||||
* Result with not iterable, not empty data.
|
||||
* Mock of the tested class.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $notIterableDataResult;
|
||||
|
||||
/**
|
||||
* Result with status provided instead of real data
|
||||
*
|
||||
* @var Result
|
||||
*/
|
||||
private $statusInsteadDataResult;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Result::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
static::assertTrue($this->emptyDataResult->isEmpty());
|
||||
static::assertFalse($this->iterableDataResult->isEmpty());
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedData()
|
||||
{
|
||||
$emptyData = $this->emptyDataResult->getData();
|
||||
$iterableData = $this->iterableDataResult->getData();
|
||||
$notIterableData = $this->notIterableDataResult->getData();
|
||||
|
||||
static::assertEmpty($emptyData);
|
||||
static::assertNotEmpty($iterableData);
|
||||
static::assertNotEmpty($notIterableData);
|
||||
|
||||
static::assertCount(count($this->emptyData), $emptyData);
|
||||
static::assertCount(count($this->iterableData), $iterableData);
|
||||
static::assertInstanceOf(BaseItem::class, $notIterableData);
|
||||
}
|
||||
|
||||
public function testGetDataUsingRawData()
|
||||
{
|
||||
$emptyData = $this->emptyDataResult->getData(true);
|
||||
$iterableData = $this->iterableDataResult->getData(true);
|
||||
|
||||
static::assertEmpty($emptyData);
|
||||
static::assertNotEmpty($iterableData);
|
||||
|
||||
static::assertCount(count($this->emptyData), $emptyData);
|
||||
static::assertCount(count($this->iterableData), $iterableData);
|
||||
|
||||
static::assertEquals($this->emptyData, $emptyData);
|
||||
static::assertEquals($this->iterableData, $iterableData);
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
|
||||
{
|
||||
$this->expectException(CannotProcessDataException::class);
|
||||
$this->statusInsteadDataResult->getData();
|
||||
}
|
||||
|
||||
public function testGetProcessedDataVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(Result::class, 'getProcessedData', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetResultProcessorVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(Result::class, 'getResultProcessor', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
public function testGetStatusWhenIsNotProvided()
|
||||
{
|
||||
$result = new Result(MethodType::ADD_PARTICIPANTS, []);
|
||||
|
||||
static::assertEquals(null, $result->getStatus());
|
||||
static::assertEquals([], $result->getData(true));
|
||||
}
|
||||
|
||||
public function testGetStatusWhenIsProvided()
|
||||
{
|
||||
static::assertEquals($this->statusInsteadData['status'], $this->statusInsteadDataResult->getStatus());
|
||||
static::assertEquals([], $this->statusInsteadDataResult->getData(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc{
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->emptyData = [];
|
||||
|
||||
$this->notIterableData = [
|
||||
'result' => base64_encode('lorem-ipsum'),
|
||||
];
|
||||
|
||||
$this->iterableData = [
|
||||
[
|
||||
'sid' => '123',
|
||||
'surveyls_title' => 'Test',
|
||||
'startdate' => null,
|
||||
'expires' => null,
|
||||
'active' => 'N',
|
||||
],
|
||||
[
|
||||
'sid' => '456',
|
||||
'surveyls_title' => 'Another Test',
|
||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'expires' => null,
|
||||
'active' => 'Y',
|
||||
],
|
||||
];
|
||||
|
||||
$this->statusInsteadData = [
|
||||
'status' => 'Invalid data',
|
||||
];
|
||||
|
||||
$emptyData = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->emptyData,
|
||||
];
|
||||
|
||||
$iterableData = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->iterableData,
|
||||
];
|
||||
|
||||
$notIterableData = [
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
$this->notIterableData,
|
||||
];
|
||||
|
||||
$this->emptyDataResult = $this->getResultMock($emptyData);
|
||||
$this->iterableDataResult = $this->getResultMock($iterableData);
|
||||
$this->notIterableDataResult = $this->getResultMock($notIterableData);
|
||||
$this->statusInsteadDataResult = new Result(MethodType::LIST_PARTICIPANTS, $this->statusInsteadData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mock of the tested class
|
||||
*
|
||||
* @param array $constructorArguments Arguments of constructor for prepared mock
|
||||
* @return Result
|
||||
*/
|
||||
private function getResultMock($constructorArguments)
|
||||
{
|
||||
return $this->getMockForAbstractClass(Result::class, $constructorArguments);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user