/** * @dataProvider exampleSettings */ public function testAccountPostRequest($settings) { Castle_RequestTransport::setResponse(200, $settings); $settings = new Castle_Account($settings); $settings->public_name = 'New name'; $settings->save(); $request = $this->assertRequest('post', '/account'); $this->assertArrayHasKey('settings', $request['params']); $this->assertEquals('New name', $request['params']['settings']['public_name']); }
public function assertRequest($method, $url, $headers = null) { $request = Castle_RequestTransport::getLastRequest(); $this->assertEquals($method, $request['method']); $this->assertEquals(Castle_Request::apiUrl($url), $request['url']); if (is_array($headers)) { foreach ($headers as $key => $value) { $this->assertArrayHasKey($key, $request['headers']); $this->assertEquals($request['headers'][$key], $value); } } return $request; }
public static function reset() { self::$lastRequest = array(); self::$params = array(); }
public function tearDown() { Castle_RequestTransport::reset(); Castle_RequestTransport::setResponse(204, ''); }
/** * @expectedException Castle_InvalidParametersError */ public function testInvalidParametersRequest() { Castle_RequestTransport::setResponse(422); $req = new Castle_Request(); $req->send('GET', '/users'); }
public function send($method, $url, $params = null) { $this->preFlightCheck(); $client = self::clientUserAgent(); $body = empty($params) ? null : json_encode($params); $cookies = Castle::getCookieStore(); $requestHeaders = json_encode(self::getHeaders()); $headers = array('X-Castle-Cookie-Id: ' . $cookies->read('__cid'), 'X-Castle-User-Agent: ' . self::getUserAgent(), 'X-Castle-Headers: ' . $requestHeaders, 'X-Castle-Ip: ' . self::getIp(), 'X-Castle-Client-User-Agent: ' . $client, 'Content-Type: application/json', 'Content-Length: ' . strlen($body)); // Check if there is a current session and pass it along $session = Castle::getTokenStore()->getSession(); if (isset($session)) { $headers[] = 'X-Castle-Session-Token: ' . $session; } $request = new Castle_RequestTransport(); $request->send($method, self::apiUrl($url), $body, $headers); return $this->handleResponse($request); }
public function testTrack() { Castle_RequestTransport::setResponse(204, ''); Castle::track(array('name' => '$login.failed')); $this->assertRequest('post', '/events'); }
public function tearDown() { Castle_RequestTransport::reset(); }
/** * @expectedException Castle_InvalidParametersError */ public function testInvalidParameters() { Castle_RequestTransport::setResponse(422); $this->request->send('GET', '/test'); }
public function testEscapeUrl() { $user = new TestUser('Hofbräuhaus / München'); $user->fetch(); $request = Castle_RequestTransport::getLastRequest(); $this->assertStringEndsWith('Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen', $request['url']); }
public function testApprove() { Castle_RequestTransport::setResponse(200, '{}'); Castle::authentications(1)->approve(); $this->assertRequest('post', '/authentications/1/approve'); }