2009-05-13 02:00:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TemplateTask file
|
|
|
|
*
|
|
|
|
* Test Case for TemplateTask generation shell task
|
|
|
|
*
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-10-24 20:58:22 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-10-24 20:58:22 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
2009-05-13 02:00:30 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-07 05:31:45 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('TemplateTask', 'Console/Command/Task');
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
|
|
|
* TemplateTaskTest class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
2009-05-13 02:00:30 +00:00
|
|
|
*/
|
|
|
|
class TemplateTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
2010-09-25 04:47:32 +00:00
|
|
|
* setup method
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-25 04:47:32 +00:00
|
|
|
public function setup() {
|
2010-10-07 02:52:42 +00:00
|
|
|
parent::setUp();
|
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2011-04-17 10:18:25 +00:00
|
|
|
$this->Task = $this->getMock('TemplateTask',
|
2010-10-07 02:52:42 +00:00
|
|
|
array('in', 'err', 'createFile', '_stop', 'clear'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-09 04:22:31 +00:00
|
|
|
);
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
2010-09-25 04:47:32 +00:00
|
|
|
* teardown method
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-07 02:52:42 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
|
|
|
* test that set sets variables
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSet() {
|
2009-05-13 02:00:30 +00:00
|
|
|
$this->Task->set('one', 'two');
|
|
|
|
$this->assertTrue(isset($this->Task->templateVars['one']));
|
|
|
|
$this->assertEqual($this->Task->templateVars['one'], 'two');
|
|
|
|
|
|
|
|
$this->Task->set(array('one' => 'three', 'four' => 'five'));
|
|
|
|
$this->assertTrue(isset($this->Task->templateVars['one']));
|
|
|
|
$this->assertEqual($this->Task->templateVars['one'], 'three');
|
|
|
|
$this->assertTrue(isset($this->Task->templateVars['four']));
|
|
|
|
$this->assertEqual($this->Task->templateVars['four'], 'five');
|
2011-04-17 10:18:25 +00:00
|
|
|
|
2010-09-18 04:13:03 +00:00
|
|
|
$this->Task->templateVars = array();
|
|
|
|
$this->Task->set(array(3 => 'three', 4 => 'four'));
|
|
|
|
$this->Task->set(array(1 => 'one', 2 => 'two'));
|
|
|
|
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
|
|
|
|
$this->assertEqual($this->Task->templateVars, $expected);
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
2009-07-24 19:18:37 +00:00
|
|
|
* test finding themes installed in
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testFindingInstalledThemesForBake() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$consoleLibs = CAKE . 'Console' . DS;
|
2009-05-13 02:00:30 +00:00
|
|
|
$this->Task->initialize();
|
2011-01-08 13:02:05 +00:00
|
|
|
$this->assertEqual($this->Task->templatePaths['default'], $consoleLibs . 'templates' . DS . 'default' . DS);
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetThemePath() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$defaultTheme = CAKE . 'Console' . DS . 'templates' . DS . 'default' .DS;
|
2009-07-01 04:24:20 +00:00
|
|
|
$this->Task->templatePaths = array('default' => $defaultTheme);
|
2010-06-09 04:22:31 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
|
2009-07-01 04:24:20 +00:00
|
|
|
|
|
|
|
$result = $this->Task->getThemePath();
|
|
|
|
$this->assertEqual($result, $defaultTheme);
|
|
|
|
|
|
|
|
$this->Task->templatePaths = array('default' => $defaultTheme, 'other' => '/some/path');
|
|
|
|
$this->Task->params['theme'] = 'other';
|
|
|
|
$result = $this->Task->getThemePath();
|
|
|
|
$this->assertEqual($result, '/some/path');
|
|
|
|
|
|
|
|
$this->Task->params = array();
|
|
|
|
$result = $this->Task->getThemePath();
|
|
|
|
$this->assertEqual($result, $defaultTheme);
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->assertEqual($this->Task->params['theme'], 'default');
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
|
|
|
* test generate
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGenerate() {
|
2009-07-26 05:29:08 +00:00
|
|
|
App::build(array(
|
2011-03-07 05:31:45 +00:00
|
|
|
'Console' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS
|
2009-07-26 05:29:08 +00:00
|
|
|
)
|
|
|
|
));
|
2009-07-01 04:24:20 +00:00
|
|
|
$this->Task->initialize();
|
2010-06-09 04:22:31 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
|
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
|
2009-05-13 02:00:30 +00:00
|
|
|
$expected = "I got rendered\nfoo";
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-01 04:24:20 +00:00
|
|
|
/**
|
|
|
|
* test generate with a missing template in the chosen theme.
|
|
|
|
* ensure fallback to default works.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGenerateWithTemplateFallbacks() {
|
2009-07-26 05:29:08 +00:00
|
|
|
App::build(array(
|
2011-03-07 05:31:45 +00:00
|
|
|
'Console' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS,
|
2009-07-26 05:29:08 +00:00
|
|
|
CAKE_CORE_INCLUDE_PATH . DS . 'console' . DS
|
|
|
|
)
|
|
|
|
));
|
2009-07-01 04:24:20 +00:00
|
|
|
$this->Task->initialize();
|
|
|
|
$this->Task->params['theme'] = 'test';
|
|
|
|
$this->Task->set(array(
|
|
|
|
'model' => 'Article',
|
|
|
|
'table' => 'articles',
|
|
|
|
'import' => false,
|
|
|
|
'records' => false,
|
|
|
|
'schema' => ''
|
|
|
|
));
|
|
|
|
$result = $this->Task->generate('classes', 'fixture');
|
|
|
|
$this->assertPattern('/ArticleFixture extends CakeTestFixture/', $result);
|
|
|
|
}
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|