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)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
2010-07-04 17:14:04 +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
|
2010-07-04 17:14:04 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2010-07-02 02:47:20 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-07-02 02:47:20 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-10 02:09:05 +00:00
|
|
|
App::uses('HelperCollection', 'View');
|
2011-01-28 06:03:08 +00:00
|
|
|
App::uses('HtmlHelper', 'View/Helper');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('View', 'View');
|
2010-07-02 02:47:20 +00:00
|
|
|
|
2011-01-10 02:27:53 +00:00
|
|
|
/**
|
|
|
|
* Extended HtmlHelper
|
|
|
|
*/
|
|
|
|
class HtmlAliasHelper extends HtmlHelper {
|
|
|
|
}
|
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
|
|
|
* Class HelperCollectionTest
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.View
|
|
|
|
*/
|
2010-07-02 02:47:20 +00:00
|
|
|
class HelperCollectionTest extends CakeTestCase {
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2010-07-02 02:47:20 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* setUp
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function tearDown() {
|
2011-05-06 05:53:01 +00:00
|
|
|
CakePlugin::unload();
|
2010-07-03 15:36:53 +00:00
|
|
|
unset($this->Helpers, $this->View);
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::tearDown();
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test triggering callbacks on loaded helpers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoad() {
|
2010-07-02 02:47:20 +00:00
|
|
|
$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
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Helpers->loaded();
|
|
|
|
$this->assertEquals(array('Html'), $result, 'loaded() 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
|
|
|
}
|
|
|
|
|
2012-03-28 04:06:16 +00:00
|
|
|
/**
|
|
|
|
* test lazy loading of helpers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLazyLoad() {
|
|
|
|
$result = $this->Helpers->Html;
|
|
|
|
$this->assertInstanceOf('HtmlHelper', $result);
|
|
|
|
|
|
|
|
$result = $this->Helpers->Form;
|
|
|
|
$this->assertInstanceOf('FormHelper', $result);
|
|
|
|
|
|
|
|
App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
|
|
|
|
$this->View->plugin = 'TestPlugin';
|
|
|
|
CakePlugin::load(array('TestPlugin'));
|
|
|
|
$result = $this->Helpers->OtherHelper;
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $result);
|
|
|
|
}
|
|
|
|
|
2012-03-29 02:42:46 +00:00
|
|
|
/**
|
|
|
|
* test lazy loading of helpers
|
|
|
|
*
|
|
|
|
* @expectedException MissingHelperException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLazyLoadException() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Helpers->NotAHelper;
|
2012-03-29 02:42:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 02:27:53 +00:00
|
|
|
/**
|
|
|
|
* Tests loading as an alias
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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);
|
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Helpers->loaded();
|
|
|
|
$this->assertEquals(array('Html'), $result, 'loaded() results are wrong.');
|
2011-01-10 02:27:53 +00:00
|
|
|
|
|
|
|
$this->assertTrue($this->Helpers->enabled('Html'));
|
|
|
|
|
|
|
|
$result = $this->Helpers->load('Html');
|
|
|
|
$this->assertInstanceOf('HtmlAliasHelper', $result);
|
2011-01-15 01:44:33 +00:00
|
|
|
|
2012-02-18 12:31:29 +00:00
|
|
|
App::build(array('Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2011-01-15 01:44:33 +00:00
|
|
|
$result = $this->Helpers->load('SomeOther', array('className' => 'TestPlugin.OtherHelper'));
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $result);
|
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
|
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Helpers->loaded();
|
|
|
|
$this->assertEquals(array('Html', 'SomeOther'), $result, 'loaded() results are wrong.');
|
2011-01-15 01:44:33 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadWithEnabledFalse() {
|
2010-11-07 04:07:27 +00:00
|
|
|
$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
|
|
|
|
*
|
2011-10-15 18:06:31 +00:00
|
|
|
* @expectedException MissingHelperException
|
2010-07-02 02:47:20 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-15 18:06:31 +00:00
|
|
|
public function testLoadMissingHelper() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
|
2010-07-02 02:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test loading a plugin helper.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadPluginHelper() {
|
2010-07-02 02:47:20 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2010-07-02 02:47:20 +00:00
|
|
|
));
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2010-07-02 02:47:20 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUnload() {
|
2010-07-02 03:58:43 +00:00
|
|
|
$this->Helpers->load('Form');
|
|
|
|
$this->Helpers->load('Html');
|
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Helpers->loaded();
|
2010-07-02 03:58:43 +00:00
|
|
|
$this->assertEquals(array('Form', 'Html'), $result, 'loaded helpers is wrong');
|
|
|
|
|
|
|
|
$this->Helpers->unload('Html');
|
2012-11-16 11:14:28 +00:00
|
|
|
$this->assertNotContains('Html', $this->Helpers->loaded());
|
|
|
|
$this->assertContains('Form', $this->Helpers->loaded());
|
2010-07-02 03:58:43 +00:00
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Helpers->loaded();
|
2010-07-02 03:58:43 +00:00
|
|
|
$this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
|
|
|
|
}
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
}
|