Skip to content

Commit

Permalink
PluginsControllerTest (#2840)
Browse files Browse the repository at this point in the history
Co-authored-by: ryuring <[email protected]>
  • Loading branch information
nghiem-mb and ryuring authored Nov 2, 2023
1 parent 492ccd3 commit 4fb5a35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

use BaserCore\Test\Factory\PluginFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BaserCore\Utility\BcUtil;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use Cake\TestSuite\IntegrationTestTrait;
use BaserCore\Controller\Admin\PluginsController;
use Cake\Event\Event;
Expand Down Expand Up @@ -179,13 +179,10 @@ public function testDetachAndInstallAndUninstall(): void

$from = BcUtil::getPluginPath('BcBlog');
$pluginDir = dirname($from);
$folder = new Folder();
$folder = new BcFolder($from);
$folder->create();
$to = $pluginDir . DS . 'BcBlogBak';
$folder->copy($to, [
'from' => $from,
'mode' => 0777
]);
$folder->create($from, 0777);
$folder->copy($from, $to);
$this->post('/baser/admin/baser-core/plugins/uninstall/BcBlog', $data);
$this->assertRedirect([
'plugin' => 'BaserCore',
Expand All @@ -194,11 +191,7 @@ public function testDetachAndInstallAndUninstall(): void
'action' => 'index'
]);
$this->assertFlashMessage('プラグイン「BcBlog」を削除しました。');
$folder->move($from, [
'from' => $to,
'mode' => 0777,
'schema' => Folder::OVERWRITE
]);
$folder->move($from, $to);
$this->put('/baser/admin/baser-core/plugins/install/BcBlog', $data);
}

Expand All @@ -212,9 +205,8 @@ public function testUpdate(): void
$this->enableCsrfToken();
$path = Plugin::path('BcPluginSample');
rename($path . 'VERSION.txt', $path . 'VERSION.bak.txt');
$file = new File($path . 'VERSION.txt');
$file = new BcFile($path . 'VERSION.txt');
$file->write('0.0.2');
$file->close();
PluginFactory::make(['name' => 'BcPluginSample', 'version' => '0.0.1'])->persist();
$this->put('/baser/admin/baser-core/plugins/update/BcPluginSample', [
'connection' => 'test',
Expand Down Expand Up @@ -244,16 +236,14 @@ public function testUpdateCore(): void
copy(ROOT . DS . 'composer.lock', ROOT . DS . 'composer.lock.bak');

// replace を削除
$file = new File(ROOT . DS . 'composer.json');
$file = new BcFile(ROOT . DS . 'composer.json');
$data = $file->read();
$regex = '/("replace": {.+?},)/s';
$data = preg_replace($regex, '' , $data);
$file->write($data);
$file->close();

$file = new File(BASER . 'VERSION.txt');
$file = new BcFile(BASER . 'VERSION.txt');
$file->write('5.0.0');
$file->close();
$this->put('/baser/admin/baser-core/plugins/update', [
'connection' => 'test',
'update' => 1,
Expand Down Expand Up @@ -311,9 +301,9 @@ public function test_add()

$path = BASER_PLUGINS . 'BcPluginSample';
$zipSrcPath = TMP . 'zip' . DS;
$folder = new Folder();
$folder->create($zipSrcPath, 0777);
$folder->copy($zipSrcPath . 'BcPluginSample2', ['from' => $path, 'mode' => 0777]);
$folder = new BcFolder($zipSrcPath. 'BcPluginSample2');
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
$plugin = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand All @@ -338,8 +328,9 @@ public function test_add()
]);
$this->assertFlashMessage('新規プラグイン「' . $plugin . '」を追加しました。');

$folder = new Folder();
$folder->delete(BASER_PLUGINS . $plugin);
$folder->delete($zipSrcPath);
$folder = new BcFolder(BASER_PLUGINS . $plugin);
$folder->delete();
$folder = new BcFolder($zipSrcPath);
$folder->delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace BaserCore\Test\TestCase\Controller\Api\Admin;

use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFolder;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
Expand Down Expand Up @@ -122,13 +123,13 @@ public function testInstall($pluginName, $statusCode, $message)
'permission' => "1"
];
$pluginPath = App::path('plugins')[0] . DS . 'BcTest';
$folder = new Folder($pluginPath);
$folder->create($pluginPath, 0777);
$folder = new BcFolder($pluginPath);
$folder->create();
$this->post('/baser/api/admin/baser-core/plugins/install/' . $pluginName .'.json?token=' . $this->accessToken, $data);
$this->assertResponseCode($statusCode);
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals($message, $result->message);
$folder->delete($pluginPath);
$folder->delete();
}
public function installDataProvider()
{
Expand Down Expand Up @@ -208,9 +209,9 @@ public function test_add()

$path = BASER_PLUGINS . 'BcPluginSample';
$zipSrcPath = TMP . 'zip' . DS;
$folder = new Folder();
$folder->create($zipSrcPath, 0777);
$folder->copy($zipSrcPath . 'BcPluginSample2', ['from' => $path, 'mode' => 0777]);
$folder = new BcFolder($zipSrcPath. 'BcPluginSample2');
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcPluginSample2');
$plugin = 'BcPluginSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand All @@ -222,9 +223,8 @@ public function test_add()
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals('新規プラグイン「' . $plugin . '」を追加しました。', $result->message);

$folder = new Folder();
$folder->delete(BASER_PLUGINS . $plugin);
$folder->delete($zipSrcPath);
$folder = new BcFolder(BASER_PLUGINS . $plugin);
$folder->delete();
}

/**
Expand Down

0 comments on commit 4fb5a35

Please sign in to comment.