示例#1
0
 /**
  * @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']);
 }
示例#2
0
 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;
 }
示例#3
0
 public static function reset()
 {
     self::$lastRequest = array();
     self::$params = array();
 }
示例#4
0
 public function tearDown()
 {
     Castle_RequestTransport::reset();
     Castle_RequestTransport::setResponse(204, '');
 }
示例#5
0
 /**
  * @expectedException Castle_InvalidParametersError
  */
 public function testInvalidParametersRequest()
 {
     Castle_RequestTransport::setResponse(422);
     $req = new Castle_Request();
     $req->send('GET', '/users');
 }
示例#6
0
 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);
 }
示例#7
0
 public function testTrack()
 {
     Castle_RequestTransport::setResponse(204, '');
     Castle::track(array('name' => '$login.failed'));
     $this->assertRequest('post', '/events');
 }
示例#8
0
 public function tearDown()
 {
     Castle_RequestTransport::reset();
 }
示例#9
0
 /**
  * @expectedException Castle_InvalidParametersError
  */
 public function testInvalidParameters()
 {
     Castle_RequestTransport::setResponse(422);
     $this->request->send('GET', '/test');
 }
示例#10
0
 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']);
 }
示例#11
0
 public function testApprove()
 {
     Castle_RequestTransport::setResponse(200, '{}');
     Castle::authentications(1)->approve();
     $this->assertRequest('post', '/authentications/1/approve');
 }