1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Api;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\WebapiAbstract;
class GuestCartRepositoryTest extends WebapiAbstract
{
/**
* @var ObjectManager
*/
private $objectManager;
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}
protected function tearDown()
{
try {
$cart = $this->getCart('test01');
$cartId = $cart->getId();
$cart->delete();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = $this->objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
$quoteIdMask->load($cartId, 'quote_id');
$quoteIdMask->delete();
} catch (\InvalidArgumentException $e) {
// Do nothing if cart fixture was not used
}
parent::tearDown();
}
/**
* Retrieve quote by given reserved order ID
*
* @param string $reservedOrderId
* @return \Magento\Quote\Model\Quote
* @throws \InvalidArgumentException
*/
protected function getCart($reservedOrderId)
{
/** @var $cart \Magento\Quote\Model\Quote */
$cart = $this->objectManager->get(\Magento\Quote\Model\Quote::class);
$cart->load($reservedOrderId, 'reserved_order_id');
if (!$cart->getId()) {
throw new \InvalidArgumentException('There is no quote with provided reserved order ID.');
}
return $cart;
}
/**
* @magentoApiDataFixture Magento/Sales/_files/quote.php
*/
public function testGetCart()
{
$cart = $this->getCart('test01');
$cartId = $cart->getId();
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
->create();
$quoteIdMask->load($cartId, 'quote_id');
$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/guest-carts/' . $quoteIdMask->getMaskedId(),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => 'quoteGuestCartRepositoryV1',
'serviceVersion' => 'V1',
'operation' => 'quoteGuestCartRepositoryV1Get',
],
];
$requestData = ['cartId' => $quoteIdMask->getMaskedId()];
$cartData = $this->_webApiCall($serviceInfo, $requestData);
$this->assertEquals($cart->getId(), $cartData['id']);
$this->assertEquals($cart->getCreatedAt(), $cartData['created_at']);
$this->assertEquals($cart->getUpdatedAt(), $cartData['updated_at']);
$this->assertEquals($cart->getIsActive(), $cartData['is_active']);
$this->assertEquals($cart->getIsVirtual(), $cartData['is_virtual']);
$this->assertEquals($cart->getOrigOrderId(), $cartData['orig_order_id']);
$this->assertEquals($cart->getItemsCount(), $cartData['items_count']);
$this->assertEquals($cart->getItemsQty(), $cartData['items_qty']);
//following checks will be uncommented when all cart related services are ready
$this->assertContains('customer', $cartData);
$this->assertEquals(true, $cartData['customer_is_guest']);
$this->assertContains('currency', $cartData);
$this->assertEquals($cart->getGlobalCurrencyCode(), $cartData['currency']['global_currency_code']);
$this->assertEquals($cart->getBaseCurrencyCode(), $cartData['currency']['base_currency_code']);
$this->assertEquals($cart->getQuoteCurrencyCode(), $cartData['currency']['quote_currency_code']);
$this->assertEquals($cart->getStoreCurrencyCode(), $cartData['currency']['store_currency_code']);
$this->assertEquals($cart->getBaseToGlobalRate(), $cartData['currency']['base_to_global_rate']);
$this->assertEquals($cart->getBaseToQuoteRate(), $cartData['currency']['base_to_quote_rate']);
$this->assertEquals($cart->getStoreToBaseRate(), $cartData['currency']['store_to_base_rate']);
$this->assertEquals($cart->getStoreToQuoteRate(), $cartData['currency']['store_to_quote_rate']);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage No such entity with
*/
public function testGetCartThrowsExceptionIfThereIsNoCartWithProvidedId()
{
$cartId = 9999;
$serviceInfo = [
'soap' => [
'service' => 'quoteGuestCartRepositoryV1',
'serviceVersion' => 'V1',
'operation' => 'quoteGuestCartRepositoryV1Get',
],
'rest' => [
'resourcePath' => '/V1/guest-carts/' . $cartId,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
];
$requestData = ['cartId' => $cartId];
$this->_webApiCall($serviceInfo, $requestData);
}
}