diff --git a/app/code/Magento/InstantPurchase/Test/Unit/CustomerData/InstantPurchaseTest.php b/app/code/Magento/InstantPurchase/Test/Unit/CustomerData/InstantPurchaseTest.php new file mode 100644 index 0000000000000..c608338fd10c5 --- /dev/null +++ b/app/code/Magento/InstantPurchase/Test/Unit/CustomerData/InstantPurchaseTest.php @@ -0,0 +1,187 @@ +customerSession = $this->createMock(Session::class); + $this->storeManager = $this->createMock(StoreManagerInterface::class); + $this->instantPurchase = $this->createMock(InstantPurchaseModel::class); + $this->paymentTokenFormatter = $this->createMock(PaymentTokenFormatter::class); + $this->customerAddressesFormatter = $this->createMock(CustomerAddressesFormatter::class); + $this->shippingMethodFormatter = $this->createMock(ShippingMethodFormatter::class); + $this->store = $this->createMock(Store::class); + $this->customer = $this->createMock(Customer::class); + $this->instantPurchaseOption = $this->createMock(InstantPurchaseOption::class); + + $this->objectManager = new ObjectManagerHelper($this); + $this->customerData = $this->objectManager->getObject( + CustomerData::class, + [ + 'customerSession' => $this->customerSession, + 'storeManager' => $this->storeManager, + 'instantPurchase' => $this->instantPurchase, + 'paymentTokenFormatter' => $this->paymentTokenFormatter, + 'customerAddressesFormatter' => $this->customerAddressesFormatter, + 'shippingMethodFormatter' => $this->shippingMethodFormatter + ] + ); + } + + /** + * Test getSectionData() + * + * @param $isLogin + * @param $isAvailable + * @param $expected + * @dataProvider getSectionDataProvider + */ + public function testGetSectionData($isLogin, $isAvailable, $expected) + { + $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn($isLogin); + + $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store); + + $this->customerSession->expects($this->any())->method('getCustomer') + ->willReturn($this->customer); + + $this->instantPurchase->expects($this->any())->method('getOption') + ->with($this->store, $this->customer) + ->willReturn($this->instantPurchaseOption); + + $this->instantPurchaseOption->expects($this->any())->method('isAvailable') + ->willReturn($isAvailable); + + $this->assertEquals($expected, $this->customerData->getSectionData()); + } + + /** + * Data Provider for test getSectionData() + * + * @return array + */ + public function getSectionDataProvider() + { + return [ + 'No Login and available instant purchase' => [ + false, + true, + ['available' => false] + ], + + 'Login and no available instant purchase option' => [ + true, + false, + ['available' => false] + ], + + 'Login and available instant purchase option' => [ + true, + true, + [ + 'available' => true, + 'paymentToken' => [ + 'publicHash' => '', + 'summary' => '' + ], + 'shippingAddress' => [ + 'id' => null, + 'summary' => '' + ], + 'billingAddress' => [ + 'id' => null, + 'summary' => '' + ], + 'shippingMethod' => [ + 'carrier' => null, + 'method' => null, + 'summary' => '' + ] + ] + ] + ]; + } +}