These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Tests; |
||
3 | |||
4 | use Redaxscript\Auth; |
||
5 | use Redaxscript\Db; |
||
6 | use Redaxscript\Server; |
||
7 | |||
8 | /** |
||
9 | * AuthTest |
||
10 | * |
||
11 | * @since 3.0.0 |
||
12 | * |
||
13 | * @package Redaxscript |
||
14 | * @category Tests |
||
15 | * @author Henry Ruhs |
||
16 | * |
||
17 | * @covers Redaxscript\Auth |
||
18 | */ |
||
19 | |||
20 | class AuthTest extends TestCaseAbstract |
||
21 | { |
||
22 | /** |
||
23 | * setUp |
||
24 | * |
||
25 | * @since 3.1.0 |
||
26 | */ |
||
27 | |||
28 | public function setUp() : void |
||
29 | { |
||
30 | parent::setUp(); |
||
31 | $optionArray = |
||
32 | [ |
||
33 | 'adminName' => 'Test', |
||
34 | 'adminUser' => 'test', |
||
35 | 'adminPassword' => 'test', |
||
36 | 'adminEmail' => '[email protected]' |
||
37 | ]; |
||
38 | $installer = $this->installerFactory(); |
||
0 ignored issues
–
show
|
|||
39 | $installer->init(); |
||
40 | $installer->rawCreate(); |
||
41 | $installer->insertUsers($optionArray); |
||
42 | Db::forTablePrefix('users') |
||
43 | ->whereIdIs(1) |
||
44 | ->findOne() |
||
45 | ->set('language', 'en') |
||
46 | ->save(); |
||
47 | Db::forTablePrefix('groups') |
||
48 | ->create() |
||
49 | ->set( |
||
50 | [ |
||
51 | 'name' => 'Group One', |
||
52 | 'alias' => 'group-one', |
||
53 | 'description' => 'Unlimited access', |
||
54 | 'categories' => '[1,2,3]', |
||
55 | 'articles' => '[1,2,3]', |
||
56 | 'extras' => '[1,2,3]', |
||
57 | 'comments' => '[1,2,3]', |
||
58 | 'groups' => '[1,2,3]', |
||
59 | 'users' => '[1,2,3]', |
||
60 | 'modules' => '[1,2,3]', |
||
61 | 'settings' => 1, |
||
62 | 'filter' => 0 |
||
63 | ]) |
||
64 | ->save(); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * tearDown |
||
69 | * |
||
70 | * @since 3.1.0 |
||
71 | */ |
||
72 | |||
73 | public function tearDown() : void |
||
74 | { |
||
75 | $this->dropDatabase(); |
||
0 ignored issues
–
show
The method
dropDatabase() does not seem to exist on object<Redaxscript\Tests\AuthTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
76 | } |
||
77 | |||
78 | /** |
||
79 | * testInit |
||
80 | * |
||
81 | * @since 3.0.0 |
||
82 | */ |
||
83 | |||
84 | public function testInit() : void |
||
85 | { |
||
86 | /* setup */ |
||
87 | |||
88 | $root = new Server\Root($this->_request); |
||
89 | $this->_request->setSession($root->getOutput() . '/auth', |
||
90 | [ |
||
91 | 'user' => |
||
92 | [ |
||
93 | 'test' => 'test' |
||
94 | ], |
||
95 | 'permission' => |
||
96 | [ |
||
97 | 'test' => 'test' |
||
98 | ] |
||
99 | ]); |
||
100 | $auth = new Auth($this->_request); |
||
101 | $auth->init(); |
||
102 | |||
103 | /* compare */ |
||
104 | |||
105 | $this->assertEquals('test', $auth->getUser('test')); |
||
106 | $this->assertEquals('test', $auth->getPermission('test')); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * testLogin |
||
111 | * |
||
112 | * @since 3.0.0 |
||
113 | */ |
||
114 | |||
115 | public function testLoginAndLogout() : void |
||
116 | { |
||
117 | /* setup */ |
||
118 | |||
119 | $auth = new Auth($this->_request); |
||
120 | $auth->logout(); |
||
121 | |||
122 | /* compare */ |
||
123 | |||
124 | $this->assertEquals(0, $auth->login()); |
||
125 | $this->assertEquals(1, $auth->login(1)); |
||
126 | $this->assertEquals(1, $auth->logout()); |
||
127 | $this->assertEquals(0, $auth->logout()); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * testGetUserInvalid |
||
132 | * |
||
133 | * @since 3.0.0 |
||
134 | */ |
||
135 | |||
136 | public function testGetUserInvalid() : void |
||
137 | { |
||
138 | /* setup */ |
||
139 | |||
140 | $auth = new Auth($this->_request); |
||
141 | $auth->login(1); |
||
142 | |||
143 | /* actual */ |
||
144 | |||
145 | $actual = $auth->getUser('invalidKey'); |
||
146 | |||
147 | /* compare */ |
||
148 | |||
149 | $this->assertEquals(0, $actual); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * testGetPermission |
||
154 | * |
||
155 | * @since 3.0.0 |
||
156 | * |
||
157 | * @param string $method |
||
158 | * @param array $typeArray |
||
159 | * @param string $groups |
||
160 | * |
||
161 | * @dataProvider providerAutoloader |
||
162 | */ |
||
163 | |||
164 | public function testGetPermission(string $method = null, array $typeArray = [], string $groups = null) : void |
||
165 | { |
||
166 | /* setup */ |
||
167 | |||
168 | Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('groups', $groups)->save(); |
||
169 | $auth = new Auth($this->_request); |
||
170 | $auth->login(1); |
||
171 | |||
172 | /* process type */ |
||
173 | |||
174 | foreach ($typeArray as $key => $value) |
||
175 | { |
||
176 | $this->assertEquals($auth->$method($key), $value); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * testGetFilter |
||
182 | * |
||
183 | * @since 3.0.0 |
||
184 | * |
||
185 | * @param string $groups |
||
186 | * @param bool $expect |
||
187 | * |
||
188 | * @dataProvider providerAutoloader |
||
189 | */ |
||
190 | |||
191 | public function testGetFilter(string $groups = null, bool $expect = null) : void |
||
192 | { |
||
193 | /* setup */ |
||
194 | |||
195 | Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('groups', $groups)->save(); |
||
196 | $auth = new Auth($this->_request); |
||
197 | $auth->login(1); |
||
198 | |||
199 | /* actual */ |
||
200 | |||
201 | $actual = $auth->getFilter(); |
||
202 | |||
203 | /* compare */ |
||
204 | |||
205 | $this->assertEquals($expect, $actual); |
||
206 | } |
||
207 | } |
||
208 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.