mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-13 10:31:51 +01:00
First, initial commit
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<?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\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* 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 PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* 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 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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?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\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* 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 PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* 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 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]);
|
||||
}
|
||||
}
|
||||
@@ -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\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 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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
<?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\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* 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 PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* 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 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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?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\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* 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 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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$reflection = new ReflectionClass(ResultProcessor::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
static::assertNull($constructor);
|
||||
}
|
||||
|
||||
public function testProcessWithEmptyRawData()
|
||||
{
|
||||
$rawData = [];
|
||||
$processor = new ResultProcessor();
|
||||
|
||||
static::assertNull($processor->process(MethodType::LIST_SURVEYS, $rawData));
|
||||
}
|
||||
|
||||
public function testProcessWithIterableData()
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, SurveyTest::getSurveysRawData());
|
||||
|
||||
static::assertNotEmpty($processed);
|
||||
static::assertTrue(is_array($processed));
|
||||
static::assertCount(2, $processed);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(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);
|
||||
}
|
||||
}
|
||||
182
tests/Meritoo/LimeSurvey/Test/ApiClient/Result/ResultTest.php
Normal file
182
tests/Meritoo/LimeSurvey/Test/ApiClient/Result/ResultTest.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?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\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;
|
||||
|
||||
/**
|
||||
* Mock of the tested class.
|
||||
* With empty data returned by the LimeSurvey's API.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $emptyDataMock;
|
||||
|
||||
/**
|
||||
* Mock of the tested class.
|
||||
* With iterable, not empty data.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $iterableDataMock;
|
||||
|
||||
/**
|
||||
* Mock of the tested class.
|
||||
* With not iterable, not empty data.
|
||||
*
|
||||
* @var PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $notIterableDataMock;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(Result::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
static::assertTrue($this->emptyDataMock->isEmpty());
|
||||
static::assertFalse($this->iterableDataMock->isEmpty());
|
||||
}
|
||||
|
||||
public function testGetDataUsingProcessedData()
|
||||
{
|
||||
$emptyData = $this->emptyDataMock->getData();
|
||||
$iterableData = $this->iterableDataMock->getData();
|
||||
$notIterableData = $this->notIterableDataMock->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->emptyDataMock->getData(true);
|
||||
$iterableData = $this->iterableDataMock->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 testGetProcessedDataVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Result::class, 'getProcessedData', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetResultProcessorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Result::class, 'getResultProcessor', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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',
|
||||
],
|
||||
];
|
||||
|
||||
$emptyDataArguments = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->emptyData,
|
||||
];
|
||||
|
||||
$iterableDataArguments = [
|
||||
MethodType::LIST_SURVEYS,
|
||||
$this->iterableData,
|
||||
];
|
||||
|
||||
$notIterableDataArguments = [
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
$this->notIterableData,
|
||||
];
|
||||
|
||||
$this->emptyDataMock = $this->getResultMock($emptyDataArguments);
|
||||
$this->iterableDataMock = $this->getResultMock($iterableDataArguments);
|
||||
$this->notIterableDataMock = $this->getResultMock($notIterableDataArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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