Skip to content

Commit 7750874

Browse files
committed
ISSUE-345: login test
1 parent 8beb8cd commit 7750874

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"nette/caching": "^3.1.0",
4343
"nikic/php-parser": "^v4.10.4",
4444
"phpmd/phpmd": "^2.9.1",
45-
"symfony/process": "^6.4"
45+
"symfony/process": "^6.4",
46+
"symfony/panther": "*",
47+
"dbrekelmans/bdi": "*"
4648
},
4749
"autoload": {
4850
"psr-4": {

tests/Integration/Auth/LoginTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\WebFrontend\Tests\Integration\Auth;
6+
7+
use Symfony\Component\Panther\PantherTestCase;
8+
use Symfony\Component\Panther\Client;
9+
10+
class LoginTest extends PantherTestCase
11+
{
12+
protected static ?Client $client = null;
13+
14+
public function setUp(): void
15+
{
16+
parent::setUp();
17+
self::$client = static::createPantherClient([
18+
'browser' => static::CHROME,
19+
]);
20+
}
21+
22+
public function tearDown(): void
23+
{
24+
self::$client?->quit();
25+
parent::tearDown();
26+
}
27+
28+
public function testLoginPageFormFieldsAreVisible(): void
29+
{
30+
self::$client->request('GET', '/app_test.php/login');
31+
32+
$this->assertPageTitleContains('phpList - Login');
33+
34+
$this->assertSelectorExists('input[name="username"]');
35+
$this->assertSelectorExists('input[name="password"]');
36+
$this->assertSelectorTextContains('label[for="username"]', 'Username');
37+
$this->assertSelectorTextContains('label[for="password"]', 'Password');
38+
$this->assertSelectorExists('button[type="submit"]');
39+
$this->assertSelectorTextContains('button[type="submit"]', 'Sign in');
40+
$this->assertSelectorExists('.login-container');
41+
$this->assertSelectorExists('#vue-app');
42+
43+
$this->assertSelectorTextContains('h1', 'Sign in to phpList');
44+
}
45+
46+
public function testLoginFormSubmission(): void
47+
{
48+
self::$client->request('GET', '/app_test.php/login');
49+
50+
self::$client->submitForm('Sign in', [
51+
'username' => 'invalid_user',
52+
'password' => 'invalid_password'
53+
]);
54+
55+
$this->assertPageTitleContains('Login');
56+
$this->assertSelectorExists('.alert.alert-danger');
57+
}
58+
}

tests/Unit/Controller/AuthControllerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPUnit\Framework\MockObject\MockObject;
1010
use PHPUnit\Framework\TestCase;
1111
use RuntimeException;
12-
use Symfony\Component\HttpFoundation\ParameterBag;
1312
use Symfony\Component\HttpFoundation\RedirectResponse;
1413
use Symfony\Component\HttpFoundation\Request;
1514
use Symfony\Component\HttpFoundation\Response;
@@ -65,7 +64,7 @@ public function testLoginWithGetRequest(): void
6564

6665
$response = $this->controller->login($request);
6766

68-
$this->assertStringContainsString('security/login.html.twig', $response->getContent());
67+
$this->assertStringContainsString('auth/login.html.twig', $response->getContent());
6968
$this->assertStringContainsString('with params', $response->getContent());
7069
}
7170

@@ -93,7 +92,7 @@ public function testLoginWithGetRequestAndError(): void
9392

9493
$response = $this->controller->login($request);
9594

96-
$this->assertStringContainsString('security/login.html.twig', $response->getContent());
95+
$this->assertStringContainsString('auth/login.html.twig', $response->getContent());
9796
$this->assertStringContainsString('Test error message', $response->getContent());
9897
}
9998

@@ -153,7 +152,7 @@ public function testLoginWithPostRequestFailure(): void
153152

154153
$response = $this->controller->login($request);
155154

156-
$this->assertStringContainsString('security/login.html.twig', $response->getContent());
155+
$this->assertStringContainsString('auth/login.html.twig', $response->getContent());
157156
$this->assertStringContainsString('Invalid credentials', $response->getContent());
158157
}
159158

0 commit comments

Comments
 (0)