Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigProviderPluginTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ConfigProviderPluginTest extends \PHPUnit\Framework\TestCase
9 {
14 
19 
24 
28  protected $maskFactoryMock;
29 
34 
38  protected $plugin;
39 
43  protected $subjectMock;
44 
45  protected function setUp()
46  {
47  $this->persistentHelperMock = $this->createMock(\Magento\Persistent\Helper\Data::class);
48  $this->persistentSessionMock = $this->createMock(\Magento\Persistent\Helper\Session::class);
49  $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
50  $this->maskFactoryMock = $this->createPartialMock(
51  \Magento\Quote\Model\QuoteIdMaskFactory::class,
52  ['create', '__wakeup']
53  );
54  $this->customerSessionMock = $this->createMock(\Magento\Customer\Model\Session::class);
55  $this->subjectMock = $this->createMock(\Magento\Checkout\Model\DefaultConfigProvider::class);
56 
57  $this->plugin = new \Magento\Persistent\Model\Checkout\ConfigProviderPlugin(
58  $this->persistentHelperMock,
59  $this->persistentSessionMock,
60  $this->checkoutSessionMock,
61  $this->maskFactoryMock,
62  $this->customerSessionMock
63  );
64  }
65 
73  public function testAfterGetConfigNegative($persistenceEnabled, $isPersistent, $isLoggedIn)
74  {
75  $result = [40, 30, 50];
76 
77  $this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn($persistenceEnabled);
78  $this->persistentSessionMock->expects($this->any())->method('isPersistent')->willReturn($isPersistent);
79  $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
80  $this->maskFactoryMock->expects($this->never())->method('create');
81  $this->assertEquals($result, $this->plugin->afterGetConfig($this->subjectMock, $result));
82  }
83 
87  public function configDataProvider()
88  {
89  return [
90  [false, true, true], //disabled persistence case
91  [true, false, true], //persistence enabled but not persistent session
92  [true, true, true], //logged in user
93  ];
94  }
95 
96  public function testAfterGetConfigPositive()
97  {
98  $maskedId = 3005;
99  $result = [40, 30, 50];
100  $expectedResult = $result;
101  $expectedResult['quoteData']['entity_id'] = $maskedId;
102 
103  $this->persistentHelperMock->expects($this->once())->method('isEnabled')->willReturn(true);
104  $this->persistentSessionMock->expects($this->once())->method('isPersistent')->willReturn(true);
105  $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
106 
107  $quoteMaskMock = $this->createPartialMock(\Magento\Quote\Model\QuoteIdMask::class, ['load', 'getMaskedId']);
108  $this->maskFactoryMock->expects($this->once())->method('create')->willReturn($quoteMaskMock);
109  $quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
110 
111  $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
112  $quoteMaskMock->expects($this->once())->method('load')->willReturnSelf();
113  $quoteMaskMock->expects($this->once())->method('getMaskedId')->willReturn($maskedId);
114  $this->assertEquals($expectedResult, $this->plugin->afterGetConfig($this->subjectMock, $result));
115  }
116 }
testAfterGetConfigNegative($persistenceEnabled, $isPersistent, $isLoggedIn)