TemplateTaskTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\Console\Command\Task;
  16. use Cake\Console\Command\Task\TemplateTask;
  17. use Cake\Core\App;
  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\Console\Command\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 finding themes installed in
  47. *
  48. * @return void
  49. */
  50. public function testFindingInstalledThemesForBake() {
  51. $consoleLibs = CAKE . 'Console' . DS;
  52. $this->Task->initialize();
  53. $this->assertPathEquals($this->Task->templatePaths['default'], $consoleLibs . 'Templates/default/');
  54. }
  55. /**
  56. * test getting the correct theme name. Ensure that with only one theme, or a theme param
  57. * that the user is not bugged. If there are more, find and return the correct theme name
  58. *
  59. * @return void
  60. */
  61. public function testGetThemePath() {
  62. $defaultTheme = CAKE . 'Console/Templates/default/';
  63. $this->Task->templatePaths = array('default' => $defaultTheme);
  64. $this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
  65. $result = $this->Task->getThemePath();
  66. $this->assertEquals($defaultTheme, $result);
  67. $this->Task->templatePaths = array('other' => '/some/path', 'default' => $defaultTheme);
  68. $this->Task->params['theme'] = 'other';
  69. $result = $this->Task->getThemePath();
  70. $this->assertEquals('/some/path', $result);
  71. $this->Task->params = array();
  72. $result = $this->Task->getThemePath();
  73. $this->assertEquals('/some/path', $result);
  74. $this->assertEquals('other', $this->Task->params['theme']);
  75. }
  76. /**
  77. * test generate
  78. *
  79. * @return void
  80. */
  81. public function testGenerate() {
  82. $this->Task->initialize();
  83. $this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
  84. $result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
  85. $expected = "I got rendered\nfoo";
  86. $this->assertTextEquals($expected, $result);
  87. }
  88. /**
  89. * test generate with a missing template in the chosen theme.
  90. * ensure fallback to default works.
  91. *
  92. * @return void
  93. */
  94. public function testGenerateWithTemplateFallbacks() {
  95. $this->Task->initialize();
  96. $this->Task->params['theme'] = 'test';
  97. $this->Task->set(array(
  98. 'name' => 'Article',
  99. 'model' => 'Article',
  100. 'table' => 'articles',
  101. 'import' => false,
  102. 'records' => false,
  103. 'schema' => '',
  104. 'namespace' => ''
  105. ));
  106. $result = $this->Task->generate('classes', 'fixture');
  107. $this->assertRegExp('/ArticleFixture extends .*TestFixture/', $result);
  108. }
  109. }