| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- /**
- * CakePHP : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://cakephp.org CakePHP Project
- * @since 3.0.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Shell\Task;
- use Cake\Core\Plugin;
- use Cake\Filesystem\Folder;
- use Cake\TestSuite\TestCase;
- /**
- * AssetsTaskTest class
- */
- class AssetsTaskTest extends TestCase
- {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp()
- {
- parent::setUp();
- $this->skipIf(
- DS === '\\',
- 'Skip AssetsTask tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
- );
- $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
- ->disableOriginalConstructor()
- ->getMock();
- $this->Task = $this->getMockBuilder('Cake\Shell\Task\AssetsTask')
- ->setMethods(['in', 'out', 'err', '_stop'])
- ->setConstructorArgs([$this->io])
- ->getMock();
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown()
- {
- parent::tearDown();
- unset($this->Task);
- Plugin::unload();
- }
- /**
- * testSymlink method
- *
- * @return void
- */
- public function testSymlink()
- {
- Plugin::load('TestPlugin');
- Plugin::load('Company/TestPluginThree');
- $this->Task->symlink();
- $path = WWW_ROOT . 'test_plugin';
- $link = new \SplFileInfo($path);
- $this->assertFileExists($path . DS . 'root.js');
- if (DS === '\\') {
- $this->assertTrue($link->isDir());
- $folder = new Folder($path);
- $folder->delete();
- } else {
- $this->assertTrue($link->isLink());
- unlink($path);
- }
- $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
- $link = new \SplFileInfo($path);
- // If "company" directory exists beforehand "test_plugin_three" would
- // be a link. But if the directory is created by the shell itself
- // symlinking fails and the assets folder is copied as fallback.
- $this->assertTrue($link->isDir());
- $this->assertFileExists($path . DS . 'css' . DS . 'company.css');
- $folder = new Folder(WWW_ROOT . 'company');
- $folder->delete();
- }
- /**
- * testSymlinkWhenVendorDirectoryExits
- *
- * @return void
- */
- public function testSymlinkWhenVendorDirectoryExits()
- {
- Plugin::load('Company/TestPluginThree');
- mkdir(WWW_ROOT . 'company');
- $this->Task->symlink();
- $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
- $link = new \SplFileInfo($path);
- if (DS === '\\') {
- $this->assertTrue($link->isDir());
- } else {
- $this->assertTrue($link->isLink());
- }
- $this->assertFileExists($path . DS . 'css' . DS . 'company.css');
- $folder = new Folder(WWW_ROOT . 'company');
- $folder->delete();
- }
- /**
- * testSymlinkWhenTargetAlreadyExits
- *
- * @return void
- */
- public function testSymlinkWhenTargetAlreadyExits()
- {
- Plugin::load('TestTheme');
- $shell = $this->getMockBuilder('Cake\Shell\Task\AssetsTask')
- ->setMethods(['in', 'out', 'err', '_stop', '_createSymlink', '_copyDirectory'])
- ->setConstructorArgs([$this->io])
- ->getMock();
- $this->assertDirectoryExists(WWW_ROOT . 'test_theme');
- $shell->expects($this->never())->method('_createSymlink');
- $shell->expects($this->never())->method('_copyDirectory');
- $shell->symlink();
- }
- /**
- * test that plugins without webroot are not processed
- *
- * @return void
- */
- public function testForPluginWithoutWebroot()
- {
- Plugin::load('TestPluginTwo');
- $this->Task->symlink();
- $this->assertFileNotExists(WWW_ROOT . 'test_plugin_two');
- }
- /**
- * testSymlinkingSpecifiedPlugin
- *
- * @return void
- */
- public function testSymlinkingSpecifiedPlugin()
- {
- Plugin::load('TestPlugin');
- Plugin::load('Company/TestPluginThree');
- $this->Task->symlink('TestPlugin');
- $path = WWW_ROOT . 'test_plugin';
- $link = new \SplFileInfo($path);
- $this->assertFileExists($path . DS . 'root.js');
- unlink($path);
- $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
- $link = new \SplFileInfo($path);
- $this->assertFalse($link->isDir());
- $this->assertFalse($link->isLink());
- }
- /**
- * testCopy
- *
- * @return void
- */
- public function testCopy()
- {
- Plugin::load('TestPlugin');
- Plugin::load('Company/TestPluginThree');
- $this->Task->copy();
- $path = WWW_ROOT . 'test_plugin';
- $dir = new \SplFileInfo($path);
- $this->assertTrue($dir->isDir());
- $this->assertFileExists($path . DS . 'root.js');
- $folder = new Folder($path);
- $folder->delete();
- $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
- $link = new \SplFileInfo($path);
- $this->assertTrue($link->isDir());
- $this->assertFileExists($path . DS . 'css' . DS . 'company.css');
- $folder = new Folder(WWW_ROOT . 'company');
- $folder->delete();
- }
- /**
- * testCopyOverwrite
- *
- * @return void
- */
- public function testCopyOverwrite()
- {
- Plugin::load('TestPlugin');
- $this->Task->copy();
- $pluginPath = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'webroot';
- $path = WWW_ROOT . 'test_plugin';
- $dir = new \SplFileInfo($path);
- $this->assertTrue($dir->isDir());
- $this->assertFileExists($path . DS . 'root.js');
- file_put_contents($path . DS . 'root.js', 'updated');
- $this->Task->copy();
- $this->assertFileNotEquals($path . DS . 'root.js', $pluginPath . DS . 'root.js');
- $this->Task->params['overwrite'] = true;
- $this->Task->copy();
- $this->assertFileEquals($path . DS . 'root.js', $pluginPath . DS . 'root.js');
- $folder = new Folder($path);
- $folder->delete();
- }
- }
|