|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -use Leuverink\AssetInjector\Contracts\AssetInjector; |
| 3 | +use Tests\Stubs\Implement; |
| 4 | +use Tests\Stubs\DisabledImplement; |
| 5 | +use Leuverink\AssetInjector\AssetManager; |
4 | 6 |
|
5 | 7 | it('injects assets into response', function () {
|
| 8 | + AssetManager::register(new Implement); |
| 9 | + |
6 | 10 | Route::get('test-inject-in-response', fn () => '<html><head></head></html>');
|
7 | 11 |
|
8 | 12 | $this->get('test-inject-in-response')
|
|
11 | 15 | });
|
12 | 16 |
|
13 | 17 | it('injects assets into head tag', function () {
|
| 18 | + AssetManager::register(new Implement); |
| 19 | + |
14 | 20 | Route::get('test-inject-in-response', fn () => '<html><head></head></html>');
|
15 | 21 |
|
16 | 22 | $expected = <<< 'HTML'
|
|
27 | 33 | });
|
28 | 34 |
|
29 | 35 | it('injects assets into html body when no head tag is present', function () {
|
| 36 | + AssetManager::register(new Implement); |
| 37 | + |
30 | 38 | Route::get('test-inject-in-response', fn () => '<html></html>');
|
31 | 39 |
|
32 | 40 | $expected = <<< 'HTML'
|
|
43 | 51 | });
|
44 | 52 |
|
45 | 53 | it('injects assets into the end of the html body when no head tag is present', function () {
|
| 54 | + AssetManager::register(new Implement); |
| 55 | + |
46 | 56 | Route::get('test-inject-in-response', fn () => '<html><p>Hello World</p></html>');
|
47 | 57 |
|
48 | 58 | $expected = <<< 'HTML'
|
|
59 | 69 | });
|
60 | 70 |
|
61 | 71 | it('doesnt inject assets into responses without a closing html tag', function () {
|
| 72 | + AssetManager::register(new Implement); |
| 73 | + |
62 | 74 | Route::get('test-inject-in-response', fn () => 'OK');
|
63 | 75 |
|
64 | 76 | $this->get('test-inject-in-response')
|
|
67 | 79 | });
|
68 | 80 |
|
69 | 81 | it('doesnt inject assets when implementation returns false from enabled method', function () {
|
70 |
| - $this->partialMock(AssetInjector::class) |
71 |
| - ->shouldReceive('enabled')->once() |
72 |
| - ->andReturn(false); |
| 82 | + AssetManager::register(new Implement); |
| 83 | + AssetManager::register(new DisabledImplement); |
73 | 84 |
|
74 | 85 | Route::get('test-inject-in-response', fn () => '<html><head></head></html>');
|
75 | 86 |
|
76 | 87 | $this->get('test-inject-in-response')
|
77 | 88 | ->assertOk()
|
78 |
| - ->assertDontSee('<!--[TEST_PACKAGE]-->', false); |
| 89 | + ->assertSee('<!--[TEST_PACKAGE]-->', false) |
| 90 | + ->assertDontSee('<!--[DISABLED_TEST_PACKAGE]-->', false); |
| 91 | +}); |
| 92 | + |
| 93 | +it('can inject more than one implement', function () { |
| 94 | + AssetManager::register(new Implement); |
| 95 | + AssetManager::register(new Implement); |
| 96 | + |
| 97 | + Route::get('test-inject-in-response', fn () => '<html><head></head></html>'); |
| 98 | + |
| 99 | + $this->get('test-inject-in-response') |
| 100 | + ->assertOk() |
| 101 | + ->assertSee(<<<'HTML' |
| 102 | + <!--[TEST_PACKAGE]--> |
| 103 | + TEST_PACKAGE_ASSETS_INJECTED |
| 104 | + <!--[ENDTEST_PACKAGE]--> |
| 105 | +
|
| 106 | + <!--[TEST_PACKAGE]--> |
| 107 | + TEST_PACKAGE_ASSETS_INJECTED |
| 108 | + <!--[ENDTEST_PACKAGE]--> |
| 109 | + HTML, false); |
79 | 110 | });
|
0 commit comments