QueryParamsResolverTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Url\Test\Unit;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. class QueryParamsResolverTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Framework\Url\QueryParamsResolver */
  11. protected $object;
  12. protected function setUp()
  13. {
  14. $objectManager = new ObjectManager($this);
  15. $this->object = $objectManager->getObject(\Magento\Framework\Url\QueryParamsResolver::class);
  16. }
  17. public function testGetQuery()
  18. {
  19. $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
  20. $this->assertEquals('foo=bar&true=false', $this->object->getQuery());
  21. }
  22. public function testGetQueryEscaped()
  23. {
  24. $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
  25. $this->assertEquals('foo=bar&amp;true=false', $this->object->getQuery(true));
  26. }
  27. public function testSetQuery()
  28. {
  29. $this->object->setQuery('foo=bar&true=false');
  30. $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
  31. }
  32. public function testSetQueryIdempotent()
  33. {
  34. $this->object->setQuery(null);
  35. $this->assertEquals([], $this->object->getQueryParams());
  36. }
  37. public function testSetQueryParam()
  38. {
  39. $this->object->setQueryParam('foo', 'bar');
  40. $this->object->setQueryParam('true', 'false');
  41. $this->object->setQueryParam('foo', 'bar');
  42. $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
  43. }
  44. public function testSetQueryParams()
  45. {
  46. $this->object->setQueryParams(['foo' => 'bar', 'true' => 'false']);
  47. $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
  48. }
  49. public function testAddQueryParamsIdempotent()
  50. {
  51. $this->object->setData('query_params', ['foo' => 'bar', 'true' => 'false']);
  52. $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
  53. $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
  54. }
  55. }