TemplateTaskTest.php 2.6 KB

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