From 26742e3ae310e8a4748b91e29346f5c1857b9dda Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 4 Dec 2017 17:04:04 +0800 Subject: [PATCH] Add tests for `Services/Hook` --- app/Services/Hook.php | 2 ++ tests/ServicesTest/HookTest.php | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/ServicesTest/HookTest.php diff --git a/app/Services/Hook.php b/app/Services/Hook.php index 88081acc..e8dc1946 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -48,6 +48,8 @@ class Hook * Add a route. A router instance will be passed to the given callback. * * @param Closure $callback + * + * TODO: Needs to be tested. */ public static function addRoute(Closure $callback) { diff --git a/tests/ServicesTest/HookTest.php b/tests/ServicesTest/HookTest.php new file mode 100644 index 00000000..e0f14735 --- /dev/null +++ b/tests/ServicesTest/HookTest.php @@ -0,0 +1,55 @@ + 'Go to closet', + 'link' => '/user/closet', + 'icon' => 'fa-book' + ]); + $this->actAs('normal') + ->visit('/user') + ->see('Go to closet') + ->see('/user/closet') + ->see('fa-book') + ->click('Go to closet') + ->seePageIs('/user/closet'); + } + + public function testRegisterPluginTransScripts() + { + Hook::registerPluginTransScripts('example-plugin'); + $this->get('/') + ->see('example-plugin/lang/en/locale.js'); + } + + public function testAddStyleFileToPage() + { + Hook::addStyleFileToPage('/style/all'); + $this->visit('/') + ->see(''); + + Hook::addStyleFileToPage('/style/pattern', ['skinlib']); + $this->visit('/') + ->dontSee(''); + $this->visit('/skinlib') + ->see(''); + } + + public function testAddScriptFileToPage() + { + Hook::addScriptFileToPage('/script/all'); + $this->visit('/') + ->see(''); + + Hook::addScriptFileToPage('/script/pattern', ['skinlib']); + $this->visit('/') + ->dontSee(''); + $this->visit('/skinlib') + ->see(''); + } +}