Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

3
vendor/symfony/browser-kit/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
vendor/
composer.lock
phpunit.xml

18
vendor/symfony/browser-kit/CHANGELOG.md vendored Normal file
View file

@ -0,0 +1,18 @@
CHANGELOG
=========
2.3.0
-----
* [BC BREAK] `Client::followRedirect()` won't redirect responses with
a non-3xx Status Code and `Location` header anymore, as per
http://tools.ietf.org/html/rfc2616#section-14.30
* added `Client::getInternalRequest()` and `Client::getInternalResponse()` to
have access to the BrowserKit internal request and response objects
2.1.0
-----
* [BC BREAK] The CookieJar internals have changed to allow cookies with the
same name on different sub-domains/sub-paths

619
vendor/symfony/browser-kit/Client.php vendored Normal file
View file

@ -0,0 +1,619 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Link;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\Process\PhpProcess;
/**
* Client simulates a browser.
*
* To make the actual request, you need to implement the doRequest() method.
*
* If you want to be able to run requests in their own process (insulated flag),
* you need to also implement the getScript() method.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
abstract class Client
{
protected $history;
protected $cookieJar;
protected $server = array();
protected $internalRequest;
protected $request;
protected $internalResponse;
protected $response;
protected $crawler;
protected $insulated = false;
protected $redirect;
protected $followRedirects = true;
private $maxRedirects = -1;
private $redirectCount = 0;
private $isMainRequest = true;
/**
* Constructor.
*
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
*
* @api
*/
public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)
{
$this->setServerParameters($server);
$this->history = $history ?: new History();
$this->cookieJar = $cookieJar ?: new CookieJar();
}
/**
* Sets whether to automatically follow redirects or not.
*
* @param bool $followRedirect Whether to follow redirects
*
* @api
*/
public function followRedirects($followRedirect = true)
{
$this->followRedirects = (bool) $followRedirect;
}
/**
* Sets the maximum number of requests that crawler can follow.
*
* @param int $maxRedirects
*/
public function setMaxRedirects($maxRedirects)
{
$this->maxRedirects = $maxRedirects < 0 ? -1 : $maxRedirects;
$this->followRedirects = -1 != $this->maxRedirects;
}
/**
* Sets the insulated flag.
*
* @param bool $insulated Whether to insulate the requests or not
*
* @throws \RuntimeException When Symfony Process Component is not installed
*
* @api
*/
public function insulate($insulated = true)
{
if ($insulated && !class_exists('Symfony\\Component\\Process\\Process')) {
throw new \RuntimeException('Unable to isolate requests as the Symfony Process Component is not installed.');
}
$this->insulated = (bool) $insulated;
}
/**
* Sets server parameters.
*
* @param array $server An array of server parameters
*
* @api
*/
public function setServerParameters(array $server)
{
$this->server = array_merge(array(
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
), $server);
}
/**
* Sets single server parameter.
*
* @param string $key A key of the parameter
* @param string $value A value of the parameter
*/
public function setServerParameter($key, $value)
{
$this->server[$key] = $value;
}
/**
* Gets single server parameter for specified key.
*
* @param string $key A key of the parameter to get
* @param string $default A default value when key is undefined
*
* @return string A value of the parameter
*/
public function getServerParameter($key, $default = '')
{
return (isset($this->server[$key])) ? $this->server[$key] : $default;
}
/**
* Returns the History instance.
*
* @return History A History instance
*
* @api
*/
public function getHistory()
{
return $this->history;
}
/**
* Returns the CookieJar instance.
*
* @return CookieJar A CookieJar instance
*
* @api
*/
public function getCookieJar()
{
return $this->cookieJar;
}
/**
* Returns the current Crawler instance.
*
* @return Crawler|null A Crawler instance
*
* @api
*/
public function getCrawler()
{
return $this->crawler;
}
/**
* Returns the current BrowserKit Response instance.
*
* @return Response|null A BrowserKit Response instance
*
* @api
*/
public function getInternalResponse()
{
return $this->internalResponse;
}
/**
* Returns the current origin response instance.
*
* The origin response is the response instance that is returned
* by the code that handles requests.
*
* @return object|null A response instance
*
* @see doRequest()
*
* @api
*/
public function getResponse()
{
return $this->response;
}
/**
* Returns the current BrowserKit Request instance.
*
* @return Request|null A BrowserKit Request instance
*
* @api
*/
public function getInternalRequest()
{
return $this->internalRequest;
}
/**
* Returns the current origin Request instance.
*
* The origin request is the request instance that is sent
* to the code that handles requests.
*
* @return object|null A Request instance
*
* @see doRequest()
*
* @api
*/
public function getRequest()
{
return $this->request;
}
/**
* Clicks on a given link.
*
* @param Link $link A Link instance
*
* @return Crawler
*
* @api
*/
public function click(Link $link)
{
if ($link instanceof Form) {
return $this->submit($link);
}
return $this->request($link->getMethod(), $link->getUri());
}
/**
* Submits a form.
*
* @param Form $form A Form instance
* @param array $values An array of form field values
*
* @return Crawler
*
* @api
*/
public function submit(Form $form, array $values = array())
{
$form->setValues($values);
return $this->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles());
}
/**
* Calls a URI.
*
* @param string $method The request method
* @param string $uri The URI to fetch
* @param array $parameters The Request parameters
* @param array $files The files
* @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
* @param string $content The raw body data
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*
* @api
*/
public function request($method, $uri, array $parameters = array(), array $files = array(), array $server = array(), $content = null, $changeHistory = true)
{
if ($this->isMainRequest) {
$this->redirectCount = 0;
} else {
++$this->redirectCount;
}
$uri = $this->getAbsoluteUri($uri);
if (!empty($server['HTTP_HOST'])) {
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
}
if (isset($server['HTTPS'])) {
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}
$server = array_merge($this->server, $server);
if (!$this->history->isEmpty()) {
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}
$server['HTTP_HOST'] = $this->extractHost($uri);
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
$this->request = $this->filterRequest($this->internalRequest);
if (true === $changeHistory) {
$this->history->add($this->internalRequest);
}
if ($this->insulated) {
$this->response = $this->doRequestInProcess($this->request);
} else {
$this->response = $this->doRequest($this->request);
}
$this->internalResponse = $this->filterResponse($this->response);
$this->cookieJar->updateFromResponse($this->internalResponse, $uri);
$status = $this->internalResponse->getStatus();
if ($status >= 300 && $status < 400) {
$this->redirect = $this->internalResponse->getHeader('Location');
} else {
$this->redirect = null;
}
if ($this->followRedirects && $this->redirect) {
return $this->crawler = $this->followRedirect();
}
return $this->crawler = $this->createCrawlerFromContent($this->internalRequest->getUri(), $this->internalResponse->getContent(), $this->internalResponse->getHeader('Content-Type'));
}
/**
* Makes a request in another process.
*
* @param object $request An origin request instance
*
* @return object An origin response instance
*
* @throws \RuntimeException When processing returns exit code
*/
protected function doRequestInProcess($request)
{
// We set the TMPDIR (for Macs) and TEMP (for Windows), because on these platforms the temp directory changes based on the user.
$process = new PhpProcess($this->getScript($request), null, array('TMPDIR' => sys_get_temp_dir(), 'TEMP' => sys_get_temp_dir()));
$process->run();
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
}
return unserialize($process->getOutput());
}
/**
* Makes a request.
*
* @param object $request An origin request instance
*
* @return object An origin response instance
*/
abstract protected function doRequest($request);
/**
* Returns the script to execute when the request must be insulated.
*
* @param object $request An origin request instance
*
* @throws \LogicException When this abstract class is not implemented
*/
protected function getScript($request)
{
throw new \LogicException('To insulate requests, you need to override the getScript() method.');
}
/**
* Filters the BrowserKit request to the origin one.
*
* @param Request $request The BrowserKit Request to filter
*
* @return object An origin request instance
*/
protected function filterRequest(Request $request)
{
return $request;
}
/**
* Filters the origin response to the BrowserKit one.
*
* @param object $response The origin response to filter
*
* @return Response An BrowserKit Response instance
*/
protected function filterResponse($response)
{
return $response;
}
/**
* Creates a crawler.
*
* This method returns null if the DomCrawler component is not available.
*
* @param string $uri A URI
* @param string $content Content for the crawler to use
* @param string $type Content type
*
* @return Crawler|null
*/
protected function createCrawlerFromContent($uri, $content, $type)
{
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {
return;
}
$crawler = new Crawler(null, $uri);
$crawler->addContent($content, $type);
return $crawler;
}
/**
* Goes back in the browser history.
*
* @return Crawler
*
* @api
*/
public function back()
{
return $this->requestFromRequest($this->history->back(), false);
}
/**
* Goes forward in the browser history.
*
* @return Crawler
*
* @api
*/
public function forward()
{
return $this->requestFromRequest($this->history->forward(), false);
}
/**
* Reloads the current browser.
*
* @return Crawler
*
* @api
*/
public function reload()
{
return $this->requestFromRequest($this->history->current(), false);
}
/**
* Follow redirects?
*
* @return Crawler
*
* @throws \LogicException If request was not a redirect
*
* @api
*/
public function followRedirect()
{
if (empty($this->redirect)) {
throw new \LogicException('The request was not redirected.');
}
if (-1 !== $this->maxRedirects) {
if ($this->redirectCount > $this->maxRedirects) {
throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $this->maxRedirects));
}
}
$request = $this->internalRequest;
if (in_array($this->internalResponse->getStatus(), array(302, 303))) {
$method = 'get';
$files = array();
$content = null;
} else {
$method = $request->getMethod();
$files = $request->getFiles();
$content = $request->getContent();
}
if ('get' === strtolower($method)) {
// Don't forward parameters for GET request as it should reach the redirection URI
$parameters = array();
} else {
$parameters = $request->getParameters();
}
$server = $request->getServer();
$server = $this->updateServerFromUri($server, $this->redirect);
$this->isMainRequest = false;
$response = $this->request($method, $this->redirect, $parameters, $files, $server, $content);
$this->isMainRequest = true;
return $response;
}
/**
* Restarts the client.
*
* It flushes history and all cookies.
*
* @api
*/
public function restart()
{
$this->cookieJar->clear();
$this->history->clear();
}
/**
* Takes a URI and converts it to absolute if it is not already absolute.
*
* @param string $uri A URI
*
* @return string An absolute URI
*/
protected function getAbsoluteUri($uri)
{
// already absolute?
if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) {
return $uri;
}
if (!$this->history->isEmpty()) {
$currentUri = $this->history->current()->getUri();
} else {
$currentUri = sprintf('http%s://%s/',
isset($this->server['HTTPS']) ? 's' : '',
isset($this->server['HTTP_HOST']) ? $this->server['HTTP_HOST'] : 'localhost'
);
}
// protocol relative URL
if (0 === strpos($uri, '//')) {
return parse_url($currentUri, PHP_URL_SCHEME).':'.$uri;
}
// anchor?
if (!$uri || '#' == $uri[0]) {
return preg_replace('/#.*?$/', '', $currentUri).$uri;
}
if ('/' !== $uri[0]) {
$path = parse_url($currentUri, PHP_URL_PATH);
if ('/' !== substr($path, -1)) {
$path = substr($path, 0, strrpos($path, '/') + 1);
}
$uri = $path.$uri;
}
return preg_replace('#^(.*?//[^/]+)\/.*$#', '$1', $currentUri).$uri;
}
/**
* Makes a request from a Request object directly.
*
* @param Request $request A Request instance
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
protected function requestFromRequest(Request $request, $changeHistory = true)
{
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
}
private function updateServerFromUri($server, $uri)
{
$server['HTTP_HOST'] = $this->extractHost($uri);
$scheme = parse_url($uri, PHP_URL_SCHEME);
$server['HTTPS'] = null === $scheme ? $server['HTTPS'] : 'https' == $scheme;
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);
return $server;
}
private function extractHost($uri)
{
$host = parse_url($uri, PHP_URL_HOST);
if ($port = parse_url($uri, PHP_URL_PORT)) {
return $host.':'.$port;
}
return $host;
}
}

335
vendor/symfony/browser-kit/Cookie.php vendored Normal file
View file

@ -0,0 +1,335 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
/**
* Cookie represents an HTTP cookie.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
class Cookie
{
/**
* Handles dates as defined by RFC 2616 section 3.3.1, and also some other
* non-standard, but common formats.
*
* @var array
*/
private static $dateFormats = array(
'D, d M Y H:i:s T',
'D, d-M-y H:i:s T',
'D, d-M-Y H:i:s T',
'D, d-m-y H:i:s T',
'D, d-m-Y H:i:s T',
'D M j G:i:s Y',
'D M d H:i:s Y T',
);
protected $name;
protected $value;
protected $expires;
protected $path;
protected $domain;
protected $secure;
protected $httponly;
protected $rawValue;
/**
* Sets a cookie.
*
* @param string $name The cookie name
* @param string $value The value of the cookie
* @param string $expires The time the cookie expires
* @param string $path The path on the server in which the cookie will be available on
* @param string $domain The domain that the cookie is available
* @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
* @param bool $httponly The cookie httponly flag
* @param bool $encodedValue Whether the value is encoded or not
*
* @api
*/
public function __construct($name, $value, $expires = null, $path = null, $domain = '', $secure = false, $httponly = true, $encodedValue = false)
{
if ($encodedValue) {
$this->value = urldecode($value);
$this->rawValue = $value;
} else {
$this->value = $value;
$this->rawValue = urlencode($value);
}
$this->name = $name;
$this->path = empty($path) ? '/' : $path;
$this->domain = $domain;
$this->secure = (bool) $secure;
$this->httponly = (bool) $httponly;
if (null !== $expires) {
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
if (false === $timestampAsDateTime) {
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
}
$this->expires = $timestampAsDateTime->getTimestamp();
}
}
/**
* Returns the HTTP representation of the Cookie.
*
* @return string The HTTP representation of the Cookie
*
* @throws \UnexpectedValueException
*
* @api
*/
public function __toString()
{
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);
if (null !== $this->expires) {
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0]));
}
if ('' !== $this->domain) {
$cookie .= '; domain='.$this->domain;
}
if ($this->path) {
$cookie .= '; path='.$this->path;
}
if ($this->secure) {
$cookie .= '; secure';
}
if ($this->httponly) {
$cookie .= '; httponly';
}
return $cookie;
}
/**
* Creates a Cookie instance from a Set-Cookie header value.
*
* @param string $cookie A Set-Cookie header value
* @param string $url The base URL
*
* @return Cookie A Cookie instance
*
* @throws \InvalidArgumentException
*
* @api
*/
public static function fromString($cookie, $url = null)
{
$parts = explode(';', $cookie);
if (false === strpos($parts[0], '=')) {
throw new \InvalidArgumentException(sprintf('The cookie string "%s" is not valid.', $parts[0]));
}
list($name, $value) = explode('=', array_shift($parts), 2);
$values = array(
'name' => trim($name),
'value' => trim($value),
'expires' => null,
'path' => '/',
'domain' => '',
'secure' => false,
'httponly' => false,
'passedRawValue' => true,
);
if (null !== $url) {
if ((false === $urlParts = parse_url($url)) || !isset($urlParts['host'])) {
throw new \InvalidArgumentException(sprintf('The URL "%s" is not valid.', $url));
}
$values['domain'] = $urlParts['host'];
$values['path'] = isset($urlParts['path']) ? substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) : '';
}
foreach ($parts as $part) {
$part = trim($part);
if ('secure' === strtolower($part)) {
// Ignore the secure flag if the original URI is not given or is not HTTPS
if (!$url || !isset($urlParts['scheme']) || 'https' != $urlParts['scheme']) {
continue;
}
$values['secure'] = true;
continue;
}
if ('httponly' === strtolower($part)) {
$values['httponly'] = true;
continue;
}
if (2 === count($elements = explode('=', $part, 2))) {
if ('expires' === strtolower($elements[0])) {
$elements[1] = self::parseDate($elements[1]);
}
$values[strtolower($elements[0])] = $elements[1];
}
}
return new static(
$values['name'],
$values['value'],
$values['expires'],
$values['path'],
$values['domain'],
$values['secure'],
$values['httponly'],
$values['passedRawValue']
);
}
private static function parseDate($dateValue)
{
// trim single quotes around date if present
if (($length = strlen($dateValue)) > 1 && "'" === $dateValue[0] && "'" === $dateValue[$length - 1]) {
$dateValue = substr($dateValue, 1, -1);
}
foreach (self::$dateFormats as $dateFormat) {
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
return $date->getTimestamp();
}
}
// attempt a fallback for unusual formatting
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
return $date->getTimestamp();
}
throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
}
/**
* Gets the name of the cookie.
*
* @return string The cookie name
*
* @api
*/
public function getName()
{
return $this->name;
}
/**
* Gets the value of the cookie.
*
* @return string The cookie value
*
* @api
*/
public function getValue()
{
return $this->value;
}
/**
* Gets the raw value of the cookie.
*
* @return string The cookie value
*
* @api
*/
public function getRawValue()
{
return $this->rawValue;
}
/**
* Gets the expires time of the cookie.
*
* @return string The cookie expires time
*
* @api
*/
public function getExpiresTime()
{
return $this->expires;
}
/**
* Gets the path of the cookie.
*
* @return string The cookie path
*
* @api
*/
public function getPath()
{
return $this->path;
}
/**
* Gets the domain of the cookie.
*
* @return string The cookie domain
*
* @api
*/
public function getDomain()
{
return $this->domain;
}
/**
* Returns the secure flag of the cookie.
*
* @return bool The cookie secure flag
*
* @api
*/
public function isSecure()
{
return $this->secure;
}
/**
* Returns the httponly flag of the cookie.
*
* @return bool The cookie httponly flag
*
* @api
*/
public function isHttpOnly()
{
return $this->httponly;
}
/**
* Returns true if the cookie has expired.
*
* @return bool true if the cookie has expired, false otherwise
*
* @api
*/
public function isExpired()
{
return null !== $this->expires && 0 !== $this->expires && $this->expires < time();
}
}

265
vendor/symfony/browser-kit/CookieJar.php vendored Normal file
View file

@ -0,0 +1,265 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
/**
* CookieJar.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
class CookieJar
{
protected $cookieJar = array();
/**
* Sets a cookie.
*
* @param Cookie $cookie A Cookie instance
*
* @api
*/
public function set(Cookie $cookie)
{
$this->cookieJar[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
}
/**
* Gets a cookie by name.
*
* You should never use an empty domain, but if you do so,
* this method returns the first cookie for the given name/path
* (this behavior ensures a BC behavior with previous versions of
* Symfony).
*
* @param string $name The cookie name
* @param string $path The cookie path
* @param string $domain The cookie domain
*
* @return Cookie|null A Cookie instance or null if the cookie does not exist
*
* @api
*/
public function get($name, $path = '/', $domain = null)
{
$this->flushExpiredCookies();
if (!empty($domain)) {
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
if ($cookieDomain) {
$cookieDomain = '.'.ltrim($cookieDomain, '.');
if ($cookieDomain != substr('.'.$domain, -strlen($cookieDomain))) {
continue;
}
}
foreach ($pathCookies as $cookiePath => $namedCookies) {
if ($cookiePath != substr($path, 0, strlen($cookiePath))) {
continue;
}
if (isset($namedCookies[$name])) {
return $namedCookies[$name];
}
}
}
return;
}
// avoid relying on this behavior that is mainly here for BC reasons
foreach ($this->cookieJar as $cookies) {
if (isset($cookies[$path][$name])) {
return $cookies[$path][$name];
}
}
}
/**
* Removes a cookie by name.
*
* You should never use an empty domain, but if you do so,
* all cookies for the given name/path expire (this behavior
* ensures a BC behavior with previous versions of Symfony).
*
* @param string $name The cookie name
* @param string $path The cookie path
* @param string $domain The cookie domain
*
* @api
*/
public function expire($name, $path = '/', $domain = null)
{
if (null === $path) {
$path = '/';
}
if (empty($domain)) {
// an empty domain means any domain
// this should never happen but it allows for a better BC
$domains = array_keys($this->cookieJar);
} else {
$domains = array($domain);
}
foreach ($domains as $domain) {
unset($this->cookieJar[$domain][$path][$name]);
if (empty($this->cookieJar[$domain][$path])) {
unset($this->cookieJar[$domain][$path]);
if (empty($this->cookieJar[$domain])) {
unset($this->cookieJar[$domain]);
}
}
}
}
/**
* Removes all the cookies from the jar.
*
* @api
*/
public function clear()
{
$this->cookieJar = array();
}
/**
* Updates the cookie jar from a response Set-Cookie headers.
*
* @param array $setCookies Set-Cookie headers from an HTTP response
* @param string $uri The base URL
*/
public function updateFromSetCookie(array $setCookies, $uri = null)
{
$cookies = array();
foreach ($setCookies as $cookie) {
foreach (explode(',', $cookie) as $i => $part) {
if (0 === $i || preg_match('/^(?P<token>\s*[0-9A-Za-z!#\$%\&\'\*\+\-\.^_`\|~]+)=/', $part)) {
$cookies[] = ltrim($part);
} else {
$cookies[count($cookies) - 1] .= ','.$part;
}
}
}
foreach ($cookies as $cookie) {
try {
$this->set(Cookie::fromString($cookie, $uri));
} catch (\InvalidArgumentException $e) {
// invalid cookies are just ignored
}
}
}
/**
* Updates the cookie jar from a Response object.
*
* @param Response $response A Response object
* @param string $uri The base URL
*/
public function updateFromResponse(Response $response, $uri = null)
{
$this->updateFromSetCookie($response->getHeader('Set-Cookie', false), $uri);
}
/**
* Returns not yet expired cookies.
*
* @return Cookie[] An array of cookies
*/
public function all()
{
$this->flushExpiredCookies();
$flattenedCookies = array();
foreach ($this->cookieJar as $path) {
foreach ($path as $cookies) {
foreach ($cookies as $cookie) {
$flattenedCookies[] = $cookie;
}
}
}
return $flattenedCookies;
}
/**
* Returns not yet expired cookie values for the given URI.
*
* @param string $uri A URI
* @param bool $returnsRawValue Returns raw value or urldecoded value
*
* @return array An array of cookie values
*/
public function allValues($uri, $returnsRawValue = false)
{
$this->flushExpiredCookies();
$parts = array_replace(array('path' => '/'), parse_url($uri));
$cookies = array();
foreach ($this->cookieJar as $domain => $pathCookies) {
if ($domain) {
$domain = '.'.ltrim($domain, '.');
if ($domain != substr('.'.$parts['host'], -strlen($domain))) {
continue;
}
}
foreach ($pathCookies as $path => $namedCookies) {
if ($path != substr($parts['path'], 0, strlen($path))) {
continue;
}
foreach ($namedCookies as $cookie) {
if ($cookie->isSecure() && 'https' != $parts['scheme']) {
continue;
}
$cookies[$cookie->getName()] = $returnsRawValue ? $cookie->getRawValue() : $cookie->getValue();
}
}
}
return $cookies;
}
/**
* Returns not yet expired raw cookie values for the given URI.
*
* @param string $uri A URI
*
* @return array An array of cookie values
*/
public function allRawValues($uri)
{
return $this->allValues($uri, true);
}
/**
* Removes all expired cookies.
*/
public function flushExpiredCookies()
{
foreach ($this->cookieJar as $domain => $pathCookies) {
foreach ($pathCookies as $path => $namedCookies) {
foreach ($namedCookies as $name => $cookie) {
if ($cookie->isExpired()) {
unset($this->cookieJar[$domain][$path][$name]);
}
}
}
}
}
}

102
vendor/symfony/browser-kit/History.php vendored Normal file
View file

@ -0,0 +1,102 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
/**
* History.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class History
{
protected $stack = array();
protected $position = -1;
/**
* Clears the history.
*/
public function clear()
{
$this->stack = array();
$this->position = -1;
}
/**
* Adds a Request to the history.
*
* @param Request $request A Request instance
*/
public function add(Request $request)
{
$this->stack = array_slice($this->stack, 0, $this->position + 1);
$this->stack[] = clone $request;
$this->position = count($this->stack) - 1;
}
/**
* Returns true if the history is empty.
*
* @return bool true if the history is empty, false otherwise
*/
public function isEmpty()
{
return count($this->stack) == 0;
}
/**
* Goes back in the history.
*
* @return Request A Request instance
*
* @throws \LogicException if the stack is already on the first page
*/
public function back()
{
if ($this->position < 1) {
throw new \LogicException('You are already on the first page.');
}
return clone $this->stack[--$this->position];
}
/**
* Goes forward in the history.
*
* @return Request A Request instance
*
* @throws \LogicException if the stack is already on the last page
*/
public function forward()
{
if ($this->position > count($this->stack) - 2) {
throw new \LogicException('You are already on the last page.');
}
return clone $this->stack[++$this->position];
}
/**
* Returns the current element in the history.
*
* @return Request A Request instance
*
* @throws \LogicException if the stack is empty
*/
public function current()
{
if (-1 == $this->position) {
throw new \LogicException('The page history is empty.');
}
return clone $this->stack[$this->position];
}
}

19
vendor/symfony/browser-kit/LICENSE vendored Normal file
View file

@ -0,0 +1,19 @@
Copyright (c) 2004-2015 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

23
vendor/symfony/browser-kit/README.md vendored Normal file
View file

@ -0,0 +1,23 @@
BrowserKit Component
====================
BrowserKit simulates the behavior of a web browser.
The component only provide an abstract client and does not provide any
"default" backend for the HTTP layer.
Resources
---------
For a simple implementation of a browser based on an HTTP layer, have a look
at [Goutte](https://github.com/FriendsOfPHP/Goutte).
For an implementation based on HttpKernelInterface, have a look at the
[Client](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Client.php)
provided by the HttpKernel component.
You can run the unit tests with the following command:
$ cd path/to/Symfony/Component/BrowserKit/
$ composer install
$ phpunit

138
vendor/symfony/browser-kit/Request.php vendored Normal file
View file

@ -0,0 +1,138 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
/**
* Request object.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
class Request
{
protected $uri;
protected $method;
protected $parameters;
protected $files;
protected $cookies;
protected $server;
protected $content;
/**
* Constructor.
*
* @param string $uri The request URI
* @param string $method The HTTP method request
* @param array $parameters The request parameters
* @param array $files An array of uploaded files
* @param array $cookies An array of cookies
* @param array $server An array of server parameters
* @param string $content The raw body data
*
* @api
*/
public function __construct($uri, $method, array $parameters = array(), array $files = array(), array $cookies = array(), array $server = array(), $content = null)
{
$this->uri = $uri;
$this->method = $method;
$this->parameters = $parameters;
$this->files = $files;
$this->cookies = $cookies;
$this->server = $server;
$this->content = $content;
}
/**
* Gets the request URI.
*
* @return string The request URI
*
* @api
*/
public function getUri()
{
return $this->uri;
}
/**
* Gets the request HTTP method.
*
* @return string The request HTTP method
*
* @api
*/
public function getMethod()
{
return $this->method;
}
/**
* Gets the request parameters.
*
* @return array The request parameters
*
* @api
*/
public function getParameters()
{
return $this->parameters;
}
/**
* Gets the request server files.
*
* @return array The request files
*
* @api
*/
public function getFiles()
{
return $this->files;
}
/**
* Gets the request cookies.
*
* @return array The request cookies
*
* @api
*/
public function getCookies()
{
return $this->cookies;
}
/**
* Gets the request server parameters.
*
* @return array The request server parameters
*
* @api
*/
public function getServer()
{
return $this->server;
}
/**
* Gets the request raw body data.
*
* @return string The request raw body data.
*
* @api
*/
public function getContent()
{
return $this->content;
}
}

139
vendor/symfony/browser-kit/Response.php vendored Normal file
View file

@ -0,0 +1,139 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit;
/**
* Response object.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
*/
class Response
{
protected $content;
protected $status;
protected $headers;
/**
* Constructor.
*
* The headers array is a set of key/value pairs. If a header is present multiple times
* then the value is an array of all the values.
*
* @param string $content The content of the response
* @param int $status The response status code
* @param array $headers An array of headers
*
* @api
*/
public function __construct($content = '', $status = 200, array $headers = array())
{
$this->content = $content;
$this->status = $status;
$this->headers = $headers;
}
/**
* Converts the response object to string containing all headers and the response content.
*
* @return string The response with headers and content
*/
public function __toString()
{
$headers = '';
foreach ($this->headers as $name => $value) {
if (is_string($value)) {
$headers .= $this->buildHeader($name, $value);
} else {
foreach ($value as $headerValue) {
$headers .= $this->buildHeader($name, $headerValue);
}
}
}
return $headers."\n".$this->content;
}
/**
* Returns the build header line.
*
* @param string $name The header name
* @param string $value The header value
*
* @return string The built header line
*/
protected function buildHeader($name, $value)
{
return sprintf("%s: %s\n", $name, $value);
}
/**
* Gets the response content.
*
* @return string The response content
*
* @api
*/
public function getContent()
{
return $this->content;
}
/**
* Gets the response status code.
*
* @return int The response status code
*
* @api
*/
public function getStatus()
{
return $this->status;
}
/**
* Gets the response headers.
*
* @return array The response headers
*
* @api
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Gets a response header.
*
* @param string $header The header name
* @param bool $first Whether to return the first value or all header values
*
* @return string|array The first header value if $first is true, an array of values otherwise
*/
public function getHeader($header, $first = true)
{
$normalizedHeader = str_replace('-', '_', strtolower($header));
foreach ($this->headers as $key => $value) {
if (str_replace('-', '_', strtolower($key)) === $normalizedHeader) {
if ($first) {
return is_array($value) ? (count($value) ? $value[0] : '') : $value;
}
return is_array($value) ? $value : array($value);
}
}
return $first ? null : array();
}
}

View file

@ -0,0 +1,639 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\Response;
class SpecialResponse extends Response
{
}
class TestClient extends Client
{
protected $nextResponse = null;
protected $nextScript = null;
public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}
public function setNextScript($script)
{
$this->nextScript = $script;
}
protected function doRequest($request)
{
if (null === $this->nextResponse) {
return new Response();
}
$response = $this->nextResponse;
$this->nextResponse = null;
return $response;
}
protected function filterResponse($response)
{
if ($response instanceof SpecialResponse) {
return new Response($response->getContent(), $response->getStatus(), $response->getHeaders());
}
return $response;
}
protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();
return <<<EOF
<?php
require_once('$path');
echo serialize($this->nextScript);
EOF;
}
}
class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Symfony\Component\BrowserKit\Client::getHistory
*/
public function testGetHistory()
{
$client = new TestClient(array(), $history = new History());
$this->assertSame($history, $client->getHistory(), '->getHistory() returns the History');
}
/**
* @covers Symfony\Component\BrowserKit\Client::getCookieJar
*/
public function testGetCookieJar()
{
$client = new TestClient(array(), null, $cookieJar = new CookieJar());
$this->assertSame($cookieJar, $client->getCookieJar(), '->getCookieJar() returns the CookieJar');
}
/**
* @covers Symfony\Component\BrowserKit\Client::getRequest
*/
public function testGetRequest()
{
$client = new TestClient();
$client->request('GET', 'http://example.com/');
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
}
public function testGetRequestWithIpAsHost()
{
$client = new TestClient();
$client->request('GET', 'https://example.com/foo', array(), array(), array('HTTP_HOST' => '127.0.0.1'));
$this->assertEquals('https://127.0.0.1/foo', $client->getRequest()->getUri());
}
public function testGetResponse()
{
$client = new TestClient();
$client->setNextResponse(new Response('foo'));
$client->request('GET', 'http://example.com/');
$this->assertEquals('foo', $client->getResponse()->getContent(), '->getCrawler() returns the Response of the last request');
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getResponse(), '->getCrawler() returns the Response of the last request');
}
public function testGetInternalResponse()
{
$client = new TestClient();
$client->setNextResponse(new SpecialResponse('foo'));
$client->request('GET', 'http://example.com/');
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
$this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getInternalResponse());
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse());
}
public function testGetContent()
{
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
$client = new TestClient();
$client->request('POST', 'http://example.com/jsonrpc', array(), array(), array(), $json);
$this->assertEquals($json, $client->getRequest()->getContent());
}
/**
* @covers Symfony\Component\BrowserKit\Client::getCrawler
*/
public function testGetCrawler()
{
$client = new TestClient();
$client->setNextResponse(new Response('foo'));
$crawler = $client->request('GET', 'http://example.com/');
$this->assertSame($crawler, $client->getCrawler(), '->getCrawler() returns the Crawler of the last request');
}
public function testRequestHttpHeaders()
{
$client = new TestClient();
$client->request('GET', '/');
$headers = $client->getRequest()->getServer();
$this->assertEquals('localhost', $headers['HTTP_HOST'], '->request() sets the HTTP_HOST header');
$client = new TestClient();
$client->request('GET', 'http://www.example.com');
$headers = $client->getRequest()->getServer();
$this->assertEquals('www.example.com', $headers['HTTP_HOST'], '->request() sets the HTTP_HOST header');
$client->request('GET', 'https://www.example.com');
$headers = $client->getRequest()->getServer();
$this->assertTrue($headers['HTTPS'], '->request() sets the HTTPS header');
$client = new TestClient();
$client->request('GET', 'http://www.example.com:8080');
$headers = $client->getRequest()->getServer();
$this->assertEquals('www.example.com:8080', $headers['HTTP_HOST'], '->request() sets the HTTP_HOST header with port');
}
public function testRequestURIConversion()
{
$client = new TestClient();
$client->request('GET', '/foo');
$this->assertEquals('http://localhost/foo', $client->getRequest()->getUri(), '->request() converts the URI to an absolute one');
$client = new TestClient();
$client->request('GET', 'http://www.example.com');
$this->assertEquals('http://www.example.com', $client->getRequest()->getUri(), '->request() does not change absolute URIs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/');
$client->request('GET', '/foo');
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo');
$client->request('GET', '#');
$this->assertEquals('http://www.example.com/foo#', $client->getRequest()->getUri(), '->request() uses the previous request for #');
$client->request('GET', '#');
$this->assertEquals('http://www.example.com/foo#', $client->getRequest()->getUri(), '->request() uses the previous request for #');
$client->request('GET', '#foo');
$this->assertEquals('http://www.example.com/foo#foo', $client->getRequest()->getUri(), '->request() uses the previous request for #');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/');
$client->request('GET', 'bar');
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'bar');
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/');
$client->request('GET', 'http');
$this->assertEquals('http://www.example.com/foo/http', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo');
$client->request('GET', 'http/bar');
$this->assertEquals('http://www.example.com/http/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
$client = new TestClient();
$client->request('GET', 'http://www.example.com/');
$client->request('GET', 'http');
$this->assertEquals('http://www.example.com/http', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
}
public function testRequestURIConversionByServerHost()
{
$client = new TestClient();
$server = array('HTTP_HOST' => 'www.exampl+e.com:8000');
$parameters = array();
$files = array();
$client->request('GET', 'http://exampl+e.com', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');
$client->request('GET', 'http://exampl+e.com:8888', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');
$client->request('GET', 'http://exampl+e.com:8000', $parameters, $files, $server);
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
}
public function testRequestReferer()
{
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'bar');
$server = $client->getRequest()->getServer();
$this->assertEquals('http://www.example.com/foo/foobar', $server['HTTP_REFERER'], '->request() sets the referer');
}
public function testRequestHistory()
{
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'bar');
$this->assertEquals('http://www.example.com/foo/bar', $client->getHistory()->current()->getUri(), '->request() updates the History');
$this->assertEquals('http://www.example.com/foo/foobar', $client->getHistory()->back()->getUri(), '->request() updates the History');
}
public function testRequestCookies()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>', 200, array('Set-Cookie' => 'foo=bar')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->allValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
$client->request('GET', 'bar');
$this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->allValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
}
public function testRequestSecureCookies()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>', 200, array('Set-Cookie' => 'foo=bar; path=/; secure')));
$client->request('GET', 'https://www.example.com/foo/foobar');
$this->assertTrue($client->getCookieJar()->get('foo', '/', 'www.example.com')->isSecure());
}
public function testClick()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
$client->click($crawler->filter('a')->link());
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() clicks on links');
}
public function testClickForm()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
$client->click($crawler->filter('input')->form());
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->click() Form submit forms');
}
public function testSubmit()
{
$client = new TestClient();
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
$client->submit($crawler->filter('input')->form());
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms');
}
public function testSubmitPreserveAuth()
{
$client = new TestClient(array('PHP_AUTH_USER' => 'foo', 'PHP_AUTH_PW' => 'bar'));
$client->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$crawler = $client->request('GET', 'http://www.example.com/foo/foobar');
$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('PHP_AUTH_USER', $server);
$this->assertEquals('foo', $server['PHP_AUTH_USER']);
$this->assertArrayHasKey('PHP_AUTH_PW', $server);
$this->assertEquals('bar', $server['PHP_AUTH_PW']);
$client->submit($crawler->filter('input')->form());
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->submit() submit forms');
$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('PHP_AUTH_USER', $server);
$this->assertEquals('foo', $server['PHP_AUTH_USER']);
$this->assertArrayHasKey('PHP_AUTH_PW', $server);
$this->assertEquals('bar', $server['PHP_AUTH_PW']);
}
public function testFollowRedirect()
{
$client = new TestClient();
$client->followRedirects(false);
$client->request('GET', 'http://www.example.com/foo/foobar');
try {
$client->followRedirect();
$this->fail('->followRedirect() throws a \LogicException if the request was not redirected');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was not redirected');
}
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->followRedirect();
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() automatically follows redirects if followRedirects is true');
$client = new TestClient();
$client->setNextResponse(new Response('', 201, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/foo/foobar', $client->getRequest()->getUri(), '->followRedirect() does not follow redirect if HTTP Code is not 30x');
$client = new TestClient();
$client->setNextResponse(new Response('', 201, array('Location' => 'http://www.example.com/redirected')));
$client->followRedirects(false);
$client->request('GET', 'http://www.example.com/foo/foobar');
try {
$client->followRedirect();
$this->fail('->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request did not respond with 30x HTTP Code');
}
}
public function testFollowRelativeRedirect()
{
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected:1234')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected:1234', $client->getRequest()->getUri(), '->followRedirect() follows relative urls');
}
public function testFollowRedirectWithMaxRedirects()
{
$client = new TestClient();
$client->setMaxRedirects(1);
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected2')));
try {
$client->followRedirect();
$this->fail('->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->followRedirect() throws a \LogicException if the request was redirected and limit of redirections was reached');
}
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows relative URLs');
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '//www.example.org/')));
$client->request('GET', 'https://www.example.com/');
$this->assertEquals('https://www.example.org/', $client->getRequest()->getUri(), '->followRedirect() follows protocol-relative URLs');
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));
$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
$this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
}
public function testFollowRedirectWithCookies()
{
$client = new TestClient();
$client->followRedirects(false);
$client->setNextResponse(new Response('', 302, array(
'Location' => 'http://www.example.com/redirected',
'Set-Cookie' => 'foo=bar',
)));
$client->request('GET', 'http://www.example.com/');
$this->assertEquals(array(), $client->getRequest()->getCookies());
$client->followRedirect();
$this->assertEquals(array('foo' => 'bar'), $client->getRequest()->getCookies());
}
public function testFollowRedirectWithHeaders()
{
$headers = array(
'HTTP_HOST' => 'www.example.com',
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
'CONTENT_TYPE' => 'application/vnd.custom+xml',
'HTTPS' => false,
);
$client = new TestClient();
$client->followRedirects(false);
$client->setNextResponse(new Response('', 302, array(
'Location' => 'http://www.example.com/redirected',
)));
$client->request('GET', 'http://www.example.com/', array(), array(), array(
'CONTENT_TYPE' => 'application/vnd.custom+xml',
));
$this->assertEquals($headers, $client->getRequest()->getServer());
$client->followRedirect();
$headers['HTTP_REFERER'] = 'http://www.example.com/';
$this->assertEquals($headers, $client->getRequest()->getServer());
}
public function testFollowRedirectWithPort()
{
$headers = array(
'HTTP_HOST' => 'www.example.com:8080',
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
'HTTPS' => false,
'HTTP_REFERER' => 'http://www.example.com:8080/',
);
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array(
'Location' => 'http://www.example.com:8080/redirected',
)));
$client->request('GET', 'http://www.example.com:8080/');
$this->assertEquals($headers, $client->getRequest()->getServer());
}
public function testBack()
{
$client = new TestClient();
$parameters = array('foo' => 'bar');
$files = array('myfile.foo' => 'baz');
$server = array('X_TEST_FOO' => 'bazbar');
$content = 'foobarbaz';
$client->request('GET', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);
$client->request('GET', 'http://www.example.com/foo');
$client->back();
$this->assertEquals('http://www.example.com/foo/foobar', $client->getRequest()->getUri(), '->back() goes back in the history');
$this->assertArrayHasKey('foo', $client->getRequest()->getParameters(), '->back() keeps parameters');
$this->assertArrayHasKey('myfile.foo', $client->getRequest()->getFiles(), '->back() keeps files');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->back() keeps $_SERVER');
$this->assertEquals($content, $client->getRequest()->getContent(), '->back() keeps content');
}
public function testForward()
{
$client = new TestClient();
$parameters = array('foo' => 'bar');
$files = array('myfile.foo' => 'baz');
$server = array('X_TEST_FOO' => 'bazbar');
$content = 'foobarbaz';
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->request('GET', 'http://www.example.com/foo', $parameters, $files, $server, $content);
$client->back();
$client->forward();
$this->assertEquals('http://www.example.com/foo', $client->getRequest()->getUri(), '->forward() goes forward in the history');
$this->assertArrayHasKey('foo', $client->getRequest()->getParameters(), '->forward() keeps parameters');
$this->assertArrayHasKey('myfile.foo', $client->getRequest()->getFiles(), '->forward() keeps files');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->forward() keeps $_SERVER');
$this->assertEquals($content, $client->getRequest()->getContent(), '->forward() keeps content');
}
public function testReload()
{
$client = new TestClient();
$parameters = array('foo' => 'bar');
$files = array('myfile.foo' => 'baz');
$server = array('X_TEST_FOO' => 'bazbar');
$content = 'foobarbaz';
$client->request('GET', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);
$client->reload();
$this->assertEquals('http://www.example.com/foo/foobar', $client->getRequest()->getUri(), '->reload() reloads the current page');
$this->assertArrayHasKey('foo', $client->getRequest()->getParameters(), '->reload() keeps parameters');
$this->assertArrayHasKey('myfile.foo', $client->getRequest()->getFiles(), '->reload() keeps files');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->reload() keeps $_SERVER');
$this->assertEquals($content, $client->getRequest()->getContent(), '->reload() keeps content');
}
public function testRestart()
{
$client = new TestClient();
$client->request('GET', 'http://www.example.com/foo/foobar');
$client->restart();
$this->assertTrue($client->getHistory()->isEmpty(), '->restart() clears the history');
$this->assertEquals(array(), $client->getCookieJar()->all(), '->restart() clears the cookies');
}
public function testInsulatedRequests()
{
$client = new TestClient();
$client->insulate();
$client->setNextScript("new Symfony\Component\BrowserKit\Response('foobar')");
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('foobar', $client->getResponse()->getContent(), '->insulate() process the request in a forked process');
$client->setNextScript("new Symfony\Component\BrowserKit\Response('foobar)");
try {
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->fail('->request() throws a \RuntimeException if the script has an error');
} catch (\Exception $e) {
$this->assertInstanceOf('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error');
}
}
public function testGetServerParameter()
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertEquals('testvalue', $client->getServerParameter('testkey', 'testvalue'));
}
public function testSetServerParameter()
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$client->setServerParameter('HTTP_HOST', 'testhost');
$this->assertEquals('testhost', $client->getServerParameter('HTTP_HOST'));
$client->setServerParameter('HTTP_USER_AGENT', 'testua');
$this->assertEquals('testua', $client->getServerParameter('HTTP_USER_AGENT'));
}
public function testSetServerParameterInRequest()
{
$client = new TestClient();
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$client->request('GET', 'https://www.example.com/https/www.example.com', array(), array(), array(
'HTTP_HOST' => 'testhost',
'HTTP_USER_AGENT' => 'testua',
'HTTPS' => false,
'NEW_SERVER_KEY' => 'new-server-key-value',
));
$this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertEquals('http://testhost/https/www.example.com', $client->getRequest()->getUri());
$server = $client->getRequest()->getServer();
$this->assertArrayHasKey('HTTP_USER_AGENT', $server);
$this->assertEquals('testua', $server['HTTP_USER_AGENT']);
$this->assertArrayHasKey('HTTP_HOST', $server);
$this->assertEquals('testhost', $server['HTTP_HOST']);
$this->assertArrayHasKey('NEW_SERVER_KEY', $server);
$this->assertEquals('new-server-key-value', $server['NEW_SERVER_KEY']);
$this->assertArrayHasKey('HTTPS', $server);
$this->assertFalse($server['HTTPS']);
}
}

View file

@ -0,0 +1,231 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\BrowserKit\Response;
class CookieJarTest extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie = new Cookie('foo', 'bar'));
$this->assertEquals($cookie, $cookieJar->get('foo'), '->set() sets a cookie');
$this->assertNull($cookieJar->get('foobar'), '->get() returns null if the cookie does not exist');
$cookieJar->set($cookie = new Cookie('foo', 'bar', time() - 86400));
$this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
}
public function testExpire()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie = new Cookie('foo', 'bar'));
$cookieJar->expire('foo');
$this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
}
public function testAll()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar'));
$cookieJar->set($cookie2 = new Cookie('bar', 'foo'));
$this->assertEquals(array($cookie1, $cookie2), $cookieJar->all(), '->all() returns all cookies in the jar');
}
public function testClear()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar'));
$cookieJar->set($cookie2 = new Cookie('bar', 'foo'));
$cookieJar->clear();
$this->assertEquals(array(), $cookieJar->all(), '->clear() expires all cookies');
}
public function testUpdateFromResponse()
{
$response = new Response('', 200, array('Set-Cookie' => 'foo=foo'));
$cookieJar = new CookieJar();
$cookieJar->updateFromResponse($response);
$this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromResponse() updates cookies from a Response objects');
}
public function testUpdateFromSetCookie()
{
$setCookies = array('foo=foo');
$cookieJar = new CookieJar();
$cookieJar->set(new Cookie('bar', 'bar'));
$cookieJar->updateFromSetCookie($setCookies);
$this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $cookieJar->get('foo'));
$this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $cookieJar->get('bar'));
$this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromSetCookie() updates cookies from a Set-Cookie header');
$this->assertEquals('bar', $cookieJar->get('bar')->getValue(), '->updateFromSetCookie() keeps existing cookies');
}
public function testUpdateFromEmptySetCookie()
{
$cookieJar = new CookieJar();
$cookieJar->updateFromSetCookie(array(''));
$this->assertEquals(array(), $cookieJar->all());
}
public function testUpdateFromSetCookieWithMultipleCookies()
{
$timestamp = time() + 3600;
$date = gmdate('D, d M Y H:i:s \G\M\T', $timestamp);
$setCookies = array(sprintf('foo=foo; expires=%s; domain=.symfony.com; path=/, bar=bar; domain=.blog.symfony.com, PHPSESSID=id; expires=%s', $date, $date));
$cookieJar = new CookieJar();
$cookieJar->updateFromSetCookie($setCookies);
$fooCookie = $cookieJar->get('foo', '/', '.symfony.com');
$barCookie = $cookieJar->get('bar', '/', '.blog.symfony.com');
$phpCookie = $cookieJar->get('PHPSESSID');
$this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $fooCookie);
$this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $barCookie);
$this->assertInstanceOf('Symfony\Component\BrowserKit\Cookie', $phpCookie);
$this->assertEquals('foo', $fooCookie->getValue());
$this->assertEquals('bar', $barCookie->getValue());
$this->assertEquals('id', $phpCookie->getValue());
$this->assertEquals($timestamp, $fooCookie->getExpiresTime());
$this->assertNull($barCookie->getExpiresTime());
$this->assertEquals($timestamp, $phpCookie->getExpiresTime());
}
/**
* @dataProvider provideAllValuesValues
*/
public function testAllValues($uri, $values)
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
$cookieJar->set($cookie2 = new Cookie('foo_expired', 'foo', time() - 86400));
$cookieJar->set($cookie3 = new Cookie('foo_path', 'foo', null, '/foo'));
$cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', '.example.com'));
$cookieJar->set($cookie4 = new Cookie('foo_strict_domain', 'foo', null, '/', '.www4.example.com'));
$cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));
$this->assertEquals($values, array_keys($cookieJar->allValues($uri)), '->allValues() returns the cookie for a given URI');
}
public function provideAllValuesValues()
{
return array(
array('http://www.example.com', array('foo_nothing', 'foo_domain')),
array('http://www.example.com/', array('foo_nothing', 'foo_domain')),
array('http://foo.example.com/', array('foo_nothing', 'foo_domain')),
array('http://foo.example1.com/', array('foo_nothing')),
array('https://foo.example.com/', array('foo_nothing', 'foo_secure', 'foo_domain')),
array('http://www.example.com/foo/bar', array('foo_nothing', 'foo_path', 'foo_domain')),
array('http://www4.example.com/', array('foo_nothing', 'foo_domain', 'foo_strict_domain')),
);
}
public function testEncodedValues()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true));
$this->assertEquals(array('foo' => 'bar=baz'), $cookieJar->allValues('/'));
$this->assertEquals(array('foo' => 'bar%3Dbaz'), $cookieJar->allRawValues('/'));
}
public function testCookieExpireWithSameNameButDifferentPaths()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/foo'));
$cookieJar->set($cookie2 = new Cookie('foo', 'bar2', null, '/bar'));
$cookieJar->expire('foo', '/foo');
$this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
$this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
$this->assertEquals(array(), $cookieJar->allValues('http://example.com/foo'));
$this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://example.com/bar'));
}
public function testCookieExpireWithNullPaths()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/'));
$cookieJar->expire('foo', null);
$this->assertNull($cookieJar->get('foo'), '->get() returns null if the cookie is expired');
$this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
}
public function testCookieWithSameNameButDifferentPaths()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/foo'));
$cookieJar->set($cookie2 = new Cookie('foo', 'bar2', null, '/bar'));
$this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
$this->assertEquals(array('foo' => 'bar1'), $cookieJar->allValues('http://example.com/foo'));
$this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://example.com/bar'));
}
public function testCookieWithSameNameButDifferentDomains()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar1', null, '/', 'foo.example.com'));
$cookieJar->set($cookie2 = new Cookie('foo', 'bar2', null, '/', 'bar.example.com'));
$this->assertEquals(array(), array_keys($cookieJar->allValues('http://example.com/')));
$this->assertEquals(array('foo' => 'bar1'), $cookieJar->allValues('http://foo.example.com/'));
$this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://bar.example.com/'));
}
public function testCookieGetWithSubdomain()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar', null, '/', '.example.com'));
$cookieJar->set($cookie2 = new Cookie('foo1', 'bar', null, '/', 'test.example.com'));
$this->assertEquals($cookie1, $cookieJar->get('foo', '/', 'foo.example.com'));
$this->assertEquals($cookie1, $cookieJar->get('foo', '/', 'example.com'));
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'test.example.com'));
}
public function testCookieGetWithSubdirectory()
{
$cookieJar = new CookieJar();
$cookieJar->set($cookie1 = new Cookie('foo', 'bar', null, '/test', '.example.com'));
$cookieJar->set($cookie2 = new Cookie('foo1', 'bar1', null, '/', '.example.com'));
$this->assertNull($cookieJar->get('foo', '/', '.example.com'));
$this->assertNull($cookieJar->get('foo', '/bar', '.example.com'));
$this->assertEquals($cookie1, $cookieJar->get('foo', '/test', 'example.com'));
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'example.com'));
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar', 'example.com'));
}
public function testCookieWithWildcardDomain()
{
$cookieJar = new CookieJar();
$cookieJar->set(new Cookie('foo', 'bar', null, '/', '.example.com'));
$this->assertEquals(array('foo' => 'bar'), $cookieJar->allValues('http://www.example.com'));
$this->assertEmpty($cookieJar->allValues('http://wwwexample.com'));
}
}

View file

@ -0,0 +1,179 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\Cookie;
class CookieTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getTestsForToFromString
*/
public function testToFromString($cookie, $url = null)
{
$this->assertEquals($cookie, (string) Cookie::fromString($cookie, $url));
}
public function getTestsForToFromString()
{
return array(
array('foo=bar; path=/'),
array('foo=bar; path=/foo'),
array('foo=bar; domain=google.com; path=/'),
array('foo=bar; domain=example.com; path=/; secure', 'https://example.com/'),
array('foo=bar; path=/; httponly'),
array('foo=bar; domain=google.com; path=/foo; secure; httponly', 'https://google.com/'),
array('foo=bar=baz; path=/'),
array('foo=bar%3Dbaz; path=/'),
);
}
public function testFromStringIgnoreSecureFlag()
{
$this->assertFalse(Cookie::fromString('foo=bar; secure')->isSecure());
$this->assertFalse(Cookie::fromString('foo=bar; secure', 'http://example.com/')->isSecure());
}
/**
* @dataProvider getExpireCookieStrings
*/
public function testFromStringAcceptsSeveralExpiresDateFormats($cookie)
{
$this->assertEquals(1596185377, Cookie::fromString($cookie)->getExpiresTime());
}
public function getExpireCookieStrings()
{
return array(
array('foo=bar; expires=Fri, 31-Jul-2020 08:49:37 GMT'),
array('foo=bar; expires=Fri, 31 Jul 2020 08:49:37 GMT'),
array('foo=bar; expires=Fri, 31-07-2020 08:49:37 GMT'),
array('foo=bar; expires=Fri, 31-07-20 08:49:37 GMT'),
array('foo=bar; expires=Friday, 31-Jul-20 08:49:37 GMT'),
array('foo=bar; expires=Fri Jul 31 08:49:37 2020'),
array('foo=bar; expires=\'Fri Jul 31 08:49:37 2020\''),
array('foo=bar; expires=Friday July 31st 2020, 08:49:37 GMT'),
);
}
public function testFromStringWithCapitalization()
{
$this->assertEquals('Foo=Bar; path=/', (string) Cookie::fromString('Foo=Bar'));
$this->assertEquals('foo=bar; expires=Fri, 31 Dec 2010 23:59:59 GMT; path=/', (string) Cookie::fromString('foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT'));
$this->assertEquals('foo=bar; domain=www.example.org; path=/; httponly', (string) Cookie::fromString('foo=bar; DOMAIN=www.example.org; HttpOnly'));
}
public function testFromStringWithUrl()
{
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com/'));
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com'));
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar', 'http://www.example.com?foo'));
$this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::fromString('foo=bar', 'http://www.example.com/foo/bar'));
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::fromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
$this->assertEquals('foo=bar; domain=www.myotherexample.com; path=/', (string) Cookie::fromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
}
public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
{
$this->setExpectedException('InvalidArgumentException');
Cookie::fromString('foo');
}
public function testFromStringThrowsAnExceptionIfCookieDateIsNotValid()
{
$this->setExpectedException('InvalidArgumentException');
Cookie::fromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
}
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
{
$this->setExpectedException('InvalidArgumentException');
Cookie::fromString('foo=bar', 'foobar');
}
public function testGetName()
{
$cookie = new Cookie('foo', 'bar');
$this->assertEquals('foo', $cookie->getName(), '->getName() returns the cookie name');
}
public function testGetValue()
{
$cookie = new Cookie('foo', 'bar');
$this->assertEquals('bar', $cookie->getValue(), '->getValue() returns the cookie value');
$cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
$this->assertEquals('bar=baz', $cookie->getValue(), '->getValue() returns the urldecoded cookie value');
}
public function testGetRawValue()
{
$cookie = new Cookie('foo', 'bar=baz'); // decoded value
$this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the urlencoded cookie value');
$cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
$this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the non-urldecoded cookie value');
}
public function testGetPath()
{
$cookie = new Cookie('foo', 'bar', 0);
$this->assertEquals('/', $cookie->getPath(), '->getPath() returns / is no path is defined');
$cookie = new Cookie('foo', 'bar', 0, '/foo');
$this->assertEquals('/foo', $cookie->getPath(), '->getPath() returns the cookie path');
}
public function testGetDomain()
{
$cookie = new Cookie('foo', 'bar', 0, '/', 'foo.com');
$this->assertEquals('foo.com', $cookie->getDomain(), '->getDomain() returns the cookie domain');
}
public function testIsSecure()
{
$cookie = new Cookie('foo', 'bar');
$this->assertFalse($cookie->isSecure(), '->isSecure() returns false if not defined');
$cookie = new Cookie('foo', 'bar', 0, '/', 'foo.com', true);
$this->assertTrue($cookie->isSecure(), '->isSecure() returns the cookie secure flag');
}
public function testIsHttponly()
{
$cookie = new Cookie('foo', 'bar');
$this->assertTrue($cookie->isHttpOnly(), '->isHttpOnly() returns false if not defined');
$cookie = new Cookie('foo', 'bar', 0, '/', 'foo.com', false, true);
$this->assertTrue($cookie->isHttpOnly(), '->isHttpOnly() returns the cookie httponly flag');
}
public function testGetExpiresTime()
{
$cookie = new Cookie('foo', 'bar');
$this->assertNull($cookie->getExpiresTime(), '->getExpiresTime() returns the expires time');
$cookie = new Cookie('foo', 'bar', $time = time() - 86400);
$this->assertEquals($time, $cookie->getExpiresTime(), '->getExpiresTime() returns the expires time');
}
public function testIsExpired()
{
$cookie = new Cookie('foo', 'bar');
$this->assertFalse($cookie->isExpired(), '->isExpired() returns false when the cookie never expires (null as expires time)');
$cookie = new Cookie('foo', 'bar', time() - 86400);
$this->assertTrue($cookie->isExpired(), '->isExpired() returns true when the cookie is expired');
$cookie = new Cookie('foo', 'bar', 0);
$this->assertFalse($cookie->isExpired());
}
}

View file

@ -0,0 +1,101 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\Request;
class HistoryTest extends \PHPUnit_Framework_TestCase
{
public function testAdd()
{
$history = new History();
$history->add(new Request('http://www.example1.com/', 'get'));
$this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->add() adds a request to the history');
$history->add(new Request('http://www.example2.com/', 'get'));
$this->assertSame('http://www.example2.com/', $history->current()->getUri(), '->add() adds a request to the history');
$history->add(new Request('http://www.example3.com/', 'get'));
$history->back();
$history->add(new Request('http://www.example4.com/', 'get'));
$this->assertSame('http://www.example4.com/', $history->current()->getUri(), '->add() adds a request to the history');
$history->back();
$this->assertSame('http://www.example2.com/', $history->current()->getUri(), '->add() adds a request to the history');
}
public function testClearIsEmpty()
{
$history = new History();
$history->add(new Request('http://www.example.com/', 'get'));
$this->assertFalse($history->isEmpty(), '->isEmpty() returns false if the history is not empty');
$history->clear();
$this->assertTrue($history->isEmpty(), '->isEmpty() true if the history is empty');
}
public function testCurrent()
{
$history = new History();
try {
$history->current();
$this->fail('->current() throws a \LogicException if the history is empty');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is empty');
}
$history->add(new Request('http://www.example.com/', 'get'));
$this->assertSame('http://www.example.com/', $history->current()->getUri(), '->current() returns the current request in the history');
}
public function testBack()
{
$history = new History();
$history->add(new Request('http://www.example.com/', 'get'));
try {
$history->back();
$this->fail('->back() throws a \LogicException if the history is already on the first page');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is already on the first page');
}
$history->add(new Request('http://www.example1.com/', 'get'));
$history->back();
$this->assertSame('http://www.example.com/', $history->current()->getUri(), '->back() returns the previous request in the history');
}
public function testForward()
{
$history = new History();
$history->add(new Request('http://www.example.com/', 'get'));
$history->add(new Request('http://www.example1.com/', 'get'));
try {
$history->forward();
$this->fail('->forward() throws a \LogicException if the history is already on the last page');
} catch (\Exception $e) {
$this->assertInstanceOf('LogicException', $e, '->forward() throws a \LogicException if the history is already on the last page');
}
$history->back();
$history->forward();
$this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->forward() returns the next request in the history');
}
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\Request;
class RequestTest extends \PHPUnit_Framework_TestCase
{
public function testGetUri()
{
$request = new Request('http://www.example.com/', 'get');
$this->assertEquals('http://www.example.com/', $request->getUri(), '->getUri() returns the URI of the request');
}
public function testGetMethod()
{
$request = new Request('http://www.example.com/', 'get');
$this->assertEquals('get', $request->getMethod(), '->getMethod() returns the method of the request');
}
public function testGetParameters()
{
$request = new Request('http://www.example.com/', 'get', array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $request->getParameters(), '->getParameters() returns the parameters of the request');
}
public function testGetFiles()
{
$request = new Request('http://www.example.com/', 'get', array(), array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $request->getFiles(), '->getFiles() returns the uploaded files of the request');
}
public function testGetCookies()
{
$request = new Request('http://www.example.com/', 'get', array(), array(), array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $request->getCookies(), '->getCookies() returns the cookies of the request');
}
public function testGetServer()
{
$request = new Request('http://www.example.com/', 'get', array(), array(), array(), array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $request->getServer(), '->getServer() returns the server parameters of the request');
}
}

View file

@ -0,0 +1,76 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\BrowserKit\Tests;
use Symfony\Component\BrowserKit\Response;
class ResponseTest extends \PHPUnit_Framework_TestCase
{
public function testGetUri()
{
$response = new Response('foo');
$this->assertEquals('foo', $response->getContent(), '->getContent() returns the content of the response');
}
public function testGetStatus()
{
$response = new Response('foo', 304);
$this->assertEquals('304', $response->getStatus(), '->getStatus() returns the status of the response');
}
public function testGetHeaders()
{
$response = new Response('foo', 200, array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $response->getHeaders(), '->getHeaders() returns the headers of the response');
}
public function testGetHeader()
{
$response = new Response('foo', 200, array(
'Content-Type' => 'text/html',
'Set-Cookie' => array('foo=bar', 'bar=foo'),
));
$this->assertEquals('text/html', $response->getHeader('Content-Type'), '->getHeader() returns a header of the response');
$this->assertEquals('text/html', $response->getHeader('content-type'), '->getHeader() returns a header of the response');
$this->assertEquals('text/html', $response->getHeader('content_type'), '->getHeader() returns a header of the response');
$this->assertEquals('foo=bar', $response->getHeader('Set-Cookie'), '->getHeader() returns the first header value');
$this->assertEquals(array('foo=bar', 'bar=foo'), $response->getHeader('Set-Cookie', false), '->getHeader() returns all header values if first is false');
$this->assertNull($response->getHeader('foo'), '->getHeader() returns null if the header is not defined');
$this->assertEquals(array(), $response->getHeader('foo', false), '->getHeader() returns an empty array if the header is not defined and first is set to false');
}
public function testMagicToString()
{
$response = new Response('foo', 304, array('foo' => 'bar'));
$this->assertEquals("foo: bar\n\nfoo", $response->__toString(), '->__toString() returns the headers and the content as a string');
}
public function testMagicToStringWithMultipleSetCookieHeader()
{
$headers = array(
'content-type' => 'text/html; charset=utf-8',
'set-cookie' => array('foo=bar', 'bar=foo'),
);
$expected = 'content-type: text/html; charset=utf-8'."\n";
$expected .= 'set-cookie: foo=bar'."\n";
$expected .= 'set-cookie: bar=foo'."\n\n";
$expected .= 'foo';
$response = new Response('foo', 304, $headers);
$this->assertEquals($expected, $response->__toString(), '->__toString() returns the headers and the content as a string');
}
}

View file

@ -0,0 +1,39 @@
{
"name": "symfony/browser-kit",
"type": "library",
"description": "Symfony BrowserKit Component",
"keywords": [],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": ">=5.3.9",
"symfony/dom-crawler": "~2.0,>=2.0.5"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7",
"symfony/process": "~2.0,>=2.0.5",
"symfony/css-selector": "~2.0,>=2.0.5"
},
"suggest": {
"symfony/process": ""
},
"autoload": {
"psr-4": { "Symfony\\Component\\BrowserKit\\": "" }
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
}
}

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Symfony BrowserKit Component Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>