addJavascript('alert();'); } /** * @expectedException Zend_View_Exception */ public function testHelperFailingCallForward() { $jquery = new ZendX_JQuery_View_Helper_JQuery(); $jquery->addAsdf(); } public function testShouldCallHelperWithoutExceptions() { $jquery = $this->view->jQuery(); $this->assertTrue($jquery instanceof ZendX_JQuery_View_Helper_JQuery_Container); } public function testShouldAllowSpecifyingJQueryVersion() { $this->jquery->setVersion('1.2.3'); $this->assertEquals('1.2.3', $this->jquery->getVersion()); } public function testShouldUseDefaultSupportedVersionWhenNotSpecifiedOtherwise() { $this->assertEquals(ZendX_JQuery::DEFAULT_JQUERY_VERSION, $this->jquery->getVersion()); $this->assertEquals(ZendX_JQuery::DEFAULT_JQUERY_VERSION, $this->jquery->getCdnVersion()); } /** * Behaviour changed in 1.8 * * @group ZF-5667 */ public function testUsingCdnShouldNotEnableHelperAnymore() { $this->jquery->setCdnVersion(); $this->assertFalse($this->jquery->isEnabled()); } public function testShouldBeNotEnabledByDefault() { $this->assertFalse($this->jquery->isEnabled()); } public function testUsingLocalPath() { $this->jquery->setLocalPath('/js/jquery.min.js'); $this->assertFalse($this->jquery->useCDN()); $this->assertFalse($this->jquery->isEnabled()); $this->assertTrue($this->jquery->useLocalPath()); $this->assertContains('/js/jquery.min.js', $this->jquery->getLocalPath()); $render = $this->jquery->__toString(); $this->assertNotContains('/js/jquery.min.js', $render); } public function testUiDisabledDefault() { $this->assertFalse($this->jquery->uiIsEnabled()); } public function testUiUsingCdnByDefault() { $this->assertFalse($this->jquery->useUiLocal()); $this->assertTrue($this->jquery->useUiCdn()); $this->assertNull($this->jquery->getUiPath()); } public function testGetUiVersionReturnsDefaultSupportedVersionIfNotSpecifiedOtherwise() { $this->assertEquals(ZendX_JQuery::DEFAULT_UI_VERSION, $this->jquery->getUiVersion()); $this->assertEquals(ZendX_JQuery::DEFAULT_UI_VERSION, $this->jquery->getUiVersion()); } public function testShouldAllowEnableUi() { $this->jquery->uiEnable(); $render = $this->jquery->__toString(); $this->assertContains('jquery-ui', $render); $this->assertContains($this->jquery->getUiVersion(), $render); } public function testShouldAllowSetUiVersion() { $this->jquery->setUiVersion('1.5.1'); $this->assertContains('1.5.1', $this->jquery->getUiVersion()); } public function testShouldAllowSetLocalUiPath() { $this->jquery->setUiLocalPath('/js/jquery-ui.min.js'); $this->assertTrue($this->jquery->useUiLocal()); $this->assertFalse($this->jquery->useUiCdn()); $this->assertContains('/js/jquery-ui.min.js', $this->jquery->getUiPath()); } public function testNoConflictShouldBeDisabledDefault() { $this->assertFalse(ZendX_JQuery_View_Helper_JQuery::getNoConflictMode()); } public function testUsingNoConflictMode() { ZendX_JQuery_View_Helper_JQuery::enableNoConflictMode(); $this->jquery->setCDNVersion('1.2.6'); $this->jquery->enable(); $render = $this->jquery->__toString(); $this->assertContains('var $j = jQuery.noConflict();', $render); } public function testDefaultRenderModeShouldIncludeAllBlocks() { $this->assertEquals(ZendX_JQuery::RENDER_ALL, $this->jquery->getRenderMode()); } public function testShouldAllowSettingRenderMode() { $this->jquery->setRenderMode(1); $this->assertEquals(1, $this->jquery->getRenderMode()); $this->jquery->setRenderMode(2); $this->assertEquals(2, $this->jquery->getRenderMode()); $this->jquery->setRenderMode(4); $this->assertEquals(4, $this->jquery->getRenderMode()); } public function testShouldAllowUsingAddOnLoadStack() { $this->jquery->addOnLoad('$(document).alert();'); $this->assertEquals(array('$(document).alert();'), $this->jquery->getOnLoadActions()); } public function testShouldAllowStackingMultipleOnLoad() { $this->jquery->addOnLoad('1'); $this->jquery->addOnLoad('2'); $this->assertEquals(2, count($this->jquery->getOnLoadActions())); } public function testAddOnLoadEnablesJQuery() { $this->assertFalse($this->jquery->isEnabled()); $this->jquery->addOnLoad('1'); $this->assertTrue($this->jquery->isEnabled()); } public function testShouldAllowCaptureOnLoad() { $this->jquery->onLoadCaptureStart(); echo '$(document).alert();'; $this->jquery->onLoadCaptureEnd(); $this->assertEquals(array('$(document).alert();'), $this->jquery->getOnLoadActions()); } public function testShouldAllowCaptureJavascript() { $this->jquery->javascriptCaptureStart(); echo '$(document).alert();'; $this->jquery->javascriptCaptureEnd(); $this->assertEquals(array('$(document).alert();'), $this->jquery->getJavascript()); $this->jquery->clearJavascript(); $this->assertEquals(array(), $this->jquery->getJavascript()); } /** * @expectedException Zend_Exception */ public function testShouldDisallowNestingCapturesWithException() { $this->jquery->javascriptCaptureStart(); $this->jquery->javascriptCaptureStart(); } /** * @expectedException Zend_Exception */ public function testShouldDisallowNestingCapturesWithException2() { $this->jquery->onLoadCaptureStart(); $this->jquery->onLoadCaptureStart(); $this->setExpectedException('Zend_Exception'); } public function testAddJavascriptFiles() { $this->jquery->addJavascriptFile('/js/test.js'); $this->jquery->addJavascriptFile('/js/test2.js'); $this->jquery->addJavascriptFile('http://example.com/test3.js'); $this->assertEquals(array('/js/test.js', '/js/test2.js', 'http://example.com/test3.js'), $this->jquery->getJavascriptFiles()); } public function testAddedJavascriptFilesCanBeCleared() { $this->jquery->addJavascriptFile('/js/test.js'); $this->jquery->addJavascriptFile('/js/test2.js'); $this->jquery->addJavascriptFile('http://example.com/test3.js'); $this->jquery->clearJavascriptFiles(); $this->assertEquals(array(), $this->jquery->getJavascriptFiles()); } public function testAddedJavascriptFilesRender() { $this->jquery->addJavascriptFile('/js/test.js'); $this->jquery->addJavascriptFile('/js/test2.js'); $this->jquery->addJavascriptFile('http://example.com/test3.js'); $this->jquery->enable(); $render = $this->jquery->__toString(); $this->assertContains('src="/js/test.js"', $render); $this->assertContains('src="/js/test2.js"', $render); $this->assertContains('src="http://example.com/test3.js', $render); } public function testAddStylesheet() { $this->jquery->addStylesheet('test.css'); $this->jquery->addStylesheet('test2.css'); $this->assertEquals(array('test.css', 'test2.css'), $this->jquery->getStylesheets()); } public function testShouldRenderNothingOnDisable() { $this->jquery->setCDNVersion('1.2.6'); $this->jquery->addJavascriptFile('test.js'); $this->jquery->disable(); $this->assertEquals(strlen(''), strlen($this->jquery->__toString())); } public function testShouldAllowBasicSetupWithCDN() { $this->jquery->enable(); $this->jquery->setCDNVersion('1.2.3'); $this->jquery->addJavascriptFile('test.js'); $render = $this->jquery->__toString(); $this->assertTrue($this->jquery->useCDN()); $this->assertContains('jquery.min.js', $render); $this->assertContains('1.2.3', $render); $this->assertContains('test.js', $render); $this->assertContains('