2010-07-02 02:47:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* HelperCollectionTest file
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
2010-07-04 17:14:04 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-07-02 02:47:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
2010-07-04 17:14:04 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2010-07-02 02:47:20 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2010-07-04 17:14:04 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2010-07-02 02:47:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
App::import('Core', 'HelperCollection');
|
|
|
|
App::import('View', 'View');
|
|
|
|
|
2011-01-10 02:27:53 +00:00
|
|
|
/**
|
|
|
|
* Extended HtmlHelper
|
|
|
|
*/
|
|
|
|
App::import('Helper', 'Html');
|
|
|
|
class HtmlAliasHelper extends HtmlHelper {
|
|
|
|
}
|
|
|
|
|
2010-07-02 02:47:20 +00:00
|
|
|
class HelperCollectionTest extends CakeTestCase {
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setup() {
|
2010-07-03 15:36:53 +00:00
|
|
|
$this->View = $this->getMock('View', array(), array(null));
|
|
|
|
$this->Helpers = new HelperCollection($this->View);
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* teardown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function teardown() {
|
2010-07-03 15:36:53 +00:00
|
|
|
unset($this->Helpers, $this->View);
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test triggering callbacks on loaded helpers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoad() {
|
|
|
|
$result = $this->Helpers->load('Html');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('HtmlHelper', $result);
|
|
|
|
$this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
|
2010-07-02 03:00:48 +00:00
|
|
|
|
|
|
|
$result = $this->Helpers->attached();
|
|
|
|
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
|
2010-07-02 03:58:43 +00:00
|
|
|
|
2010-07-02 03:00:48 +00:00
|
|
|
$this->assertTrue($this->Helpers->enabled('Html'));
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 02:27:53 +00:00
|
|
|
/**
|
|
|
|
* Tests loading as an alias
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadWithAlias() {
|
2011-01-14 02:04:06 +00:00
|
|
|
$result = $this->Helpers->load('Html', array('className' => 'HtmlAlias'));
|
2011-01-10 02:27:53 +00:00
|
|
|
$this->assertInstanceOf('HtmlAliasHelper', $result);
|
|
|
|
$this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html);
|
|
|
|
|
|
|
|
$result = $this->Helpers->attached();
|
|
|
|
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
|
|
|
|
|
|
|
|
$this->assertTrue($this->Helpers->enabled('Html'));
|
|
|
|
|
|
|
|
$result = $this->Helpers->load('Html');
|
|
|
|
$this->assertInstanceOf('HtmlAliasHelper', $result);
|
2011-01-15 01:44:33 +00:00
|
|
|
|
|
|
|
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)));
|
|
|
|
$result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper'));
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $result);
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
|
|
|
|
|
|
|
|
$result = $this->Helpers->attached();
|
|
|
|
$this->assertEquals(array('Html', 'SomeOther'), $result, 'attached() results are wrong.');
|
|
|
|
App::build();
|
2011-01-10 02:27:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 03:15:48 +00:00
|
|
|
/**
|
2010-11-07 04:07:27 +00:00
|
|
|
* test that the enabled setting disables the helper.
|
2010-07-03 03:15:48 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-11-07 04:07:27 +00:00
|
|
|
function testLoadWithEnabledFalse() {
|
|
|
|
$result = $this->Helpers->load('Html', array('enabled' => false));
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('HtmlHelper', $result);
|
|
|
|
$this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
|
2010-11-06 18:58:27 +00:00
|
|
|
|
|
|
|
$this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled');
|
|
|
|
}
|
|
|
|
|
2010-07-02 02:47:20 +00:00
|
|
|
/**
|
|
|
|
* test missinghelper exception
|
|
|
|
*
|
|
|
|
* @expectedException MissingHelperFileException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadMissingHelperFile() {
|
|
|
|
$result = $this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test loading a plugin helper.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadPluginHelper() {
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
|
|
));
|
|
|
|
$result = $this->Helpers->load('TestPlugin.OtherHelper');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $result, 'Helper class is wrong.');
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->OtherHelper, 'Class is wrong');
|
2010-07-02 02:47:20 +00:00
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
2010-07-02 03:58:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test unload()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUnload() {
|
|
|
|
$this->Helpers->load('Form');
|
|
|
|
$this->Helpers->load('Html');
|
|
|
|
|
|
|
|
$result = $this->Helpers->attached();
|
|
|
|
$this->assertEquals(array('Form', 'Html'), $result, 'loaded helpers is wrong');
|
|
|
|
|
|
|
|
$this->Helpers->unload('Html');
|
|
|
|
$this->assertFalse(isset($this->Helpers->Html));
|
|
|
|
$this->assertTrue(isset($this->Helpers->Form));
|
|
|
|
|
|
|
|
$result = $this->Helpers->attached();
|
|
|
|
$this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
|
|
|
|
}
|
|
|
|
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|