PluginAssetsShellTest.php 5.8 KB

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