Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
use PHPUnit\Framework\TestCase;
class ConfigurationControllerTest extends TestCase
{
public function testUpdate()
{
$configurationController = new \Configuration\controllers\ConfigurationController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'smtp',
'host' => 'smtp.outlook.com',
'port' => '45',
'auth' => true,
'user' => 'user@test.com',
'password' => '12345',
'secure' => 'ssl',
'from' => 'info@maarch.org',
'charset' => 'utf-8',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $configurationController->getByService($request, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->configuration);
$this->assertInternalType('int', $responseBody->configuration->id);
$this->assertSame('admin_email_server', $responseBody->configuration->service);
$this->assertNotNull($responseBody->configuration->value);
$jsonTest = json_encode(
[
'type' => 'smtp',
'host' => 'smtp.outlook.com',
'port' => '45',
'auth' => true,
'user' => 'user@test.com',
'secure' => 'ssl',
'from' => 'info@maarch.org',
'charset' => 'utf-8',
]
);
$this->assertJsonStringEqualsJsonString($jsonTest, json_encode($responseBody->configuration->value));
// UPDATE auth false
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'smtp',
'host' => 'smtp.outlook.com',
'port' => '231',
'auth' => false,
'user' => '',
'password' => '',
'secure' => 'tls',
'from' => 'info@maarch.org',
'charset' => 'utf-8',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $configurationController->getByService($request, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->configuration);
$this->assertInternalType('int', $responseBody->configuration->id);
$this->assertSame('admin_email_server', $responseBody->configuration->service);
$this->assertNotNull($responseBody->configuration->value);
$jsonTest = json_encode(
[
'type' => 'smtp',
'host' => 'smtp.outlook.com',
'port' => '231',
'auth' => false,
'user' => '',
'secure' => 'tls',
'from' => 'info@maarch.org',
'charset' => 'utf-8',
]
);
$this->assertJsonStringEqualsJsonString($jsonTest, json_encode($responseBody->configuration->value));
// UPDATE SENDMAIL
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'sendmail'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $configurationController->getByService($request, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->configuration);
$this->assertInternalType('int', $responseBody->configuration->id);
$this->assertSame('admin_email_server', $responseBody->configuration->service);
$this->assertNotNull($responseBody->configuration->value);
$jsonTest = json_encode(
[
'type' => 'sendmail',
'passwordAlreadyExists' => false
]
);
$this->assertJsonStringEqualsJsonString($jsonTest, json_encode($responseBody->configuration->value));
// UPDATE ERROR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'sendmail'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server_fail']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Service configuration does not exist', $responseBody->errors);
// UPDATE ERROR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('Configuration type is missing', $responseBody->errors);
// UPDATE ERROR
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'smtp',
'port' => '231',
'auth' => 'aze',
'user' => '',
'password' => '',
'secure' => 'tls',
'from' => 'info@maarch.org',
'charset' => 'utf-8',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('smtp configuration data is missing or not well formatted', $responseBody->errors);
}
public function testReset()
{
$configurationController = new \Configuration\controllers\ConfigurationController();
// UPDATE
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'type' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => '465',
'auth' => true,
'user' => 'name@maarch.org',
'password' => '12345',
'secure' => 'ssl',
'from' => 'notifications@maarch.org',
'charset' => 'utf-8',
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $configurationController->update($fullRequest, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$response = $configurationController->getByService($request, new \Slim\Http\Response(), ['service' => 'admin_email_server']);
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->configuration);
$this->assertInternalType('int', $responseBody->configuration->id);
$this->assertSame('admin_email_server', $responseBody->configuration->service);
$this->assertNotNull($responseBody->configuration->value);
$jsonTest = json_encode(
[
'type' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => '465',
'auth' => true,
'user' => 'name@maarch.org',
'secure' => 'ssl',
'from' => 'notifications@maarch.org',
'charset' => 'utf-8',
]
);
$this->assertJsonStringEqualsJsonString($jsonTest, json_encode($responseBody->configuration->value));
}
}