PluginAssetsShellTest.php 4.9 KB

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