public function testNonexistentAjaxMethodException() { /** @var CM_View_Abstract|PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->getMockForAbstractClass('CM_View_Abstract'); $site = CM_Site_Abstract::factory(); $request = $this->createRequestAjax($view, 'someReallyBadMethod', ['params' => 'foo']); $response = CM_Http_Response_View_Ajax::createFromRequest($request, $site, $this->getServiceManager()); $exception = $this->catchException(function () use($response) { $response->process(); }); $this->assertInstanceOf('CM_Exception_Invalid', $exception); /** @var CM_Exception_Invalid $exception */ $this->assertSame('Method not found', $exception->getMessage()); $this->assertSame(['method' => 'ajax_someReallyBadMethod'], $exception->getMetaInfo()); }
/** * @param CM_View_Abstract $view * @param string $methodName * @param array|null $params * @param CM_Frontend_Environment|null $environment * @return CM_Http_Response_View_Ajax */ public function getResponseAjax(CM_View_Abstract $view, $methodName, array $params = null, CM_Frontend_Environment $environment = null) { $site = CM_Site_Abstract::factory(); $request = $this->createRequestAjax($view, $methodName, $params, null, null, $site); if ($environment) { $request->mockMethod('getViewer')->set(function () use($environment) { return $environment->getViewer(); }); } $response = CM_Http_Response_View_Ajax::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); return $response; }
public function testLoadPageTrackingError() { CM_Config::get()->CM_Http_Response_Page->exceptionsToCatch['CM_Exception_Nonexistent'] = ['errorPage' => 'CM_Page_View_Ajax_Test_Mock']; $site = CM_Site_Abstract::factory(); $page = new CM_Page_View_Ajax_Test_Mock(); $env = new CM_Frontend_Environment($site, CMTest_TH::createUser()); $params = ['path' => '/iwhdfkjlsh', 'currentLayout' => $page->getLayout($env)]; $request = $this->createRequestAjax($page, 'loadPage', $params); $response = CM_Http_Response_View_Ajax::createFromRequest($request, $site, $this->_getServiceManagerWithGA('ga123')); $response->process(); $this->assertViewResponseSuccess($response); $responseContent = CM_Params::decode($response->getContent(), true); $jsTracking = $responseContent['success']['data']['jsTracking']; $html = $responseContent['success']['data']['pageRendering']['html']; $this->assertSame(1, substr_count($jsTracking, 'ga("send", "pageview"')); $this->assertContains('ga("send", "pageview", "\\/iwhdfkjlsh")', $jsTracking); $this->assertContains('CM_Page_View_Ajax_Test_Mock', $html); }