12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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\Tests\Component\HttpFoundation;
- use Symfony\Component\HttpFoundation\ServerBag;
- /**
- * ServerBagTest
- *
- * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
- */
- class ServerBagTest extends \PHPUnit_Framework_TestCase
- {
- public function testShouldExtractHeadersFromServerArray()
- {
- $server = array(
- 'SOME_SERVER_VARIABLE' => 'value',
- 'SOME_SERVER_VARIABLE2' => 'value',
- 'ROOT' => 'value',
- 'HTTP_CONTENT_TYPE' => 'text/html',
- 'HTTP_CONTENT_LENGTH' => '0',
- 'HTTP_ETAG' => 'asdf',
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => 'bar',
- );
- $bag = new ServerBag($server);
- $this->assertEquals(array(
- 'CONTENT_TYPE' => 'text/html',
- 'CONTENT_LENGTH' => '0',
- 'ETAG' => 'asdf',
- 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => 'bar',
- ), $bag->getHeaders());
- }
- public function testHttpPasswordIsOptional()
- {
- $bag = new ServerBag(array('PHP_AUTH_USER' => 'foo'));
- $this->assertEquals(array(
- 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => ''
- ), $bag->getHeaders());
- }
- public function testHttpBasicAuthWithPhpCgi()
- {
- $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')));
- $this->assertEquals(array(
- 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => 'bar'
- ), $bag->getHeaders());
- }
- public function testHttpBasicAuthWithPhpCgiRedirect()
- {
- $bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:bar')));
- $this->assertEquals(array(
- 'AUTHORIZATION' => 'Basic '.base64_encode('foo:bar'),
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => 'bar'
- ), $bag->getHeaders());
- }
- public function testHttpBasicAuthWithPhpCgiEmptyPassword()
- {
- $bag = new ServerBag(array('HTTP_AUTHORIZATION' => 'Basic '.base64_encode('foo:')));
- $this->assertEquals(array(
- 'AUTHORIZATION' => 'Basic '.base64_encode('foo:'),
- 'PHP_AUTH_USER' => 'foo',
- 'PHP_AUTH_PW' => ''
- ), $bag->getHeaders());
- }
- }
|