TemplateTaskTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\Core\Plugin;
  18. use Cake\Shell\Task\TemplateTask;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * TemplateTaskTest class
  22. */
  23. class TemplateTaskTest 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('Cake\Shell\Task\TemplateTask',
  33. array('in', 'err', 'createFile', '_stop', 'clear'),
  34. array($io)
  35. );
  36. }
  37. /**
  38. * tearDown method
  39. *
  40. * @return void
  41. */
  42. public function tearDown() {
  43. parent::tearDown();
  44. unset($this->Task);
  45. Plugin::unload();
  46. }
  47. /**
  48. * test generate
  49. *
  50. * @return void
  51. */
  52. public function testGenerate() {
  53. $this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
  54. $result = $this->Task->generate('classes/test_object', array('test' => 'foo'));
  55. $expected = "I got rendered\nfoo";
  56. $this->assertTextEquals($expected, $result);
  57. }
  58. /**
  59. * test generate with an overriden template it gets used
  60. *
  61. * @return void
  62. */
  63. public function testGenerateWithTemplateOverride() {
  64. Plugin::load('TestBakeTheme');
  65. $this->Task->params['theme'] = 'TestBakeTheme';
  66. $this->Task->set(array(
  67. 'plugin' => 'Special'
  68. ));
  69. $result = $this->Task->generate('config/routes');
  70. $this->assertContains('These are my routes. There are many like them but these are my own.', $result);
  71. }
  72. /**
  73. * test generate with a missing template in the chosen template.
  74. * ensure fallback to default works.
  75. *
  76. * @return void
  77. */
  78. public function testGenerateWithTemplateFallbacks() {
  79. Plugin::load('TestBakeTheme');
  80. $this->Task->params['theme'] = 'TestBakeTheme';
  81. $this->Task->set(array(
  82. 'name' => 'Articles',
  83. 'table' => 'articles',
  84. 'import' => false,
  85. 'records' => false,
  86. 'schema' => '',
  87. 'namespace' => ''
  88. ));
  89. $result = $this->Task->generate('tests/fixture');
  90. $this->assertRegExp('/ArticlesFixture extends .*TestFixture/', $result);
  91. }
  92. }