Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StateKeyTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class StateKeyTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $storeManagerMock;
17 
22 
26  protected $queryFactoryMock;
27 
31  protected $model;
32 
33  protected function setUp()
34  {
35  $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
36  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
37  $this->queryFactoryMock = $this->createMock(\Magento\Search\Model\QueryFactory::class);
38 
39  $this->model = new StateKey($this->storeManagerMock, $this->customerSessionMock, $this->queryFactoryMock);
40  }
41 
46  public function testToString()
47  {
48  $categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
49  $categoryMock->expects($this->once())->method('getId')->will($this->returnValue('1'));
50 
51  $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
52  $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
53  $storeMock->expects($this->once())->method('getId')->will($this->returnValue('2'));
54 
55  $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue('3'));
56 
57  $queryMock = $this->createPartialMock(\Magento\Search\Model\Query::class, ['getId']);
58  $queryMock->expects($this->once())->method('getId')->will($this->returnValue('4'));
59  $this->queryFactoryMock->expects($this->once())->method('get')->will($this->returnValue($queryMock));
60 
61  $this->assertEquals('Q_4_STORE_2_CAT_1_CUSTGROUP_3', $this->model->toString($categoryMock));
62  }
63 }