2009-05-13 02:00:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TemplateTask file
|
|
|
|
*
|
|
|
|
* Test Case for TemplateTask generation shell task
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-05-13 02:00:30 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-13 02:00:30 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-05-13 02:00:30 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
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');
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2009-05-13 02:00:30 +00:00
|
|
|
/**
|
|
|
|
* TemplateTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
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
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* setUp method
|
2009-05-13 02:00:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +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
|
|
|
/**
|
2011-12-04 21:27:51 +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']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('two', $this->Task->templateVars['one']);
|
2009-05-13 02:00:30 +00:00
|
|
|
|
|
|
|
$this->Task->set(array('one' => 'three', 'four' => 'five'));
|
|
|
|
$this->assertTrue(isset($this->Task->templateVars['one']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('three', $this->Task->templateVars['one']);
|
2009-05-13 02:00:30 +00:00
|
|
|
$this->assertTrue(isset($this->Task->templateVars['four']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('five', $this->Task->templateVars['four']);
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->Task->templateVars);
|
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-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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
|
|
|
/**
|
2012-12-22 22:48:15 +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
|
2009-07-01 04:24:20 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetThemePath() {
|
2012-03-11 04:32:02 +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();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($defaultTheme, $result);
|
2009-07-01 04:24:20 +00:00
|
|
|
|
2012-04-24 00:46:20 +00:00
|
|
|
$this->Task->templatePaths = array('other' => '/some/path', 'default' => $defaultTheme);
|
2009-07-01 04:24:20 +00:00
|
|
|
$this->Task->params['theme'] = 'other';
|
|
|
|
$result = $this->Task->getThemePath();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/some/path', $result);
|
2009-07-01 04:24:20 +00:00
|
|
|
|
|
|
|
$this->Task->params = array();
|
|
|
|
$result = $this->Task->getThemePath();
|
2012-04-24 00:46:20 +00:00
|
|
|
$this->assertEquals('/some/path', $result);
|
|
|
|
$this->assertEquals('other', $this->Task->params['theme']);
|
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(
|
2012-03-11 04:32:02 +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";
|
2012-04-24 00:40:42 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|
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(
|
2012-03-11 04:32:02 +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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/ArticleFixture extends CakeTestFixture/', $result);
|
2009-07-01 04:24:20 +00:00
|
|
|
}
|
2009-05-13 02:00:30 +00:00
|
|
|
}
|