1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Frontend\Modules\Profiles\Tests\Engine; |
4
|
|
|
|
5
|
|
|
use Frontend\Modules\Profiles\Engine\Model; |
6
|
|
|
use Common\WebTestCase; |
7
|
|
|
use Frontend\Modules\Profiles\Engine\Profile; |
8
|
|
|
|
9
|
|
|
final class ProfileTest extends WebTestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp(): void |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
if (!defined('APPLICATION')) { |
16
|
|
|
define('APPLICATION', 'Frontend'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
if (!defined('LANGUAGE')) { |
20
|
|
|
define('LANGUAGE', 'en'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$client = self::createClient(); |
24
|
|
|
$this->loadFixtures($client); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCreatingProfile(): void |
28
|
|
|
{ |
29
|
|
|
$profile = new Profile(); |
30
|
|
|
|
31
|
|
|
$profile->setDisplayName('Fork CMS'); |
32
|
|
|
$this->assertEquals('Fork CMS', $profile->getDisplayName()); |
33
|
|
|
|
34
|
|
|
$profile->setEmail('[email protected]'); |
35
|
|
|
$this->assertEquals('[email protected]', $profile->getEmail()); |
36
|
|
|
|
37
|
|
|
$profile->setRegisteredOn(1234567890); |
38
|
|
|
$this->assertEquals(1234567890, $profile->getRegisteredOn()); |
39
|
|
|
|
40
|
|
|
$profile->setStatus('random_status'); |
41
|
|
|
$this->assertEquals('random_status', $profile->getStatus()); |
42
|
|
|
|
43
|
|
|
$profile->setUrl('fork-cms'); |
44
|
|
|
$this->assertEquals('fork-cms', $profile->getUrl()); |
45
|
|
|
|
46
|
|
|
// @TODO These settings setters don't work because the profile doesn't have an ID, this should be fixed |
47
|
|
|
/*$profile->setSettings( |
|
|
|
|
48
|
|
|
[ |
49
|
|
|
'my_first_setting' => 'My first value', |
50
|
|
|
'my_second_setting' => 'My second value', |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
$this->assertEquals( |
54
|
|
|
[ |
55
|
|
|
'my_first_setting' => 'My first value', |
56
|
|
|
'my_second_setting' => 'My second value', |
57
|
|
|
], |
58
|
|
|
$profile->getSettings() |
59
|
|
|
); |
60
|
|
|
$this->assertEquals('My first value', $profile->getSetting('my_first_setting')); |
61
|
|
|
|
62
|
|
|
$profile->setSetting('my_second_setting', 'My updated value'); |
63
|
|
|
$this->assertEquals('My updated value', $profile->getSetting('my_second_setting')); |
64
|
|
|
|
65
|
|
|
$profileArray = $profile->toArray(); |
66
|
|
|
$this->assertArrayHasKey('display_name', $profileArray); |
67
|
|
|
$this->assertEquals('Fork CMS', $profileArray['display_name']); |
68
|
|
|
$this->assertArrayHasKey('registered_on', $profileArray); |
69
|
|
|
$this->assertEquals(1234567890, $profileArray['registered_on']);*/ |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testLoadingOfProfile() |
73
|
|
|
{ |
74
|
|
|
$profileId = $this->addProfile(); |
75
|
|
|
|
76
|
|
|
$profile = new Profile($profileId); |
77
|
|
|
|
78
|
|
|
$this->assertEquals('Fork CMS', $profile->getDisplayName()); |
79
|
|
|
$this->assertEquals('[email protected]', $profile->getEmail()); |
80
|
|
|
$this->assertEquals(1520243112, $profile->getRegisteredOn()); |
81
|
|
|
$this->assertEquals('active', $profile->getStatus()); |
82
|
|
|
$this->assertEquals('fork-cms', $profile->getUrl()); |
83
|
|
|
|
84
|
|
|
$profile->setSettings( |
85
|
|
|
[ |
86
|
|
|
'my_first_setting' => 'My first value', |
87
|
|
|
'my_second_setting' => 'My second value', |
88
|
|
|
] |
89
|
|
|
); |
90
|
|
|
$this->assertEquals( |
91
|
|
|
[ |
92
|
|
|
'my_first_setting' => 'My first value', |
93
|
|
|
'my_second_setting' => 'My second value', |
94
|
|
|
], |
95
|
|
|
$profile->getSettings() |
96
|
|
|
); |
97
|
|
|
$this->assertEquals('My first value', $profile->getSetting('my_first_setting')); |
98
|
|
|
|
99
|
|
|
$profile->setSetting('my_second_setting', 'My updated value'); |
100
|
|
|
$this->assertEquals('My updated value', $profile->getSetting('my_second_setting')); |
101
|
|
|
|
102
|
|
|
$profileArray = $profile->toArray(); |
103
|
|
|
$this->assertArrayHasKey('display_name', $profileArray); |
104
|
|
|
$this->assertEquals('Fork CMS', $profileArray['display_name']); |
105
|
|
|
$this->assertArrayHasKey('registered_on', $profileArray); |
106
|
|
|
$this->assertEquals(1520243112, $profileArray['registered_on']); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function addProfile(): int |
110
|
|
|
{ |
111
|
|
|
return Model::insert($this->getProfileData()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getProfileData(): array |
115
|
|
|
{ |
116
|
|
|
return [ |
117
|
|
|
'email' => '[email protected]', |
118
|
|
|
'password' => '$2y$10$1Ev9QQNYZBjdU1ELKjKNqelcV.j2l3CgtVkHl0aMvbNpg1g73S5lC', |
119
|
|
|
'status' => 'active', |
120
|
|
|
'display_name' => 'Fork CMS', |
121
|
|
|
'url' => 'fork-cms', |
122
|
|
|
'registered_on' => '2018-03-05 09:45:12', |
123
|
|
|
'last_login' => '1970-01-01 00:00:00', |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.