mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 18:11:50 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5de59f50b | ||
|
|
6e54d39972 | ||
|
|
b3b0e66fb3 | ||
|
|
0fbfc9780d | ||
|
|
92315bd853 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@
|
|||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
### Composer
|
### Composer
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
/composer.lock
|
||||||
/composer.phar
|
/composer.phar
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "Client of LimeSurvey API",
|
"description": "Client of LimeSurvey API",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.5",
|
"version": "0.0.7",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo",
|
"name": "Meritoo",
|
||||||
|
|||||||
3581
composer.lock
generated
3581
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -59,21 +59,33 @@ class ConnectionConfiguration
|
|||||||
*/
|
*/
|
||||||
private $debugMode = false;
|
private $debugMode = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If is set to true, the SSL certificate verification is turned on. Otherwise - turned off.
|
||||||
|
* It's useful while running application with custom, non-official SSL certificate, e.g. while development process.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $verifySslCertificate = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param string $baseUrl Base url. Protocol & domain.
|
* @param string $baseUrl Base url. Protocol & domain.
|
||||||
* @param string $username Name of user used to authenticate to LimeSurvey
|
* @param string $username Name of user used to authenticate to LimeSurvey
|
||||||
* @param string $password Password used to authenticate to LimeSurvey
|
* @param string $password Password used to authenticate to LimeSurvey
|
||||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise -
|
||||||
|
* turned off.
|
||||||
|
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned
|
||||||
|
* on. Otherwise - turned off.
|
||||||
*/
|
*/
|
||||||
public function __construct($baseUrl, $username, $password, $debugMode = false)
|
public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setBaseUrl($baseUrl)
|
->setBaseUrl($baseUrl)
|
||||||
->setUsername($username)
|
->setUsername($username)
|
||||||
->setPassword($password)
|
->setPassword($password)
|
||||||
->setDebugMode($debugMode);
|
->setDebugMode($debugMode)
|
||||||
|
->setVerifySslCertificate($verifySslCertificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,6 +213,30 @@ class ConnectionConfiguration
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if the SSL certificate verification is turned on
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isVerifySslCertificateOn()
|
||||||
|
{
|
||||||
|
return $this->verifySslCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets information if the SSL certificate verification is turned on
|
||||||
|
*
|
||||||
|
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned on.
|
||||||
|
* Otherwise - turned off.
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setVerifySslCertificate($verifySslCertificate = true)
|
||||||
|
{
|
||||||
|
$this->verifySslCertificate = $verifySslCertificate;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
* Additional / extra methods (neither getters, nor setters)
|
* Additional / extra methods (neither getters, nor setters)
|
||||||
|
|||||||
@@ -85,7 +85,20 @@ class JsonRpcClientManager
|
|||||||
* The "debug" mode is turned on?
|
* The "debug" mode is turned on?
|
||||||
*/
|
*/
|
||||||
if ($this->connectionConfiguration->isDebugModeOn()) {
|
if ($this->connectionConfiguration->isDebugModeOn()) {
|
||||||
$this->rpcClient->getHttpClient()->withDebug();
|
$this
|
||||||
|
->rpcClient
|
||||||
|
->getHttpClient()
|
||||||
|
->withDebug();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The SSL certificate verification is turned off?
|
||||||
|
*/
|
||||||
|
if (!$this->connectionConfiguration->isVerifySslCertificateOn()) {
|
||||||
|
$this
|
||||||
|
->rpcClient
|
||||||
|
->getHttpClient()
|
||||||
|
->withoutSslVerification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,23 @@ use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
|||||||
*/
|
*/
|
||||||
class ConnectionConfigurationTest extends BaseTestCase
|
class ConnectionConfigurationTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Configuration with default values of optional constructor's arguments
|
||||||
|
*
|
||||||
|
* @var ConnectionConfiguration
|
||||||
|
*/
|
||||||
|
private $configurationWithDefaults;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration without default values of optional constructor's arguments
|
||||||
|
*
|
||||||
|
* @var ConnectionConfiguration
|
||||||
|
*/
|
||||||
|
private $configurationAnother;
|
||||||
|
|
||||||
public function testConstructorVisibilityAndArguments()
|
public function testConstructorVisibilityAndArguments()
|
||||||
{
|
{
|
||||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 4, 3);
|
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,69 +63,92 @@ class ConnectionConfigurationTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
static::assertEquals('http://test.com', $this->configurationWithDefaults->getBaseUrl());
|
||||||
|
static::assertEquals('test1', $this->configurationWithDefaults->getUsername());
|
||||||
|
static::assertEquals('test2', $this->configurationWithDefaults->getPassword());
|
||||||
|
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||||
|
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||||
|
|
||||||
static::assertEquals('http://test.com', $configuration->getBaseUrl());
|
static::assertEquals('http://lets-test.com', $this->configurationAnother->getBaseUrl());
|
||||||
static::assertEquals('test1', $configuration->getUsername());
|
static::assertEquals('test11', $this->configurationAnother->getUsername());
|
||||||
static::assertEquals('test2', $configuration->getPassword());
|
static::assertEquals('test22', $this->configurationAnother->getPassword());
|
||||||
static::assertFalse($configuration->isDebugModeOn());
|
static::assertTrue($this->configurationAnother->isDebugModeOn());
|
||||||
|
static::assertFalse($this->configurationAnother->isVerifySslCertificateOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetBaseUrl()
|
public function testSetBaseUrl()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setBaseUrl('http://lorem.ipsum');
|
||||||
|
static::assertEquals('http://lorem.ipsum', $this->configurationWithDefaults->getBaseUrl());
|
||||||
|
|
||||||
$configuration->setBaseUrl('http://lorem.ipsum');
|
$this->configurationWithDefaults->setBaseUrl('http://lorem.ipsum/');
|
||||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
static::assertEquals('http://lorem.ipsum', $this->configurationWithDefaults->getBaseUrl());
|
||||||
|
|
||||||
$configuration->setBaseUrl('http://lorem.ipsum/');
|
|
||||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetRemoteControlUrl()
|
public function testSetRemoteControlUrl()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setRemoteControlUrl('/lorem/ipsum');
|
||||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
static::assertEquals('/lorem/ipsum', $this->configurationWithDefaults->getRemoteControlUrl());
|
||||||
|
|
||||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetUsername()
|
public function testSetUsername()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setUsername('lorem');
|
||||||
$configuration->setUsername('lorem');
|
static::assertEquals('lorem', $this->configurationWithDefaults->getUsername());
|
||||||
|
|
||||||
static::assertEquals('lorem', $configuration->getUsername());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPassword()
|
public function testSetPassword()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setPassword('ipsum');
|
||||||
$configuration->setPassword('ipsum');
|
static::assertEquals('ipsum', $this->configurationWithDefaults->getPassword());
|
||||||
|
|
||||||
static::assertEquals('ipsum', $configuration->getPassword());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDebugMode()
|
public function testSetDebugMode()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setDebugMode();
|
||||||
|
$this->configurationAnother->setDebugMode();
|
||||||
|
|
||||||
$configuration->setDebugMode();
|
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||||
static::assertFalse($configuration->isDebugModeOn());
|
static::assertFalse($this->configurationAnother->isDebugModeOn());
|
||||||
|
|
||||||
$configuration->setDebugMode(false);
|
$this->configurationWithDefaults->setDebugMode(false);
|
||||||
static::assertFalse($configuration->isDebugModeOn());
|
$this->configurationAnother->setDebugMode(false);
|
||||||
|
|
||||||
$configuration->setDebugMode(true);
|
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||||
static::assertTrue($configuration->isDebugModeOn());
|
static::assertFalse($this->configurationAnother->isDebugModeOn());
|
||||||
|
|
||||||
|
$this->configurationWithDefaults->setDebugMode(true);
|
||||||
|
$this->configurationAnother->setDebugMode(true);
|
||||||
|
|
||||||
|
static::assertTrue($this->configurationWithDefaults->isDebugModeOn());
|
||||||
|
static::assertTrue($this->configurationAnother->isDebugModeOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetVerifySslCertificate()
|
||||||
|
{
|
||||||
|
$this->configurationWithDefaults->setVerifySslCertificate();
|
||||||
|
$this->configurationAnother->setVerifySslCertificate();
|
||||||
|
|
||||||
|
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||||
|
static::assertTrue($this->configurationAnother->isVerifySslCertificateOn());
|
||||||
|
|
||||||
|
$this->configurationWithDefaults->setVerifySslCertificate(false);
|
||||||
|
$this->configurationAnother->setVerifySslCertificate(false);
|
||||||
|
|
||||||
|
static::assertFalse($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||||
|
static::assertFalse($this->configurationAnother->isVerifySslCertificateOn());
|
||||||
|
|
||||||
|
$this->configurationWithDefaults->setVerifySslCertificate(true);
|
||||||
|
$this->configurationAnother->setVerifySslCertificate(true);
|
||||||
|
|
||||||
|
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||||
|
static::assertTrue($this->configurationAnother->isVerifySslCertificateOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetFullUrl()
|
public function testGetFullUrl()
|
||||||
{
|
{
|
||||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
$this->configurationWithDefaults->setRemoteControlUrl('lorem/ipsum');
|
||||||
$configuration->setRemoteControlUrl('lorem/ipsum');
|
static::assertEquals('http://test.com/lorem/ipsum', $this->configurationWithDefaults->getFullUrl());
|
||||||
|
|
||||||
static::assertEquals('http://test.com/lorem/ipsum', $configuration->getFullUrl());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,4 +186,15 @@ class ConnectionConfigurationTest extends BaseTestCase
|
|||||||
'htp:/dolor.com',
|
'htp:/dolor.com',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->configurationWithDefaults = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||||
|
$this->configurationAnother = new ConnectionConfiguration('http://lets-test.com', 'test11', 'test22', true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user