Fix big offset for Hook::addMenuItem

This commit is contained in:
Pig Fang 2018-08-21 14:43:46 +08:00
parent f1378367d7
commit 7ec7eb2467
2 changed files with 19 additions and 4 deletions

View File

@ -39,6 +39,10 @@ class Hook
$offset++; $offset++;
} }
if ($position >= $offset) {
$new[] = $menu;
}
$event->menu[$category] = $new; $event->menu[$category] = $new;
}); });
} }

View File

@ -13,15 +13,26 @@ class HookTest extends TestCase
public function testAddMenuItem() public function testAddMenuItem()
{ {
Hook::addMenuItem('user', 0, [ Hook::addMenuItem('user', 0, [
'title' => 'Go to closet', 'title' => 'Link A',
'link' => '/user/closet', 'link' => '/to/a',
'icon' => 'fa-book' 'icon' => 'fa-book'
]); ]);
$this->actAs('normal') $this->actAs('normal')
->get('/user') ->get('/user')
->assertSee('Go to closet') ->assertSee('Link A')
->assertSee('/user/closet') ->assertSee('/to/a')
->assertSee('fa-book'); ->assertSee('fa-book');
// Out of bound
Hook::addMenuItem('user', 10, [
'title' => 'Link B',
'link' => '/to/b',
'icon' => 'fa-book'
]);
$this->actAs('normal')
->get('/user')
->assertSee('Link B')
->assertSee('/to/b');
} }
public function testRegisterPluginTransScripts() public function testRegisterPluginTransScripts()