mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3b0e66fb3 | ||
|
|
0fbfc9780d | ||
|
|
92315bd853 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
### Composer
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/composer.lock
|
||||
/composer.phar
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "Client of LimeSurvey API",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Meritoo",
|
||||
|
||||
3581
composer.lock
generated
3581
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -59,15 +59,26 @@ class ConnectionConfiguration
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user 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 string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user 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 $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
|
||||
->setBaseUrl($baseUrl)
|
||||
@@ -201,6 +212,30 @@ class ConnectionConfiguration
|
||||
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)
|
||||
|
||||
@@ -85,7 +85,20 @@ class JsonRpcClientManager
|
||||
* The "debug" mode is turned on?
|
||||
*/
|
||||
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,16 @@ use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Simple instance of the configuration
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $simpleConfiguration;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 4, 3);
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,69 +56,67 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
|
||||
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());
|
||||
static::assertEquals('http://test.com', $this->simpleConfiguration->getBaseUrl());
|
||||
static::assertEquals('test1', $this->simpleConfiguration->getUsername());
|
||||
static::assertEquals('test2', $this->simpleConfiguration->getPassword());
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testSetBaseUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->simpleConfiguration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $this->simpleConfiguration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
$this->simpleConfiguration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $this->simpleConfiguration->getBaseUrl());
|
||||
}
|
||||
|
||||
public function testSetRemoteControlUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
||||
|
||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
||||
$this->simpleConfiguration->setRemoteControlUrl('/lorem/ipsum');
|
||||
static::assertEquals('/lorem/ipsum', $this->simpleConfiguration->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testSetUsername()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setUsername('lorem');
|
||||
|
||||
static::assertEquals('lorem', $configuration->getUsername());
|
||||
$this->simpleConfiguration->setUsername('lorem');
|
||||
static::assertEquals('lorem', $this->simpleConfiguration->getUsername());
|
||||
}
|
||||
|
||||
public function testSetPassword()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setPassword('ipsum');
|
||||
|
||||
static::assertEquals('ipsum', $configuration->getPassword());
|
||||
$this->simpleConfiguration->setPassword('ipsum');
|
||||
static::assertEquals('ipsum', $this->simpleConfiguration->getPassword());
|
||||
}
|
||||
|
||||
public function testSetDebugMode()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->simpleConfiguration->setDebugMode();
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode();
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
$this->simpleConfiguration->setDebugMode(false);
|
||||
static::assertFalse($this->simpleConfiguration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(false);
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
$this->simpleConfiguration->setDebugMode(true);
|
||||
static::assertTrue($this->simpleConfiguration->isDebugModeOn());
|
||||
}
|
||||
|
||||
$configuration->setDebugMode(true);
|
||||
static::assertTrue($configuration->isDebugModeOn());
|
||||
public function testSetVerifySslCertificate()
|
||||
{
|
||||
$this->simpleConfiguration->setVerifySslCertificate();
|
||||
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
|
||||
$this->simpleConfiguration->setVerifySslCertificate(false);
|
||||
static::assertFalse($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
|
||||
$this->simpleConfiguration->setVerifySslCertificate(true);
|
||||
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
|
||||
}
|
||||
|
||||
public function testGetFullUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('lorem/ipsum');
|
||||
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $configuration->getFullUrl());
|
||||
$this->simpleConfiguration->setRemoteControlUrl('lorem/ipsum');
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $this->simpleConfiguration->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,4 +154,13 @@ class ConnectionConfigurationTest extends BaseTestCase
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->simpleConfiguration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user