CellTaskTest.php 3.2 KB

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