Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerScopeDataTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class CustomerScopeDataTest extends \PHPUnit\Framework\TestCase
15 {
17  private $model;
18 
20  private $contextMock;
21 
23  private $storeManagerMock;
24 
26  private $scopeConfigMock;
27 
29  private $encoderMock;
30 
32  private $serializerMock;
33 
34  protected function setUp()
35  {
36  $this->contextMock = $this->getMockBuilder(Context::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39 
40  $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
41  ->getMock();
42 
43  $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
44  ->getMock();
45 
46  $this->encoderMock = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class)
47  ->getMock();
48 
49  $this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
50  ->getMock();
51 
52  $this->contextMock->expects($this->exactly(2))
53  ->method('getStoreManager')
54  ->willReturn($this->storeManagerMock);
55 
56  $this->contextMock->expects($this->once())
57  ->method('getScopeConfig')
58  ->willReturn($this->scopeConfigMock);
59 
60  $this->model = new CustomerScopeData(
61  $this->contextMock,
62  $this->encoderMock,
63  [],
64  $this->serializerMock
65  );
66  }
67 
68  public function testGetWebsiteId()
69  {
70  $storeId = 1;
71 
72  $storeMock = $this->getMockBuilder(StoreInterface::class)
73  ->setMethods(['getWebsiteId'])
74  ->getMockForAbstractClass();
75 
76  $storeMock->expects($this->any())
77  ->method('getWebsiteId')
78  ->willReturn($storeId);
79 
80  $this->storeManagerMock->expects($this->any())
81  ->method('getStore')
82  ->with(null)
83  ->willReturn($storeMock);
84 
85  $this->assertEquals($storeId, $this->model->getWebsiteId());
86  }
87 
88  public function testEncodeConfiguration()
89  {
90  $rules = [
91  '*' => [
92  'Magento_Customer/js/invalidation-processor' => [
93  'invalidationRules' => [
94  'website-rule' => [
95  'Magento_Customer/js/invalidation-rules/website-rule' => [
96  'scopeConfig' => [
97  'websiteId' => 1,
98  ]
99  ]
100  ]
101  ]
102  ]
103  ],
104  ];
105 
106  $this->serializerMock->expects($this->any())
107  ->method('serialize')
108  ->with($rules)
109  ->willReturn(json_encode($rules));
110 
111  $this->assertEquals(
112  json_encode($rules),
113  $this->model->encodeConfiguration($rules)
114  );
115  }
116 }