06de8902dc8cd92b1c306db4a4a8c99ea5f17a97
[yaffs-website] / vendor / symfony / http-kernel / Tests / UriSignerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\UriSigner;
16
17 class UriSignerTest extends TestCase
18 {
19     public function testSign()
20     {
21         $signer = new UriSigner('foobar');
22
23         $this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
24         $this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
25     }
26
27     public function testCheck()
28     {
29         $signer = new UriSigner('foobar');
30
31         $this->assertFalse($signer->check('http://example.com/foo?_hash=foo'));
32         $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo'));
33         $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo&bar=foo'));
34
35         $this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
36         $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
37         $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer')));
38
39         $this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
40     }
41
42     public function testCheckWithDifferentArgSeparator()
43     {
44         $this->iniSet('arg_separator.output', '&amp;');
45         $signer = new UriSigner('foobar');
46
47         $this->assertSame(
48             'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
49             $signer->sign('http://example.com/foo?foo=bar&baz=bay')
50         );
51         $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
52     }
53 }