forked from laravel/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThrottleLoginsTest.php
66 lines (57 loc) · 2.52 KB
/
ThrottleLoginsTest.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
<?php
namespace Laravel\Ui\Tests\AuthBackend;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Orchestra\Testbench\TestCase;
use Illuminate\Http\Request;
use PHPUnit\Framework\MockObject\MockObject;
class ThrottleLoginsTest extends TestCase
{
/**
* @test
* @dataProvider specialCharacterProvider
*/
public function it_can_replace_special_characters(string $value, string $expected): void
{
$throttle = $this->getMockForTrait(ThrottlesLogins::class);
$reflection = new \ReflectionClass($throttle);
$method = $reflection->getMethod('removeSpecialCharacters');
$method->setAccessible(true);
$this->assertSame($expected, $method->invoke($throttle, $value));
}
public function specialCharacterProvider(): array
{
return [
['ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ', 'abcdefghijklmnopqrstuvwxyz'],
['⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳', '01234567891011121314151617181920'],
['⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾', '12345678910'],
['⓿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴', '011121314151617181920'],
['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
['0123456789', '0123456789'],
];
}
/**
* @test
* @dataProvider emailProvider
*/
public function it_can_generate_throttle_key(string $email, string $expectedEmail): void
{
$throttle = $this->getMockForTrait(ThrottlesLogins::class, [], '', true, true, true, ['username']);
$throttle->method('username')->willReturn('email');
$reflection = new \ReflectionClass($throttle);
$method = $reflection->getMethod('throttleKey');
$method->setAccessible(true);
$request = $this->mock(Request::class);
$request->expects('input')->with('email')->andReturn($email);
$request->expects('ip')->andReturn('192.168.0.1');
$this->assertSame($expectedEmail . '|192.168.0.1', $method->invoke($throttle, $request));
}
public function emailProvider(): array
{
return [
'lowercase special characters' => ['ⓣⓔⓢⓣ@ⓛⓐⓡⓐⓥⓔⓛ.ⓒⓞⓜ', '[email protected]'],
'uppercase special characters' => ['ⓉⒺⓈⓉ@ⓁⒶⓇⒶⓋⒺⓁ.ⒸⓄⓂ', '[email protected]'],
'special character numbers' =>['test⑩⓸③@laravel.com', '[email protected]'],
'default email' => ['[email protected]', '[email protected]'],
];
}
}