CellTaskTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * CakePHP(tm) : 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(tm) 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\Task;
  16. use Cake\Core\Configure;
  17. use Cake\Core\Plugin;
  18. use Cake\Shell\Task\TemplateTask;
  19. use Cake\TestSuite\StringCompareTrait;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * CellTaskTest class
  23. */
  24. class CellTaskTest extends TestCase {
  25. use StringCompareTrait;
  26. /**
  27. * setup method
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. $this->_compareBasePath = CORE_TESTS . 'bake_compare' . DS . 'Cell' . DS;
  34. $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  35. $this->Task = $this->getMock(
  36. 'Cake\Shell\Task\CellTask',
  37. ['in', 'err', 'createFile', '_stop'],
  38. [$io]
  39. );
  40. $this->Task->Test = $this->getMock('Cake\Shell\Task\TestTask',
  41. [],
  42. [$io]
  43. );
  44. $this->Task->Template = new TemplateTask($io);
  45. $this->Task->Template->initialize();
  46. $this->Task->Template->interactive = false;
  47. }
  48. /**
  49. * Test the excute method.
  50. *
  51. * @return void
  52. */
  53. public function testMain() {
  54. $this->Task->Test->expects($this->once())
  55. ->method('bake')
  56. ->with('cell', 'Example');
  57. $this->Task->expects($this->at(0))
  58. ->method('createFile')
  59. ->with(
  60. $this->_normalizePath(APP . 'Template/Cell/Example/display.ctp'),
  61. ''
  62. );
  63. $this->Task->expects($this->at(1))
  64. ->method('createFile')
  65. ->with(
  66. $this->_normalizePath(APP . 'View/Cell/ExampleCell.php'),
  67. $this->stringContains('class ExampleCell extends Cell')
  68. );
  69. $this->Task->main('Example');
  70. }
  71. /**
  72. * Test main within a plugin.
  73. *
  74. * @return void
  75. */
  76. public function testMainPlugin() {
  77. Plugin::load('TestPlugin');
  78. $path = Plugin::path('TestPlugin');
  79. $this->Task->expects($this->at(0))
  80. ->method('createFile')
  81. ->with(
  82. $this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'),
  83. ''
  84. );
  85. $this->Task->expects($this->at(1))
  86. ->method('createFile')
  87. ->with(
  88. $this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'),
  89. $this->stringContains('class ExampleCell extends Cell')
  90. );
  91. $this->Task->main('TestPlugin.Example');
  92. }
  93. /**
  94. * Test baking within a plugin.
  95. *
  96. * @return void
  97. */
  98. public function testBakePlugin() {
  99. Plugin::load('TestPlugin');
  100. $path = Plugin::path('TestPlugin');
  101. $this->Task->plugin = 'TestPlugin';
  102. $this->Task->expects($this->at(0))
  103. ->method('createFile')
  104. ->with(
  105. $this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'),
  106. ''
  107. );
  108. $this->Task->expects($this->at(1))
  109. ->method('createFile')
  110. ->with(
  111. $this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'),
  112. $this->stringContains('class ExampleCell extends Cell')
  113. );
  114. $result = $this->Task->bake('Example');
  115. $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
  116. }
  117. }