getResponse() public method

Returns the current Response instance.
public getResponse ( ) : Symfony\Component\BrowserKit\Response
return Symfony\Component\BrowserKit\Response A Response instance
Esempio n. 1
0
 /**
  * @return AuthenticateResponse
  */
 public function authenticate()
 {
     $this->client->request('POST', self::SING_IN_URI, ['username' => $this->username, 'password' => $this->password], [], ['HTTP_ACCEPT' => 'application/json']);
     $loginResponse = json_decode($this->client->getResponse()->getContent());
     $authenticateHeaders = ['HTTP_TOKEN' => isset($loginResponse->Token) ? $loginResponse->Token : null, 'HTTP_EXPIREAT' => isset($loginResponse->ExpireAt) ? $loginResponse->ExpireAt : null, 'HTTP_USERNAME' => isset($loginResponse->Username) ? $loginResponse->Username : null];
     return new AuthenticateResponse([], $authenticateHeaders);
 }
 /**
  * @param $uri
  * @param $format
  * @return \PHPExcel
  */
 protected function getDocument($uri, $format = 'xlsx')
 {
     // generate source
     static::$client->request('GET', $uri);
     $source = static::$client->getResponse()->getContent();
     // create source directory if necessary
     if (!file_exists(__DIR__ . static::$TEMP_PATH)) {
         mkdir(__DIR__ . static::$TEMP_PATH);
     }
     // save source
     file_put_contents(__DIR__ . static::$TEMP_PATH . 'simple' . '.' . $format, $source);
     // load source
     switch ($format) {
         case 'ods':
             $reader = new PHPExcel_Reader_OOCalc();
             break;
         case 'xls':
             $reader = new PHPExcel_Reader_Excel5();
             break;
         case 'xlsx':
             $reader = new PHPExcel_Reader_Excel2007();
             break;
         default:
             throw new InvalidArgumentException();
     }
     return $reader->load(__DIR__ . static::$TEMP_PATH . 'simple' . '.' . $format);
 }
Esempio n. 3
0
 public function testGetCategories()
 {
     $this->client->request('GET', '/search/categories');
     $response = $this->client->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
     $result = json_decode($response->getContent(), true);
     $this->assertContains('test', $result);
 }
Esempio n. 4
0
 public function testGetIndexes()
 {
     $this->client->request('GET', '/search/indexes');
     $response = $this->client->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
     $result = json_decode($response->getContent(), true);
     $this->assertEquals('product', $result[0]['indexName']);
 }
Esempio n. 5
0
 protected function login(Client $client, $username = '******', $password = '******')
 {
     $client->restart();
     $crawler = $client->request('GET', '/login');
     $this->assertTrue($client->getResponse()->isSuccessful(), 'Response should be successful');
     $form = $crawler->selectButton('Login')->form();
     $client->submit($form, array('_username' => $username, '_password' => $password));
     $this->assertTrue($client->getResponse()->isRedirect(), 'Response should be redirect');
     $crawler = $client->followRedirect();
     $this->assertGreaterThan(0, $crawler->filter('html:contains("Benvenuto")')->count());
 }
Esempio n. 6
0
 /**
  * Checks response code.
  *
  * @param $num
  */
 public function seeResponseCodeIs($num)
 {
     if (method_exists($this->client->getResponse(), 'getStatusCode')) {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatusCode());
     } else {
         \PHPUnit_Framework_Assert::assertEquals($num, $this->client->getResponse()->getStatus());
     }
 }
Esempio n. 7
0
 /**
  * testing savePerDiem action.
  */
 public function testSavePerDiemAction()
 {
     // Empty request
     $crawler = $this->client->request('POST', '/secured/travel/admin/save/perdiem');
     $this->assertJson($this->client->getResponse()->getContent(), 'testSavePerDiemAction: The response\'s content is not a JSON object.');
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'application/json'), 'testSavePerDiemAction: The content-type is not a json.');
     // Filled up request
     $crawler = $this->client->request('POST', '/secured/travel/admin/save/perdiem', array('perdiem' => array(0 => array('id' => 1, 'hours' => 14, 'amount' => 24), 1 => array('id' => null, 'hours' => 12, 'amount' => 12))));
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'text/html; charset=UTF-8'), 'testSavePerDiemAction: The content-type is not html.');
 }
Esempio n. 8
0
 public function grabTextFrom($cssOrXPathOrRegex)
 {
     $nodes = $this->match($cssOrXPathOrRegex);
     if ($nodes) {
         return $nodes->first()->text();
     }
     if (@preg_match($cssOrXPathOrRegex, $this->client->getResponse()->getContent(), $matches)) {
         return $matches[1];
     }
     $this->fail("Element that matches '{$cssOrXPathOrRegex}' not found");
 }
Esempio n. 9
0
 private function addToCart($mealName, $quantity, Crawler $crawler, Client $client)
 {
     $titles = $crawler->filter('h4')->reduce(function ($crawler) use($mealName) {
         return false !== strpos($crawler->text(), $mealName);
     });
     if (count($titles) !== 1) {
         throw new \RuntimeException(sprintf('Expected 1 title containing "%s", found %s.', $mealName, count($titles)));
     }
     $link = $titles->eq(0)->parents()->first()->filter('input[data-meal]');
     $mealId = $link->attr('data-meal');
     $client->request('POST', '/cart', array('meal' => $mealId, 'mode' => 'add', 'quantity' => $quantity));
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
 }
Esempio n. 10
0
 /**
  * Sends a XMLRPC method call to remote XMLRPC-server.
  *
  * @param string $methodName
  * @param array $parameters
  */
 public function sendXMLRPCMethodCall($methodName, $parameters = array())
 {
     if (!array_key_exists('Content-Type', $this->headers)) {
         $this->headers['Content-Type'] = 'text/xml';
     }
     foreach ($this->headers as $header => $val) {
         $this->client->setServerParameter("HTTP_{$header}", $val);
     }
     $url = $this->config['url'];
     if (is_array($parameters)) {
         $parameters = $this->scalarizeArray($parameters);
     }
     $requestBody = xmlrpc_encode_request($methodName, array_values($parameters));
     $this->debugSection('Request', $url . PHP_EOL . $requestBody);
     $this->client->request('POST', $url, array(), array(), array(), $requestBody);
     $this->response = $this->client->getResponse()->getContent();
     $this->debugSection('Response', $this->response);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  *
  * @return Response|null A Response instance
  */
 public function getResponse()
 {
     return parent::getResponse();
 }
Esempio n. 12
0
 protected function createNote(Client $client, $message)
 {
     $client->request('POST', '/notes.json', array('note' => array('message' => $message)));
     $response = $client->getResponse();
     $this->assertJsonResponse($response, Response::HTTP_CREATED);
 }
 /**
  * @return SimpleXMLElement
  * @param Client $client
  */
 protected function getXml()
 {
     $xml = new SimpleXMLElement($this->client->getResponse()->getContent());
     $this->ns->registerNamespaces($xml);
     return $xml;
 }
Esempio n. 14
0
 /**
  * @param $url
  * @param $data
  * @return Response
  */
 protected function makeRequest($url, $data)
 {
     $this->client->request('POST', $url, [], [], [], json_encode($data));
     return Response::jsonUnserialize($this->client->getResponse()->getContent());
 }
 /**
  * @param string $expectedJson
  */
 protected function assertJsonResponse($expectedJson)
 {
     $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
     $this->assertEquals($expectedJson, $this->client->getResponse()->getContent());
 }
Esempio n. 16
0
 /**
  * @param $client
  * @param $position 0 based index position
  * @return mixed
  */
 private function getPageEditUriFromListByPosition(Client $client, $position)
 {
     $crawler = $client->getCrawler();
     if (strpos($client->getRequest()->getUri(), '/admin/cmf/page/page/list') === false) {
         $crawler = $client->request('GET', '/admin/cmf/page/page/list');
     }
     $this->assertTrue($client->getResponse()->isSuccessful());
     $rows = $crawler->filter('table tbody tr');
     return $rows->eq($position)->filter('td')->eq(1)->filter('a')->attr('href');
 }
Esempio n. 17
0
 protected function debugResponse()
 {
     $this->debugSection('Response', $this->client->getResponse()->getStatus());
     $this->debugSection('Page', $this->client->getHistory()->current()->getUri());
 }
Esempio n. 18
0
 /**
  * test version action
  */
 public function testVersionAction()
 {
     $crawler = $this->client->request('GET', '/secured/opithrm/versions');
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'text/html; charset=UTF-8'), 'testVersionAction: The content-type is not a html file.');
 }
Esempio n. 19
0
 protected function processExternalRequest($action, $body)
 {
     $this->processRequest($action, $body);
     return $this->client->getResponse()->getContent();
 }
Esempio n. 20
0
 /**
  * testing the resetPassword action.
  *
  * This should be the last method, because this is reset the password for the admin.
  */
 public function testResetPasswordAction()
 {
     $crawler = $this->client->request('POST', '/secured/user/password/reset', array('id' => $this->user->getId()));
     $this->assertJson($this->client->getResponse()->getContent(), 'testResetPasswordAction: The response\'s content is not a JSON object.');
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'application/json'), 'testResetPasswordAction: The content-type is not a json.');
 }
Esempio n. 21
0
 /**
  * testing deleteGroup adction.
  */
 public function testDeleteGroupAction()
 {
     $crawler = $this->client->request('POST', '/secured/admin/groups/delete', array('id' => $this->group->getId()));
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'text/html; charset=UTF-8'), 'testDeleteGroupAction: The content-type is not html.');
 }