|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Thoughtco\StatamicCacheTracker\Tests\Unit; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\Test; |
| 6 | +use Statamic\Facades; |
| 7 | +use Thoughtco\StatamicCacheTracker\Facades\Tracker; |
| 8 | +use Thoughtco\StatamicCacheTracker\Tests\TestCase; |
| 9 | + |
| 10 | +class NavTagTest extends TestCase |
| 11 | +{ |
| 12 | + #[Test] |
| 13 | + public function it_tracks_nav_tag_with_explicit_handle() |
| 14 | + { |
| 15 | + // Create a navigation structure |
| 16 | + Facades\Nav::make('footer') |
| 17 | + ->title('Footer') |
| 18 | + ->expectsRoot(true) |
| 19 | + ->collections(['pages']) |
| 20 | + ->save(); |
| 21 | + |
| 22 | + $view = <<<'BLADE' |
| 23 | +{{ nav handle="footer" }} |
| 24 | + {{ title }} |
| 25 | +{{ /nav }} |
| 26 | +BLADE; |
| 27 | + |
| 28 | + file_put_contents($this->viewPath('nav-test.antlers.html'), $view); |
| 29 | + |
| 30 | + Facades\Entry::make() |
| 31 | + ->id('nav-test-page') |
| 32 | + ->slug('nav-test') |
| 33 | + ->collection('pages') |
| 34 | + ->data(['template' => 'nav-test']) |
| 35 | + ->save(); |
| 36 | + |
| 37 | + $this->get('/nav-test'); |
| 38 | + |
| 39 | + $tags = collect(Tracker::all())->first()['tags'] ?? []; |
| 40 | + |
| 41 | + $this->assertContains('nav:footer', $tags); |
| 42 | + } |
| 43 | + |
| 44 | + #[Test] |
| 45 | + public function it_tracks_nav_tag_without_handle_using_default() |
| 46 | + { |
| 47 | + $view = <<<'BLADE' |
| 48 | +{{ nav }} |
| 49 | + {{ title }} |
| 50 | +{{ /nav }} |
| 51 | +BLADE; |
| 52 | + |
| 53 | + file_put_contents($this->viewPath('nav-default.antlers.html'), $view); |
| 54 | + |
| 55 | + Facades\Entry::make() |
| 56 | + ->id('nav-default-page') |
| 57 | + ->slug('nav-default') |
| 58 | + ->collection('pages') |
| 59 | + ->data(['template' => 'nav-default']) |
| 60 | + ->save(); |
| 61 | + |
| 62 | + $this->get('/nav-default'); |
| 63 | + |
| 64 | + $tags = collect(Tracker::all())->first()['tags'] ?? []; |
| 65 | + |
| 66 | + $this->assertContains('nav:collection::pages', $tags); |
| 67 | + } |
| 68 | + |
| 69 | + protected function viewPath($name) |
| 70 | + { |
| 71 | + return __DIR__.'/../__fixtures__/resources/views/'.$name; |
| 72 | + } |
| 73 | +} |
0 commit comments