86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use App\Services\Hook;
|
|
use Illuminate\Support\Facades\File;
|
|
use Tests\Concerns\GeneratesFakePlugins;
|
|
|
|
class HookTest extends TestCase
|
|
{
|
|
use GeneratesFakePlugins;
|
|
|
|
public function testAddMenuItem()
|
|
{
|
|
Hook::addMenuItem('user', 0, [
|
|
'title' => 'Link A',
|
|
'link' => '/to/a',
|
|
'icon' => 'fa-book',
|
|
]);
|
|
$this->actAs('normal')
|
|
->get('/user')
|
|
->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 testAddRoute()
|
|
{
|
|
Hook::addRoute(function ($route) {
|
|
$route->any('/test-hook', function () {});
|
|
});
|
|
event(new \App\Events\ConfigureRoutes(resolve(\Illuminate\Routing\Router::class)));
|
|
$this->get('/test-hook')->assertSuccessful();
|
|
}
|
|
|
|
public function testRegisterPluginTransScripts()
|
|
{
|
|
$this->generateFakePlugin(['name' => 'fake-plugin-with-i18n', 'version' => '0.0.1']);
|
|
@mkdir($path = config('plugins.directory').DIRECTORY_SEPARATOR.'fake-plugin-with-i18n/lang/en', 0755, true);
|
|
file_put_contents("$path/locale.js", '');
|
|
|
|
Hook::registerPluginTransScripts('fake-plugin-with-i18n', ['/']);
|
|
$this->get('/')->assertSee('fake-plugin-with-i18n/lang/en/locale.js');
|
|
$this->get('/skinlib')->assertDontSee('fake-plugin-with-i18n/lang/en/locale.js');
|
|
|
|
File::deleteDirectory(config('plugins.directory').DIRECTORY_SEPARATOR.'fake-plugin-with-i18n');
|
|
}
|
|
|
|
public function testAddStyleFileToPage()
|
|
{
|
|
Hook::addStyleFileToPage('/style/all');
|
|
$this->get('/')
|
|
->assertSee('<link rel="stylesheet" href="/style/all">');
|
|
|
|
Hook::addStyleFileToPage('/style/pattern', ['skinlib']);
|
|
$this->get('/')
|
|
->assertDontSee('<link rel="stylesheet" href="/style/pattern">');
|
|
$this->get('/skinlib')
|
|
->assertSee('<link rel="stylesheet" href="/style/pattern">');
|
|
}
|
|
|
|
public function testAddScriptFileToPage()
|
|
{
|
|
Hook::addScriptFileToPage('/script/all');
|
|
$this->get('/')
|
|
->assertSee('<script src="/script/all"></script>');
|
|
|
|
Hook::addScriptFileToPage('/script/pattern', ['skinlib']);
|
|
$this->get('/')
|
|
->assertDontSee('<script src="/script/pattern"></script>');
|
|
$this->get('/skinlib')
|
|
->assertSee('<script src="/script/pattern"></script>');
|
|
}
|
|
}
|