2017-12-04 17:04:04 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2019-07-03 16:19:13 +08:00
|
|
|
use App\Models\User;
|
2017-12-04 17:04:04 +08:00
|
|
|
use App\Services\Hook;
|
|
|
|
|
|
|
|
class HookTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testAddMenuItem()
|
|
|
|
{
|
|
|
|
Hook::addMenuItem('user', 0, [
|
2018-08-21 14:43:46 +08:00
|
|
|
'title' => 'Link A',
|
|
|
|
'link' => '/to/a',
|
2019-03-02 22:58:37 +08:00
|
|
|
'icon' => 'fa-book',
|
2019-06-29 00:07:40 +08:00
|
|
|
'new-tab' => true,
|
2017-12-04 17:04:04 +08:00
|
|
|
]);
|
2020-10-14 11:56:34 +08:00
|
|
|
$this->actingAs(User::factory()->create())
|
2018-07-13 16:10:23 +08:00
|
|
|
->get('/user')
|
2018-08-21 14:43:46 +08:00
|
|
|
->assertSee('Link A')
|
2019-09-17 23:10:44 +08:00
|
|
|
->assertSee('/to/a')
|
2020-03-09 12:29:00 +08:00
|
|
|
->assertSee('target="_blank"', false)
|
2018-07-13 16:10:23 +08:00
|
|
|
->assertSee('fa-book');
|
2018-08-21 14:43:46 +08:00
|
|
|
|
|
|
|
// Out of bound
|
|
|
|
Hook::addMenuItem('user', 10, [
|
|
|
|
'title' => 'Link B',
|
|
|
|
'link' => '/to/b',
|
2019-03-02 22:58:37 +08:00
|
|
|
'icon' => 'fa-book',
|
2018-08-21 14:43:46 +08:00
|
|
|
]);
|
2020-10-14 11:56:34 +08:00
|
|
|
$this->actingAs(User::factory()->create())
|
2018-08-21 14:43:46 +08:00
|
|
|
->get('/user')
|
|
|
|
->assertSee('Link B')
|
|
|
|
->assertSee('/to/b');
|
2017-12-04 17:04:04 +08:00
|
|
|
}
|
|
|
|
|
2019-04-05 09:31:36 +08:00
|
|
|
public function testAddRoute()
|
|
|
|
{
|
|
|
|
Hook::addRoute(function ($route) {
|
2019-04-19 19:36:36 +08:00
|
|
|
$route->any('/test-hook', function () {
|
|
|
|
});
|
2019-04-05 09:31:36 +08:00
|
|
|
});
|
|
|
|
event(new \App\Events\ConfigureRoutes(resolve(\Illuminate\Routing\Router::class)));
|
|
|
|
$this->get('/test-hook')->assertSuccessful();
|
|
|
|
}
|
|
|
|
|
2017-12-04 17:04:04 +08:00
|
|
|
public function testAddStyleFileToPage()
|
|
|
|
{
|
|
|
|
Hook::addStyleFileToPage('/style/all');
|
2018-07-13 16:10:23 +08:00
|
|
|
$this->get('/')
|
2020-06-28 16:05:29 +08:00
|
|
|
->assertSee('<link rel="stylesheet" href="/style/all" crossorigin="anonymous">', false);
|
2017-12-04 17:04:04 +08:00
|
|
|
|
|
|
|
Hook::addStyleFileToPage('/style/pattern', ['skinlib']);
|
2018-07-13 16:10:23 +08:00
|
|
|
$this->get('/')
|
|
|
|
->assertDontSee('<link rel="stylesheet" href="/style/pattern">');
|
|
|
|
$this->get('/skinlib')
|
2020-06-28 16:05:29 +08:00
|
|
|
->assertSee('<link rel="stylesheet" href="/style/pattern" crossorigin="anonymous">', false);
|
2017-12-04 17:04:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddScriptFileToPage()
|
|
|
|
{
|
|
|
|
Hook::addScriptFileToPage('/script/all');
|
2018-07-13 16:10:23 +08:00
|
|
|
$this->get('/')
|
2020-06-28 16:05:29 +08:00
|
|
|
->assertSee('<script src="/script/all" crossorigin="anonymous"></script>', false);
|
2017-12-04 17:04:04 +08:00
|
|
|
|
|
|
|
Hook::addScriptFileToPage('/script/pattern', ['skinlib']);
|
2018-07-13 16:10:23 +08:00
|
|
|
$this->get('/')
|
2020-06-28 16:05:29 +08:00
|
|
|
->assertDontSee('<script src="/script/pattern" crossorigin="anonymous"></script>');
|
2018-07-13 16:10:23 +08:00
|
|
|
$this->get('/skinlib')
|
2020-06-28 16:05:29 +08:00
|
|
|
->assertSee('<script src="/script/pattern" crossorigin="anonymous"></script>', false);
|
2017-12-04 17:04:04 +08:00
|
|
|
}
|
2019-07-02 23:34:27 +08:00
|
|
|
|
|
|
|
public function testAddUserBadge()
|
|
|
|
{
|
|
|
|
Hook::addUserBadge('hi', 'green');
|
2020-10-14 11:56:34 +08:00
|
|
|
$this->actingAs(User::factory()->create())
|
2019-07-02 23:34:27 +08:00
|
|
|
->get('/user')
|
2020-03-09 12:29:00 +08:00
|
|
|
->assertSee('<span class="badge bg-green mb-1 mr-2">hi</span>', false);
|
2019-07-02 23:34:27 +08:00
|
|
|
}
|
2019-07-03 16:19:13 +08:00
|
|
|
|
|
|
|
public function testSendNotification()
|
|
|
|
{
|
2020-10-14 11:56:34 +08:00
|
|
|
$user = User::factory()->create();
|
2019-07-03 16:19:13 +08:00
|
|
|
Hook::sendNotification([$user], 'Ibara Mayaka');
|
2020-02-16 10:03:47 +08:00
|
|
|
$user->refresh();
|
|
|
|
$this->assertCount(1, $user->unreadNotifications);
|
2019-07-03 16:19:13 +08:00
|
|
|
}
|
2019-07-03 19:33:08 +08:00
|
|
|
|
|
|
|
public function testPushMiddleware()
|
|
|
|
{
|
2020-02-01 10:12:31 +08:00
|
|
|
Hook::pushMiddleware(Concerns\FakeMiddleware::class);
|
2019-07-03 19:33:08 +08:00
|
|
|
$this->get('/')->assertHeader('X-Middleware-Test');
|
|
|
|
}
|
2017-12-04 17:04:04 +08:00
|
|
|
}
|