/** * @dataProvider dataProviderIsAllowed * @param string $config * @param string $module * @param string $controller * @param string $action * @param array $issuersWithJobs * @param bool $isAllowed * @param string $urn */ public function testIsAllowed($config, $module, $controller, $action, $issuersWithJobs, $isAllowed, $urn = '') { $configMock = $this->getMock('Mage_Core_Model_Config', array('getNode')); $configMock->expects($this->any())->method('getNode')->with($this->equalTo('default/xcom/initializer_acl'))->will($this->returnValue(new Varien_Simplexml_Element($config))); $request = new Mage_Core_Controller_Request_Http(); $request->setControllerModule($module)->setControllerName($controller)->setActionName($action); $request->setRequestUri($urn)->setPathInfo(); $fabricHelper = $this->mockHelper('xcom_xfabric', array('getNodeByXpath')); $fabricHelper->expects($this->any())->method('getNodeByXpath')->will($this->returnValue(1)); $jobResource = $this->mockResource('xcom_initializer/job', array('hasJobsLeft', 'isDataCollected')); $jobResource->expects($this->any())->method('isDataCollected')->will($this->returnValue(empty($issuersWithJobs))); if (empty($issuersWithJobs)) { $jobResource->expects($this->never())->method('hasJobsLeft'); } else { $i = 1; foreach (array('xcom_mapping', 'xcom_other') as $issuer) { $jobResource->expects($this->at($i))->method('hasJobsLeft')->with($this->equalTo($issuer))->will($this->returnValue((int) in_array($issuer, $issuersWithJobs))); $i++; } } Mage::setConfigMock($configMock); $result = $this->_object->isAllowed($request); Mage::setUseMockConfig(false); $this->assertEquals($isAllowed, $result); }
/** * Calls the diehard/load controller without spawning a new request * * @param array $params * @return string */ public function getDynamicBlockReplacement($params) { // Append dynamic block content to end of page to be replaced by javascript, but not Ajax if ($params['blocks'] || !empty($params['all_blocks'])) { // Init store if it has not been yet (page served from cache) if (!$this->helper()->isAppInited()) { $this->helper()->initApp(); } else { // Reset layout Mage::unregister('_singleton/core/layout'); Mage::getSingleton('core/layout'); // TODO Mage::app()->getLayout() is not reset using the method above! // TODO Consider resetting Magento entirely using Mage::reset(); } // Create a sub-request to get JSON response $uri = $this->getBaseUrl() . '/_diehard/load/ajax'; $request = new Mage_Core_Controller_Request_Http($uri); $request->setRouteName('diehard'); $request->setModuleName('_diehard'); $request->setControllerName('load'); $request->setActionName('ajax'); $request->setControllerModule('Cm_Diehard'); $request->setParam('full_action_name', $params['full_action_name']); if (!empty($params['all_blocks'])) { $request->setParam('all_blocks', 1); } else { $request->setParam('blocks', $params['blocks']); } $request->setParam('params', $params['params']); $request->setDispatched(true); // Override parameters in request singleton (for Mage_Core_Block_Abstract#getRequest()) Mage::app()->getRequest()->clearParams(); Mage::app()->getRequest()->setParams($request->getParams()); Mage::app()->getRequest()->setParams($request->getParam('params')); // Render sub-request into sub-response object $response = new Mage_Core_Controller_Response_Http(); require_once Mage::getModuleDir('controllers', 'Cm_Diehard') . '/LoadController.php'; $controller = new Cm_Diehard_LoadController($request, $response); $controller->dispatch('json'); $replacement = ''; if ($this->helper()->isDebug()) { $replacement .= '<!-- Dynamic blocks rendered: ' . (empty($params['all_blocks']) ? implode(',', $params['blocks']) : 'ALL') . ' -->' . "\n"; } $replacement .= "<script type=\"text/javascript\">/* <![CDATA[ */Diehard.replaceBlocks({$response->getBody()});/* ]]> */</script>"; return $replacement; } else { if ($this->helper()->isDebug()) { return '<!-- No dynamic blocks -->'; } else { return ''; } } }