forked from minkphp/driver-testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicAuthTest.php
80 lines (56 loc) · 2.42 KB
/
BasicAuthTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
final class BasicAuthTest extends TestCase
{
/**
* @dataProvider setBasicAuthDataProvider
*/
public function testSetBasicAuth(string $user, string $pass, string $pageText): void
{
$session = $this->getSession();
$session->setBasicAuth($user, $pass);
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertStringContainsString($pageText, $session->getPage()->getContent());
}
/**
* @return iterable<string, array{string, string, string}>
*/
public static function setBasicAuthDataProvider(): iterable
{
yield 'valid credentials' => ['mink-user', 'mink-password', 'is authenticated'];
yield 'no credentials' => ['', '', 'is not authenticated'];
}
public function testBasicAuthInUrl(): void
{
$session = $this->getSession();
$url = $this->pathTo('/basic_auth.php');
$url = str_replace('://', '://mink-user:mink-password@', $url);
$session->visit($url);
$this->assertStringContainsString('is authenticated', $session->getPage()->getContent());
$url = $this->pathTo('/basic_auth.php');
$url = str_replace('://', '://mink-user:wrong@', $url);
$session->visit($url);
$this->assertStringContainsString('is not authenticated', $session->getPage()->getContent());
}
public function testResetBasicAuth(): void
{
$session = $this->getSession();
$session->setBasicAuth('mink-user', 'mink-password');
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertStringContainsString('is authenticated', $session->getPage()->getContent());
$session->setBasicAuth(false);
$session->visit($this->pathTo('/headers.php'));
$this->assertStringNotContainsString('PHP_AUTH_USER', $session->getPage()->getContent());
}
public function testResetWithBasicAuth(): void
{
$session = $this->getSession();
$session->setBasicAuth('mink-user', 'mink-password');
$session->visit($this->pathTo('/basic_auth.php'));
$this->assertStringContainsString('is authenticated', $session->getPage()->getContent());
$session->reset();
$session->visit($this->pathTo('/headers.php'));
$this->assertStringNotContainsString('PHP_AUTH_USER', $session->getPage()->getContent());
}
}