/** * Submit a post request * * @uses Director::test() * @param string $url * @param array $data * @param array $headers * @param Session $session * @param string $body * @param array $cookies * @return HTTPResponse */ public function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) { $headers = (array) $headers; if ($this->lastUrl && !isset($headers['Referer'])) { $headers['Referer'] = $this->lastUrl; } $this->lastResponse = Director::test($url, $data, $session ?: $this->session, null, $body, $headers, $cookies ?: $this->cookies); $this->lastUrl = $url; if (!$this->lastResponse) { user_error("Director::test({$url}) returned null", E_USER_WARNING); } return $this->lastResponse; }
/** * Test a submission of this form. * @param string $action * @param array $data * @return HTTPResponse the response object that the handling controller produces. You can interrogate this in * your unit test. * @throws HTTPResponse_Exception */ public function testSubmission($action, $data) { $data['action_' . $action] = true; return Director::test($this->FormAction(), $data, Controller::curr()->getSession()); }
/** * Test that the cacheblocks invalidate when a flush occurs. */ public function testBlocksInvalidateOnFlush() { Director::test('/?flush=1'); $this->_reset(true); // Generate cached value for foo = 1 $this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 1)), '1'); // Test without flush Director::test('/'); $this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 3)), '1'); // Test with flush Director::test('/?flush=1'); $this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 2)), '2'); }
public function testBasicAuthFailureIncreasesFailedLoginCount() { // Prior to login $check = Member::get()->filter('Email', '*****@*****.**')->first(); $this->assertEquals(0, $check->FailedLoginCount); // First failed attempt $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'test'; $response = Director::test('BasicAuthTest_ControllerSecuredWithoutPermission'); $check = Member::get()->filter('Email', '*****@*****.**')->first(); $this->assertEquals(1, $check->FailedLoginCount); // Second failed attempt $_SERVER['PHP_AUTH_PW'] = 'testwrong'; $response = Director::test('BasicAuthTest_ControllerSecuredWithoutPermission'); $check = Member::get()->filter('Email', '*****@*****.**')->first(); $this->assertEquals(2, $check->FailedLoginCount); // successful basic auth should reset failed login count $_SERVER['PHP_AUTH_PW'] = 'Password'; $response = Director::test('BasicAuthTest_ControllerSecuredWithoutPermission'); $check = Member::get()->filter('Email', '*****@*****.**')->first(); $this->assertEquals(0, $check->FailedLoginCount); }
/** * Test that stage parameter is blocked by non-administrative users */ public function testReadingModeSecurity() { $this->setExpectedException('SilverStripe\\Control\\HTTPResponse_Exception'); $session = Injector::inst()->create('SilverStripe\\Control\\Session', array()); $result = Director::test('/?stage=Stage', null, $session); }
public function testMethodsOnParentClassesOfRequestHandlerDeclined() { $response = Director::test('testGoodBase1/getIterator'); $this->assertEquals(404, $response->getStatusCode()); }
public function testRequestFilterInDirectorTest() { $filter = new TestRequestFilter(); $processor = new RequestProcessor(array($filter)); Injector::inst()->registerService($processor, 'SilverStripe\\Control\\RequestProcessor'); $response = Director::test('some-dummy-url'); $this->assertEquals(1, $filter->preCalls); $this->assertEquals(1, $filter->postCalls); $filter->failPost = true; $this->setExpectedException('SilverStripe\\Control\\HTTPResponse_Exception'); $response = Director::test('some-dummy-url'); $this->assertEquals(2, $filter->preCalls); $this->assertEquals(2, $filter->postCalls); $filter->failPre = true; $response = Director::test('some-dummy-url'); $this->assertEquals(3, $filter->preCalls); // preCall 'false' will trigger an exception and prevent post call execution $this->assertEquals(2, $filter->postCalls); }