view = $this->getView(); $this->helper = new Zend_Dojo_View_Helper_Editor(); $this->helper->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 testHelperShouldRenderTextareaWithAlteredId() { $html = $this->helper->editor('foo'); $this->assertRegexp('#]*(id="foo-Editor")#', $html, $html); $this->assertContains('', $html); } public function testHelperShouldRenderHiddenElementWithGivenIdentifier() { $html = $this->helper->editor('foo'); if (!preg_match('#(]*(?:type="hidden")[^>]*>)#', $html, $matches)) { $this->fail('No hidden element generated'); } $this->assertContains('id="foo"', $matches[1]); } public function testHelperShouldRenderDojoTypeWhenUsedDeclaratively() { $html = $this->helper->editor('foo'); $this->assertRegexp('#]*(dojoType="dijit.Editor")#', $html); } public function testHelperShouldRegisterDijitModule() { $html = $this->helper->editor('foo'); $modules = $this->view->dojo()->getModules(); $this->assertContains('dijit.Editor', $modules); } public function testHelperShouldNormalizeArrayName() { $html = $this->helper->editor('foo[]'); $this->assertRegexp('#]*(name="foo\[Editor\]\[\]")#', $html, $html); $this->assertRegexp('#]*(id="foo-Editor")#', $html, $html); $html = $this->helper->editor('foo[bar]'); $this->assertRegexp('#]*(name="foo\[bar\]\[Editor\]")#', $html, $html); $this->assertRegexp('#]*(id="foo-bar-Editor")#', $html, $html); } public function testHelperShouldJsonifyPlugins() { $plugins = array('copy', 'cut', 'paste'); $html = $this->helper->editor('foo', '', array('plugins' => $plugins)); $pluginsString = Zend_Json::encode($plugins); $pluginsString = str_replace('"', "'", $pluginsString); $this->assertRegexp('#]*(plugins="' . preg_quote($pluginsString) . '")#', $html); } public function testHelperShouldCreateJavascriptToConnectTextareaToHiddenValue() { $this->helper->editor('foo'); $onLoadActions = $this->view->dojo()->getOnLoadActions(); $found = false; foreach ($onLoadActions as $action) { if (strstr($action, "dojo.byId('foo').value = dijit.byId('foo-Editor').getValue(false);")) { $found = true; break; } } $this->assertTrue($found, var_export($onLoadActions, 1)); } public function testHelperShouldCreateJavascriptToFindParentForm() { $this->helper->editor('foo'); $javascript = $this->view->dojo()->getJavascript(); $found = false; foreach ($javascript as $action) { if (strstr($action, "zend.findParentForm = function")) { $found = true; break; } } $this->assertTrue($found, var_export($javascript, 1)); } public function testHelperShouldNotRegisterDojoStylesheet() { $this->helper->editor('foo'); $this->assertFalse($this->view->dojo()->registerDojoStylesheet()); } } // Call Zend_Dojo_View_Helper_EditorTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_EditorTest::main") { Zend_Dojo_View_Helper_EditorTest::main(); }