UpgradeCommandTest.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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' => [
  34. 'Flash' => ['default.ctp' => ''],
  35. 'foo.ctp' => '',
  36. ],
  37. 'Layout' => ['default.ctp' => ''],
  38. 'Cell' => [
  39. 'MyCell' => ['display.ctp' => ''],
  40. ],
  41. 'Plugin' => [
  42. 'TestPlugin' => [
  43. 'Layout' => ['Email' => ['text.php' => '']],
  44. 'Element' => ['bar.ctp' => ''],
  45. 'Posts' => ['index.ctp' => ''],
  46. ],
  47. ],
  48. 'Pages' => [
  49. 'home.ctp' => '',
  50. ],
  51. ],
  52. ],
  53. 'plugins' => [
  54. 'TestPlugin' => [
  55. 'src' => [
  56. // This is ensure "src/Cell" does not get renamed.
  57. 'Cell' => [
  58. 'TestPluginCell.php' => '',
  59. ],
  60. 'Template' => [
  61. 'Element' => [
  62. 'foo.ctp' => '',
  63. ],
  64. 'Layout' => [
  65. 'plugin.ctp' => '',
  66. 'Email' => ['html.php' => ''],
  67. ],
  68. 'Cell' => [
  69. 'TestPluginCell' => ['bar.ctp' => ''],
  70. ],
  71. ],
  72. ],
  73. ],
  74. 'PluginWithoutTemplates' => [
  75. 'src' => [],
  76. ],
  77. ],
  78. ],
  79. 'forLocale' => [
  80. 'src' => [
  81. 'Locale' => [
  82. 'default.pot' => '',
  83. 'en' => [
  84. 'default.po' => '',
  85. ],
  86. ],
  87. ],
  88. 'plugins' => [
  89. 'TestVendor' => [
  90. 'TestPlugin' => [
  91. 'src' => [
  92. 'Locale' => [
  93. 'default.pot' => '',
  94. 'fr' => [
  95. 'default.po' => '',
  96. ],
  97. ],
  98. ],
  99. ],
  100. ],
  101. 'TestPluginWithLocale' => [
  102. 'src' => [],
  103. ],
  104. ],
  105. ],
  106. ];
  107. /**
  108. * pluginPaths
  109. *
  110. * @var array
  111. */
  112. protected $pluginPaths = [];
  113. /**
  114. * localePaths
  115. *
  116. * @var array
  117. */
  118. protected $localePaths = [];
  119. /**
  120. * Namespace
  121. *
  122. * @var string
  123. */
  124. protected $namespace = '';
  125. /**
  126. * setup method
  127. *
  128. * @return void
  129. */
  130. public function setUp(): void
  131. {
  132. parent::setUp();
  133. $this->useCommandRunner(true);
  134. $this->fs = vfsStream::setup('root');
  135. $this->pluginPaths = Configure::read('App.paths.plugins');
  136. Configure::write('App.paths.plugins', [$this->fs->url() . '/plugins'], true);
  137. $this->localePaths = Configure::read('App.paths.locales');
  138. Configure::write('App.paths.locales', [$this->fs->url() . '/src/Locale'], true);
  139. $this->namespace = Configure::read('App.namespace');
  140. Configure::write('App.namespace', 'TestApp');
  141. }
  142. /**
  143. * tearDown
  144. *
  145. * @return void
  146. */
  147. public function tearDown(): void
  148. {
  149. Configure::write('App.paths.plugins', $this->pluginPaths);
  150. Configure::write('App.paths.locales', $this->localePaths);
  151. Configure::write('App.namespace', $this->namespace);
  152. }
  153. /**
  154. * testUpgradeTemplate
  155. *
  156. * @return void
  157. */
  158. public function testUpgradeTemplate()
  159. {
  160. vfsStream::create($this->dirStructure['forTemplate']);
  161. $this->exec('upgrade templates --path ' . $this->fs->url());
  162. $ds = [
  163. 'src' => [],
  164. 'templates' => [
  165. 'email' => ['html' => ['def.php' => '']],
  166. 'element' => [
  167. 'flash' => ['default.php' => ''],
  168. 'foo.php' => '',
  169. ],
  170. 'layout' => ['default.php' => ''],
  171. 'cell' => [
  172. 'MyCell' => ['display.php' => ''],
  173. ],
  174. 'plugin' => [
  175. 'TestPlugin' => [
  176. 'layout' => ['email' => ['text.php' => '']],
  177. 'element' => ['bar.php' => ''],
  178. 'Posts' => ['index.php' => ''],
  179. ],
  180. ],
  181. 'Pages' => [
  182. 'home.php' => '',
  183. ],
  184. ],
  185. 'plugins' => [
  186. 'TestPlugin' => [
  187. 'src' => [
  188. // This is ensure "src/Cell" does not get renamed.
  189. 'Cell' => [
  190. 'TestPluginCell.php' => '',
  191. ],
  192. ],
  193. 'templates' => [
  194. 'element' => [
  195. 'foo.php' => '',
  196. ],
  197. 'layout' => [
  198. 'plugin.php' => '',
  199. 'email' => ['html.php' => ''],
  200. ],
  201. 'cell' => [
  202. 'TestPluginCell' => ['bar.php' => ''],
  203. ],
  204. ],
  205. ],
  206. 'PluginWithoutTemplates' => [
  207. 'src' => [],
  208. ],
  209. ],
  210. ];
  211. $this->assertEquals(
  212. ['root' => $ds],
  213. vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure()
  214. );
  215. }
  216. /**
  217. * testUpgradeLocale
  218. *
  219. * @return void
  220. */
  221. public function testUpgradeLocale()
  222. {
  223. vfsStream::create($this->dirStructure['forLocale']);
  224. $this->exec('upgrade locales --path ' . $this->fs->url());
  225. $ds = [
  226. 'src' => [],
  227. 'resources' => [
  228. 'locales' => [
  229. 'default.pot' => '',
  230. 'en' => [
  231. 'default.po' => '',
  232. ],
  233. ],
  234. ],
  235. 'plugins' => [
  236. 'TestVendor' => [
  237. 'TestPlugin' => [
  238. 'src' => [],
  239. 'resources' => [
  240. 'locales' => [
  241. 'default.pot' => '',
  242. 'fr' => [
  243. 'default.po' => '',
  244. ],
  245. ],
  246. ],
  247. ],
  248. ],
  249. 'TestPluginWithLocale' => [
  250. 'src' => [],
  251. ],
  252. ],
  253. ];
  254. $this->assertEquals(
  255. ['root' => $ds],
  256. vfsStream::inspect(new vfsStreamStructureVisitor())->getStructure()
  257. );
  258. }
  259. }