Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryParamsResolverTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class QueryParamsResolverTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $object;
15 
16  protected function setUp()
17  {
18  $objectManager = new ObjectManager($this);
19  $this->object = $objectManager->getObject(\Magento\Framework\Url\QueryParamsResolver::class);
20  }
21 
22  public function testGetQuery()
23  {
24  $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
25  $this->assertEquals('foo=bar&true=false', $this->object->getQuery());
26  }
27 
28  public function testGetQueryEscaped()
29  {
30  $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
31  $this->assertEquals('foo=bar&amp;true=false', $this->object->getQuery(true));
32  }
33 
34  public function testSetQuery()
35  {
36  $this->object->setQuery('foo=bar&true=false');
37  $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
38  }
39 
40  public function testSetQueryIdempotent()
41  {
42  $this->object->setQuery(null);
43  $this->assertEquals([], $this->object->getQueryParams());
44  }
45 
46  public function testSetQueryParam()
47  {
48  $this->object->setQueryParam('foo', 'bar');
49  $this->object->setQueryParam('true', 'false');
50  $this->object->setQueryParam('foo', 'bar');
51  $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
52  }
53 
54  public function testSetQueryParams()
55  {
56  $this->object->setQueryParams(['foo' => 'bar', 'true' => 'false']);
57  $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
58  }
59 
60  public function testAddQueryParamsIdempotent()
61  {
62  $this->object->setData('query_params', ['foo' => 'bar', 'true' => 'false']);
63  $this->object->addQueryParams(['foo' => 'bar', 'true' => 'false']);
64  $this->assertEquals(['foo' => 'bar', 'true' => 'false'], $this->object->getQueryParams());
65  }
66 }
$objectManager
Definition: bootstrap.php:17