|
1
|
|
|
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Feature; |
|
2
|
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelCaffeine\Tests\TestCase; |
|
4
|
|
|
|
|
5
|
|
|
class CaffeineTest extends TestCase |
|
6
|
|
|
{ |
|
7
|
|
|
public function testDripEndpoint() |
|
8
|
|
|
{ |
|
9
|
|
|
$dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip'); |
|
10
|
|
|
|
|
11
|
|
|
$response = $this->get($dripRoute); |
|
12
|
|
|
|
|
13
|
|
|
$response->assertStatus(204); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testMiddlewareInjectsDripScript() |
|
17
|
|
|
{ |
|
18
|
|
|
$expectedResult = file_get_contents(__DIR__ . '/../Fixtures/expired_script.txt'); |
|
19
|
|
|
|
|
20
|
|
|
$response = $this->get(route('genealabs-laravel-caffeine.tests.form')); |
|
21
|
|
|
|
|
22
|
|
|
$response->assertSee($expectedResult); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
View Code Duplication |
public function testSuccessfulDrip() |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip'); |
|
28
|
|
|
$html = $this->get(route('genealabs-laravel-caffeine.tests.form')) |
|
29
|
|
|
->getContent(); |
|
30
|
|
|
$matches = []; |
|
31
|
|
|
preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches); |
|
32
|
|
|
$csrfToken = $matches[1]; |
|
33
|
|
|
|
|
34
|
|
|
$response = $this->get($dripRoute, [ |
|
35
|
|
|
'_token' => $csrfToken, |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
$response->assertStatus(204); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
View Code Duplication |
public function testExpiredDrip() |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$dripRoute = config( |
|
44
|
|
|
'genealabs-laravel-caffeine.dripInterval', |
|
45
|
|
|
'genealabs/laravel-caffeine/drip' |
|
46
|
|
|
); |
|
47
|
|
|
$html = $this->get(route('genealabs-laravel-caffeine.tests.form')) |
|
48
|
|
|
->getContent(); |
|
49
|
|
|
$matches = []; |
|
50
|
|
|
preg_match( |
|
51
|
|
|
'/<meta name="csrf-token" content="(.*?)">/', |
|
52
|
|
|
$html, |
|
53
|
|
|
$matches |
|
54
|
|
|
); |
|
55
|
|
|
$csrfToken = $matches[1]; |
|
56
|
|
|
|
|
57
|
|
|
app('session')->flush(); |
|
58
|
|
|
$response = $this->get($dripRoute, [ |
|
59
|
|
|
'_token' => $csrfToken, |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$response->assertStatus(404); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testDisabledCaffeination() |
|
66
|
|
|
{ |
|
67
|
|
|
$html = $this |
|
68
|
|
|
->get(route('genealabs-laravel-caffeine.tests.disabled-page')) |
|
69
|
|
|
->getContent(); |
|
70
|
|
|
|
|
71
|
|
|
$isDisabled = (bool) preg_match( |
|
72
|
|
|
'/<meta name="caffeinated" content="false">/', |
|
73
|
|
|
$html |
|
74
|
|
|
); |
|
75
|
|
|
$hasDripper = (bool) preg_match( |
|
76
|
|
|
'/\bconst caffeineSendDrip\b/', |
|
77
|
|
|
$html |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertTrue($isDisabled); |
|
81
|
|
|
$this->assertFalse($hasDripper); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testNonStringReturnContent() |
|
85
|
|
|
{ |
|
86
|
|
|
$response = $this->get(route('genealabs-laravel-caffeine.tests.null-response')); |
|
87
|
|
|
|
|
88
|
|
|
$response->assertDontSee('const caffeineSendDrip'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|