mc-blessing-skin/tests/HttpTest/ControllersTest/AdminControllerTest.php

60 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2017-11-02 16:50:00 +08:00
<?php
2018-08-17 15:25:08 +08:00
namespace Tests;
2017-11-02 16:50:00 +08:00
use App\Models\Texture;
2019-12-14 11:10:37 +08:00
use App\Models\User;
2019-08-28 16:04:26 +08:00
use App\Services\Plugin;
2017-11-02 16:50:00 +08:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2019-07-03 13:19:57 +08:00
class AdminControllerTest extends TestCase
2017-11-02 16:50:00 +08:00
{
use DatabaseTransactions;
2019-02-27 23:44:50 +08:00
protected function setUp(): void
2017-11-02 16:50:00 +08:00
{
// Do not use `WithoutMiddleware` trait
parent::setUp();
2020-10-14 11:56:34 +08:00
$this->actingAs(User::factory()->admin()->create());
2017-11-02 16:50:00 +08:00
}
2019-12-21 10:41:38 +08:00
public function testIndex()
{
$filter = Fakes\Filter::fake();
$this->get('/admin')->assertSuccessful();
$filter->assertApplied('grid:admin.index');
}
2019-03-19 19:16:03 +08:00
public function testChartData()
2017-11-02 16:50:00 +08:00
{
2020-10-14 11:56:34 +08:00
User::factory()->create();
User::factory()->create(['register_at' => '2019-01-01 00:00:00']);
Texture::factory()->create();
2019-03-19 23:35:13 +08:00
$this->getJson('/admin/chart')
2019-07-03 13:19:57 +08:00
->assertJson(['labels' => [
2019-03-19 23:35:13 +08:00
trans('admin.index.user-registration'),
2019-04-19 19:36:36 +08:00
trans('admin.index.texture-uploads'),
2019-03-19 23:35:13 +08:00
]])
2019-07-03 13:19:57 +08:00
->assertJsonStructure(['labels', 'xAxis', 'data']);
2017-11-02 16:50:00 +08:00
}
2019-08-28 14:52:51 +08:00
public function testStatus()
{
2019-08-28 16:04:26 +08:00
$this->mock(\App\Services\PluginManager::class, function ($mock) {
$mock->shouldReceive('getEnabledPlugins')
->andReturn(collect([
'a' => new Plugin('', ['title' => 'MyPlugin', 'version' => '0.0.0']),
2019-08-28 16:04:26 +08:00
]));
});
2019-12-21 10:41:38 +08:00
$filter = Fakes\Filter::fake();
2019-08-28 16:04:26 +08:00
2019-08-28 14:52:51 +08:00
$this->get('/admin/status')
->assertSee(PHP_VERSION)
2019-08-28 16:04:26 +08:00
->assertSee('(1)')
->assertSee('MyPlugin')
->assertSee('0.0.0');
2019-12-21 10:41:38 +08:00
$filter->assertApplied('grid:admin.status');
2019-08-28 14:52:51 +08:00
}
2017-11-02 16:50:00 +08:00
}