UpgradeCommandTest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Command;
  17. use Cake\Core\Configure;
  18. use Cake\TestSuite\ConsoleIntegrationTestTrait;
  19. use Cake\TestSuite\TestCase;
  20. use org\bovigo\vfs\vfsStream;
  21. use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
  22. /**
  23. * UpgradeCommand test.
  24. */
  25. class UpgradeCommandTest extends TestCase
  26. {
  27. use ConsoleIntegrationTestTrait;
  28. protected $dirStructure = [
  29. 'forTemplate' => [
  30. 'src' => [
  31. 'Template' => [
  32. 'Email' => ['html' => ['def.php' => '']],
  33. 'Element' => ['foo.ctp' => ''],
  34. 'Layout' => ['default.ctp' => ''],
  35. 'Cell' => [
  36. 'MyCell' => ['display.ctp' => ''],
  37. ],
  38. 'Plugin' => [
  39. 'TestPlugin' => [
  40. 'Layout' => ['Email' => ['text.php' => '']],
  41. 'Element' => ['bar.ctp' => ''],
  42. 'Posts' => ['index.ctp' => ''],
  43. ],
  44. ],
  45. 'Pages' => [
  46. 'home.ctp' => '',
  47. ],
  48. ],
  49. ],
  50. 'plugins' => [
  51. 'TestPlugin' => [
  52. 'src' => [
  53. // This is ensure "src/Cell" does not get renamed.
  54. 'Cell' => [
  55. 'TestPluginCell.php' => '',
  56. ],
  57. 'Template' => [
  58. 'Element' => [
  59. 'foo.ctp' => '',
  60. ],
  61. 'Layout' => [
  62. 'plugin.ctp' => '',
  63. 'Email' => ['html.php' => ''],
  64. ],
  65. 'Cell' => [
  66. 'TestPluginCell' => ['bar.ctp' => ''],
  67. ],
  68. ],
  69. ],
  70. ],
  71. 'PluginWithoutTemplates' => [
  72. 'src' => [],
  73. ],
  74. ],
  75. ],
  76. 'forLocale' => [
  77. 'src' => [
  78. 'Locale' => [
  79. 'default.pot' => '',
  80. 'en' => [
  81. 'default.po' => '',
  82. ],
  83. ],
  84. ],
  85. 'plugins' => [
  86. 'TestVendor' => [
  87. 'TestPlugin' => [
  88. 'src' => [
  89. 'Locale' => [
  90. 'default.pot' => '',
  91. 'fr' => [
  92. 'default.po' => '',
  93. ],
  94. ],
  95. ],
  96. ],
  97. ],
  98. 'TestPluginWithLocale' => [
  99. 'src' => [],
  100. ],
  101. ],
  102. ],
  103. ];
  104. /**
  105. * pluginPaths
  106. *
  107. * @var array
  108. */
  109. protected $pluginPaths = [];
  110. /**
  111. * localePaths
  112. *
  113. * @var array
  114. */
  115. protected $localePaths = [];
  116. /**
  117. * Namespace
  118. *
  119. * @var string
  120. */
  121. protected $namespace = '';
  122. /**
  123. * setup method
  124. *
  125. * @return void
  126. */
  127. public function setUp()
  128. {
  129. parent::setUp();
  130. $this->useCommandRunner(true);
  131. $this->fs = vfsStream::setup('root');
  132. $this->pluginPaths = Configure::read('App.paths.plugins');
  133. Configure::write('App.paths.plugins', [$this->fs->url() . '/plugins'], true);
  134. $this->localePaths = Configure::read('App.paths.locales');
  135. Configure::write('App.paths.locales', [$this->fs->url() . '/src/Locale'], true);
  136. $this->namespace = Configure::read('App.namespace');
  137. Configure::write('App.namespace', 'TestApp');
  138. }
  139. /**
  140. * tearDown
  141. *
  142. * @return void
  143. */
  144. public function tearDown()
  145. {
  146. Configure::write('App.paths.plugins', $this->pluginPaths);
  147. Configure::write('App.paths.locales', $this->localePaths);
  148. Configure::write('App.namespace', $this->namespace);
  149. }
  150. /**
  151. * testUpgradeTemplate
  152. *
  153. * @return void
  154. */
  155. public function testUpgradeTemplate()
  156. {
  157. vfsStream::create($this->dirStructure['forTemplate']);
  158. $this->exec('upgrade templates --path ' . $this->fs->url());
  159. $ds = [
  160. 'src' => [],
  161. 'templates' => [
  162. 'email' => ['html' => ['def.php' => '']],
  163. 'element' => ['foo.php' => ''],
  164. 'layout' => ['default.php' => ''],
  165. 'cell' => [
  166. 'MyCell' => ['display.php' => ''],
  167. ],
  168. 'plugin' => [
  169. 'TestPlugin' => [
  170. 'layout' => ['email' => ['text.php' => '']],
  171. 'element' => ['bar.php' => ''],
  172. 'Posts' => ['index.php' => ''],
  173. ],
  174. ],
  175. 'Pages' => [
  176. 'home.php' => '',
  177. ],
  178. ],
  179. 'plugins' => [
  180. 'TestPlugin' => [
  181. 'src' => [
  182. // This is ensure "src/Cell" does not get renamed.
  183. 'Cell' => [
  184. 'TestPluginCell.php' => '',
  185. ],
  186. ],
  187. 'templates' => [
  188. 'element' => [
  189. 'foo.php' => '',
  190. ],
  191. 'layout' => [
  192. 'plugin.php' => '',
  193. 'email' => ['html.php' => ''],
  194. ],
  195. 'cell' => [
  196. 'TestPluginCell' => ['bar.php' => ''],
  197. ],
  198. ],
  199. ],
  200. 'PluginWithoutTemplates' => [
  201. 'src' => [],
  202. ],
  203. ],
  204. ];
  205. $this->assertEquals(
  206. ['root' => $ds],
  207. vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure()
  208. );
  209. }
  210. /**
  211. * testUpgradeLocale
  212. *
  213. * @return void
  214. */
  215. public function testUpgradeLocale()
  216. {
  217. vfsStream::create($this->dirStructure['forLocale']);
  218. $this->exec('upgrade locales --path ' . $this->fs->url());
  219. $ds = [
  220. 'src' => [],
  221. 'resources' => [
  222. 'locales' => [
  223. 'default.pot' => '',
  224. 'en' => [
  225. 'default.po' => '',
  226. ],
  227. ],
  228. ],
  229. 'plugins' => [
  230. 'TestVendor' => [
  231. 'TestPlugin' => [
  232. 'src' => [],
  233. 'resources' => [
  234. 'locales' => [
  235. 'default.pot' => '',
  236. 'fr' => [
  237. 'default.po' => '',
  238. ],
  239. ],
  240. ],
  241. ],
  242. ],
  243. 'TestPluginWithLocale' => [
  244. 'src' => [],
  245. ],
  246. ],
  247. ];
  248. $this->assertEquals(
  249. ['root' => $ds],
  250. vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure()
  251. );
  252. }
  253. }