PluginAssetsShellTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  35. $this->shell = $this->getMock(
  36. 'Cake\Shell\PluginAssetsShell',
  37. array('in', 'out', 'err', '_stop'),
  38. array($this->io)
  39. );
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @return void
  45. */
  46. public function tearDown() {
  47. parent::tearDown();
  48. unset($this->shell);
  49. Plugin::unload();
  50. }
  51. /**
  52. * testSymlink method
  53. *
  54. * @return void
  55. */
  56. public function testSymlink() {
  57. Plugin::load('TestPlugin');
  58. Plugin::load('Company/TestPluginThree');
  59. $this->shell->symlink();
  60. $path = WWW_ROOT . 'test_plugin';
  61. $link = new \SplFileInfo($path);
  62. $this->assertTrue(file_exists($path . DS . 'root.js'));
  63. if (DIRECTORY_SEPARATOR === '\\') {
  64. $this->assertTrue($link->isDir());
  65. $folder = new Folder($path);
  66. $folder->delete();
  67. } else {
  68. $this->assertTrue($link->isLink());
  69. unlink($path);
  70. }
  71. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  72. $link = new \SplFileInfo($path);
  73. // If "company" directory exists beforehand "test_plugin_three" would
  74. // be a link. But if the directory is created by the shell itself
  75. // symlinking fails and the assets folder is copied as fallback.
  76. $this->assertTrue($link->isDir());
  77. $this->assertTrue(file_exists($path . DS . 'css' . DS . 'company.css'));
  78. $folder = new Folder(WWW_ROOT . 'company');
  79. $folder->delete();
  80. }
  81. /**
  82. * testSymlinkWhenVendorDirectoryExits
  83. *
  84. * @return void
  85. */
  86. public function testSymlinkWhenVendorDirectoryExits() {
  87. Plugin::load('Company/TestPluginThree');
  88. mkdir(WWW_ROOT . 'company');
  89. $this->shell->symlink();
  90. $path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
  91. $link = new \SplFileInfo($path);
  92. $this->assertTrue($link->isLink());
  93. $this->assertTrue(file_exists($path . DS . 'css' . DS . 'company.css'));
  94. $folder = new Folder(WWW_ROOT . 'company');
  95. $folder->delete();
  96. }
  97. /**
  98. * testSymlinkWhenTargetAlreadyExits
  99. *
  100. * @return void
  101. */
  102. public function testSymlinkWhenTargetAlreadyExits() {
  103. Plugin::load('TestTheme');
  104. $shell = $this->getMock(
  105. 'Cake\Shell\PluginAssetsShell',
  106. array('in', 'out', 'err', '_stop', '_createSymlink', '_copyDirectory'),
  107. array($this->io)
  108. );
  109. $this->assertTrue(is_dir(WWW_ROOT . 'test_theme'));
  110. $shell->expects($this->never())->method('_createSymlink');
  111. $shell->expects($this->never())->method('_copyDirectory');
  112. $shell->symlink();
  113. }
  114. /**
  115. * test that plugins without webroot are not processed
  116. *
  117. * @return void
  118. */
  119. public function testForPluginWithoutWebroot() {
  120. Plugin::load('TestPluginTwo');
  121. $this->shell->symlink();
  122. $this->assertFalse(file_exists(WWW_ROOT . 'test_plugin_two'));
  123. }
  124. }