-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathAbstractMiddlewareRunnerTest.php
More file actions
81 lines (68 loc) · 3.02 KB
/
Copy pathAbstractMiddlewareRunnerTest.php
File metadata and controls
81 lines (68 loc) · 3.02 KB
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
<?php
declare (strict_types=1);
namespace PhpMiddlewareTest\PhpDebugBar;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Laminas\Diactoros\Response;
abstract class AbstractMiddlewareRunnerTest extends TestCase
{
final public function testAppendJsIntoHtmlContent(): void
{
$response = $this->dispatchApplication([
'REQUEST_URI' => '/hello',
'REQUEST_METHOD' => 'GET',
'HTTP_ACCEPT' => 'text/html',
], [
'/hello' => function (ServerRequestInterface $request) {
$response = new Response();
$response->getBody()->write('Hello!');
return $response;
},
]);
$responseBody = (string) $response->getBody();
$this->assertStringContainsString('var phpdebugbar = new PhpDebugBar.DebugBar();', $responseBody);
$this->assertStringContainsString('Hello!', $responseBody);
$this->assertStringContainsString('"/phpdebugbar/debugbar.js"', $responseBody);
}
final public function testNotAppendInitializationCodeIntoXmlHttpRequestContent(): void
{
$response = $this->dispatchApplication([
'REQUEST_URI' => '/hello',
'REQUEST_METHOD' => 'GET',
'HTTP_ACCEPT' => 'text/html',
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
], [
'/hello' => function (ServerRequestInterface $request) {
return new Response\HtmlResponse('Hello!');
},
]);
$responseBody = (string) $response->getBody();
$this->assertStringContainsString('Hello!', $responseBody);
$this->assertStringContainsString('phpdebugbar.addDataSet(', $responseBody);
$this->assertStringNotContainsString('var phpdebugbar = new PhpDebugBar.DebugBar();', $responseBody);
$this->assertStringNotContainsString('"/phpdebugbar/debugbar.js"', $responseBody);
}
final public function testGetStatics(): void
{
$response = $this->dispatchApplication([
'DOCUMENT_ROOT' => __DIR__,
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '40226',
'SERVER_SOFTWARE' => 'PHP 7.0.8-3ubuntu3 Development Server',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_NAME' => '0.0.0.0',
'SERVER_PORT' => '8080',
'REQUEST_URI' => '/phpdebugbar/debugbar.js',
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => '/phpdebugbar/debugbar.js',
'SCRIPT_FILENAME' => __FILE__,
'PHP_SELF' => '/phpdebugbar/debugbar.js',
'HTTP_HOST' => '0.0.0.0:8080',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
]);
$contentType = $response->getHeaderLine('Content-type');
$this->assertStringContainsString('text/javascript', $contentType);
}
abstract protected function dispatchApplication(array $server, array $pipe = []): ResponseInterface;
}