public function grabTextFrom($cssOrXPathOrRegex) { if (@preg_match($cssOrXPathOrRegex, $this->client->getInternalResponse()->getContent(), $matches)) { return $matches[1]; } $nodes = $this->match($cssOrXPathOrRegex); if ($nodes->count()) { return $nodes->first()->text(); } throw new ElementNotFound($cssOrXPathOrRegex, 'Element that matches CSS or XPath or Regex'); }
protected function execute($method = 'GET', $url, $parameters = [], $files = []) { $this->debugSection("Request headers", $this->headers); foreach ($this->headers as $header => $val) { $header = str_replace('-', '_', strtoupper($header)); $this->client->setServerParameter("HTTP_{$header}", $val); // Issue #1650 - Symfony BrowserKit changes HOST header to request URL if ($header === 'HOST') { $this->client->setServerParameter("HTTP_ HOST", $val); } // Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_ if ($this->isFunctional && $header === 'CONTENT_TYPE') { $this->client->setServerParameter($header, $val); } } // allow full url to be requested if (strpos($url, '://') === false) { $url = $this->config['url'] . $url; } $this->params = $parameters; $parameters = $this->encodeApplicationJson($method, $parameters); if (is_array($parameters) || $method === 'GET') { if (!empty($parameters) && $method === 'GET') { $url .= '?' . http_build_query($parameters); } if ($method == 'GET') { $this->debugSection("Request", "{$method} {$url}"); } else { $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters)); } $this->client->request($method, $url, $parameters, $files); } else { $requestData = $parameters; if (!ctype_print($requestData) && false === mb_detect_encoding($requestData, mb_detect_order(), true)) { // if the request data has non-printable bytes and it is not a valid unicode string, reformat the // display string to signify the presence of request data $requestData = '[binary-data length:' . strlen($requestData) . ' md5:' . md5($requestData) . ']'; } $this->debugSection("Request", "{$method} {$url} " . $requestData); $this->client->request($method, $url, [], $files, [], $parameters); } $this->response = (string) $this->connectionModule->_getResponseContent(); $this->debugSection("Response", $this->response); if (count($this->client->getInternalRequest()->getCookies())) { $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies()); } $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders()); $this->debugSection("Status", $this->client->getInternalResponse()->getStatus()); }
/** * @param $result * @return mixed */ protected function redirectIfNecessary($result, $maxRedirects, $redirectCount) { $locationHeader = $this->client->getInternalResponse()->getHeader('Location'); if ($locationHeader) { if ($redirectCount == $maxRedirects) { throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $maxRedirects)); } $this->debugSection('Redirecting to', $locationHeader); $result = $this->client->followRedirect(); $this->debugResponse($locationHeader); return $this->redirectIfNecessary($result, $maxRedirects, $redirectCount + 1); } $this->client->followRedirects(true); return $result; }
/** * 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->getInternalResponse()->getContent(); $this->debugSection('Response', $this->response); }
protected function execute($method = 'GET', $url, $parameters = [], $files = []) { $this->debugSection("Request headers", $this->headers); if ($parameters instanceof \JsonSerializable) { $parameters = $parameters->jsonSerialize(); } foreach ($this->headers as $header => $val) { $header = str_replace('-', '_', strtoupper($header)); $this->client->setServerParameter("HTTP_{$header}", $val); // Issue #1650 - Symfony BrowserKit changes HOST header to request URL if (strtolower($header) == 'host') { $this->client->setServerParameter("HTTP_ HOST", $val); } // Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_ if ($this->isFunctional and $header == 'CONTENT_TYPE') { $this->client->setServerParameter($header, $val); } } // allow full url to be requested $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url; $this->params = $parameters; $parameters = $this->encodeApplicationJson($method, $parameters); if (is_array($parameters) || $method == 'GET') { if (!empty($parameters) && $method == 'GET') { $url .= '?' . http_build_query($parameters); } if ($method == 'GET') { $this->debugSection("Request", "{$method} {$url}"); } else { $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters)); } $this->client->request($method, $url, $parameters, $files); } else { $this->debugSection("Request", "{$method} {$url} " . $parameters); $this->client->request($method, $url, [], $files, [], $parameters); } $this->response = (string) $this->client->getInternalResponse()->getContent(); $this->debugSection("Response", $this->response); if (count($this->client->getInternalRequest()->getCookies())) { $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies()); } $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders()); $this->debugSection("Status", $this->client->getInternalResponse()->getStatus()); }
protected function assertPageNotContains($needle, $message = '') { $constraint = new PageConstraint($needle, $this->_getCurrentUri()); $this->assertThatItsNot($this->client->getInternalResponse()->getContent(), $constraint, $message); }
/** * Checks that response code is not equal to provided value. * * @param $code */ public function dontSeeResponseCodeIs($code) { $this->assertNotEquals($code, $this->client->getInternalResponse()->getStatus()); }
protected function processExternalRequest($action, $body) { $this->processRequest($action, $body); return $this->client->getInternalResponse()->getContent(); }