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

208
vendor/fabpot/goutte/Goutte/Client.php vendored Normal file
View file

@ -0,0 +1,208 @@
<?php
/*
* This file is part of the Goutte 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 Goutte;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\BrowserKit\Client as BaseClient;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\BrowserKit\Response;
/**
* Client.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Michael Dowling <michael@guzzlephp.org>
* @author Charles Sarrazin <charles@sarraz.in>
*/
class Client extends BaseClient
{
protected $client;
private $headers = array();
private $auth = null;
public function setClient(GuzzleClientInterface $client)
{
$this->client = $client;
return $this;
}
public function getClient()
{
if (!$this->client) {
$this->client = new GuzzleClient(array('defaults' => array('allow_redirects' => false, 'cookies' => true)));
}
return $this->client;
}
public function setHeader($name, $value)
{
$this->headers[$name] = $value;
return $this;
}
public function removeHeader($name)
{
unset($this->headers[$name]);
}
public function setAuth($user, $password = '', $type = 'basic')
{
$this->auth = array($user, $password, $type);
return $this;
}
public function resetAuth()
{
$this->auth = null;
return $this;
}
/**
* @param Request $request
*
* @return Response
*/
protected function doRequest($request)
{
$headers = array();
foreach ($request->getServer() as $key => $val) {
$key = strtolower(str_replace('_', '-', $key));
$contentHeaders = array('content-length' => true, 'content-md5' => true, 'content-type' => true);
if (0 === strpos($key, 'http-')) {
$headers[substr($key, 5)] = $val;
}
// CONTENT_* are not prefixed with HTTP_
elseif (isset($contentHeaders[$key])) {
$headers[$key] = $val;
}
}
$cookies = CookieJar::fromArray(
$this->getCookieJar()->allRawValues($request->getUri()),
parse_url($request->getUri(), PHP_URL_HOST)
);
$requestOptions = array(
'cookies' => $cookies,
'allow_redirects' => false,
'auth' => $this->auth,
);
if (!in_array($request->getMethod(), array('GET', 'HEAD'))) {
if (null !== $content = $request->getContent()) {
$requestOptions['body'] = $content;
} else {
if ($files = $request->getFiles()) {
$requestOptions['multipart'] = [];
$this->addPostFields($request->getParameters(), $requestOptions['multipart']);
$this->addPostFiles($files, $requestOptions['multipart']);
} else {
$requestOptions['form_params'] = $request->getParameters();
}
}
}
if (!empty($headers)) {
$requestOptions['headers'] = $headers;
}
$method = $request->getMethod();
$uri = $request->getUri();
foreach ($this->headers as $name => $value) {
$requestOptions['headers'][$name] = $value;
}
// Let BrowserKit handle redirects
try {
$response = $this->getClient()->request($method, $uri, $requestOptions);
} catch (RequestException $e) {
$response = $e->getResponse();
if (null === $response) {
throw $e;
}
}
return $this->createResponse($response);
}
protected function addPostFiles(array $files, array &$multipart, $arrayName = '')
{
if (empty($files)) {
return;
}
foreach ($files as $name => $info) {
if (!empty($arrayName)) {
$name = $arrayName.'['.$name.']';
}
$file = [
'name' => $name,
];
if (is_array($info)) {
if (isset($info['tmp_name'])) {
if ('' !== $info['tmp_name']) {
$file['contents'] = fopen($info['tmp_name'], 'r');
if (isset($info['name'])) {
$file['filename'] = $info['name'];
}
} else {
continue;
}
} else {
$this->addPostFiles($info, $multipart, $name);
continue;
}
} else {
$file['contents'] = fopen($info, 'r');
}
$multipart[] = $file;
}
}
public function addPostFields(array $formParams, array &$multipart, $arrayName = '')
{
foreach ($formParams as $name => $value) {
if (!empty($arrayName)) {
$name = $arrayName.'['.$name.']';
}
if (is_array($value)) {
$this->addPostFields($value, $multipart, $name);
} else {
$multipart[] = [
'name' => $name,
'contents' => $value,
];
}
}
}
protected function createResponse(ResponseInterface $response)
{
return new Response((string) $response->getBody(), $response->getStatusCode(), $response->getHeaders());
}
}

View file

@ -0,0 +1,14 @@
<?php
/*
* This file is part of the Goutte utility.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
require_once 'phar://'.__FILE__.'/vendor/autoload.php';
__HALT_COMPILER();

View file

@ -0,0 +1,375 @@
<?php
/*
* This file is part of the Goutte 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 Goutte\Tests;
use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Middleware;
use Symfony\Component\BrowserKit\Cookie;
/**
* Goutte Client Test.
*
* @author Michael Dowling <michael@guzzlephp.org>
* @author Charles Sarrazin <charles@sarraz.in>
*/
class ClientTest extends \PHPUnit_Framework_TestCase
{
protected $history;
/** @var MockHandler */
protected $mock;
protected function getGuzzle(array $responses = [])
{
if (empty($responses)) {
$responses = [new GuzzleResponse(200, [], '<html><body><p>Hi</p></body></html>')];
}
$this->mock = new MockHandler($responses);
$handlerStack = HandlerStack::create($this->mock);
$this->history = [];
$handlerStack->push(Middleware::history($this->history));
$guzzle = new GuzzleClient(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack));
return $guzzle;
}
public function testCreatesDefaultClient()
{
$client = new Client();
$this->assertInstanceOf('GuzzleHttp\\ClientInterface', $client->getClient());
}
public function testUsesCustomClient()
{
$guzzle = new GuzzleClient();
$client = new Client();
$this->assertSame($client, $client->setClient($guzzle));
$this->assertSame($guzzle, $client->getClient());
}
public function testUsesCustomHeaders()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setHeader('X-Test', 'test');
$client->request('GET', 'http://www.example.com/');
$this->assertEquals('test', end($this->history)['request']->getHeaderLine('X-Test'));
}
public function testCustomUserAgent()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setHeader('User-Agent', 'foo');
$client->request('GET', 'http://www.example.com/');
$this->assertEquals('Symfony2 BrowserKit, foo', end($this->history)['request']->getHeaderLine('User-Agent'));
}
public function testUsesAuth()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
$client->request('GET', 'http://www.example.com/');
$request = end($this->history)['request'];
$this->assertEquals('Basic bWU6Kio=', $request->getHeaderLine('Authorization'));
}
public function testResetsAuth()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->setAuth('me', '**');
$client->resetAuth();
$client->request('GET', 'http://www.example.com/');
$request = end($this->history)['request'];
$this->assertEquals('', $request->getHeaderLine('authorization'));
}
public function testUsesCookies()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->getCookieJar()->set(new Cookie('test', '123'));
$client->request('GET', 'http://www.example.com/');
$request = end($this->history)['request'];
$this->assertEquals('test=123', $request->getHeaderLine('Cookie'));
}
public function testUsesCookiesWithCustomPort()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$client->getCookieJar()->set(new Cookie('test', '123'));
$client->request('GET', 'http://www.example.com:8000/');
$request = end($this->history)['request'];
$this->assertEquals('test=123', $request->getHeaderLine('Cookie'));
}
public function testUsesPostFiles()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => array(
'name' => 'test.txt',
'tmp_name' => __DIR__.'/fixtures.txt',
),
);
$client->request('POST', 'http://www.example.com/', array(), $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"test\"; filename=\"test.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents()
);
}
public function testUsesPostNamedFiles()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => __DIR__.'/fixtures.txt',
);
$client->request('POST', 'http://www.example.com/', array(), $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"test\"; filename=\"fixtures.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents()
);
}
public function testUsesPostFilesNestedFields()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'form' => array(
'test' => array(
'name' => 'test.txt',
'tmp_name' => __DIR__.'/fixtures.txt',
),
),
);
$client->request('POST', 'http://www.example.com/', array(), $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"form[test]\"; filename=\"test.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents()
);
}
public function testPostFormWithFiles()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => __DIR__.'/fixtures.txt',
);
$params = array(
'foo' => 'bar',
);
$client->request('POST', 'http://www.example.com/', $params, $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"foo\"\r\nContent-Length: 3\r\n"
."\r\nbar\r\n"
."--$boundary\r\nContent-Disposition: form-data; name=\"test\"; filename=\"fixtures.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents());
}
public function testPostEmbeddedFormWithFiles()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => __DIR__.'/fixtures.txt',
);
$params = array(
'foo' => array(
'bar' => 'baz',
),
);
$client->request('POST', 'http://www.example.com/', $params, $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"foo[bar]\"\r\nContent-Length: 3\r\n"
."\r\nbaz\r\n"
."--$boundary\r\nContent-Disposition: form-data; name=\"test\"; filename=\"fixtures.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents());
}
public function testUsesPostFilesOnClientSide()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => __DIR__.'/fixtures.txt',
);
$client->request('POST', 'http://www.example.com/', array(), $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals(
"--$boundary\r\nContent-Disposition: form-data; name=\"test\"; filename=\"fixtures.txt\"\r\nContent-Length: 4\r\n"
."Content-Type: text/plain\r\n\r\nfoo\n\r\n--$boundary--\r\n",
$stream->getContents()
);
}
public function testUsesPostFilesUploadError()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
),
);
$client->request('POST', 'http://www.example.com/', array(), $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
$this->assertEquals("--$boundary--\r\n", $stream->getContents());
}
public function testCreatesResponse()
{
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$crawler = $client->request('GET', 'http://www.example.com/');
$this->assertEquals('Hi', $crawler->filter('p')->text());
}
public function testHandlesRedirectsCorrectly()
{
$guzzle = $this->getGuzzle([
new GuzzleResponse(301, array(
'Location' => 'http://www.example.com/',
)),
new GuzzleResponse(200, [], '<html><body><p>Test</p></body></html>'),
]);
$client = new Client();
$client->setClient($guzzle);
$crawler = $client->request('GET', 'http://www.example.com/');
$this->assertEquals('Test', $crawler->filter('p')->text());
// Ensure that two requests were sent
$this->assertEquals(2, count($this->history));
}
public function testConvertsGuzzleHeadersToArrays()
{
$guzzle = $this->getGuzzle([
new GuzzleResponse(200, array(
'Date' => 'Tue, 04 Jun 2013 13:22:41 GMT',
)),
]);
$client = new Client();
$client->setClient($guzzle);
$client->request('GET', 'http://www.example.com/');
$response = $client->getResponse();
$headers = $response->getHeaders();
$this->assertInternalType('array', array_shift($headers), 'Header not converted from Guzzle\Http\Message\Header to array');
}
public function testNullResponseException()
{
$this->setExpectedException('GuzzleHttp\Exception\RequestException');
$guzzle = $this->getGuzzle([
new RequestException('', $this->getMock('Psr\Http\Message\RequestInterface')),
]);
$client = new Client();
$client->setClient($guzzle);
$client->request('GET', 'http://www.example.com/');
$client->getResponse();
}
public function testHttps()
{
$guzzle = $this->getGuzzle([
new GuzzleResponse(200, [], '<html><body><p>Test</p></body></html>'),
]);
$client = new Client();
$client->setClient($guzzle);
$crawler = $client->request('GET', 'https://www.example.com/');
$this->assertEquals('Test', $crawler->filter('p')->text());
}
public function testCustomUserAgentConstructor()
{
$guzzle = $this->getGuzzle();
$client = new Client([
'HTTP_HOST' => '1.2.3.4',
'HTTP_USER_AGENT' => 'SomeHost',
]);
$client->setClient($guzzle);
$client->request('GET', 'http://www.example.com/');
$this->assertEquals('SomeHost', end($this->history)['request']->getHeaderLine('User-Agent'));
}
}

View file

@ -0,0 +1 @@
foo