/** * You aren't supposed to call this multiple times per test... * @param string $url The relative url (e.g. "/en/catalog/product/view/id/123") */ protected function load($url, $post = array()) { $request = Mage::app()->getRequest(); $request->setRequestUri($url); if ($post) { $request->setPost($post); $_SERVER['REQUEST_METHOD'] = 'POST'; } // real magic! $controller = new Mage_Core_Controller_Varien_Front(); $controller->init(); $request->setPathInfo()->setDispatched(false); if (!$request->isStraight()) { Mage::getModel('core/url_rewrite')->rewrite(); } $controller->rewrite(); $i = 0; while (!$request->isDispatched() && $i++ < 100) { foreach ($controller->getRouters() as $router) { if ($router->match($request)) { break; } } } if ($i > 100) { throw new Exception('Front controller reached 100 router match iterations'); } return $controller->getResponse(); }
public function testDispatch() { if (!Magento_Test_Bootstrap::canTestHeaders()) { $this->markTestSkipped('Cant\'t test dispatch process without sending headers'); } $_SERVER['HTTP_HOST'] = 'localhost'; $this->_model->init(); /* empty action */ $this->_model->getRequest()->setRequestUri('core/index/index'); $this->_model->dispatch(); $this->assertEmpty($this->_model->getResponse()->getBody()); }