-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathDebugbarTest.php
108 lines (88 loc) · 3.51 KB
/
DebugbarTest.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Barryvdh\Debugbar\Tests;
use Barryvdh\Debugbar\LaravelDebugbar;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Routing\Router;
use Illuminate\Support\Str;
class DebugbarTest extends TestCase
{
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
// Force the Debugbar to Enable on test/cli applications
$app->resolving(LaravelDebugbar::class, function ($debugbar) {
$refObject = new \ReflectionObject($debugbar);
$refProperty = $refObject->getProperty('enabled');
$refProperty->setAccessible(true);
$refProperty->setValue($debugbar, true);
});
}
public function testItInjectsOnPlainText()
{
$crawler = $this->call('GET', 'web/plain');
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItInjectsOnEmptyResponse()
{
$crawler = $this->call('GET', 'web/empty');
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItInjectsOnNullyResponse()
{
$crawler = $this->call('GET', 'web/null');
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItInjectsOnHtml()
{
$crawler = $this->call('GET', 'web/html');
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItDoesntInjectOnJson()
{
$crawler = $this->call('GET', 'api/ping');
$this->assertFalse(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItDoesntInjectOnJsonLookingString()
{
$crawler = $this->call('GET', 'web/fakejson');
$this->assertFalse(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItDoesntInjectsOnHxRequestWithHxTarget()
{
$crawler = $this->get('web/html', [
'Hx-Request' => 'true',
'Hx-Target' => 'main',
]);
$this->assertFalse(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
public function testItInjectsOnHxRequestWithoutHxTarget()
{
$crawler = $this->get('web/html', [
'Hx-Request' => 'true',
]);
$this->assertTrue(Str::contains($crawler->content(), 'debugbar'));
$this->assertEquals(200, $crawler->getStatusCode());
$this->assertNotEmpty($crawler->headers->get('phpdebugbar-id'));
}
}