-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathMiddlewareTest.php
79 lines (62 loc) · 2.26 KB
/
MiddlewareTest.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
<?php
/*
* This file is part of Laravel HTMLMin.
*
* (c) Graham Campbell <[email protected]>
* (c) Raza Mehdi <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace HTMLMin\Tests\HTMLMin\Functional;
use HTMLMin\HTMLMin\Http\Middleware\MinifyMiddleware;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Response;
/**
* This is the live enabled test class.
*
* @author Graham Campbell <[email protected]>
*/
class MiddlewareTest extends AbstractFunctionalTestCase
{
/**
* Setup the application environment.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app->config->set('htmlmin.live', true);
}
public function testNewSetup()
{
$this->app->view->addNamespace('stubs', realpath(__DIR__.'/stubs'));
$this->app->router->get('htmlmin-test-route', ['middleware' => MinifyMiddleware::class, function () {
return Response::view('stubs::test');
}]);
$actual = $this->call('GET', 'htmlmin-test-route')->getContent();
$expected = file_get_contents(__DIR__.'/stubs/live.txt');
$this->assertSameIgnoreLineEndings($expected, $actual);
}
public function testRedirect()
{
$this->app->router->get('htmlmin-test-route', ['middleware' => MinifyMiddleware::class, function () {
return Redirect::to('foo');
}]);
$response = $this->call('GET', 'htmlmin-test-route');
$this->assertSame($this->app->url->to('foo'), $response->headers->get('Location'));
}
public function testJson()
{
$this->app->router->get('htmlmin-test-route', ['middleware' => MinifyMiddleware::class, function () {
return Response::json(['foo' => 'bar', ['baz']], 200, [], JSON_PRETTY_PRINT);
}]);
$actual = $this->call('GET', 'htmlmin-test-route')->getContent();
$expected = file_get_contents(__DIR__.'/stubs/live.json');
$this->assertSameIgnoreLineEndings($expected, $actual);
}
}