UriSignerTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests;
  11. use Symfony\Component\HttpKernel\UriSigner;
  12. class UriSignerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testSign()
  15. {
  16. $signer = new UriSigner('foobar');
  17. $this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
  18. $this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
  19. }
  20. public function testCheck()
  21. {
  22. $signer = new UriSigner('foobar');
  23. $this->assertFalse($signer->check('http://example.com/foo?_hash=foo'));
  24. $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo'));
  25. $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo&bar=foo'));
  26. $this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
  27. $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
  28. }
  29. }