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++;
}
if ($position >= $offset) {
$new[] = $menu;
}
$event->menu[$category] = $new;
});
}

View File

@ -13,15 +13,26 @@ class HookTest extends TestCase
public function testAddMenuItem()
{
Hook::addMenuItem('user', 0, [
'title' => 'Go to closet',
'link' => '/user/closet',
'title' => 'Link A',
'link' => '/to/a',
'icon' => 'fa-book'
]);
$this->actAs('normal')
->get('/user')
->assertSee('Go to closet')
->assertSee('/user/closet')
->assertSee('Link A')
->assertSee('/to/a')
->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()