|
|
@@ -14,17 +14,21 @@ declare(strict_types=1);
|
|
|
* @since 3.0.0
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
|
|
*/
|
|
|
-namespace Cake\Test\TestCase\Shell\Task;
|
|
|
+namespace Cake\Test\TestCase\Command;
|
|
|
|
|
|
+use Cake\Console\Command;
|
|
|
use Cake\Core\Configure;
|
|
|
use Cake\Filesystem\Filesystem;
|
|
|
+use Cake\TestSuite\ConsoleIntegrationTestTrait;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
|
|
/**
|
|
|
- * AssetsTaskTest class
|
|
|
+ * PluginAssetsCommandsTest class
|
|
|
*/
|
|
|
-class AssetsTaskTest extends TestCase
|
|
|
+class PluginAssetsCommandsTest extends TestCase
|
|
|
{
|
|
|
+ use ConsoleIntegrationTestTrait;
|
|
|
+
|
|
|
protected $wwwRoot;
|
|
|
|
|
|
/**
|
|
|
@@ -50,17 +54,15 @@ class AssetsTaskTest extends TestCase
|
|
|
->disableOriginalConstructor()
|
|
|
->getMock();
|
|
|
|
|
|
- $this->Task = $this->getMockBuilder('Cake\Shell\Task\AssetsTask')
|
|
|
- ->setMethods(['in', 'out', 'err', '_stop'])
|
|
|
- ->setConstructorArgs([$this->io])
|
|
|
- ->getMock();
|
|
|
-
|
|
|
$this->wwwRoot = TMP . 'assets_task_webroot' . DS;
|
|
|
Configure::write('App.wwwRoot', $this->wwwRoot);
|
|
|
|
|
|
$this->fs = new Filesystem();
|
|
|
$this->fs->deleteDir($this->wwwRoot);
|
|
|
$this->fs->copyDir(WWW_ROOT, $this->wwwRoot);
|
|
|
+
|
|
|
+ $this->useCommandRunner();
|
|
|
+ $this->setAppNamespace();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -71,7 +73,6 @@ class AssetsTaskTest extends TestCase
|
|
|
public function tearDown(): void
|
|
|
{
|
|
|
parent::tearDown();
|
|
|
- unset($this->Task);
|
|
|
$this->clearPlugins();
|
|
|
}
|
|
|
|
|
|
@@ -82,9 +83,10 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testSymlink()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
- $this->Task->symlink();
|
|
|
+ $this->exec('plugin assets symlink');
|
|
|
+ $this->assertExitCode(Command::CODE_SUCCESS);
|
|
|
|
|
|
$path = $this->wwwRoot . 'test_plugin';
|
|
|
$this->assertFileExists($path . DS . 'root.js');
|
|
|
@@ -113,7 +115,7 @@ class AssetsTaskTest extends TestCase
|
|
|
|
|
|
mkdir($this->wwwRoot . 'company');
|
|
|
|
|
|
- $this->Task->symlink();
|
|
|
+ $this->exec('plugin assets symlink');
|
|
|
$path = $this->wwwRoot . 'company' . DS . 'test_plugin_three';
|
|
|
if (DS === '\\') {
|
|
|
$this->assertDirectoryExits($path);
|
|
|
@@ -153,7 +155,7 @@ class AssetsTaskTest extends TestCase
|
|
|
{
|
|
|
$this->loadPlugins(['TestPluginTwo']);
|
|
|
|
|
|
- $this->Task->symlink();
|
|
|
+ $this->exec('plugin assets symlink');
|
|
|
$this->assertFileNotExists($this->wwwRoot . 'test_plugin_two');
|
|
|
}
|
|
|
|
|
|
@@ -164,9 +166,9 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testSymlinkingSpecifiedPlugin()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
- $this->Task->symlink('TestPlugin');
|
|
|
+ $this->exec('plugin assets symlink', ['TestPlugin']);
|
|
|
|
|
|
$path = $this->wwwRoot . 'test_plugin';
|
|
|
$link = new \SplFileInfo($path);
|
|
|
@@ -185,9 +187,9 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testCopy()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
- $this->Task->copy();
|
|
|
+ $this->exec('plugin assets copy');
|
|
|
|
|
|
$path = $this->wwwRoot . 'test_plugin';
|
|
|
$this->assertDirectoryExists($path);
|
|
|
@@ -205,9 +207,9 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testCopyOverwrite()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false]]);
|
|
|
|
|
|
- $this->Task->copy();
|
|
|
+ $this->exec('plugin assets copy');
|
|
|
|
|
|
$pluginPath = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot';
|
|
|
|
|
|
@@ -218,12 +220,11 @@ class AssetsTaskTest extends TestCase
|
|
|
|
|
|
file_put_contents($path . DS . 'root.js', 'updated');
|
|
|
|
|
|
- $this->Task->copy();
|
|
|
+ $this->exec('plugin assets copy');
|
|
|
|
|
|
$this->assertFileNotEquals($path . DS . 'root.js', $pluginPath . DS . 'root.js');
|
|
|
|
|
|
- $this->Task->params['overwrite'] = true;
|
|
|
- $this->Task->copy();
|
|
|
+ $this->exec('plugin assets copy', ['--overwrite']);
|
|
|
|
|
|
$this->assertFileEquals($path . DS . 'root.js', $pluginPath . DS . 'root.js');
|
|
|
}
|
|
|
@@ -241,18 +242,18 @@ class AssetsTaskTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
mkdir($this->wwwRoot . 'company');
|
|
|
|
|
|
- $this->Task->symlink();
|
|
|
+ $this->exec('plugin assets symlink');
|
|
|
|
|
|
$this->assertTrue(is_link($this->wwwRoot . 'test_plugin'));
|
|
|
|
|
|
$path = $this->wwwRoot . 'company' . DS . 'test_plugin_three';
|
|
|
$this->assertTrue(is_link($path));
|
|
|
|
|
|
- $this->Task->remove();
|
|
|
+ $this->exec('plugin assets remove');
|
|
|
|
|
|
$this->assertFalse(is_link($this->wwwRoot . 'test_plugin'));
|
|
|
$this->assertFalse(is_link($path));
|
|
|
@@ -268,15 +269,15 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testRemoveFolder()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
- $this->Task->copy();
|
|
|
+ $this->exec('plugin assets copy');
|
|
|
|
|
|
$this->assertTrue(is_dir($this->wwwRoot . 'test_plugin'));
|
|
|
|
|
|
$this->assertTrue(is_dir($this->wwwRoot . 'company' . DS . 'test_plugin_three'));
|
|
|
|
|
|
- $this->Task->remove();
|
|
|
+ $this->exec('plugin assets remove');
|
|
|
|
|
|
$this->assertDirectoryNotExists($this->wwwRoot . 'test_plugin');
|
|
|
$this->assertDirectoryNotExists($this->wwwRoot . 'company' . DS . 'test_plugin_three');
|
|
|
@@ -292,7 +293,7 @@ class AssetsTaskTest extends TestCase
|
|
|
*/
|
|
|
public function testOverwrite()
|
|
|
{
|
|
|
- $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
|
|
|
+ $this->loadPlugins(['TestPlugin' => ['routes' => false], 'Company/TestPluginThree']);
|
|
|
|
|
|
$path = $this->wwwRoot . 'test_plugin';
|
|
|
|
|
|
@@ -300,8 +301,7 @@ class AssetsTaskTest extends TestCase
|
|
|
$filectime = filectime($path);
|
|
|
|
|
|
sleep(1);
|
|
|
- $this->Task->params['overwrite'] = true;
|
|
|
- $this->Task->symlink('TestPlugin');
|
|
|
+ $this->exec('plugin assets symlink', ['TestPlugin', '--overwrite']);
|
|
|
if (DS === '\\') {
|
|
|
$this->assertDirectoryExists($path);
|
|
|
} else {
|
|
|
@@ -322,8 +322,7 @@ class AssetsTaskTest extends TestCase
|
|
|
$filectime = filectime($path);
|
|
|
|
|
|
sleep(1);
|
|
|
- $this->Task->params['overwrite'] = true;
|
|
|
- $this->Task->copy('Company/TestPluginThree');
|
|
|
+ $this->exec('plugin assets copy', ['Company/TestPluginThree', '--overwrite']);
|
|
|
|
|
|
$newfilectime = filectime($path);
|
|
|
$this->assertTrue($newfilectime > $filectime);
|