2017-11-16 10:09:58 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
use App\Events;
|
|
|
|
use ZipArchive;
|
2018-08-19 17:39:33 +08:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use Tests\Concerns\GeneratesFakePlugins;
|
2017-11-16 10:09:58 +08:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
|
|
class PluginControllerTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
2018-08-19 17:39:33 +08:00
|
|
|
use GeneratesFakePlugins;
|
2017-11-16 10:09:58 +08:00
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2017-11-17 07:54:39 +08:00
|
|
|
|
2018-08-19 17:39:33 +08:00
|
|
|
$this->generateFakePlugin(['name' => 'fake-plugin-for-test', 'version' => '1.1.4']);
|
|
|
|
$this->generateFakePlugin(['name' => 'fake-plugin-with-config-view', 'version' => '5.1.4', 'config' => 'config.blade.php']);
|
|
|
|
|
|
|
|
return $this->actAs('superAdmin');
|
2017-11-16 10:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testShowManage()
|
|
|
|
{
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->get('/admin/plugins/manage')
|
|
|
|
->assertSee(trans('general.plugin-manage'));
|
2017-11-16 10:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfig()
|
|
|
|
{
|
|
|
|
// Plugin is disabled
|
2018-08-19 17:39:33 +08:00
|
|
|
$this->get('/admin/plugins/config/fake-plugin-with-config-view')
|
|
|
|
->assertNotFound();
|
2017-11-16 10:09:58 +08:00
|
|
|
|
|
|
|
// Plugin is enabled but it doesn't have config view
|
2018-08-19 17:39:33 +08:00
|
|
|
plugin('fake-plugin-for-test')->setEnabled(true);
|
2017-11-16 10:09:58 +08:00
|
|
|
$this->get('/admin/plugins/config/avatar-api')
|
2019-02-16 21:12:06 +08:00
|
|
|
->assertSee(trans('admin.plugins.operations.no-config-notice'))
|
2018-08-19 17:39:33 +08:00
|
|
|
->assertNotFound();
|
2017-11-16 10:09:58 +08:00
|
|
|
|
|
|
|
// Plugin has config view
|
2018-08-19 17:54:00 +08:00
|
|
|
plugin('fake-plugin-with-config-view')->setEnabled(true);
|
|
|
|
$this->get('/admin/plugins/config/fake-plugin-with-config-view')
|
2018-07-13 15:38:22 +08:00
|
|
|
->assertSuccessful();
|
2017-11-16 10:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testManage()
|
|
|
|
{
|
|
|
|
// An not-existed plugin
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', ['name' => 'nope'])
|
|
|
|
->assertJson([
|
2017-11-16 10:09:58 +08:00
|
|
|
'errno' => 1,
|
|
|
|
'msg' => trans('admin.plugins.operations.not-found')
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Invalid action
|
2018-08-19 17:39:33 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', ['name' => 'fake-plugin-for-test'])
|
2018-07-13 15:38:22 +08:00
|
|
|
->assertJson([
|
2017-11-16 10:09:58 +08:00
|
|
|
'errno' => 1,
|
|
|
|
'msg' => trans('admin.invalid-action')
|
|
|
|
]);
|
|
|
|
|
2018-06-29 18:26:48 +08:00
|
|
|
// Enable a plugin with unsatisfied dependencies
|
2018-08-19 17:39:33 +08:00
|
|
|
app('plugins')->getPlugin('fake-plugin-for-test')->setRequirements([
|
2018-09-06 19:31:35 +08:00
|
|
|
'blessing-skin-server' => '^3.4.0 || ^4.0.0',
|
2018-08-19 17:39:33 +08:00
|
|
|
'fake-plugin-with-config-view' => '^6.6.6',
|
2018-06-29 18:26:48 +08:00
|
|
|
'whatever' => '^1.0.0'
|
|
|
|
]);
|
2018-08-19 17:39:33 +08:00
|
|
|
app('plugins')->enable('fake-plugin-with-config-view');
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', [
|
2018-08-19 17:39:33 +08:00
|
|
|
'name' => 'fake-plugin-for-test',
|
2018-06-29 18:26:48 +08:00
|
|
|
'action' => 'enable'
|
2018-07-13 15:38:22 +08:00
|
|
|
])->assertJson([
|
2018-06-29 18:26:48 +08:00
|
|
|
'errno' => 1,
|
2018-06-29 20:54:40 +08:00
|
|
|
'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
|
|
|
|
'reason' => [
|
2018-06-29 18:26:48 +08:00
|
|
|
trans('admin.plugins.operations.unsatisfied.version', [
|
2018-08-19 17:39:33 +08:00
|
|
|
'name' => 'fake-plugin-with-config-view',
|
2018-06-29 20:54:40 +08:00
|
|
|
'constraint' => '^6.6.6'
|
2018-06-29 18:26:48 +08:00
|
|
|
]),
|
|
|
|
trans('admin.plugins.operations.unsatisfied.disabled', [
|
2018-06-29 20:54:40 +08:00
|
|
|
'name' => 'whatever'
|
2018-06-29 18:26:48 +08:00
|
|
|
])
|
2018-06-29 20:54:40 +08:00
|
|
|
]
|
2018-06-29 18:26:48 +08:00
|
|
|
]);
|
|
|
|
|
2017-11-16 10:09:58 +08:00
|
|
|
// Enable a plugin
|
2018-08-19 17:39:33 +08:00
|
|
|
app('plugins')->getPlugin('fake-plugin-for-test')->setRequirements([]);
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', [
|
2018-08-19 17:39:33 +08:00
|
|
|
'name' => 'fake-plugin-for-test',
|
2017-11-16 10:09:58 +08:00
|
|
|
'action' => 'enable'
|
2018-07-13 15:38:22 +08:00
|
|
|
])->assertJson([
|
2017-11-16 10:09:58 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans(
|
|
|
|
'admin.plugins.operations.enabled',
|
2018-08-19 17:39:33 +08:00
|
|
|
['plugin' => plugin('fake-plugin-for-test')->title]
|
2017-11-16 10:09:58 +08:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Disable a plugin
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', [
|
2018-08-19 17:39:33 +08:00
|
|
|
'name' => 'fake-plugin-for-test',
|
2017-11-16 10:09:58 +08:00
|
|
|
'action' => 'disable'
|
2018-07-13 15:38:22 +08:00
|
|
|
])->assertJson([
|
2017-11-16 10:09:58 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans(
|
|
|
|
'admin.plugins.operations.disabled',
|
2018-08-19 17:39:33 +08:00
|
|
|
['plugin' => plugin('fake-plugin-for-test')->title]
|
2017-11-16 10:09:58 +08:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Delete a plugin
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->postJson('/admin/plugins/manage', [
|
2018-08-19 17:39:33 +08:00
|
|
|
'name' => 'fake-plugin-for-test',
|
2017-11-16 10:09:58 +08:00
|
|
|
'action' => 'delete'
|
2018-07-13 15:38:22 +08:00
|
|
|
])->assertJson([
|
2017-11-16 10:09:58 +08:00
|
|
|
'errno' => 0,
|
|
|
|
'msg' => trans('admin.plugins.operations.deleted')
|
|
|
|
]);
|
2018-08-19 17:39:33 +08:00
|
|
|
$this->assertFalse(file_exists(base_path('plugins/fake-plugin-for-test/')));
|
2017-11-16 10:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPluginData()
|
|
|
|
{
|
2018-07-13 15:38:22 +08:00
|
|
|
$this->getJson('/admin/plugins/data')
|
|
|
|
->assertJsonStructure([
|
2018-08-19 17:39:33 +08:00
|
|
|
[
|
2017-11-16 10:09:58 +08:00
|
|
|
'name',
|
|
|
|
'version',
|
|
|
|
'title',
|
|
|
|
'description',
|
2018-08-11 23:36:28 +08:00
|
|
|
'author',
|
2017-11-16 10:09:58 +08:00
|
|
|
'url',
|
2018-08-11 23:36:28 +08:00
|
|
|
'enabled',
|
2018-08-19 17:39:33 +08:00
|
|
|
'config',
|
2018-08-11 23:36:28 +08:00
|
|
|
'dependencies'
|
2018-08-19 17:39:33 +08:00
|
|
|
]
|
2017-11-16 10:09:58 +08:00
|
|
|
]);
|
|
|
|
}
|
2018-08-19 17:39:33 +08:00
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
// Clean fake plugins
|
|
|
|
File::deleteDirectory(base_path('plugins/fake-plugin-for-test'));
|
|
|
|
File::deleteDirectory(base_path('plugins/fake-plugin-with-config-view'));
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2017-11-16 10:09:58 +08:00
|
|
|
}
|