Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 122 lines (111 sloc) 3.113 kb
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
<?php
/**
* TemplateTask file
*
* Test Case for TemplateTask generation shell task
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Shell');

if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
}

if (!class_exists('ShellDispatcher')) {
ob_start();
$argv = false;
require CAKE . 'console' . DS . 'cake.php';
ob_end_clean();
}

if (!class_exists('TemplateTask')) {
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
}

Mock::generatePartial(
'ShellDispatcher', 'TestTemplateTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);

Mock::generatePartial(
'TemplateTask', 'MockTemplateTask',
array('in', 'out', 'err', 'createFile', '_stop')
);

/**
* TemplateTaskTest class
*
* @package cake
* @subpackage cake.tests.cases.console.libs.tasks
*/
class TemplateTaskTest extends CakeTestCase {
/**
* setUp method
*
* @return void
* @access public
*/
function startTest() {
$this->Dispatcher =& new TestTemplateTaskMockShellDispatcher();
$this->Task =& new MockTemplateTask($this->Dispatcher);
$this->Task->Dispatch = new $this->Dispatcher;
$this->Task->Dispatch->shellPaths = Configure::read('shellPaths');
}

/**
* tearDown method
*
* @return void
* @access public
*/
function endTest() {
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
}

/**
* test that set sets variables
*
* @return void
**/
function testSet() {
$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');
}

/**
* test Initialize
*
* @return void
**/
function testInitialize() {
$this->Task->initialize();
$this->assertEqual($this->Task->templatePaths, $this->Task->Dispatch->shellPaths);
}

/**
* test generate
*
* @return void
**/
function testGenerate() {
$this->Task->templatePaths = array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
);
$result = $this->Task->generate('objects', 'test_object', array('test' => 'foo'));
$expected = "I got rendered\nfoo";
$this->assertEqual($result, $expected);
}
}
?>
Something went wrong with that request. Please try again.