TemplateTaskTest.php 3.5 KB

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