Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
639
vendor/symfony/browser-kit/Tests/ClientTest.php
vendored
639
vendor/symfony/browser-kit/Tests/ClientTest.php
vendored
|
@ -1,639 +0,0 @@
|
|||
<?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']);
|
||||
}
|
||||
}
|
231
vendor/symfony/browser-kit/Tests/CookieJarTest.php
vendored
231
vendor/symfony/browser-kit/Tests/CookieJarTest.php
vendored
|
@ -1,231 +0,0 @@
|
|||
<?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'));
|
||||
}
|
||||
}
|
179
vendor/symfony/browser-kit/Tests/CookieTest.php
vendored
179
vendor/symfony/browser-kit/Tests/CookieTest.php
vendored
|
@ -1,179 +0,0 @@
|
|||
<?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());
|
||||
}
|
||||
}
|
101
vendor/symfony/browser-kit/Tests/HistoryTest.php
vendored
101
vendor/symfony/browser-kit/Tests/HistoryTest.php
vendored
|
@ -1,101 +0,0 @@
|
|||
<?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');
|
||||
}
|
||||
}
|
53
vendor/symfony/browser-kit/Tests/RequestTest.php
vendored
53
vendor/symfony/browser-kit/Tests/RequestTest.php
vendored
|
@ -1,53 +0,0 @@
|
|||
<?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');
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?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');
|
||||
}
|
||||
}
|
Reference in a new issue