AssetsTaskTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Shell\Task;
  16. use Cake\Core\App;
  17. use Cake\Core\Configure;
  18. use Cake\Core\Plugin;
  19. use Cake\Filesystem\Folder;
  20. use Cake\Shell\Task\AssetsTask;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * AssetsTaskTest class
  24. *
  25. */
  26. class AssetsTaskTest extends TestCase
  27. {
  28. /**
  29. * setUp method
  30. *
  31. * @return void
  32. */
  33. public function setUp()
  34. {
  35. parent::setUp();
  36. $this->skipIf(
  37. DS === '\\',
  38. 'Skip AssetsTask tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
  39. );
  40. $this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  41. $this->Task = $this->getMock(
  42. 'Cake\Shell\Task\AssetsTask',
  43. ['in', 'out', 'err', '_stop'],
  44. [$this->io]
  45. );
  46. }
  47. /**
  48. * tearDown method
  49. *
  50. * @return void
  51. */
  52. public function tearDown()
  53. {
  54. parent::tearDown();
  55. unset($this->Task);
  56. Plugin::unload();
  57. }
  58. /**
  59. * testSymlink method
  60. *
  61. * @return void
  62. */
  63. public function testSymlink()
  64. {
  65. Plugin::load('TestPlugin');
  66. Plugin::load('Company/TestPluginThree');
  67. $this->Task->symlink();
  68. $path = WWW_ROOT . 'test_plugin';
  69. $link = new \SplFileInfo($path);
  70. $this->assertTrue(file_exists($path . DS . 'root.js'));
  71. if (DS === '\\') {
  72. $this->assertTrue($link->isDir());
  73. $folder = new Folder($path);
  74. $folder->delete();
  75. } else {
  76. $this->assertTrue($link->isLink());
  77. unlink($path);
  78. }
  79. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  80. $link = new \SplFileInfo($path);
  81. // If "company" directory exists beforehand "test_plugin_three" would
  82. // be a link. But if the directory is created by the shell itself
  83. // symlinking fails and the assets folder is copied as fallback.
  84. $this->assertTrue($link->isDir());
  85. $this->assertTrue(file_exists($path . DS . 'css' . DS . 'company.css'));
  86. $folder = new Folder(WWW_ROOT . 'company');
  87. $folder->delete();
  88. }
  89. /**
  90. * testSymlinkWhenVendorDirectoryExits
  91. *
  92. * @return void
  93. */
  94. public function testSymlinkWhenVendorDirectoryExits()
  95. {
  96. Plugin::load('Company/TestPluginThree');
  97. mkdir(WWW_ROOT . 'company');
  98. $this->Task->symlink();
  99. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  100. $link = new \SplFileInfo($path);
  101. if (DS === '\\') {
  102. $this->assertTrue($link->isDir());
  103. } else {
  104. $this->assertTrue($link->isLink());
  105. }
  106. $this->assertTrue(file_exists($path . DS . 'css' . DS . 'company.css'));
  107. $folder = new Folder(WWW_ROOT . 'company');
  108. $folder->delete();
  109. }
  110. /**
  111. * testSymlinkWhenTargetAlreadyExits
  112. *
  113. * @return void
  114. */
  115. public function testSymlinkWhenTargetAlreadyExits()
  116. {
  117. Plugin::load('TestTheme');
  118. $shell = $this->getMock(
  119. 'Cake\Shell\Task\AssetsTask',
  120. ['in', 'out', 'err', '_stop', '_createSymlink', '_copyDirectory'],
  121. [$this->io]
  122. );
  123. $this->assertTrue(is_dir(WWW_ROOT . 'test_theme'));
  124. $shell->expects($this->never())->method('_createSymlink');
  125. $shell->expects($this->never())->method('_copyDirectory');
  126. $shell->symlink();
  127. }
  128. /**
  129. * test that plugins without webroot are not processed
  130. *
  131. * @return void
  132. */
  133. public function testForPluginWithoutWebroot()
  134. {
  135. Plugin::load('TestPluginTwo');
  136. $this->Task->symlink();
  137. $this->assertFalse(file_exists(WWW_ROOT . 'test_plugin_two'));
  138. }
  139. /**
  140. * testSymlinkingSpecifiedPlugin
  141. *
  142. * @return void
  143. */
  144. public function testSymlinkingSpecifiedPlugin()
  145. {
  146. Plugin::load('TestPlugin');
  147. Plugin::load('Company/TestPluginThree');
  148. $this->Task->symlink('TestPlugin');
  149. $path = WWW_ROOT . 'test_plugin';
  150. $link = new \SplFileInfo($path);
  151. $this->assertTrue(file_exists($path . DS . 'root.js'));
  152. unlink($path);
  153. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  154. $link = new \SplFileInfo($path);
  155. $this->assertFalse($link->isDir());
  156. $this->assertFalse($link->isLink());
  157. }
  158. /**
  159. * testCopy
  160. *
  161. * @return void
  162. */
  163. public function testCopy()
  164. {
  165. Plugin::load('TestPlugin');
  166. Plugin::load('Company/TestPluginThree');
  167. $this->Task->copy();
  168. $path = WWW_ROOT . 'test_plugin';
  169. $dir = new \SplFileInfo($path);
  170. $this->assertTrue($dir->isDir());
  171. $this->assertTrue(file_exists($path . DS . 'root.js'));
  172. $folder = new Folder($path);
  173. $folder->delete();
  174. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  175. $link = new \SplFileInfo($path);
  176. $this->assertTrue($link->isDir());
  177. $this->assertTrue(file_exists($path . DS . 'css' . DS . 'company.css'));
  178. $folder = new Folder(WWW_ROOT . 'company');
  179. $folder->delete();
  180. }
  181. }