Skip to content

Commit 5af91a4

Browse files
committed
fix cs
1 parent 2a12197 commit 5af91a4

File tree

2 files changed

+27
-73
lines changed

2 files changed

+27
-73
lines changed

src/Controller/Component/LoginComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -229,8 +230,7 @@ protected function saveRehashedPassword($checker, ServerRequest $request, Entity
229230
Log::warning("Error saving user id $user->id password after rehashing: getUsersTable method not found");
230231
return;
231232
}
232-
if (!$this->getController()->getUsersTable()->save($user))
233-
{
233+
if (!$this->getController()->getUsersTable()->save($user)) {
234234
Log::warning("Error saving user id $user->id password after rehashing: " . implode(', ', $user->getErrors()));
235235
}
236236
}
Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**
@@ -13,90 +14,43 @@
1314

1415
namespace CakeDC\Users\Test\TestCase\Controller\Component;
1516

17+
use Authentication\AuthenticationService;
18+
use Authentication\Authenticator\Result;
19+
use Authentication\Identity;
1620
use Cake\Controller\ComponentRegistry;
1721
use Cake\Controller\Controller;
1822
use Cake\Core\Configure;
1923
use Cake\TestSuite\TestCase;
24+
use CakeDC\Users\Controller\Component\LoginComponent;
2025
use CakeDC\Users\Controller\Component\SetupComponent;
2126

22-
/**
23-
* Class SetupComponentTest
24-
*
25-
* @package CakeDC\Users\Test\TestCase\Controller\Component
26-
*/
2727
class LoginComponentTest extends TestCase
2828
{
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-
*/
4629
public function setUp(): void
4730
{
4831
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([]);
7837
}
7938

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()
9140
{
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+
'email' => '[email protected]',
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);
10155
}
10256
}

0 commit comments

Comments
 (0)