12 class CartTest extends \PHPUnit\Framework\TestCase
51 $this->checkoutSessionMock = $this->createMock(\
Magento\Checkout\Model\Session::class);
52 $this->catalogUrlMock = $this->createPartialMock(
54 [
'getRewriteByProductStore']
56 $this->checkoutCartMock = $this->createMock(\
Magento\Checkout\Model\Cart::class);
57 $this->checkoutHelperMock = $this->createMock(\
Magento\Checkout\Helper\Data::class);
58 $this->layoutMock = $this->createMock(\
Magento\Framework\View\LayoutInterface::class);
59 $this->itemPoolInterfaceMock = $this->createMock(\
Magento\Checkout\CustomerData\ItemPoolInterface::class);
61 $this->model = new \Magento\Checkout\CustomerData\Cart(
62 $this->checkoutSessionMock,
63 $this->catalogUrlMock,
64 $this->checkoutCartMock,
65 $this->checkoutHelperMock,
66 $this->itemPoolInterfaceMock,
73 $quoteMock = $this->createMock(\
Magento\Quote\Model\Quote::class);
74 $this->checkoutSessionMock->expects($this->once())->method(
'getQuote')->willReturn($quoteMock);
75 $this->checkoutHelperMock->expects($this->once())->method(
'isAllowedGuestCheckout')->with($quoteMock)
78 $this->assertTrue($this->model->isGuestCheckoutAllowed());
87 $productRewrite = [
$productId => [
'rewrite' =>
'product']];
88 $itemData = [
'item' =>
'data'];
89 $shortcutButtonsHtml =
'<span>Buttons</span>';
92 $subtotalMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getValue']);
93 $subtotalMock->expects($this->once())->method(
'getValue')->willReturn($subtotalValue);
94 $totals = [
'subtotal' => $subtotalMock];
96 $quoteMock = $this->createPartialMock(
97 \
Magento\Quote\Model\Quote::class,
98 [
'getTotals',
'getHasError',
'getAllVisibleItems',
'getStore']
100 $this->checkoutSessionMock->expects($this->exactly(2))->method(
'getQuote')->willReturn($quoteMock);
101 $quoteMock->expects($this->once())->method(
'getTotals')->willReturn(
$totals);
102 $quoteMock->expects($this->once())->method(
'getHasError')->willReturn(
false);
104 $this->checkoutCartMock->expects($this->once())->method(
'getSummaryQty')->willReturn($summaryQty);
105 $this->checkoutHelperMock->expects($this->once())
106 ->method(
'formatPrice')
107 ->with($subtotalValue)
108 ->willReturn($subtotalValue);
109 $this->checkoutHelperMock->expects($this->once())->method(
'canOnepageCheckout')->willReturn(
true);
111 $quoteItemMock = $this->createPartialMock(\
Magento\Quote\Model\Quote\Item::class, [
'getProduct',
'getStoreId']);
112 $quoteMock->expects($this->once())->method(
'getAllVisibleItems')->willReturn([$quoteItemMock]);
114 $storeMock = $this->createPartialMock(\
Magento\Store\Model\System\Store::class, [
'getWebsiteId']);
115 $storeMock->expects($this->once())->method(
'getWebsiteId')->willReturn(
$websiteId);
116 $quoteMock->expects($this->once())->method(
'getStore')->willReturn($storeMock);
118 $productMock = $this->createPartialMock(
119 \
Magento\Catalog\Model\Product::class,
120 [
'isVisibleInSiteVisibility',
'getId',
'setUrlDataObject']
122 $quoteItemMock->expects($this->exactly(3))->method(
'getProduct')->willReturn($productMock);
123 $quoteItemMock->expects($this->once())->method(
'getStoreId')->willReturn(
$storeId);
125 $productMock->expects($this->once())->method(
'isVisibleInSiteVisibility')->willReturn(
false);
126 $productMock->expects($this->exactly(3))->method(
'getId')->willReturn(
$productId);
127 $productMock->expects($this->once())
128 ->method(
'setUrlDataObject')
132 $this->catalogUrlMock->expects($this->once())
133 ->method(
'getRewriteByProductStore')
135 ->willReturn($productRewrite);
137 $this->itemPoolInterfaceMock->expects($this->once())
138 ->method(
'getItemData')
139 ->with($quoteItemMock)
140 ->willReturn($itemData);
142 $shortcutButtonsMock = $this->createMock(\
Magento\Catalog\Block\ShortcutButtons::class);
143 $this->layoutMock->expects($this->once())
144 ->method(
'createBlock')
145 ->with(\
Magento\Catalog\Block\ShortcutButtons::class)
146 ->willReturn($shortcutButtonsMock);
148 $shortcutButtonsMock->expects($this->once())->method(
'toHtml')->willReturn($shortcutButtonsHtml);
149 $this->checkoutHelperMock->expects($this->once())
150 ->method(
'isAllowedGuestCheckout')
155 'summary_count' => 100,
157 'possible_onepage_checkout' => 1,
161 'extra_actions' =>
'<span>Buttons</span>',
162 'isGuestCheckoutAllowed' => 1,
164 'subtotalAmount' => 200,
166 $this->assertEquals($expectedResult, $this->model->getSectionData());
175 $subtotalValue = 200;
180 $productRewrite = [
$productId => [
'rewrite' =>
'product']];
181 $itemData = [
'item' =>
'data'];
182 $shortcutButtonsHtml =
'<span>Buttons</span>';
183 $subtotalMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getValue']);
184 $subtotalMock->expects($this->once())->method(
'getValue')->willReturn($subtotalValue);
185 $totals = [
'subtotal' => $subtotalMock];
187 $quoteMock = $this->createPartialMock(
188 \
Magento\Quote\Model\Quote::class,
189 [
'getTotals',
'getHasError',
'getAllVisibleItems',
'getStore']
191 $quoteItemMock = $this->createPartialMock(
192 \
Magento\Quote\Model\Quote\Item::class,
193 [
'getProduct',
'getOptionByCode',
'getStoreId']
196 $this->checkoutSessionMock->expects($this->exactly(2))->method(
'getQuote')->willReturn($quoteMock);
197 $quoteMock->expects($this->once())->method(
'getTotals')->willReturn(
$totals);
198 $quoteMock->expects($this->once())->method(
'getHasError')->willReturn(
false);
200 $storeMock = $this->createPartialMock(\
Magento\Store\Model\System\Store::class, [
'getWebsiteId']);
201 $storeMock->expects($this->once())->method(
'getWebsiteId')->willReturn(
$websiteId);
202 $quoteMock->expects($this->once())->method(
'getStore')->willReturn($storeMock);
204 $this->checkoutCartMock->expects($this->once())->method(
'getSummaryQty')->willReturn($summaryQty);
205 $this->checkoutHelperMock->expects($this->once())
206 ->method(
'formatPrice')
207 ->with($subtotalValue)
208 ->willReturn($subtotalValue);
209 $this->checkoutHelperMock->expects($this->once())->method(
'canOnepageCheckout')->willReturn(
true);
211 $quoteMock->expects($this->once())->method(
'getAllVisibleItems')->willReturn([$quoteItemMock]);
213 $productMock = $this->createPartialMock(
214 \
Magento\Catalog\Model\Product::class,
215 [
'isVisibleInSiteVisibility',
'getId',
'setUrlDataObject']
218 $optionsMock = $this->createMock(\
Magento\Quote\Model\Quote\Item\Option::class);
219 $optionsMock->expects($this->once())->method(
'getProduct')->willReturn($productMock);
221 $quoteItemMock->expects($this->exactly(2))->method(
'getProduct')->willReturn($productMock);
222 $quoteItemMock->expects($this->exactly(2))
223 ->method(
'getOptionByCode')
224 ->with(
'product_type')
225 ->willReturn($optionsMock);
226 $quoteItemMock->expects($this->once())->method(
'getStoreId')->willReturn(
$storeId);
228 $productMock->expects($this->once())->method(
'isVisibleInSiteVisibility')->willReturn(
false);
229 $productMock->expects($this->exactly(3))->method(
'getId')->willReturn(
$productId);
230 $productMock->expects($this->once())
231 ->method(
'setUrlDataObject')
235 $this->catalogUrlMock->expects($this->once())
236 ->method(
'getRewriteByProductStore')
238 ->willReturn($productRewrite);
240 $shortcutButtonsMock = $this->createMock(\
Magento\Catalog\Block\ShortcutButtons::class);
241 $this->layoutMock->expects($this->once())
242 ->method(
'createBlock')
243 ->with(\
Magento\Catalog\Block\ShortcutButtons::class)
244 ->willReturn($shortcutButtonsMock);
246 $shortcutButtonsMock->expects($this->once())->method(
'toHtml')->willReturn($shortcutButtonsHtml);
247 $this->checkoutHelperMock->expects($this->once())
248 ->method(
'isAllowedGuestCheckout')
252 $this->itemPoolInterfaceMock->expects($this->once())
253 ->method(
'getItemData')
254 ->with($quoteItemMock)
255 ->willReturn($itemData);
258 'summary_count' => 100,
260 'possible_onepage_checkout' => 1,
264 'extra_actions' =>
'<span>Buttons</span>',
265 'isGuestCheckoutAllowed' => 1,
267 'subtotalAmount' => 200,
269 $this->assertEquals($expectedResult, $this->model->getSectionData());
testIsGuestCheckoutAllowed()
testGetSectionDataWithCompositeProduct()