Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AnalyticsTokenTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class AnalyticsTokenTest extends \PHPUnit\Framework\TestCase
15 {
19  private $reinitableConfigMock;
20 
24  private $configMock;
25 
29  private $configWriterMock;
30 
34  private $objectManagerHelper;
35 
39  private $tokenModel;
40 
44  private $tokenPath = 'analytics/general/token';
45 
49  protected function setUp()
50  {
51  $this->reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54 
55  $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $this->configWriterMock = $this->getMockBuilder(WriterInterface::class)
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $this->objectManagerHelper = new ObjectManagerHelper($this);
64 
65  $this->tokenModel = $this->objectManagerHelper->getObject(
66  AnalyticsToken::class,
67  [
68  'reinitableConfig' => $this->reinitableConfigMock,
69  'config' => $this->configMock,
70  'configWriter' => $this->configWriterMock,
71  'tokenPath' => $this->tokenPath,
72  ]
73  );
74  }
75 
79  public function testStoreToken()
80  {
81  $value = 'jjjj0000';
82 
83  $this->configWriterMock
84  ->expects($this->once())
85  ->method('save')
86  ->with($this->tokenPath, $value);
87 
88  $this->reinitableConfigMock
89  ->expects($this->once())
90  ->method('reinit')
91  ->willReturnSelf();
92 
93  $this->assertTrue($this->tokenModel->storeToken($value));
94  }
95 
99  public function testGetToken()
100  {
101  $value = 'jjjj0000';
102 
103  $this->configMock
104  ->expects($this->once())
105  ->method('getValue')
106  ->with($this->tokenPath)
107  ->willReturn($value);
108 
109  $this->assertSame($value, $this->tokenModel->getToken());
110  }
111 
115  public function testIsTokenExist()
116  {
117  $this->assertFalse($this->tokenModel->isTokenExist());
118 
119  $this->configMock
120  ->expects($this->once())
121  ->method('getValue')
122  ->with($this->tokenPath)
123  ->willReturn('0000');
124  $this->assertTrue($this->tokenModel->isTokenExist());
125  }
126 }
$value
Definition: gender.phtml:16