|
1 | 1 | <?php |
| 2 | + |
2 | 3 | declare(strict_types=1); |
3 | 4 |
|
4 | 5 | /** |
|
13 | 14 |
|
14 | 15 | namespace CakeDC\Users\Test\TestCase\Controller\Component; |
15 | 16 |
|
| 17 | +use Authentication\AuthenticationService; |
| 18 | +use Authentication\Authenticator\Result; |
| 19 | +use Authentication\Identity; |
16 | 20 | use Cake\Controller\ComponentRegistry; |
17 | 21 | use Cake\Controller\Controller; |
18 | 22 | use Cake\Core\Configure; |
19 | 23 | use Cake\TestSuite\TestCase; |
| 24 | +use CakeDC\Users\Controller\Component\LoginComponent; |
20 | 25 | use CakeDC\Users\Controller\Component\SetupComponent; |
21 | 26 |
|
22 | | -/** |
23 | | - * Class SetupComponentTest |
24 | | - * |
25 | | - * @package CakeDC\Users\Test\TestCase\Controller\Component |
26 | | - */ |
27 | 27 | class LoginComponentTest extends TestCase |
28 | 28 | { |
29 | | - /** |
30 | | - * Test subject |
31 | | - * |
32 | | - * @var \CakeDC\Users\Controller\Component\SetupComponent |
33 | | - */ |
34 | | - public $Component; |
35 | | - |
36 | | - /** |
37 | | - * @var \Cake\Controller\Controller |
38 | | - */ |
39 | | - public $Controller; |
40 | | - |
41 | | - /** |
42 | | - * setUp method |
43 | | - * |
44 | | - * @return void |
45 | | - */ |
46 | 29 | public function setUp(): void |
47 | 30 | { |
48 | 31 | parent::setUp(); |
49 | | - $this->Controller = new Controller(new \Cake\Http\ServerRequest()); |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * tearDown method |
54 | | - * |
55 | | - * @return void |
56 | | - */ |
57 | | - public function tearDown(): void |
58 | | - { |
59 | | - unset($this->Controller, $this->Component); |
60 | | - |
61 | | - parent::tearDown(); |
62 | | - } |
63 | | - |
64 | | - /** |
65 | | - * Data provider for testInitialization |
66 | | - * |
67 | | - * @return array |
68 | | - */ |
69 | | - public static function dataProviderInitialization() |
70 | | - { |
71 | | - return [ |
72 | | - [true, true, true], |
73 | | - [false, true, true], |
74 | | - [true, false, true], |
75 | | - [true, true, false], |
76 | | - [false, false, false], |
77 | | - ]; |
| 32 | + $this->request = new \Cake\Http\ServerRequest(); |
| 33 | + $this->controller = new Controller($this->request); |
| 34 | + $registry = new ComponentRegistry($this->controller); |
| 35 | + $this->component = new LoginComponent($registry); |
| 36 | + $this->component->initialize([]); |
78 | 37 | } |
79 | 38 |
|
80 | | - /** |
81 | | - * Test initial setup |
82 | | - * |
83 | | - * @param bool $authentication Should use authentication component |
84 | | - * @param bool $authorization Should use authorization component |
85 | | - * @param bool $oneTimePass Should use OneTimePassword component |
86 | | - * @throws \Exception |
87 | | - * @dataProvider dataProviderInitialization |
88 | | - * @return void |
89 | | - */ |
90 | | - public function testInitialization($authentication, $authorization, $oneTimePass) |
| 39 | + public function testLoginRehash() |
91 | 40 | { |
92 | | - Configure::write('Auth.AuthenticationComponent.load', $authentication); |
93 | | - Configure::write('Auth.AuthorizationComponent.enable', $authorization); |
94 | | - Configure::write('OneTimePasswordAuthenticator.login', $oneTimePass); |
95 | | - $registry = new ComponentRegistry($this->Controller); |
96 | | - $this->Component = new SetupComponent($registry); |
97 | | - $this->Component->initialize([]); |
98 | | - $this->assertSame($authentication, $this->Controller->components()->has('Authentication')); |
99 | | - $this->assertSame($authorization, $this->Controller->components()->has('Authorization')); |
100 | | - $this->assertSame($oneTimePass, $this->Controller->components()->has('OneTimePasswordAuthenticator')); |
| 41 | + $authenticationService = $this->getMockBuilder(AuthenticationService::class)->getMock(); |
| 42 | + $result = $this->getMockBuilder(Result::class)->disableOriginalConstructor()->getMock(); |
| 43 | + $result->expects($this->once())->method('isValid')->willReturn(true); |
| 44 | + $authenticationService->expects($this->once())->method('getResult')->willReturn($result); |
| 45 | + $this->request = $this->request->withAttribute('authentication', $authenticationService); |
| 46 | + $identity = $this->getMockBuilder(Identity::class)->disableOriginalConstructor()->getMock(); |
| 47 | + $identity->expects($this->once())->method('getOriginalData')->willReturn([ |
| 48 | + |
| 49 | + 'password' => 'password', |
| 50 | + ]); |
| 51 | + $this->request = $this->request->withAttribute('authentication', $authenticationService); |
| 52 | + $this->request = $this->request->withAttribute('identity', $identity); |
| 53 | + $this->controller->setRequest($this->request); |
| 54 | + $this->component->handleLogin(false, false); |
101 | 55 | } |
102 | 56 | } |
0 commit comments