mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
adding tests for engine overrides
This commit is contained in:
parent
369d316835
commit
fe479c636c
8 changed files with 85 additions and 6 deletions
|
@ -29,6 +29,10 @@ class NumberHelperTestObject extends NumberHelper {
|
|||
$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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ class TextHelperTestObject extends TextHelper {
|
|||
$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
|
||||
*
|
||||
|
|
|
@ -29,6 +29,10 @@ class TimeHelperTestObject extends TimeHelper {
|
|||
$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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
class TestPluginEngine {
|
||||
|
||||
}
|
5
lib/Cake/Test/test_app/Utility/TestAppEngine.php
Normal file
5
lib/Cake/Test/test_app/Utility/TestAppEngine.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
class TestAppEngine {
|
||||
|
||||
}
|
|
@ -45,8 +45,8 @@ class NumberHelper extends AppHelper {
|
|||
function __construct(View $View, $settings = array()) {
|
||||
$settings = Set::merge(array('engine' => 'CakeNumber'), $settings);
|
||||
parent::__construct($View, $settings);
|
||||
$engineClass = $settings['engine'];
|
||||
App::uses($engineClass, 'Utility');
|
||||
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
|
||||
App::uses($engineClass, $plugin . 'Utility');
|
||||
if (class_exists($engineClass)) {
|
||||
$this->_CakeNumber = new $engineClass($settings);
|
||||
} else {
|
||||
|
|
|
@ -62,8 +62,8 @@ class TextHelper extends AppHelper {
|
|||
public function __construct(View $View, $settings = array()) {
|
||||
$settings = Set::merge(array('engine' => 'String'), $settings);
|
||||
parent::__construct($View, $settings);
|
||||
$engineClass = $settings['engine'];
|
||||
App::uses($engineClass, 'Utility');
|
||||
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
|
||||
App::uses($engineClass, $plugin . 'Utility');
|
||||
if (class_exists($engineClass)) {
|
||||
$this->_String = new $engineClass($settings);
|
||||
} else {
|
||||
|
|
|
@ -46,8 +46,8 @@ class TimeHelper extends AppHelper {
|
|||
public function __construct(View $View, $settings = array()) {
|
||||
$settings = Set::merge(array('engine' => 'CakeTime'), $settings);
|
||||
parent::__construct($View, $settings);
|
||||
$engineClass = $settings['engine'];
|
||||
App::uses($engineClass, 'Utility');
|
||||
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
|
||||
App::uses($engineClass, $plugin . 'Utility');
|
||||
if (class_exists($engineClass)) {
|
||||
$this->_CakeTime = new $engineClass($settings);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue