| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Dojo
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- // Call Zend_Dojo_Form_Element_EditorTest::main() if this source file is executed directly.
- if (!defined("PHPUnit_MAIN_METHOD")) {
- define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_EditorTest::main");
- }
- /** Zend_Dojo_Form_Element_Editor */
- require_once 'Zend/Dojo/Form/Element/Editor.php';
- /** Zend_View */
- require_once 'Zend/View.php';
- /** Zend_Registry */
- require_once 'Zend/Registry.php';
- /** Zend_Dojo_View_Helper_Dojo */
- require_once 'Zend/Dojo/View/Helper/Dojo.php';
- /**
- * Test class for Zend_Dojo_Form_Element_Editor.
- *
- * @category Zend
- * @package Zend_Dojo
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Dojo
- * @group Zend_Dojo_Form
- */
- class Zend_Dojo_Form_Element_EditorTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs the test methods of this class.
- *
- * @return void
- */
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_EditorTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- /**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- *
- * @return void
- */
- public function setUp()
- {
- Zend_Registry::_unsetInstance();
- Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
- $this->view = $this->getView();
- $this->element = $this->getElement();
- $this->element->setView($this->view);
- }
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- *
- * @return void
- */
- public function tearDown()
- {
- }
- public function getView()
- {
- require_once 'Zend/View.php';
- $view = new Zend_View();
- $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
- return $view;
- }
- public function getElement()
- {
- $element = new Zend_Dojo_Form_Element_Editor(
- 'foo',
- array(
- 'value' => 'some text',
- 'label' => 'Editor',
- 'class' => 'someclass',
- 'style' => 'width: 100px;',
- )
- );
- return $element;
- }
- public function testShouldRenderEditorDijit()
- {
- $html = $this->element->render();
- $this->assertContains('dojoType="dijit.Editor"', $html, $html);
- }
- public function testShouldNotHaveCaptureEventsByDefault()
- {
- $events = $this->element->getCaptureEvents();
- $this->assertTrue(empty($events));
- }
- public function testCaptureEventAccessorsShouldProxyToDijitParams()
- {
- $this->element->setCaptureEvents(array('foo.bar', 'bar.baz', 'baz.bat'));
- $this->assertTrue($this->element->hasDijitParam('captureEvents'));
- $this->assertTrue($this->element->hasCaptureEvent('bar.baz'));
- $this->assertEquals($this->element->getDijitParam('captureEvents'), $this->element->getCaptureEvents());
- $this->element->removeCaptureEvent('bar.baz');
- $this->assertFalse($this->element->hasCaptureEvent('bar.baz'), var_export($this->element->getCaptureEvents(), 1));
- $events = $this->element->getDijitParam('captureEvents');
- $this->assertNotContains('bar.baz', $events, var_export($events, 1));
- }
- public function testShouldNotHaveEventsByDefault()
- {
- $events = $this->element->getEvents();
- $this->assertTrue(empty($events));
- }
- public function testEventAccessorsShouldProxyToDijitParams()
- {
- $this->element->setEvents(array('onClick', 'onKeyUp', 'onKeyDown'));
- $this->assertTrue($this->element->hasDijitParam('events'));
- $this->assertTrue($this->element->hasEvent('onKeyUp'));
- $this->assertEquals($this->element->getDijitParam('events'), $this->element->getEvents());
- $this->element->removeEvent('onKeyUp');
- $this->assertFalse($this->element->hasEvent('onKeyUp'), var_export($this->element->getEvents(), 1));
- $events = $this->element->getDijitParam('events');
- $this->assertNotContains('onKeyUp', $events, var_export($events, 1));
- }
- public function testShouldNotHavePluginsByDefault()
- {
- $plugins = $this->element->getPlugins();
- $this->assertTrue(empty($plugins));
- }
- public function testPluginAccessorsShouldProxyToDijitParams()
- {
- $this->element->setPlugins(array('undo', 'bold', 'italic'));
- $this->assertTrue($this->element->hasDijitParam('plugins'));
- $this->assertTrue($this->element->hasPlugin('bold'));
- $this->assertEquals($this->element->getDijitParam('plugins'), $this->element->getPlugins());
- $this->element->removePlugin('bold');
- $this->assertFalse($this->element->hasPlugin('bold'), var_export($this->element->getPlugins(), 1));
- $plugins = $this->element->getDijitParam('plugins');
- $this->assertNotContains('bold', $plugins, var_export($plugins, 1));
- }
- public function testEditActionIntervalShouldDefaultToThree()
- {
- $this->assertEquals(3, $this->element->getEditActionInterval());
- }
- public function testEditActionIntervalAccessorsShouldProxyToDijitParams()
- {
- $this->element->setEditActionInterval(60);
- $this->assertEquals($this->element->getDijitParam('editActionInterval'), $this->element->getEditActionInterval());
- $this->assertEquals(60, $this->element->getEditActionInterval());
- }
- public function testFocusOnLoadShouldBeFalseByDefault()
- {
- $this->assertFalse($this->element->getFocusOnLoad());
- }
- public function testFocusOnLoadAccessorsShouldProxyToDijitParams()
- {
- $this->element->setFocusOnLoad(true);
- $this->assertEquals($this->element->getDijitParam('focusOnLoad'), $this->element->getFocusOnLoad());
- $this->assertTrue($this->element->getFocusOnLoad());
- }
- public function testHeightShouldHaveDefaultValue()
- {
- $this->assertEquals('300px', $this->element->getHeight());
- }
- public function testHeightAccessorsShouldProxyToDijitParams()
- {
- $this->element->setHeight('25em');
- $this->assertEquals($this->element->getDijitParam('height'), $this->element->getHeight());
- $this->assertEquals('25em', $this->element->getHeight());
- }
- public function testInheritWidthShouldBeFalseByDefault()
- {
- $this->assertFalse($this->element->getInheritWidth());
- }
- public function testInheritWidthAccessorsShouldProxyToDijitParams()
- {
- $this->element->setInheritWidth(true);
- $this->assertEquals($this->element->getDijitParam('inheritWidth'), $this->element->getInheritWidth());
- $this->assertTrue($this->element->getInheritWidth());
- }
- public function testMinHeightShouldHaveDefaultValue()
- {
- $this->assertEquals('1em', $this->element->getMinHeight());
- }
- public function testMinHeightAccessorsShouldProxyToDijitParams()
- {
- $this->element->setMinHeight('25em');
- $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
- $this->assertEquals('25em', $this->element->getMinHeight());
- }
- public function testShouldNotHaveStyleSheetsByDefault()
- {
- $styleSheets = $this->element->getStyleSheets();
- $this->assertTrue(empty($styleSheets));
- }
- public function testStyleSheetAccessorsShouldProxyToDijitParams()
- {
- $this->element->setStyleSheets(array('/js/dojo/resources/dojo.css', '/js/custom/styles.css', '/js/dijit/themes/tundra/tundra.css'));
- $this->assertTrue($this->element->hasDijitParam('styleSheets'));
- $this->assertTrue($this->element->hasStyleSheet('/js/custom/styles.css'));
- $this->assertEquals($this->element->getDijitParam('styleSheets'), $this->element->getStyleSheets());
- $this->element->removeStyleSheet('/js/custom/styles.css');
- $this->assertFalse($this->element->hasStyleSheet('/js/custom/styles.css'), var_export($this->element->getStyleSheets(), 1));
- $styleSheets = $this->element->getDijitParam('styleSheets');
- $this->assertNotContains('/js/custom/styles.css', $styleSheets, var_export($styleSheets, 1));
- }
- public function testUpdateIntervalShouldHaveDefaultValue()
- {
- $this->assertEquals(200, $this->element->getUpdateInterval());
- }
- public function testUpdateIntervalAccessorsShouldProxyToDijitParams()
- {
- $this->element->setUpdateInterval(300);
- $this->assertEquals($this->element->getDijitParam('updateInterval'), $this->element->getUpdateInterval());
- $this->assertEquals(300, $this->element->getUpdateInterval());
- }
-
- public function testCanAddMultipleSeparatorsToEditor()
- {
- $this->element->setPlugins(array('undo', '|', 'bold', '|', 'italic'));
-
- $plugins = $this->element->getPlugins();
- $this->assertEquals(5, count($plugins));
- }
-
- public function testMinHeightCanBeSetToPixels()
- {
- $this->element->setMinHeight('250px');
- $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
- $this->assertEquals('250px', $this->element->getMinHeight());
- }
-
- public function testMinHeightCanBeSetToPercentage()
- {
- $this->element->setMinHeight('50%');
- $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
- $this->assertEquals('50%', $this->element->getMinHeight());
- }
-
- public function testMinHeightDefaultMeasurementIsEm()
- {
- $this->element->setMinHeight('10');
- $this->assertEquals($this->element->getDijitParam('minHeight'), $this->element->getMinHeight());
- $this->assertEquals('10em', $this->element->getMinHeight());
- }
- /** @group ZF-11511 */
- public function testShouldNotHaveExtraPluginsByDefault()
- {
- $extraPlugins = $this->element->getExtraPlugins();
- $this->assertTrue(empty($extraPlugins));
- }
- /** @group ZF-11511 */
- public function testExtraPluginAccessorsShouldProxyToDijitParams()
- {
- $this->element->setExtraPlugins(array('undo', 'bold', 'italic'));
- $this->assertTrue($this->element->hasDijitParam('extraPlugins'));
- $this->assertTrue($this->element->hasExtraPlugin('bold'));
- $this->assertEquals($this->element->getDijitParam('extraPlugins'), $this->element->getExtraPlugins());
- $this->element->removeExtraPlugin('bold');
- $this->assertFalse($this->element->hasExtraPlugin('bold'), var_export($this->element->getExtraPlugins(), 1));
- $extraPlugins = $this->element->getDijitParam('extraPlugins');
- $this->assertNotContains('bold', $extraPlugins, var_export($extraPlugins, 1));
- }
- }
- // Call Zend_Dojo_Form_Element_EditorTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_EditorTest::main") {
- Zend_Dojo_Form_Element_EditorTest::main();
- }
|