Skip to content

Commit b94ad3c

Browse files
committed
Add test for shorthand
1 parent 7d0ae64 commit b94ad3c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Http/Middleware/CacheTracker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private function setupTagHooks()
181181
});
182182

183183
Tags\Nav::hook('init', function ($value, $next) use ($self) {
184-
$handle = 'nav:'.$this->params->get('handle', 'collection::pages');
184+
$handle = 'nav:'.$this->params->get('handle', Str::after($this->tag, 'nav:'));
185185
$self->addContentTag($handle);
186186

187187
return $next($value);

tests/Unit/NavTagTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,38 @@ public function it_tracks_nav_tag_with_explicit_handle()
4141
$this->assertContains('nav:footer', $tags);
4242
}
4343

44+
#[Test]
45+
public function it_tracks_nav_tag_with_shorthand_handle()
46+
{
47+
// Create a navigation structure
48+
Facades\Nav::make('footer')
49+
->title('Footer')
50+
->expectsRoot(true)
51+
->collections(['pages'])
52+
->save();
53+
54+
$view = <<<'BLADE'
55+
{{ nav:footer }}
56+
{{ title }}
57+
{{ /nav:footer }}
58+
BLADE;
59+
60+
file_put_contents($this->viewPath('nav-test.antlers.html'), $view);
61+
62+
Facades\Entry::make()
63+
->id('nav-test-page')
64+
->slug('nav-test')
65+
->collection('pages')
66+
->data(['template' => 'nav-test'])
67+
->save();
68+
69+
$this->get('/nav-test');
70+
71+
$tags = collect(Tracker::all())->first()['tags'] ?? [];
72+
73+
$this->assertContains('nav:footer', $tags);
74+
}
75+
4476
#[Test]
4577
public function it_tracks_nav_tag_without_handle_using_default()
4678
{

0 commit comments

Comments
 (0)