/** * Returns the test controller * * @return Controller */ function _getController($request, $response) { if ($this->testController === null) { $this->testController = parent::_getController($request, $response); } $this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers); $this->testController->setRequest($request); $this->testController->response = $this->response; return $this->testController; }
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) { // Bootstrap session so that Session::get() accesses the right instance $dummyController = new Controller(); $dummyController->setSession($session); $dummyController->setRequest($request); $dummyController->pushCurrent(); // Block non-authenticated users from setting the stage mode if (!Versioned::can_choose_site_stage($request)) { $permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live")); // Force output since RequestFilter::preRequest doesn't support response overriding $response = Security::permissionFailure($dummyController, $permissionMessage); $session->inst_save(); $dummyController->popCurrent(); // Prevent output in testing if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) { throw new SS_HTTPResponse_Exception($response); } $response->output(); die; } Versioned::choose_site_stage(); $dummyController->popCurrent(); return true; }
/** * Returns the test controller * * @return Controller */ protected function _getController($request, $response) { if ($this->testController === null) { $this->testController = parent::_getController($request, $response); } $this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers); $this->testController->setRequest($request); $this->testController->response = $this->response; foreach ($this->testController->Components->loaded() as $component) { $object = $this->testController->Components->{$component}; if (isset($object->response)) { $object->response = $response; } if (isset($object->request)) { $object->request = $request; } } return $this->testController; }
public function setApp() { View::reset(); View::useLib('MockTest'); View::conf($this->toupticonf['viewConf']); MocktestView::useLib($this->toupticonf['view'] . 'View'); Controller::setResponse($this->response); Controller::setRequest($this->request); $this->app = new MiddlewareStack(); $this->toupti = new Toupti($this->toupticonf['toupti']); $this->app->add($this->toupti); }
public function testIsFlush() { $controller = new Controller(); $req = new SS_HTTPRequest('GET', '/', array('flush' => 1)); $controller->setRequest($req); $this->assertTrue(Cacheable::is_flush($controller)); $req = new SS_HTTPRequest('GET', '/', array('flush' => 'all')); $controller->setRequest($req); $this->assertTrue(Cacheable::is_flush($controller)); $req = new SS_HTTPRequest('GET', '/', array('fluff' => 1)); $controller->setRequest($req); $this->assertFalse(Cacheable::is_flush($controller)); }
function setRequest($request) { parent::setRequest($request); }
function testPullRegionWithRenderContext() { // this is a dirty dirty mess. sorry. $req = new SS_HTTPRequest('GET', '/test1'); $req->addHeader(AjaxHTTPResponse::PULL_HEADER, 'TestProductGroupItem:BUYABLE'); $req->addHeader('X-Requested-With', 'XMLHttpRequest'); $ctrl = new Controller(); $ctrl->pushCurrent(); $ctrl->setRequest($req); $ctrl->setDataModel(DataModel::inst()); $ctrl->setURLParams(array()); $ctrl->init(); $response = $ctrl->getAjaxResponse(); $response->addRenderContext('BUYABLE', new ArrayData(array('Title' => 'Test Product', 'Link' => '/test-product', 'Price' => 29.99))); $data = json_decode($response->getBody(), true); $ctrl->popCurrent(); $this->assertNotEmpty($data[AjaxHTTPResponse::REGIONS_KEY]['TestProductGroupItem']); }