Add tests for Services/Hook

This commit is contained in:
Pig Fang 2017-12-04 17:04:04 +08:00
parent 97874039c6
commit 26742e3ae3
2 changed files with 57 additions and 0 deletions

View File

@ -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)
{

View File

@ -0,0 +1,55 @@
<?php
use App\Services\Hook;
class HookTest extends TestCase
{
public function testAddMenuItem()
{
Hook::addMenuItem('user', 0, [
'title' => '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('<link rel="stylesheet" href="/style/all">');
Hook::addStyleFileToPage('/style/pattern', ['skinlib']);
$this->visit('/')
->dontSee('<link rel="stylesheet" href="/style/pattern">');
$this->visit('/skinlib')
->see('<link rel="stylesheet" href="/style/pattern">');
}
public function testAddScriptFileToPage()
{
Hook::addScriptFileToPage('/script/all');
$this->visit('/')
->see('<script src="/script/all"></script>');
Hook::addScriptFileToPage('/script/pattern', ['skinlib']);
$this->visit('/')
->dontSee('<script src="/script/pattern"></script>');
$this->visit('/skinlib')
->see('<script src="/script/pattern"></script>');
}
}