TemplateTaskTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 1.3.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\App;
  17. use Cake\Shell\Task\TemplateTask;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * TemplateTaskTest class
  21. */
  22. class TemplateTaskTest extends TestCase {
  23. /**
  24. * setUp method
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  31. $this->Task = $this->getMock('Cake\Shell\Task\TemplateTask',
  32. array('in', 'err', 'createFile', '_stop', 'clear'),
  33. array($io)
  34. );
  35. }
  36. /**
  37. * tearDown method
  38. *
  39. * @return void
  40. */
  41. public function tearDown() {
  42. parent::tearDown();
  43. unset($this->Task);
  44. }
  45. /**
  46. * test generate
  47. *
  48. * @return void
  49. */
  50. public function testGenerate() {
  51. $this->Task->initialize();
  52. $this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
  53. $result = $this->Task->generate('classes/test_object', array('test' => 'foo'));
  54. $expected = "I got rendered\nfoo";
  55. $this->assertTextEquals($expected, $result);
  56. }
  57. /**
  58. * test generate with a missing template in the chosen template.
  59. * ensure fallback to default works.
  60. *
  61. * @return void
  62. */
  63. public function testGenerateWithTemplateFallbacks() {
  64. $this->Task->initialize();
  65. $this->Task->params['template'] = 'test';
  66. $this->Task->set(array(
  67. 'name' => 'Articles',
  68. 'table' => 'articles',
  69. 'import' => false,
  70. 'records' => false,
  71. 'schema' => '',
  72. 'namespace' => ''
  73. ));
  74. $result = $this->Task->generate('tests/fixture');
  75. $this->assertRegExp('/ArticlesFixture extends .*TestFixture/', $result);
  76. }
  77. }