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 testHelperShouldRenderAlteredId()
{
$html = $this->helper->editor('foo');
$this->assertContains('id="foo-Editor"', $html, $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->assertContains('dojoType="dijit.Editor"', $html);
}
public function testHelperShouldRegisterDijitModule()
{
$html = $this->helper->editor('foo');
$modules = $this->view->dojo()->getModules();
$this->assertContains('dijit.Editor', $modules);
}
public function testHelperShouldNormalizeArrayId()
{
$html = $this->helper->editor('foo[]');
$this->assertContains('id="foo-Editor"', $html, $html);
$html = $this->helper->editor('foo[bar]');
$this->assertContains('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->assertContains('plugins="' . $pluginsString . '"', $html);
}
public function testHelperShouldCreateJavascriptToConnectEditorToHiddenValue()
{
$this->helper->editor('foo');
$onLoadActions = $this->view->dojo()->getOnLoadActions();
$found = false;
foreach ($onLoadActions as $action) {
if (strstr($action, "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());
}
/**
* @group ZF-4461
*/
public function testHelperShouldRegisterPluginModulesWithDojo()
{
$plugins = array(
'createLink' => 'LinkDialog',
'fontName' => 'FontChoice',
);
$html = $this->helper->editor('foo', '', array('plugins' => array_keys($plugins)));
$dojo = $this->view->dojo()->__toString();
foreach (array_values($plugins) as $plugin) {
$this->assertContains('dojo.require("dijit._editor.plugins.' . $plugin . '")', $dojo, $dojo);
}
}
/**
* @group ZF-6753
* @group ZF-8127
*/
public function testHelperShouldUseDivByDefault()
{
$html = $this->helper->editor('foo');
$this->assertRegexp('#?div[^>]*>#', $html, $html);
}
/**
* @group ZF-6753
* @group ZF-8127
*/
public function testHelperShouldOnlyUseTextareaInNoscriptTag()
{
$html = $this->helper->editor('foo');
$this->assertRegexp('#helper->editor('foo', '', array('extraPlugins' => $extraPlugins));
$pluginsString = Zend_Json::encode($extraPlugins);
$pluginsString = str_replace('"', "'", $pluginsString);
$this->assertContains('extraPlugins="' . $pluginsString . '"', $html);
}
}
// 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();
}