From 7ec7eb24678231a8eb75fedeee342d12fbc64afa Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 21 Aug 2018 14:43:46 +0800 Subject: [PATCH] Fix big offset for Hook::addMenuItem --- app/Services/Hook.php | 4 ++++ tests/ServicesTest/HookTest.php | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Services/Hook.php b/app/Services/Hook.php index 1b8ebf96..82da0265 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -39,6 +39,10 @@ class Hook $offset++; } + if ($position >= $offset) { + $new[] = $menu; + } + $event->menu[$category] = $new; }); } diff --git a/tests/ServicesTest/HookTest.php b/tests/ServicesTest/HookTest.php index 936e1d53..3563b44e 100644 --- a/tests/ServicesTest/HookTest.php +++ b/tests/ServicesTest/HookTest.php @@ -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()