/
TemplateTaskTest.php
133 lines (119 loc) · 3.64 KB
/
TemplateTaskTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* TemplateTask file
*
* Test Case for TemplateTask generation shell task
*
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Console\Command\Task;
use Cake\Console\Command\Task\TemplateTask;
use Cake\Core\App;
use Cake\TestSuite\TestCase;
/**
* TemplateTaskTest class
*
* @package Cake.Test.Case.Console.Command.Task
*/
class TemplateTaskTest extends TestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('Cake\Console\Command\Task\TemplateTask',
array('in', 'err', 'createFile', '_stop', 'clear'),
array($out, $out, $in)
);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Task);
}
/**
* test finding themes installed in
*
* @return void
*/
public function testFindingInstalledThemesForBake() {
$consoleLibs = CAKE . 'Console/';
$this->Task->initialize();
$this->assertEquals($this->Task->templatePaths['default'], $consoleLibs . 'Templates/default/');
}
/**
* test getting the correct theme name. Ensure that with only one theme, or a theme param
* that the user is not bugged. If there are more, find and return the correct theme name
*
* @return void
*/
public function testGetThemePath() {
$defaultTheme = CAKE . 'Console/Templates/default/';
$this->Task->templatePaths = array('default' => $defaultTheme);
$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
$result = $this->Task->getThemePath();
$this->assertEquals($defaultTheme, $result);
$this->Task->templatePaths = array('other' => '/some/path', 'default' => $defaultTheme);
$this->Task->params['theme'] = 'other';
$result = $this->Task->getThemePath();
$this->assertEquals('/some/path', $result);
$this->Task->params = array();
$result = $this->Task->getThemePath();
$this->assertEquals('/some/path', $result);
$this->assertEquals('other', $this->Task->params['theme']);
}
/**
* test generate
*
* @return void
*/
public function testGenerate() {
$this->Task->initialize();
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
$expected = "I got rendered\nfoo";
$this->assertTextEquals($expected, $result);
}
/**
* test generate with a missing template in the chosen theme.
* ensure fallback to default works.
*
* @return void
*/
public function testGenerateWithTemplateFallbacks() {
$this->Task->initialize();
$this->Task->params['theme'] = 'test';
$this->Task->set(array(
'model' => 'Article',
'table' => 'articles',
'import' => false,
'records' => false,
'schema' => '',
'namespace' => ''
));
$result = $this->Task->generate('classes', 'fixture');
$this->assertRegExp('/ArticleFixture extends .*TestFixture/', $result);
}
}