Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubscriptionStatusProviderTest.php
Go to the documentation of this file.
1 <?php
7 
15 
16 class SubscriptionStatusProviderTest extends \PHPUnit\Framework\TestCase
17 {
21  private $scopeConfigMock;
22 
26  private $analyticsTokenMock;
27 
31  private $flagManagerMock;
32 
36  private $objectManagerHelper;
37 
41  private $statusProvider;
42 
46  protected function setUp()
47  {
48  $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
49  ->getMockForAbstractClass();
50 
51  $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54 
55  $this->flagManagerMock = $this->getMockBuilder(FlagManager::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $this->objectManagerHelper = new ObjectManagerHelper($this);
60 
61  $this->statusProvider = $this->objectManagerHelper->getObject(
62  SubscriptionStatusProvider::class,
63  [
64  'scopeConfig' => $this->scopeConfigMock,
65  'analyticsToken' => $this->analyticsTokenMock,
66  'flagManager' => $this->flagManagerMock,
67  ]
68  );
69  }
70 
75  public function testGetStatusShouldBeFailed(array $flagManagerData)
76  {
77  $this->analyticsTokenMock->expects($this->once())
78  ->method('isTokenExist')
79  ->willReturn(false);
80  $this->scopeConfigMock->expects($this->once())
81  ->method('getValue')
82  ->with('analytics/subscription/enabled')
83  ->willReturn(true);
84 
85  $this->expectFlagManagerReturn($flagManagerData);
86  $this->assertEquals(SubscriptionStatusProvider::FAILED, $this->statusProvider->getStatus());
87  }
88 
93  {
94  return [
95  'Subscription update doesn\'t active' => [
96  'Flag Manager data mapping' => [
99  ],
100  ],
101  'Subscription update is active' => [
102  'Flag Manager data mapping' => [
105  ],
106  ],
107  ];
108  }
109 
115  public function testGetStatusShouldBePending(array $flagManagerData, bool $isTokenExist)
116  {
117  $this->analyticsTokenMock->expects($this->once())
118  ->method('isTokenExist')
119  ->willReturn($isTokenExist);
120  $this->scopeConfigMock->expects($this->once())
121  ->method('getValue')
122  ->with('analytics/subscription/enabled')
123  ->willReturn(true);
124 
125  $this->expectFlagManagerReturn($flagManagerData);
126  $this->assertEquals(SubscriptionStatusProvider::PENDING, $this->statusProvider->getStatus());
127  }
128 
133  {
134  return [
135  'Subscription update doesn\'t active and the token does not exist' => [
136  'Flag Manager data mapping' => [
139  ],
140  'isTokenExist' => false,
141  ],
142  'Subscription update is active and the token does not exist' => [
143  'Flag Manager data mapping' => [
146  ],
147  'isTokenExist' => false,
148  ],
149  'Subscription update is active and token exist' => [
150  'Flag Manager data mapping' => [
153  ],
154  'isTokenExist' => true,
155  ],
156  ];
157  }
158 
160  {
161  $this->flagManagerMock
162  ->method('getFlagData')
164  ->willReturn(null);
165  $this->analyticsTokenMock->expects($this->once())
166  ->method('isTokenExist')
167  ->willReturn(true);
168  $this->scopeConfigMock->expects($this->once())
169  ->method('getValue')
170  ->with('analytics/subscription/enabled')
171  ->willReturn(true);
172  $this->assertEquals(SubscriptionStatusProvider::ENABLED, $this->statusProvider->getStatus());
173  }
174 
176  {
177  $this->scopeConfigMock->expects($this->once())
178  ->method('getValue')
179  ->with('analytics/subscription/enabled')
180  ->willReturn(false);
181  $this->assertEquals(SubscriptionStatusProvider::DISABLED, $this->statusProvider->getStatus());
182  }
183 
187  private function expectFlagManagerReturn(array $mapping)
188  {
189  $this->flagManagerMock
190  ->method('getFlagData')
191  ->willReturnMap($mapping);
192  }
193 }