mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
First, initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?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\Base\Result;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Test case of the base class for one item of result/data fetched while talking to the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class BaseItemTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$reflection = new ReflectionClass(BaseItem::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
|
||||
static::assertNull($constructor);
|
||||
}
|
||||
|
||||
public function testSetValues()
|
||||
{
|
||||
$mock = $this->getBaseItemMock();
|
||||
|
||||
static::assertInstanceOf(BaseItem::class, $mock->setValues([]));
|
||||
static::assertInstanceOf(BaseItem::class, $mock->setValues(['lorem']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mock of the tested class
|
||||
*
|
||||
* @return BaseItem
|
||||
*/
|
||||
private function getBaseItemMock()
|
||||
{
|
||||
$mock = $this->getMockForAbstractClass(BaseItem::class);
|
||||
|
||||
$mock
|
||||
->expects(static::any())
|
||||
->method('setValue')
|
||||
->willReturn(null);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
}
|
||||
140
tests/Meritoo/LimeSurvey/Test/ApiClient/Client/ClientTest.php
Normal file
140
tests/Meritoo/LimeSurvey/Test/ApiClient/Client/ClientTest.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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\Client;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the client of the LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ClientTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
/**
|
||||
* @param string $incorrectMethod Incorrect name of method to call
|
||||
* @dataProvider provideIncorrectMethod
|
||||
*/
|
||||
public function testRunWithIncorrectMethod($incorrectMethod)
|
||||
{
|
||||
$this->expectException(UnknownMethodException::class);
|
||||
|
||||
$client = new Client($this->configuration);
|
||||
$client->run($incorrectMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Name of method to call
|
||||
* @param array $arguments Arguments of the method to call
|
||||
* @param bool $debugMode If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
*
|
||||
* @dataProvider provideMethod
|
||||
*/
|
||||
public function testRun($method, $arguments, $debugMode)
|
||||
{
|
||||
$sessionManager = $this->createMock(SessionManager::class);
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
|
||||
$this->configuration->setDebugMode($debugMode);
|
||||
$client = new Client($this->configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertInstanceOf(Result::class, $client->run($method, $arguments));
|
||||
}
|
||||
|
||||
public function testGetRpcClientManagerVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
public function testGetSessionManagerVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect name of method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectMethod()
|
||||
{
|
||||
yield[
|
||||
'lorem',
|
||||
];
|
||||
|
||||
yield[
|
||||
'ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides correct name of method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethod()
|
||||
{
|
||||
yield[
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
[],
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
[],
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_PARTICIPANTS,
|
||||
[],
|
||||
false,
|
||||
];
|
||||
|
||||
/*
|
||||
* todo: Use/Verify other types of methods
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?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\Configuration;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidUrlException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
|
||||
/**
|
||||
* Test case of the configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param mixed $emptyBaseUrl Empty base url
|
||||
* @dataProvider provideEmptyBaseUrl
|
||||
*/
|
||||
public function testConstructorWithEmptyBaseUrl($emptyBaseUrl)
|
||||
{
|
||||
$this->expectException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($emptyBaseUrl, '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $invalidBaseUrl Invalid base url
|
||||
* @dataProvider provideInvalidBaseUrl
|
||||
*/
|
||||
public function testConstructorWithInvalidBaseUrl($invalidBaseUrl)
|
||||
{
|
||||
$this->expectException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($invalidBaseUrl, '', '');
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
static::assertEquals('http://test.com', $configuration->getBaseUrl());
|
||||
static::assertEquals('test1', $configuration->getUsername());
|
||||
static::assertEquals('test2', $configuration->getPassword());
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testSetBaseUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
}
|
||||
|
||||
public function testSetRemoteControlUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
||||
|
||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testSetUsername()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setUsername('lorem');
|
||||
|
||||
static::assertEquals('lorem', $configuration->getUsername());
|
||||
}
|
||||
|
||||
public function testSetPassword()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setPassword('ipsum');
|
||||
|
||||
static::assertEquals('ipsum', $configuration->getPassword());
|
||||
}
|
||||
|
||||
public function testSetDebugMode()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
$configuration->setDebugMode();
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(false);
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(true);
|
||||
static::assertTrue($configuration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testGetFullUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('lorem/ipsum');
|
||||
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $configuration->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides empty base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideEmptyBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideInvalidBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'lorem',
|
||||
];
|
||||
|
||||
yield[
|
||||
'ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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\Manager;
|
||||
|
||||
use JsonRPC\Client as RpcClient;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
|
||||
/**
|
||||
* Test case of the manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class JsonRpcClientManagerTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(JsonRpcClientManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunMethod()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
|
||||
$manager = $this
|
||||
->getMockBuilder(JsonRpcClientManager::class)
|
||||
->setConstructorArgs([
|
||||
$this->configuration,
|
||||
])
|
||||
->setMethods([
|
||||
'getRpcClient',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$rpcClient
|
||||
->expects(static::any())
|
||||
->method('execute')
|
||||
->willReturn([]);
|
||||
|
||||
$manager
|
||||
->expects(static::any())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
/* @var JsonRpcClientManager $manager */
|
||||
static::assertEquals([], $manager->runMethod(MethodType::LIST_SURVEYS));
|
||||
}
|
||||
|
||||
public function testRunMethodWithMockedRpcClient()
|
||||
{
|
||||
$rpcClient = $this->createMock(RpcClient::class);
|
||||
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
|
||||
|
||||
$rpcClient
|
||||
->expects(static::any())
|
||||
->method('execute')
|
||||
->willReturn(SurveyTest::getSurveysRawData());
|
||||
|
||||
$manager
|
||||
->expects(static::any())
|
||||
->method('getRpcClient')
|
||||
->willReturn($rpcClient);
|
||||
|
||||
/* @var JsonRpcClientManager $manager */
|
||||
static::assertEquals(SurveyTest::getSurveysRawData(), $manager->runMethod(MethodType::LIST_SURVEYS));
|
||||
}
|
||||
|
||||
public function testGetRpcClientVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyMethodVisibilityAndArguments(JsonRpcClientManager::class, 'getRpcClient', OopVisibilityType::IS_PROTECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->configuration = new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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\Manager;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CreateSessionKeyFailedException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
|
||||
/**
|
||||
* Test case of the manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SessionManagerTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$this->verifyConstructorVisibilityAndArguments(SessionManager::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
public function testGetSessionKeyWhenFailedWithoutReason()
|
||||
{
|
||||
$this->expectException(CreateSessionKeyFailedException::class);
|
||||
$this->expectExceptionMessage('Create of the session key has failed');
|
||||
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
|
||||
(new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum');
|
||||
}
|
||||
|
||||
public function testGetSessionKeyWhenFailedWithReason()
|
||||
{
|
||||
$reason = 'Invalid credentials';
|
||||
|
||||
$this->expectException(CreateSessionKeyFailedException::class);
|
||||
$this->expectExceptionMessage(sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason));
|
||||
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([
|
||||
'status' => $reason,
|
||||
]);
|
||||
|
||||
(new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum');
|
||||
}
|
||||
|
||||
public function testGetSessionKey()
|
||||
{
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn('12345');
|
||||
|
||||
$sessionManager = new SessionManager($clientManager);
|
||||
static::assertEquals('12345', $sessionManager->getSessionKey('lorem', 'ipsum'));
|
||||
}
|
||||
|
||||
public function testReleaseSessionKey()
|
||||
{
|
||||
$clientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$clientManager
|
||||
->expects(static::any())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
|
||||
$sessionManager = new SessionManager($clientManager);
|
||||
static::assertInstanceOf(SessionManager::class, $sessionManager->releaseSessionKey());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
204
tests/Meritoo/LimeSurvey/Test/ApiClient/Type/MethodTypeTest.php
Normal file
204
tests/Meritoo/LimeSurvey/Test/ApiClient/Type/MethodTypeTest.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?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\Type;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the type of method used while talking with LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MethodTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
/**
|
||||
* @param string $incorrectMethod Type of method to verify
|
||||
* @dataProvider provideIncorrectMethod
|
||||
*/
|
||||
public function testGetValidatedMethodWithIncorrectMethod($incorrectMethod)
|
||||
{
|
||||
$this->expectException(UnknownMethodException::class);
|
||||
MethodType::getValidatedMethod($incorrectMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Type of method to verify
|
||||
* @dataProvider provideMethod
|
||||
*/
|
||||
public function testGetValidatedMethod($method)
|
||||
{
|
||||
static::assertEquals($method, MethodType::getValidatedMethod($method));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $incorrectMethod Type of incorrectMethod to verify
|
||||
* @dataProvider provideIncorrectMethod
|
||||
*/
|
||||
public function testIsResultIterableWithIncorrectMethod($incorrectMethod)
|
||||
{
|
||||
$this->expectException(UnknownMethodException::class);
|
||||
MethodType::isResultIterable($incorrectMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Type of method to verify
|
||||
* @param bool $expected Information if result provided by the API is iterable
|
||||
*
|
||||
* @dataProvider provideIterableType
|
||||
*/
|
||||
public function testIsResultIterable($method, $expected)
|
||||
{
|
||||
static::assertEquals($expected, MethodType::isResultIterable($method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides correct type of method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethod()
|
||||
{
|
||||
yield[
|
||||
MethodType::ADD_RESPONSE,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::EXPORT_STATISTICS,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect type of method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectMethod()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of method who result provided by the API is iterable and information if it's iterable
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIterableType()
|
||||
{
|
||||
yield[
|
||||
MethodType::ADD_RESPONSE,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_PARTICIPANTS,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_QUESTIONS,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_USERS,
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllExpectedTypes()
|
||||
{
|
||||
return [
|
||||
'ADD_RESPONSE' => MethodType::ADD_RESPONSE,
|
||||
'EXPORT_STATISTICS' => MethodType::EXPORT_STATISTICS,
|
||||
'GET_PARTICIPANT_PROPERTIES' => MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
'GET_QUESTION_PROPERTIES' => MethodType::GET_QUESTION_PROPERTIES,
|
||||
'LIST_PARTICIPANTS' => MethodType::LIST_PARTICIPANTS,
|
||||
'LIST_QUESTIONS' => MethodType::LIST_QUESTIONS,
|
||||
'LIST_SURVEYS' => MethodType::LIST_SURVEYS,
|
||||
'LIST_USERS' => MethodType::LIST_USERS,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestedTypeInstance()
|
||||
{
|
||||
return new MethodType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::ADD_RESPONSE,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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\Type;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\SystemMethodType;
|
||||
|
||||
/**
|
||||
* Test case of the type of system-related method used while talking with LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SystemMethodTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllExpectedTypes()
|
||||
{
|
||||
return [
|
||||
'GET_SESSION_KEY' => SystemMethodType::GET_SESSION_KEY,
|
||||
'RELEASE_SESSION_KEY' => SystemMethodType::RELEASE_SESSION_KEY,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestedTypeInstance()
|
||||
{
|
||||
return new SystemMethodType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::GET_SESSION_KEY,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
SystemMethodType::RELEASE_SESSION_KEY,
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user