adding tests for engine overrides

This commit is contained in:
Rachman Chavik 2012-02-14 22:56:48 +07:00
parent 369d316835
commit fe479c636c
8 changed files with 85 additions and 6 deletions

View file

@ -29,6 +29,10 @@ class NumberHelperTestObject extends NumberHelper {
$this->_CakeNumber = $cakeNumber; $this->_CakeNumber = $cakeNumber;
} }
public function engine() {
return $this->_CakeNumber;
}
} }
/** /**
@ -82,4 +86,23 @@ class NumberHelperTest extends CakeTestCase {
} }
} }
/**
* test engine override
*/
public function testEngineOverride() {
App::build(array(
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
), APP::REGISTER);
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
$this->assertInstanceOf('TestAppEngine', $Number->engine());
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
$this->assertInstanceOf('TestPluginEngine', $Number->engine());
CakePlugin::unload('TestPlugin');
}
} }

View file

@ -26,6 +26,10 @@ class TextHelperTestObject extends TextHelper {
$this->_String = $string; $this->_String = $string;
} }
public function engine() {
return $this->_String;
}
} }
/** /**
@ -78,6 +82,25 @@ class TextHelperTest extends CakeTestCase {
} }
} }
/**
* test engine override
*/
public function testEngineOverride() {
App::build(array(
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
), APP::REGISTER);
$Text = new TextHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
$this->assertInstanceOf('TestAppEngine', $Text->engine());
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$Text = new TextHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
$this->assertInstanceOf('TestPluginEngine', $Text->engine());
CakePlugin::unload('TestPlugin');
}
/** /**
* testAutoLink method * testAutoLink method
* *

View file

@ -29,6 +29,10 @@ class TimeHelperTestObject extends TimeHelper {
$this->_CakeTime = $cakeTime; $this->_CakeTime = $cakeTime;
} }
public function engine() {
return $this->_CakeTime;
}
} }
/** /**
@ -88,4 +92,23 @@ class TimeHelperTest extends CakeTestCase {
} }
} }
/**
* test engine override
*/
public function testEngineOverride() {
App::build(array(
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
), APP::REGISTER);
$Time = new TimeHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
$this->assertInstanceOf('TestAppEngine', $Time->engine());
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$Time = new TimeHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
$this->assertInstanceOf('TestPluginEngine', $Time->engine());
CakePlugin::unload('TestPlugin');
}
} }

View file

@ -0,0 +1,5 @@
<?php
class TestPluginEngine {
}

View file

@ -0,0 +1,5 @@
<?php
class TestAppEngine {
}

View file

@ -45,8 +45,8 @@ class NumberHelper extends AppHelper {
function __construct(View $View, $settings = array()) { function __construct(View $View, $settings = array()) {
$settings = Set::merge(array('engine' => 'CakeNumber'), $settings); $settings = Set::merge(array('engine' => 'CakeNumber'), $settings);
parent::__construct($View, $settings); parent::__construct($View, $settings);
$engineClass = $settings['engine']; list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
App::uses($engineClass, 'Utility'); App::uses($engineClass, $plugin . 'Utility');
if (class_exists($engineClass)) { if (class_exists($engineClass)) {
$this->_CakeNumber = new $engineClass($settings); $this->_CakeNumber = new $engineClass($settings);
} else { } else {

View file

@ -62,8 +62,8 @@ class TextHelper extends AppHelper {
public function __construct(View $View, $settings = array()) { public function __construct(View $View, $settings = array()) {
$settings = Set::merge(array('engine' => 'String'), $settings); $settings = Set::merge(array('engine' => 'String'), $settings);
parent::__construct($View, $settings); parent::__construct($View, $settings);
$engineClass = $settings['engine']; list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
App::uses($engineClass, 'Utility'); App::uses($engineClass, $plugin . 'Utility');
if (class_exists($engineClass)) { if (class_exists($engineClass)) {
$this->_String = new $engineClass($settings); $this->_String = new $engineClass($settings);
} else { } else {

View file

@ -46,8 +46,8 @@ class TimeHelper extends AppHelper {
public function __construct(View $View, $settings = array()) { public function __construct(View $View, $settings = array()) {
$settings = Set::merge(array('engine' => 'CakeTime'), $settings); $settings = Set::merge(array('engine' => 'CakeTime'), $settings);
parent::__construct($View, $settings); parent::__construct($View, $settings);
$engineClass = $settings['engine']; list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
App::uses($engineClass, 'Utility'); App::uses($engineClass, $plugin . 'Utility');
if (class_exists($engineClass)) { if (class_exists($engineClass)) {
$this->_CakeTime = new $engineClass($settings); $this->_CakeTime = new $engineClass($settings);
} else { } else {