|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Integration test class. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright YetiForce Sp. z o.o. |
|
6
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
7
|
|
|
* @author Michał Lorencik <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
use App\Api; |
|
10
|
|
|
use App\Config; |
|
11
|
|
|
use App\Language; |
|
12
|
|
|
use App\Server; |
|
13
|
|
|
use App\User; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @covers \Integration::<public> |
|
18
|
|
|
* |
|
19
|
|
|
* @internal |
|
20
|
|
|
*/ |
|
21
|
|
|
final class Integration extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
private const EMAIL = '[email protected]'; |
|
24
|
|
|
private const PASSWORD = 'demo'; |
|
25
|
|
|
|
|
26
|
|
|
private static $apiObject; |
|
27
|
|
|
private static $token; |
|
28
|
|
|
|
|
29
|
|
|
public static function setUpBeforeClass(): void |
|
30
|
|
|
{ |
|
31
|
|
|
static::$apiObject = new class() extends \App\Api { |
|
|
|
|
|
|
32
|
|
|
public static function clearSelf() |
|
33
|
|
|
{ |
|
34
|
|
|
static::$instance = null; |
|
35
|
|
|
} |
|
36
|
|
|
}; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function setUp(): void |
|
40
|
|
|
{ |
|
41
|
|
|
static::$apiObject::clearSelf(); |
|
|
|
|
|
|
42
|
|
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
|
43
|
|
|
User::getUser()->set('token', static::$token); |
|
|
|
|
|
|
44
|
|
|
User::getUser()->set('logged', true); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Test portal is integrated with crm. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testIntegration() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->expectException(\App\Exceptions\AppException::class); |
|
53
|
|
|
$response = (new Api())->call(''); |
|
|
|
|
|
|
54
|
|
|
$result = (isset($response['code']) && 401 != $response['code']); |
|
55
|
|
|
static::assertTrue($result); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testLangAfterLogin() |
|
59
|
|
|
{ |
|
60
|
|
|
$params = [ |
|
61
|
|
|
'version' => Config::$version, |
|
62
|
|
|
'language' => Language::getLanguage(), |
|
63
|
|
|
'ip' => Server::getRemoteIp(), |
|
64
|
|
|
'fromUrl' => Config::$portalUrl |
|
65
|
|
|
]; |
|
66
|
|
|
$response = Api::getInstance()->call('Users/Login', ['userName' => static::EMAIL, 'password' => static::PASSWORD, 'params' => $params], 'post'); |
|
67
|
|
|
static::assertNotFalse($response); |
|
68
|
|
|
static::assertTrue($response['logged']); |
|
69
|
|
|
static::assertSame(Language::getLanguage(), $response['language']); |
|
70
|
|
|
static::$token = $response['token']; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testModulesLang() |
|
74
|
|
|
{ |
|
75
|
|
|
$response = (new User())->login(static::EMAIL, static::PASSWORD); |
|
76
|
|
|
static::assertTrue($response); |
|
77
|
|
|
$modulesList = Api::getInstance()->call('Modules'); |
|
78
|
|
|
static::assertIsArray($modulesList); |
|
79
|
|
|
static::assertSame('Contacts', $modulesList['Contacts']); |
|
80
|
|
|
static::assertSame('Accounts', $modulesList['Accounts']); |
|
81
|
|
|
static::assertSame('Leads', $modulesList['Leads']); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Test login with default data. |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testLogin() |
|
88
|
|
|
{ |
|
89
|
|
|
$response = (new User())->login(static::EMAIL, static::PASSWORD); |
|
90
|
|
|
static::assertTrue($response); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Test login with bad password. |
|
95
|
|
|
*/ |
|
96
|
|
|
public function testLoginBadData() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->expectException(\App\Exceptions\AppException::class); |
|
99
|
|
|
(new User())->login(static::EMAIL, 'wrongpassword'); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.