Completed
Pull Request — master (#76)
by
unknown
05:21
created

CaffeineTest::testNonStringReturnContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Feature;
2
3
use GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware;
4
use GeneaLabs\LaravelCaffeine\Tests\TestCase;
5
6
class CaffeineTest extends TestCase
7
{
8
    public function testDripEndpoint()
9
    {
10
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
11
12
        $response = $this->get($dripRoute);
13
14
        $response->assertStatus(204);
15
    }
16
17
    public function testMiddlewareInjectsDripScript()
18
    {
19
        $expectedResult = file_get_contents(__DIR__ . '/../Fixtures/expired_script.txt');
20
21
        $response = $this->get(route('genealabs-laravel-caffeine.tests.form'));
22
23
        $response->assertSee($expectedResult);
1 ignored issue
show
Bug introduced by
It seems like $expectedResult can also be of type false; however, parameter $value of Illuminate\Foundation\Te...stResponse::assertSee() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $response->assertSee(/** @scrutinizer ignore-type */ $expectedResult);
Loading history...
24
    }
25
26 View Code Duplication
    public function testSuccessfulDrip()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
29
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
30
            ->getContent();
31
        $matches = [];
32
        preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches);
33
        $csrfToken = $matches[1];
34
35
        $response = $this->get($dripRoute, [
36
            '_token' => $csrfToken,
37
        ]);
38
39
        $response->assertStatus(204);
40
    }
41
42 View Code Duplication
    public function testExpiredDrip()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        $dripRoute = config(
45
            'genealabs-laravel-caffeine.dripInterval',
46
            'genealabs/laravel-caffeine/drip'
47
        );
48
        $html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
49
            ->getContent();
50
        $matches = [];
51
        preg_match(
52
            '/<meta name="csrf-token" content="(.*?)">/',
53
            $html,
54
            $matches
55
        );
56
        $csrfToken = $matches[1];
57
58
        app('session')->flush();
59
        $response = $this->get($dripRoute, [
60
            '_token' => $csrfToken,
61
        ]);
62
63
        $response->assertStatus(404);
64
    }
65
66
    public function testDisabledCaffeination()
67
    {
68
        $html = $this
69
            ->get(route('genealabs-laravel-caffeine.tests.disabled-page'))
70
            ->getContent();
71
72
        $isDisabled = (bool) preg_match(
73
            '/<meta name="caffeinated" content="false">/',
74
            $html
75
        );
76
        $hasDripper = (bool) preg_match(
77
            '/\bconst caffeineSendDrip\b/',
78
            $html
79
        );
80
81
        $this->assertTrue($isDisabled);
82
        $this->assertFalse($hasDripper);
83
    }
84
85
    public function testNonStringReturnContent()
86
    {
87
        $response = $this->get(route('genealabs-laravel-caffeine.tests.null-response'));
88
89
        $response->assertDontSee('const caffeineSendDrip');
90
    }
91
92
    public function testRouteMiddleware()
93
    {
94
        app('router')->aliasMiddleware(
95
            'caffeinated',
96
            '\\' . LaravelCaffeineDripMiddleware::class
97
        );
98
99
        $response = $this
100
            ->get(route('genealabs-laravel-caffeine.tests.route-middleware'));
101
102
        $response->assertSee('const caffeineSendDrip');
103
    }
104
}
105