AssetsTaskTest.php 5.6 KB

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