From e0de6afa07b0b30fe84f3fd61b656acd74f8e525 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Wed, 8 Apr 2015 23:47:16 -0500 Subject: [PATCH 001/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Removed Authorization using Plugins - Added new ACL for managing Cart resources - Updated existing endpoints to use new Authorization Magento_Cart::manage - Added new endpoints in webapi for managing customer(mine) cart and cart items - Updated functional test for /mine use case --- .../Quote/Api/CartItemRepositoryInterface.php | 33 +++++ .../Quote/Api/CartManagementInterface.php | 8 +- .../Cart/Access/CartManagementPlugin.php | 57 -------- .../Cart/Access/CartRepositoryPlugin.php | 73 ----------- .../Quote/Model/Quote/Item/Repository.php | 28 ++++ .../Magento/Quote/Model/QuoteManagement.php | 37 ++++-- .../Cart/Access/CartManagementPluginTest.php | 63 --------- .../Cart/Access/CartRepositoryPluginTest.php | 90 ------------- app/code/Magento/Quote/etc/acl.xml | 18 +++ app/code/Magento/Quote/etc/webapi.xml | 122 ++++++++++++++---- app/code/Magento/Quote/etc/webapi_rest/di.xml | 15 --- app/code/Magento/Quote/etc/webapi_soap/di.xml | 15 --- .../Magento/Quote/Api/CartManagementTest.php | 17 ++- 13 files changed, 219 insertions(+), 357 deletions(-) delete mode 100644 app/code/Magento/Quote/Model/Cart/Access/CartManagementPlugin.php delete mode 100644 app/code/Magento/Quote/Model/Cart/Access/CartRepositoryPlugin.php delete mode 100644 app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartManagementPluginTest.php delete mode 100644 app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartRepositoryPluginTest.php create mode 100644 app/code/Magento/Quote/etc/acl.xml delete mode 100644 app/code/Magento/Quote/etc/webapi_rest/di.xml delete mode 100644 app/code/Magento/Quote/etc/webapi_soap/di.xml diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php index 992a93583b336..b191b2694033a 100644 --- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php @@ -46,4 +46,37 @@ public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem); * @throws \Magento\Framework\Exception\CouldNotSaveException The item could not be removed. */ public function deleteById($cartId, $itemId); + + /** + * Lists items that are assigned to a specified cart. + * + * @param int $customerId Customer ID. + * @return \Magento\Quote\Api\Data\CartItemInterface[] Array of items. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + */ + public function getListForCustomer($customerId); + + /** + * Adds the specified item to the specified cart. + * + * @param int $customerId Customer ID. + * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem The item. + * @return \Magento\Quote\Api\Data\CartItemInterface Item. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + * @throws \Magento\Framework\Exception\CouldNotSaveException The specified item could not be saved to the cart. + * @throws \Magento\Framework\Exception\InputException The specified item or cart is not valid. + */ + public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem); + + /** + * Removes the specified item from the specified cart. + * + * @param int $customerId Customer ID. + * @param int $cartId The cart ID. + * @param int $itemId The item ID of the item to be removed. + * @return bool + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified item or cart does not exist. + * @throws \Magento\Framework\Exception\CouldNotSaveException The item could not be removed. + */ + public function deleteByIdForCustomer($customerId, $itemId); } diff --git a/app/code/Magento/Quote/Api/CartManagementInterface.php b/app/code/Magento/Quote/Api/CartManagementInterface.php index 4bf49813ac431..5dff50e9b3a56 100644 --- a/app/code/Magento/Quote/Api/CartManagementInterface.php +++ b/app/code/Magento/Quote/Api/CartManagementInterface.php @@ -8,13 +8,13 @@ interface CartManagementInterface { /** - * Enables an administrative or guest user to create an empty cart and quote for an anonymous customer. + * Enables an customer or guest user to create an empty cart and quote for an anonymous customer. * - * @param int $storeId - * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. + * @param int|null $customerId The customer ID. * @return int Cart ID. + * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. */ - public function createEmptyCart($storeId); + public function createEmptyCart($customerId = null); /** * Returns information for the cart for a specified customer. diff --git a/app/code/Magento/Quote/Model/Cart/Access/CartManagementPlugin.php b/app/code/Magento/Quote/Model/Cart/Access/CartManagementPlugin.php deleted file mode 100644 index f7ab6e07b0ecd..0000000000000 --- a/app/code/Magento/Quote/Model/Cart/Access/CartManagementPlugin.php +++ /dev/null @@ -1,57 +0,0 @@ -userContext = $userContext; - } - - /** - * Check whether access is allowed for create cart resource - * - * @param \Magento\Quote\Api\CartManagementInterface $subject - * @param int $cartId - * @param int $customerId - * @param int $storeId - * - * @return void - * @throws AuthorizationException if access denied - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeAssignCustomer( - \Magento\Quote\Api\CartManagementInterface $subject, - $cartId, - $customerId, - $storeId - ) { - if (!in_array($this->userContext->getUserType(), $this->allowedUserTypes)) { - throw new AuthorizationException(__('Access denied')); - } - } -} diff --git a/app/code/Magento/Quote/Model/Cart/Access/CartRepositoryPlugin.php b/app/code/Magento/Quote/Model/Cart/Access/CartRepositoryPlugin.php deleted file mode 100644 index 0410af82ca10c..0000000000000 --- a/app/code/Magento/Quote/Model/Cart/Access/CartRepositoryPlugin.php +++ /dev/null @@ -1,73 +0,0 @@ -userContext = $userContext; - } - - /** - * Check whether access is allowed for cart resource - * - * @param \Magento\Quote\Api\CartRepositoryInterface $subject - * @param int $cartId - * - * @return void - * @throws AuthorizationException if access denied - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeGet( - \Magento\Quote\Api\CartRepositoryInterface $subject, - $cartId - ) { - if (!in_array($this->userContext->getUserType(), $this->allowedUserTypes)) { - throw new AuthorizationException(__('Access denied')); - } - } - - /** - * Check whether access is allowed for cart list resource - * - * @param \Magento\Quote\Api\CartRepositoryInterface $subject - * @param SearchCriteria $searchCriteria - * - * @return void - * @throws AuthorizationException if access denied - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function beforeGetList( - \Magento\Quote\Api\CartRepositoryInterface $subject, - SearchCriteria $searchCriteria - ) { - if (!in_array($this->userContext->getUserType(), $this->allowedUserTypes)) { - throw new AuthorizationException(__('Access denied')); - } - } -} diff --git a/app/code/Magento/Quote/Model/Quote/Item/Repository.php b/app/code/Magento/Quote/Model/Quote/Item/Repository.php index fc4a0f7db7ef4..0a4374e2e559a 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Repository.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Repository.php @@ -143,4 +143,32 @@ public function deleteById($cartId, $itemId) $this->delete($item); return true; } + + /** + * {@inheritdoc} + */ + public function getListForCustomer($customerId) + { + $cart = $this->quoteRepository->getActiveForCustomer($customerId); + return $this->getList($cart->getId()); + } + + /** + * {@inheritdoc} + */ + public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem) + { + $cart = $this->quoteRepository->getActiveForCustomer($customerId); + $cartItem->setQuoteId($cart->getId()); + return $this->save($cartItem); + } + + /** + * {@inheritdoc} + */ + public function deleteByIdForCustomer($customerId, $itemId) + { + $cart = $this->quoteRepository->getActiveForCustomer($customerId); + return $this->deleteById($cart->getId(), $itemId); + } } diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 7adb722ba25f8..ce3bd5b26877e 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -6,17 +6,18 @@ namespace Magento\Quote\Model; -use Magento\Quote\Model\Quote as QuoteEntity; +use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Event\ManagerInterface as EventManager; -use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory; -use Magento\Sales\Api\OrderManagementInterface as OrderManagement; +use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\StateException; +use Magento\Quote\Model\Quote as QuoteEntity; use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter; use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter; use Magento\Quote\Model\Quote\Item\ToOrderItem as ToOrderItemConverter; use Magento\Quote\Model\Quote\Payment\ToOrderPayment as ToOrderPaymentConverter; -use Magento\Authorization\Model\UserContextInterface; -use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Framework\Exception\StateException; +use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory; +use Magento\Sales\Api\OrderManagementInterface as OrderManagement; +use Magento\Store\Model\StoreManagerInterface; /** * Class QuoteManagement @@ -95,6 +96,11 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface */ protected $dataObjectHelper; + /** + * @var StoreManagerInterface + */ + protected $storeManager; + /** * @param EventManager $eventManager * @param QuoteValidator $quoteValidator @@ -110,6 +116,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository * @param \Magento\Customer\Model\CustomerFactory $customerModelFactory * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param StoreManagerInterface $storeManager * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -126,7 +133,8 @@ public function __construct( QuoteRepository $quoteRepository, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, \Magento\Customer\Model\CustomerFactory $customerModelFactory, - \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, + StoreManagerInterface $storeManager ) { $this->eventManager = $eventManager; $this->quoteValidator = $quoteValidator; @@ -142,15 +150,17 @@ public function __construct( $this->customerRepository = $customerRepository; $this->customerModelFactory = $customerModelFactory; $this->dataObjectHelper = $dataObjectHelper; + $this->storeManager = $storeManager; } /** * {@inheritdoc} */ - public function createEmptyCart($storeId) + public function createEmptyCart($customerId = null) { - $quote = $this->userContext->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER - ? $this->createCustomerCart($storeId) + $storeId = $this->storeManager->getStore()->getStoreId(); + $quote = $customerId + ? $this->createCustomerCart($customerId, $storeId) : $this->createAnonymousCart($storeId); try { @@ -213,16 +223,17 @@ protected function createAnonymousCart($storeId) /** * Creates a cart for the currently logged-in customer. * + * @param int $customerId * @param int $storeId * @return \Magento\Quote\Model\Quote Cart object. * @throws CouldNotSaveException The cart could not be created. */ - protected function createCustomerCart($storeId) + protected function createCustomerCart($customerId, $storeId) { - $customer = $this->customerRepository->getById($this->userContext->getUserId()); + $customer = $this->customerRepository->getById($customerId); try { - $this->quoteRepository->getActiveForCustomer($this->userContext->getUserId()); + $this->quoteRepository->getActiveForCustomer($customerId); throw new CouldNotSaveException(__('Cannot create quote')); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { diff --git a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartManagementPluginTest.php b/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartManagementPluginTest.php deleted file mode 100644 index 4a900ce7550ec..0000000000000 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartManagementPluginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -userContextMock = $this->getMock('Magento\Authorization\Model\UserContextInterface'); - $this->subjectMock = $this->getMock('\Magento\Quote\Api\CartManagementInterface'); - $this->model = new CartManagementPlugin($this->userContextMock); - } - - /** - * @param int $userType - * @dataProvider successTypeDataProvider - */ - public function testBeforeCreateSuccess($userType) - { - $this->userContextMock->expects($this->once())->method('getUserType')->will($this->returnValue($userType)); - $this->model->beforeAssignCustomer($this->subjectMock, 1, 1, 1); - } - - public function successTypeDataProvider() - { - return [ - 'admin' => [\Magento\Authorization\Model\UserContextInterface::USER_TYPE_ADMIN], - 'integration' => [\Magento\Authorization\Model\UserContextInterface::USER_TYPE_INTEGRATION], - ]; - } - - /** - * @expectedException \Magento\Framework\Exception\AuthorizationException - * @expectedExceptionMessage Access denied - */ - public function testBeforeCreateDenied() - { - $this->userContextMock->expects($this->once())->method('getUserType') - ->will($this->returnValue(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER)); - $this->model->beforeAssignCustomer($this->subjectMock, 1, 1, 1); - } -} diff --git a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartRepositoryPluginTest.php b/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartRepositoryPluginTest.php deleted file mode 100644 index d4e5a472c3904..0000000000000 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartRepositoryPluginTest.php +++ /dev/null @@ -1,90 +0,0 @@ -userContextMock = $this->getMock('Magento\Authorization\Model\UserContextInterface'); - $this->subjectMock = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface'); - $this->model = new CartRepositoryPlugin($this->userContextMock); - } - - /** - * @param int $userType - * @dataProvider successTypeDataProvider - */ - public function testBeforeGetSuccess($userType) - { - $this->userContextMock->expects($this->once())->method('getUserType')->will($this->returnValue($userType)); - $this->model->beforeGet($this->subjectMock, 1); - } - - /** - * @expectedException \Magento\Framework\Exception\AuthorizationException - * @expectedExceptionMessage Access denied - */ - public function testBeforeGetCartDenied() - { - $this->userContextMock->expects($this->once())->method('getUserType') - ->will($this->returnValue(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER)); - $this->model->beforeGet($this->subjectMock, 1); - } - - public function successTypeDataProvider() - { - return [ - 'admin' => [\Magento\Authorization\Model\UserContextInterface::USER_TYPE_ADMIN], - 'integration' => [\Magento\Authorization\Model\UserContextInterface::USER_TYPE_INTEGRATION], - ]; - } - - /** - * @param int $userType - * @dataProvider successTypeDataProvider - */ - public function testBeforeGetCartSuccess($userType) - { - $this->userContextMock->expects($this->once())->method('getUserType')->will($this->returnValue($userType)); - $this->model->beforeGetList( - $this->subjectMock, - $this->getMock('\Magento\Framework\Api\SearchCriteria', [], [], '', false) - ); - } - - /** - * @expectedException \Magento\Framework\Exception\AuthorizationException - * @expectedExceptionMessage Access denied - */ - public function testBeforeGetListDenied() - { - $this->userContextMock->expects($this->once())->method('getUserType') - ->will($this->returnValue(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER)); - $this->model->beforeGetList( - $this->subjectMock, - $this->getMock('\Magento\Framework\Api\SearchCriteria', [], [], '', false) - ); - } -} diff --git a/app/code/Magento/Quote/etc/acl.xml b/app/code/Magento/Quote/etc/acl.xml new file mode 100644 index 0000000000000..14792adfa7170 --- /dev/null +++ b/app/code/Magento/Quote/etc/acl.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 412dab6361b1f..3423a9e6d119a 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -7,16 +7,18 @@ --> + + - + - + @@ -28,13 +30,36 @@ - + + + + + + + + + + + %customer_id% + + + + + + + + %customer_id% + + + + + - + @@ -46,13 +71,15 @@ - + + + - + @@ -64,91 +91,134 @@ - + - + + + + + + + + + + + + %customer_id% + + + + + + + + %customer_id% + + + + + + + + %customer_id% + + + + + + + + + %customer_id% + + + + - + - + - + + + - + - + + + - + - + - + + + - + - + + + - + - - - - - - - + + diff --git a/app/code/Magento/Quote/etc/webapi_rest/di.xml b/app/code/Magento/Quote/etc/webapi_rest/di.xml deleted file mode 100644 index 67774a740401d..0000000000000 --- a/app/code/Magento/Quote/etc/webapi_rest/di.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - diff --git a/app/code/Magento/Quote/etc/webapi_soap/di.xml b/app/code/Magento/Quote/etc/webapi_soap/di.xml deleted file mode 100644 index 67774a740401d..0000000000000 --- a/app/code/Magento/Quote/etc/webapi_soap/di.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index 1f977421884bb..9898ab28a7909 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -13,6 +13,7 @@ class CartManagementTest extends WebapiAbstract const SERVICE_VERSION = 'V1'; const SERVICE_NAME = 'quoteCartManagementV1'; const RESOURCE_PATH = '/V1/carts/'; + const RESOURCE_PATH_CUSTOMER_TOKEN = "/V1/integration/customer/token"; protected $createdQuotes = []; @@ -302,22 +303,36 @@ public function testPlaceOrder() } /** + * Test to get my cart based on customer authentication token or session + * * @magentoApiDataFixture Magento/Sales/_files/quote_with_customer.php */ public function testGetCartForCustomer() { + // get customer ID token + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH_CUSTOMER_TOKEN, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + ]; + $requestData = ['username' => 'customer@example.com', 'password' => 'password']; + $token = $this->_webApiCall($serviceInfo, $requestData); + $cart = $this->getCart('test01'); $customerId = $cart->getCustomer()->getId(); $serviceInfo = [ 'rest' => [ - 'resourcePath' => '/V1/customer/' . $customerId . '/cart', + 'resourcePath' => '/V1/carts/mine', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token ], 'soap' => [ 'service' => 'quoteCartManagementV1', 'serviceVersion' => 'V1', 'operation' => 'quoteCartManagementV1GetCartForCustomer', + 'token' => $token ], ]; From 3b1786b5843bd6689b30e4410262f8f20082a080 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Fri, 10 Apr 2015 00:24:46 -0500 Subject: [PATCH 002/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fix bug in TypeProcessor to process optional types - Added interfaces and routes for guest endpoints --- .../Quote/Api/CartItemRepositoryInterface.php | 1 - .../Api/GuestCartManagementInterface.php | 25 +++++++++++++++++++ .../Api/GuestCartRepositoryInterface.php | 18 +++++++++++++ app/code/Magento/Quote/etc/webapi.xml | 7 ++++++ .../Framework/Reflection/TypeProcessor.php | 8 +++++- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Quote/Api/GuestCartManagementInterface.php create mode 100644 app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php index b191b2694033a..7ca368316aab4 100644 --- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php @@ -72,7 +72,6 @@ public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInt * Removes the specified item from the specified cart. * * @param int $customerId Customer ID. - * @param int $cartId The cart ID. * @param int $itemId The item ID of the item to be removed. * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException The specified item or cart does not exist. diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php new file mode 100644 index 0000000000000..7663add88d235 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index f458d7bd8ece6..a3c31c6b43db6 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -6,9 +6,9 @@ namespace Magento\Framework\Reflection; use Magento\Framework\Exception\SerializationException; +use Magento\Framework\Phrase; use Zend\Code\Reflection\ClassReflection; use Zend\Code\Reflection\ParameterReflection; -use Magento\Framework\Phrase; /** * Type processor of config reader properties @@ -108,6 +108,9 @@ public function setTypeData($typeName, $data) public function register($type) { $typeName = $this->normalizeType($type); + if (is_null($typeName)) { + return null; + } if (!$this->isTypeSimple($typeName) && !$this->isTypeAny($typeName)) { $typeSimple = $this->getArrayItemType($type); if (!(class_exists($typeSimple) || interface_exists($typeSimple))) { @@ -288,6 +291,9 @@ public function getGetterReturnType($methodReflection) */ public function normalizeType($type) { + if($type == 'null') { + return null; + } $normalizationMap = [ self::STRING_TYPE => self::NORMALIZED_STRING_TYPE, self::INT_TYPE => self::NORMALIZED_INT_TYPE, From b1a16ae0fd026464bcf61e4d50362c13556710ff Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Mon, 13 Apr 2015 08:58:16 -0500 Subject: [PATCH 003/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Add ability to mask cart IDs as guids for guest carts - Added implementation for Guest cart services --- .../Api/GuestCartManagementInterface.php | 17 +--- .../Api/GuestCartRepositoryInterface.php | 10 +-- .../Model/GuestCart/GuestCartManagement.php | 86 ++++++++++++++++++ .../Model/GuestCart/GuestCartRepository.php | 88 +++++++++++++++++++ app/code/Magento/Quote/Model/QuoteIdMask.php | 55 ++++++++++++ .../Model/Resource/Quote/QuoteIdMask.php | 24 +++++ .../Magento/Quote/Setup/InstallSchema.php | 32 +++++++ app/code/Magento/Quote/etc/di.xml | 3 + .../GuestCart/GuestCartManagementTest.php | 26 ++++++ 9 files changed, 316 insertions(+), 25 deletions(-) create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php create mode 100644 app/code/Magento/Quote/Model/QuoteIdMask.php create mode 100644 app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php create mode 100644 dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php index 7663add88d235..da36fd39d59d2 100644 --- a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -5,21 +5,6 @@ */ namespace Magento\Quote\Api; -interface GuestCartManagementInterface +interface GuestCartManagementInterface extends CartManagementInterface { - /** - * Enables an guest user to create an empty cart and quote for an anonymous customer. - * - * @return int Cart ID. - * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. - */ - public function createEmptyCart(); - - /** - * Places an order for a specified cart. - * - * @param int $cartId The cart ID. - * @return int Order ID. - */ - public function placeOrder($cartId); } diff --git a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php index a72ce47afa212..3a0f6bf847829 100644 --- a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php @@ -5,14 +5,6 @@ */ namespace Magento\Quote\Api; -interface GuestCartRepositoryInterface +interface GuestCartRepositoryInterface extends CartRepositoryInterface { - /** - * Enables an guest user to return information for a specified cart. - * - * @param int $cartId - * @return \Magento\Quote\Api\Data\CartInterface - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function get($cartId); } diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php new file mode 100644 index 0000000000000..58a78ed2d9ca7 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -0,0 +1,86 @@ +guestCartRepository = $guestCartRepository; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * @inheritdoc + */ + public function createEmptyCart($customerId = null) + { + /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create(); + $cartId = parent::createEmptyCart($customerId); + $quoteIdMask->setId($cartId)->save(); + return $quoteIdMask->getMaskedId(); + } + + /** + * {@inheritdoc} + */ + public function assignCustomer($cartId, $customerId, $storeId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + return parent::assignCustomer($quoteIdMask->getId(), $customerId, $storeId); + } + + /** + * {@inheritdoc} + */ + public function placeOrder($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + return parent::placeOrder($quoteIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function getCartForCustomer($customerId) + { + $cart = $this->quoteRepository->getActiveForCustomer($customerId); + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cart->getId()); + $cart->setId($quoteIdMask->getId()); + return $cart; + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php new file mode 100644 index 0000000000000..e22c3a15d9578 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -0,0 +1,88 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * @inheritdoc + */ + public function get($cartId, array $sharedStoreIds = []) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + return parent::get($quoteIdMask->getId(), $sharedStoreIds); + } + + /** + * @inheritdoc + */ + public function getActive($cartId, array $sharedStoreIds = []) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + return parent::getActive($quoteIdMask->getId(), $sharedStoreIds); + } + + /** + * @inheritdoc + */ + public function save(Quote $quote) + { + if($quote->getId()) { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($quote->getId()); + $quote->setId($quoteIdMask->getId()); + } + parent::save($quote); + } + + /** + * @inheritdoc + */ + public function delete(Quote $quote) + { + if($quote->getId()) { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($quote->getId()); + $quote->setId($quoteIdMask->getId()); + } + parent::delete($quote); + } +} diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php new file mode 100644 index 0000000000000..e1a8a41d018f3 --- /dev/null +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -0,0 +1,55 @@ +_init('Magento\Quote\Model\Resource\Quote\QuoteIdMask'); + } + + /** + * Initialize quote identifier before save + * + * @return $this + */ + public function beforeSave() + { + parent::beforeSave(); + $this->setMaskedId($this->guidv4()); + return $this; + } + + /** + * Generate guid + * + * @return string + */ + public function guidv4() + { + $data = openssl_random_pseudo_bytes(16); + + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 + + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + } +} diff --git a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php new file mode 100644 index 0000000000000..79fb4aa84063b --- /dev/null +++ b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php @@ -0,0 +1,24 @@ +_init('quote_id_mask', 'entity_id'); + } +} diff --git a/app/code/Magento/Quote/Setup/InstallSchema.php b/app/code/Magento/Quote/Setup/InstallSchema.php index 5e736acaaabe1..1114e5780f02c 100644 --- a/app/code/Magento/Quote/Setup/InstallSchema.php +++ b/app/code/Magento/Quote/Setup/InstallSchema.php @@ -1547,6 +1547,38 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con ); $installer->getConnection()->createTable($table); + /** + * Create table to store cartId and obscured UUID based cartId mapping + */ + /** + * Create table '' + */ + $table = $installer->getConnection()->newTable( + $installer->getTable('quote_id_mask') + )->addColumn( + 'entity_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false], + 'Entity Id' + )->addForeignKey( + 'entity_id', + 'entity_id', + $installer->getTable('quote'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + )->addColumn( + 'masked_id', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 16, + ['nullable' => 'false'], + 'Masked Id' + )->setComment( + 'Quote id and masked id mapping' + ); + + $installer->getConnection()->createTable($table); + $installer->endSetup(); } diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 214e414e3207d..d4c19fc502977 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -25,4 +25,7 @@ + + + diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php new file mode 100644 index 0000000000000..8a5ef7a3b77bb --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php @@ -0,0 +1,26 @@ +guestCart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + 'Magento\Quote\Api\GuestCartManagementInterface' + ); + } + + public function testCreateEmptyCart() + { + $cartId = $this->guestCart->createEmptyCart(); + $this->assertNotEmpty($cartId); + } +} From 9a0fbce28ec1c4baccb52623d47b992d48ee88ee Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Mon, 13 Apr 2015 19:32:45 -0500 Subject: [PATCH 004/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Exposed GuestCartRepository as webapi - Added functional tests for guest carts - Fixes in resource model for QuoteIdMask --- .../Model/GuestCart/GuestCartRepository.php | 12 +- app/code/Magento/Quote/Model/QuoteIdMask.php | 2 +- .../Model/Resource/Quote/QuoteIdMask.php | 1 + .../Magento/Quote/Setup/InstallSchema.php | 2 +- app/code/Magento/Quote/etc/webapi.xml | 14 ++ .../Quote/Api/GuestCartRepositoryTest.php | 129 ++++++++++++++++++ .../testsuite/Magento/Sales/_files/quote.php | 8 ++ 7 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartRepositoryTest.php diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index e22c3a15d9578..73b23183c5120 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -6,7 +6,9 @@ namespace Magento\Quote\Model\GuestCart; +use Magento\Quote\Api\GuestCartRepositoryInterface; use Magento\Quote\Model\Quote; +use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteRepository; use Magento\Store\Model\StoreManagerInterface; @@ -15,7 +17,7 @@ /** * Class GuestCartRepository */ -class GuestCartRepository extends QuoteRepository +class GuestCartRepository extends QuoteRepository implements GuestCartRepositoryInterface { /** * @var QuoteIdMaskFactory @@ -46,7 +48,7 @@ public function __construct( public function get($cartId, array $sharedStoreIds = []) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return parent::get($quoteIdMask->getId(), $sharedStoreIds); } @@ -56,7 +58,7 @@ public function get($cartId, array $sharedStoreIds = []) public function getActive($cartId, array $sharedStoreIds = []) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return parent::getActive($quoteIdMask->getId(), $sharedStoreIds); } @@ -67,7 +69,7 @@ public function save(Quote $quote) { if($quote->getId()) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($quote->getId()); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); $quote->setId($quoteIdMask->getId()); } parent::save($quote); @@ -80,7 +82,7 @@ public function delete(Quote $quote) { if($quote->getId()) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($quote->getId()); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); $quote->setId($quoteIdMask->getId()); } parent::delete($quote); diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php index e1a8a41d018f3..6063d89af6c17 100644 --- a/app/code/Magento/Quote/Model/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -43,7 +43,7 @@ public function beforeSave() * * @return string */ - public function guidv4() + protected function guidv4() { $data = openssl_random_pseudo_bytes(16); diff --git a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php index 79fb4aa84063b..6975b43c57976 100644 --- a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php @@ -20,5 +20,6 @@ class QuoteIdMask extends AbstractDb protected function _construct() { $this->_init('quote_id_mask', 'entity_id'); + $this->_isPkAutoIncrement = false; } } diff --git a/app/code/Magento/Quote/Setup/InstallSchema.php b/app/code/Magento/Quote/Setup/InstallSchema.php index 1114e5780f02c..8db3a3744c7da 100644 --- a/app/code/Magento/Quote/Setup/InstallSchema.php +++ b/app/code/Magento/Quote/Setup/InstallSchema.php @@ -1570,7 +1570,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con )->addColumn( 'masked_id', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 16, + 32, ['nullable' => 'false'], 'Masked Id' )->setComment( diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 16aa7e661a23f..c1843c82eee8a 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -55,12 +55,26 @@ + + + + + + + + + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartRepositoryTest.php new file mode 100644 index 0000000000000..b3c8e3f024e70 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartRepositoryTest.php @@ -0,0 +1,129 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + protected function tearDown() + { + try { + $cart = $this->getCart('test01'); + $cart->delete(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMask'); + $quoteIdMask->delete($cart->getId()); + } 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'); + $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') + ->create(); + $quoteIdMask->load($cartId); + + + $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); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php index 8bdafe16f41aa..2fb7467a1c15b 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php @@ -65,3 +65,11 @@ $quote->setIsMultiShipping('1'); $quote->collectTotals(); $quote->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); From 14cdb650cb58ba620baeb3443331194c39b9a845 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 00:07:23 -0500 Subject: [PATCH 005/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Added functional tests for guest carts management - Fixes for placing guest orders --- .../Api/GuestCartManagementInterface.php | 35 ++ .../Api/GuestCartRepositoryInterface.php | 8 + .../Model/GuestCart/GuestCartManagement.php | 61 ++- app/code/Magento/Quote/etc/webapi.xml | 6 + .../Quote/Api/GuestCartManagementTest.php | 346 ++++++++++++++++++ .../_files/quote_with_check_payment.php | 9 + .../Sales/_files/quote_with_customer.php | 8 + 7 files changed, 460 insertions(+), 13 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php index da36fd39d59d2..2e9d5bcb113e6 100644 --- a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -7,4 +7,39 @@ interface GuestCartManagementInterface extends CartManagementInterface { + /** + * Enables an customer or guest user to create an empty cart and quote for an anonymous customer. + * + * @param int|null $customerId The customer ID. + * @return string Cart ID. + * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. + */ + public function createEmptyCart($customerId = null); + + /** + * Returns information for the cart for a specified customer. + * + * @param int $customerId The customer ID. + * @return \Magento\Quote\Api\Data\CartInterface Cart object. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer does not exist. + */ + public function getCartForCustomer($customerId); + + /** + * Assigns a specified customer to a specified shopping cart. + * + * @param string $cartId The cart ID. + * @param int $customerId The customer ID. + * @param int $storeId + * @return boolean + */ + public function assignCustomer($cartId, $customerId, $storeId); + + /** + * Places an order for a specified cart. + * + * @param string $cartId The cart ID. + * @return int Order ID. + */ + public function placeOrder($cartId); } diff --git a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php index 3a0f6bf847829..53b256a6e8ea3 100644 --- a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php @@ -7,4 +7,12 @@ interface GuestCartRepositoryInterface extends CartRepositoryInterface { + /** + * Enables an administrative user to return information for a specified cart. + * + * @param string $cartId + * @return \Magento\Quote\Api\Data\CartInterface + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function get($cartId); } diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 58a78ed2d9ca7..18e0389b78ba9 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -6,38 +6,73 @@ namespace Magento\Quote\Model\GuestCart; +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Event\ManagerInterface as EventManager; use Magento\Quote\Api\GuestCartManagementInterface; -use Magento\Quote\Api\GuestCartRepositoryInterface; +use Magento\Quote\Model\CustomerManagement; +use Magento\Quote\Model\Quote as QuoteEntity; +use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter; +use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter; +use Magento\Quote\Model\Quote\Item\ToOrderItem as ToOrderItemConverter; +use Magento\Quote\Model\Quote\Payment\ToOrderPayment as ToOrderPaymentConverter; use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Model\QuoteManagement; +use Magento\Quote\Model\QuoteRepository; +use Magento\Quote\Model\QuoteValidator; +use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory; +use Magento\Sales\Api\OrderManagementInterface as OrderManagement; use Magento\Store\Model\StoreManagerInterface; -use Magento\Quote\Model\QuoteIdMaskFactory; /** * Class GuestCartManagement */ class GuestCartManagement extends QuoteManagement implements GuestCartManagementInterface { - /** - * @var GuestCartRepositoryInterface - */ - protected $guestCartRepository; - /** * @var QuoteIdMaskFactory */ protected $quoteIdMaskFactory; /** - * @param GuestCartRepositoryInterface $guestCartRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - GuestCartRepositoryInterface $guestCartRepository, + EventManager $eventManager, + QuoteValidator $quoteValidator, + OrderFactory $orderFactory, + OrderManagement $orderManagement, + CustomerManagement $customerManagement, + ToOrderConverter $quoteAddressToOrder, + ToOrderAddressConverter $quoteAddressToOrderAddress, + ToOrderItemConverter $quoteItemToOrderItem, + ToOrderPaymentConverter $quotePaymentToOrderPayment, + UserContextInterface $userContext, + QuoteRepository $quoteRepository, + \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, + \Magento\Customer\Model\CustomerFactory $customerModelFactory, + \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, + StoreManagerInterface $storeManager, QuoteIdMaskFactory $quoteIdMaskFactory ) { - $this->guestCartRepository = $guestCartRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; + parent::__construct( + $eventManager, + $quoteValidator, + $orderFactory, + $orderManagement, + $customerManagement, + $quoteAddressToOrder, + $quoteAddressToOrderAddress, + $quoteItemToOrderItem, + $quotePaymentToOrderPayment, + $userContext, + $quoteRepository, + $customerRepository, + $customerModelFactory, + $dataObjectHelper, + $storeManager + ); } /** @@ -58,7 +93,7 @@ public function createEmptyCart($customerId = null) public function assignCustomer($cartId, $customerId, $storeId) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return parent::assignCustomer($quoteIdMask->getId(), $customerId, $storeId); } @@ -68,7 +103,7 @@ public function assignCustomer($cartId, $customerId, $storeId) public function placeOrder($cartId) { /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cartId); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return parent::placeOrder($quoteIdMask->getId()); } @@ -79,7 +114,7 @@ public function getCartForCustomer($customerId) { $cart = $this->quoteRepository->getActiveForCustomer($customerId); /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->loadByMaskedId($cart->getId()); + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cart->getId(), 'masked_id'); $cart->setId($quoteIdMask->getId()); return $cart; } diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index c1843c82eee8a..6d71d1639ac12 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -75,6 +75,12 @@ + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php new file mode 100644 index 0000000000000..df3ec6e070269 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php @@ -0,0 +1,346 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + public function testCreate() + { + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'CreateEmptyCart', + ], + ]; + + $requestData = ['storeId' => 1]; + $quoteId = $this->_webApiCall($serviceInfo, $requestData); + $this->assertTrue(strlen($quoteId) >= 32); + $this->createdQuotes[] = $quoteId; + } + + public function tearDown() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + foreach ($this->createdQuotes as $quoteId) { + $quote->load($quoteId); + $quote->delete(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMask'); + $quoteIdMask->delete($quote->getId()); + } + } + + /** + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testAssignCustomer() + { + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + /** @var $repository \Magento\Customer\Api\CustomerRepositoryInterface */ + $repository = $this->objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface'); + /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */ + $customer = $repository->getById(1); + $customerId = $customer->getId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => 'V1', + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + ], + ]; + + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + // Cart must be anonymous (see fixture) + $this->assertEmpty($quote->getCustomerId()); + + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + // Reload target quote + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + $this->assertEquals(0, $quote->getCustomerIsGuest()); + $this->assertEquals($customer->getId(), $quote->getCustomerId()); + $this->assertEquals($customer->getFirstname(), $quote->getCustomerFirstname()); + $this->assertEquals($customer->getLastname(), $quote->getCustomerLastname()); + } + + /** + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @expectedException \Exception + */ + public function testAssignCustomerThrowsExceptionIfThereIsNoCustomerWithGivenId() + { + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + $cartId = $quote->getId(); + $customerId = 9999; + $serviceInfo = [ + 'soap' => [ + 'serviceVersion' => 'V1', + 'service' => self::SERVICE_NAME, + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + ], + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + ]; + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @expectedException \Exception + */ + public function testAssignCustomerThrowsExceptionIfThereIsNoCartWithGivenId() + { + $cartId = 9999; + $customerId = 1; + $serviceInfo = [ + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => 'V1', + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + ], + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + ]; + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Sales/_files/quote_with_customer.php + * @expectedException \Exception + * @expectedExceptionMessage Cannot assign customer to the given cart. The cart is not anonymous. + */ + public function testAssignCustomerThrowsExceptionIfTargetCartIsNotAnonymous() + { + /** @var $customer \Magento\Customer\Model\Customer */ + $customer = $this->objectManager->create('Magento\Customer\Model\Customer')->load(1); + $customerId = $customer->getId(); + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'rest' => [ + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'resourcePath' => '/V1/guest-carts/' . $cartId, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => 'V1', + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + ], + ]; + + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @magentoApiDataFixture Magento/Customer/_files/customer_non_default_website_id.php + * @expectedException \Exception + * @expectedExceptionMessage Cannot assign customer to the given cart. The cart belongs to different store. + */ + public function testAssignCustomerThrowsExceptionIfCartIsAssignedToDifferentStore() + { + $repository = $this->objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface'); + /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */ + $customer = $repository->getById(1); + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + + $customerId = $customer->getId(); + $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => 'V1', + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + ], + 'rest' => [ + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'resourcePath' => '/V1/guest-carts/' . $cartId, + ], + ]; + + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @expectedException \Exception + * @expectedExceptionMessage Cannot assign customer to the given cart. Customer already has active cart. + */ + public function testAssignCustomerThrowsExceptionIfCustomerAlreadyHasActiveCart() + { + /** @var $customer \Magento\Customer\Model\Customer */ + $customer = $this->objectManager->create('Magento\Customer\Model\Customer')->load(1); + // Customer has a quote with reserved order ID test_order_1 (see fixture) + /** @var $customerQuote \Magento\Quote\Model\Quote */ + $customerQuote = $this->objectManager->create('Magento\Quote\Model\Quote') + ->load('test_order_1', 'reserved_order_id'); + $customerQuote->setIsActive(1)->save(); + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test01', 'reserved_order_id'); + + $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $customerId = $customer->getId(); + + $serviceInfo = [ + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'operation' => self::SERVICE_NAME . 'AssignCustomer', + 'serviceVersion' => 'V1', + ], + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + ]; + + $requestData = [ + 'cartId' => $cartId, + 'customerId' => $customerId, + 'storeId' => 1, + ]; + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_check_payment.php + */ + public function testPlaceOrder() + { + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'soap' => [ + 'service' => 'quoteGuestCartManagementV1', + 'operation' => 'quoteGuestCartManagementV1PlaceOrder', + 'serviceVersion' => 'V1', + ], + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId . '/order', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + ]; + + $orderId = $this->_webApiCall($serviceInfo, ['cartId' => $cartId]); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $this->objectManager->create('Magento\Sales\Model\Order')->load($orderId); + $items = $order->getAllItems(); + $this->assertCount(1, $items); + $this->assertEquals('Simple Product', $items[0]->getName()); + $quote->delete(); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php index 355706e20824a..5133094c254f3 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php @@ -19,3 +19,12 @@ $quote->collectTotals(); $quote->save(); $quote->getPayment()->setMethod('checkmo'); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); + diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_customer.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_customer.php index 8d5992519026f..40e14157ff895 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_customer.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_customer.php @@ -15,3 +15,11 @@ ->create('Magento\Customer\Api\CustomerRepositoryInterface'); $customer = $customerRepository->getById(1); $quote->setCustomer($customer)->setCustomerIsGuest(false)->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); From 0c7c9192a91d6ac7f0a310c1b31f7295f818fc93 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 01:30:22 -0500 Subject: [PATCH 006/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Guest Car Item repository interface and implementation with webapis --- .../Quote/Api/CartItemRepositoryInterface.php | 2 +- .../Api/GuestCartItemRepositoryInterface.php | 61 +++++++++++++ .../GuestCart/GuestCartItemRepository.php | 90 +++++++++++++++++++ app/code/Magento/Quote/etc/webapi.xml | 26 ++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php index 7ca368316aab4..e2ef0aa810229 100644 --- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php @@ -28,7 +28,7 @@ public function getList($cartId); public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem); /** - * Remove bundle option + * Delete cart item * * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem * @return void diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php new file mode 100644 index 0000000000000..782ca001af054 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -0,0 +1,61 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + parent::__construct($quoteRepository, $productRepository, $itemDataFactory); + } + + /** + * {@inheritdoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::getList($quoteIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); + $cartItem->setQuoteId($quoteIdMask->getId()); + return parent::save($cartItem); + } + + /** + * {@inheritdoc} + */ + public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); + $cartItem->setQuoteId($quoteIdMask->getId()); + parent::delete($cartItem); + } + + /** + * {@inheritdoc} + */ + public function deleteById($cartId, $itemId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::deleteById($quoteIdMask->getId(), $itemId); + } + + /** + * {@inheritdoc} + */ + public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); + $cartItem->setQuoteId($quoteIdMask->getId()); + return parent::saveForCustomer($customerId, $cartItem); + } +} diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 6d71d1639ac12..17ede3d79aaba 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -128,6 +128,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From bae232e0317a20d9536ceb960290011cb1af3346 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 09:02:58 -0500 Subject: [PATCH 007/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fix webapi service methods for Cart Item repository - Api functional test fixes --- .../Quote/Api/Data/CartItemInterface.php | 4 +- app/code/Magento/Quote/etc/di.xml | 2 + app/code/Magento/Quote/etc/webapi.xml | 16 +- .../Quote/Api/GuestCartItemRepositoryTest.php | 199 ++++++++++++++++++ .../_files/quote_with_items_saved.php | 8 + .../_files/quote_with_payment_saved.php | 8 + 6 files changed, 227 insertions(+), 10 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php diff --git a/app/code/Magento/Quote/Api/Data/CartItemInterface.php b/app/code/Magento/Quote/Api/Data/CartItemInterface.php index 4951fe1698006..7fd33b1734286 100644 --- a/app/code/Magento/Quote/Api/Data/CartItemInterface.php +++ b/app/code/Magento/Quote/Api/Data/CartItemInterface.php @@ -119,14 +119,14 @@ public function setProductType($productType); /** * Returns Quote id. * - * @return int + * @return string */ public function getQuoteId(); /** * Sets Quote id. * - * @param int $quoteId + * @param string $quoteId * @return $this */ public function setQuoteId($quoteId); diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index d4c19fc502977..cb61f58506d83 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -28,4 +28,6 @@ + + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 17ede3d79aaba..ccee44d266ae0 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -130,27 +130,27 @@ - + - + - + - + - + - + - + - + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php new file mode 100644 index 0000000000000..c1794579c0140 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -0,0 +1,199 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testGetList() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $output = []; + /** @var \Magento\Quote\Api\Data\CartItemInterface $item */ + foreach ($quote->getAllItems() as $item) { + //Set masked Cart ID + $item->setQuoteId($cartId); + $data = [ + 'item_id' => $item->getItemId(), + 'sku' => $item->getSku(), + 'name' => $item->getName(), + 'price' => $item->getPrice(), + 'qty' => $item->getQty(), + 'product_type' => $item->getProductType(), + 'quote_id' => $item->getQuoteId() + ]; + + $output[] = $data; + } + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/items', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'GetList', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($output, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + */ + public function testAddItem() + { + /** @var \Magento\Catalog\Model\Product $product */ + $product = $this->objectManager->create('Magento\Catalog\Model\Product')->load(2); + $productSku = $product->getSku(); + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'items', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + $requestData = [ + "cartItem" => [ + "sku" => $productSku, + "qty" => 7, + "quote_id" => $cartId, + ], + ]; + $this->_webApiCall($serviceInfo, $requestData); + $this->assertTrue($quote->hasProductId(2)); + $this->assertEquals(7, $quote->getItemByProduct($product)->getQty()); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testRemoveItem() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + $cartId = $quote->getId(); + $product = $this->objectManager->create('Magento\Catalog\Model\Product'); + $productId = $product->getIdBySku('simple_one'); + $product->load($productId); + $itemId = $quote->getItemByProduct($product)->getId(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'DeleteById', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "itemId" => $itemId, + ]; + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + $this->assertFalse($quote->hasProductId($productId)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php + */ + public function testUpdateItem() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + $cartId = $quote->getId(); + $product = $this->objectManager->create('Magento\Catalog\Model\Product'); + $productId = $product->getIdBySku('simple_one'); + $product->load($productId); + $itemId = $quote->getItemByProduct($product)->getId(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'items/' . $itemId, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + + if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { + $requestData = [ + "cartItem" => [ + "qty" => 5, + "quote_id" => $cartId, + "itemId" => $itemId, + ], + ]; + } else { + $requestData = [ + "cartItem" => [ + "qty" => 5, + "quote_id" => $cartId, + ], + ]; + } + $this->_webApiCall($serviceInfo, $requestData); + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + $this->assertTrue($quote->hasProductId(1)); + $item = $quote->getItemByProduct($product); + $this->assertEquals(5, $item->getQty()); + $this->assertEquals($itemId, $item->getItemId()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_saved.php index d017de00edb5e..dcf8ab45afc98 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_saved.php @@ -42,3 +42,11 @@ $quote->setReservedOrderId('test_order_item_with_items') ->addProduct($product->load($product->getIdBySku('simple_one')), 1); $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php index d39da02e43d07..e15c08b356f56 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php @@ -25,3 +25,11 @@ ->setAdditionalData(serialize($paymentDetails)); $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); From e0ae8088932937434e5136ed4c4ea14813c40062 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 10:16:27 -0500 Subject: [PATCH 008/115] MAGETWO-32686 Customer-facing resources in Sales & Checkout APIs - Adds GuestCouponManagement, GuestCouponManagementItnerface - Changes webapi.xml config for anonymous access to guest coupon functionality - Adds di.xml config for GuestCouponManagementInterface implementation --- .../Api/GuestCouponManagementInterface.php | 15 +++++ .../Quote/Model/GuestCouponManagement.php | 63 +++++++++++++++++++ app/code/Magento/Quote/etc/di.xml | 1 + app/code/Magento/Quote/etc/webapi.xml | 20 ++++++ 4 files changed, 99 insertions(+) create mode 100644 app/code/Magento/Quote/Api/GuestCouponManagementInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCouponManagement.php diff --git a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php new file mode 100644 index 0000000000000..64c4a308851d9 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php @@ -0,0 +1,15 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + parent::__construct( + $quoteRepository + ); + } + + /** + * {@inheritdoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($quotedIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function set($cartId, $couponCode) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($quotedIdMask->getId(), $couponCode); + } + + /** + * {@inheritdoc} + */ + public function remove($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::remove($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index cb61f58506d83..12502f7d37edd 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -29,5 +29,6 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index ccee44d266ae0..e59115dccd9fe 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -246,6 +246,26 @@ + + + + + + + + + + + + + + + + + + + + From df570386581144addc423780c0955d877bf47bc6 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 10:18:25 -0500 Subject: [PATCH 009/115] MAGETWO-32686 Customer-facing resources in Sales & Checkout APIs - Corrects DI config for GuestCartItemRepository --- app/code/Magento/Quote/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 12502f7d37edd..5403ec864fae3 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -28,7 +28,7 @@ - + From 825eafa1409299a8c8484cabf65a26ece7af487d Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 10:28:14 -0500 Subject: [PATCH 010/115] MAGETWO-32686 Customer-facing resources in Sales & Checkout APIs - Corrects GuestCartItemRepository namespace --- .../Magento/Quote/Model/GuestCart/GuestCartItemRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index 6ad4e1e2798b8..f7c210852403a 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -4,7 +4,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Quote\GuestCart; +namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Model\Quote\Item\Repository; use Magento\Quote\Model\QuoteIdMask; From e7a0988d0c69629fe29f1f653534349925f1d054 Mon Sep 17 00:00:00 2001 From: Alexander Paliarush Date: Tue, 14 Apr 2015 19:17:10 +0300 Subject: [PATCH 011/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Create anonymous /guest-carts APIs for Magento\Quote\Api\PaymentMethodManagementInterface (MAGETWO-35843) --- .../GuestPaymentMethodManagementInterface.php | 42 +++++++++++ .../GuestPaymentMethodManagement.php | 70 +++++++++++++++++++ app/code/Magento/Quote/etc/webapi.xml | 20 ++++++ 3 files changed, 132 insertions(+) create mode 100644 app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php diff --git a/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php new file mode 100644 index 0000000000000..a33d00927e851 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php @@ -0,0 +1,42 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritdoc} + */ + public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::set($quoteIdMask->getId(), $method); + } + + /** + * {@inheritdoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($quoteIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::getList($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index e59115dccd9fe..146f47ef85eee 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -212,6 +212,26 @@ + + + + + + + + + + + + + + + + + + + + From f76ce7b4d62adbcc0eb8a649e2e2797251b47f91 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 11:20:37 -0500 Subject: [PATCH 012/115] MAGETWO-32686 Customer-facing resources in Sales & Checkout APIs - Uses the \Magento\Quote\Model\QuoteIdMaskFactory in GuestCartItemRepository --- .../Magento/Quote/Model/GuestCart/GuestCartItemRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index f7c210852403a..a8d453edb966c 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -8,7 +8,7 @@ use Magento\Quote\Model\Quote\Item\Repository; use Magento\Quote\Model\QuoteIdMask; -use Magento\Quote\Model\Resource\Quote\QuoteIdMaskFactory; +use Magento\Quote\Model\QuoteIdMaskFactory; class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface { From 960d75d8078d8bccb63d8ec250ea917355981b60 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 11:27:20 -0500 Subject: [PATCH 013/115] MAGETWO-32686 Customer-facing resources in Sales & Checkout APIs - Moves GuestCouponManagement to \Magento\Quote\Model\GuestCart\ --- .../Quote/Model/{ => GuestCart}/GuestCouponManagement.php | 3 ++- app/code/Magento/Quote/etc/di.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename app/code/Magento/Quote/Model/{ => GuestCart}/GuestCouponManagement.php (95%) diff --git a/app/code/Magento/Quote/Model/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php similarity index 95% rename from app/code/Magento/Quote/Model/GuestCouponManagement.php rename to app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index d280e617d1908..17a5017cf319d 100644 --- a/app/code/Magento/Quote/Model/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -5,9 +5,10 @@ * See COPYING.txt for license details. */ -namespace Magento\Quote\Model; +namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCouponManagementInterface; +use Magento\Quote\Model\CouponManagement; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 5403ec864fae3..245fb806a6ffe 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -29,6 +29,6 @@ - + From 46b4c2a82c6e2382255695f5130b5926e0fe1b46 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 11:46:16 -0500 Subject: [PATCH 014/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Api functional test fixes for Cart Item repository --- .../Magento/Quote/Api/GuestCartItemRepositoryTest.php | 9 +++++++++ .../Magento/Checkout/_files/quote_with_address_saved.php | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php index c1794579c0140..83ee4dd569228 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -88,6 +88,15 @@ public function testAddItem() $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . 'items', diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php index 65cdb896f134c..c06216ed07d89 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved.php @@ -12,3 +12,11 @@ require 'quote_with_address.php'; $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); From 1a4109c924c92f52861b8aa591653b178ea1e416 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 11:55:35 -0500 Subject: [PATCH 015/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Adds api-functional test for GuestCouponManagement - Corrects issues in GuestCouponManagement --- .../Model/GuestCart/GuestCouponManagement.php | 6 +- .../Quote/Api/GuestCouponManagementTest.php | 163 ++++++++++++++++++ 2 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 17a5017cf319d..ba15098012d00 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -13,7 +13,7 @@ use Magento\Quote\Model\QuoteIdMaskFactory; /** - * Coupon management object. + * Coupon management object for guest carts. */ class GuestCouponManagement extends CouponManagement implements GuestCouponManagementInterface { @@ -39,7 +39,7 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quotedIdMask->getId()); + return parent::get($quoteIdMask->getId()); } /** @@ -49,7 +49,7 @@ public function set($cartId, $couponCode) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quotedIdMask->getId(), $couponCode); + return parent::set($quoteIdMask->getId(), $couponCode); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php new file mode 100644 index 0000000000000..3e64df1e035b8 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php @@ -0,0 +1,163 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + protected function createGuestQuote($quoteId) + { + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); + $quoteIdMask->setId($quoteId); + $quoteIdMask->setDataChanges(true); + $quoteIdMask->save(); + return $quoteIdMask->getMaskedId(); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php + */ + public function testGet() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $cartId = $this->createGuestQuote($quote->getId()); + + $couponCode = $quote->getCouponCode(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons/' , + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($couponCode, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php + */ + public function testDelete() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $this->createGuestQuote($quote->getId()); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Remove', + ], + ]; + $requestData = ["cartId" => $cartId]; + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + $quote->load('test_order_1', 'reserved_order_id'); + $this->assertEquals('', $quote->getCouponCode()); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Coupon code is not valid + */ + public function testSetCouponThrowsExceptionIfCouponDoesNotExist() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $this->createGuestQuote($quote->getId()); + + $couponCode = 'invalid_coupon_code'; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons/' . $couponCode, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "couponCode" => $couponCode, + ]; + + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @magentoApiDataFixture Magento/Checkout/_files/discount_10percent.php + */ + public function testSetCouponSuccess() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test01', 'reserved_order_id'); + $cartId = $this->createGuestQuote($quote->getId()); + $salesRule = $this->objectManager->create('Magento\SalesRule\Model\Rule'); + $salesRule->load('Test Coupon', 'name'); + $couponCode = $salesRule->getCouponCode(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons/' . $couponCode, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "couponCode" => $couponCode, + ]; + + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + + $quoteWithCoupon = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quoteWithCoupon->load('test01', 'reserved_order_id'); + + $this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode); + } +} From 54dd9120ac96b58a7072486190c4510f7123f3ab Mon Sep 17 00:00:00 2001 From: Alexander Paliarush Date: Tue, 14 Apr 2015 19:58:44 +0300 Subject: [PATCH 016/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Create anonymous /guest-carts APIs for Magento\Quote\Api\PaymentMethodManagementInterface (MAGETWO-35843) --- app/code/Magento/Quote/etc/di.xml | 2 +- .../Api/GuestPaymentMethodManagementTest.php | 336 ++++++++++++++++++ .../quote_with_address_saved_rollback.php | 4 + .../quote_with_payment_saved_rollback.php | 4 + .../quote_with_simple_product_saved.php | 8 + ...ote_with_simple_product_saved_rollback.php | 4 + ...quote_with_virtual_product_and_address.php | 8 + ...h_virtual_product_and_address_rollback.php | 4 + .../quote_with_virtual_product_saved.php | 8 + ...te_with_virtual_product_saved_rollback.php | 4 + 10 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 245fb806a6ffe..fa3a4e2a1bef2 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -30,5 +30,5 @@ - + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php new file mode 100644 index 0000000000000..a1eba522ea594 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php @@ -0,0 +1,336 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + protected function tearDown() + { + $this->deleteCart('test_order_1'); + $this->deleteCart('test_order_1_with_payment'); + $this->deleteCart('test_order_with_virtual_product'); + $this->deleteCart('test_order_with_virtual_product_without_address'); + parent::tearDown(); + } + + /** + * Delete quote by given reserved order ID + * + * @param string $reservedOrderId + * @return void + */ + protected function deleteCart($reservedOrderId) + { + try { + /** @var $cart \Magento\Quote\Model\Quote */ + $cart = $this->objectManager->get('Magento\Quote\Model\Quote'); + $cart->load($reservedOrderId, 'reserved_order_id'); + if (!$cart->getId()) { + throw new \InvalidArgumentException('There is no quote with provided reserved order ID.'); + } + $cart->delete(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMask'); + $quoteIdMask->delete($cart->getId()); + } catch (\InvalidArgumentException $e) { + // Do nothing if cart fixture was not used + } + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php + */ + public function testReSetPayment() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_1_with_payment', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "method" => [ + 'method' => 'checkmo', + 'po_number' => null, + 'cc_owner' => 'John', + 'cc_type' => null, + 'cc_exp_year' => null, + 'cc_exp_month' => null, + ], + ]; + + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ + public function testSetPaymentWithVirtualProduct() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_with_virtual_product', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "method" => [ + 'method' => 'checkmo', + 'po_number' => '200', + 'cc_owner' => 'tester', + 'cc_type' => 'test', + 'cc_exp_year' => '2014', + 'cc_exp_month' => '1', + ], + ]; + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentWithSimpleProduct() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "method" => [ + 'method' => 'checkmo', + 'po_number' => '200', + 'cc_owner' => 'tester', + 'cc_type' => 'test', + 'cc_exp_year' => '2014', + 'cc_exp_month' => '1', + ], + ]; + + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Billing address is not set + */ + public function testSetPaymentWithVirtualProductWithoutAddress() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_with_virtual_product_without_address', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "method" => [ + 'method' => 'checkmo', + 'po_number' => '200', + 'cc_owner' => 'tester', + 'cc_type' => 'test', + 'cc_exp_year' => '2014', + 'cc_exp_month' => '1', + ], + ]; + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Shipping address is not set + */ + public function testSetPaymentWithSimpleProductWithoutAddress() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_with_simple_product_without_address', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'set', + ], + ]; + + $requestData = [ + "cartId" => $cartId, + "method" => [ + 'method' => 'checkmo', + 'po_number' => '200', + 'cc_owner' => 'tester', + 'cc_type' => 'test', + 'cc_exp_year' => '2014', + 'cc_exp_month' => '1', + ], + ]; + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetList() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'getList', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $requestResponse = $this->_webApiCall($serviceInfo, $requestData); + + $expectedResponse = [ + 'code' => 'checkmo', + 'title' => 'Check / Money order', + ]; + + $this->assertGreaterThan(0, count($requestResponse)); + $this->assertContains($expectedResponse, $requestResponse); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php + */ + public function testGet() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1_with_payment', 'reserved_order_id'); + $cartId = $this->getMaskedCartId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'get', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $requestResponse = $this->_webApiCall($serviceInfo, $requestData); + + $this->assertArrayHasKey('method', $requestResponse); + $this->assertArrayHasKey('po_number', $requestResponse); + $this->assertArrayHasKey('cc_owner', $requestResponse); + $this->assertArrayHasKey('cc_type', $requestResponse); + $this->assertArrayHasKey('cc_exp_year', $requestResponse); + $this->assertArrayHasKey('cc_exp_month', $requestResponse); + $this->assertArrayHasKey('additional_data', $requestResponse); + + $this->assertNotNull($requestResponse['method']); + $this->assertNotNull($requestResponse['po_number']); + $this->assertNotNull($requestResponse['cc_owner']); + $this->assertNotNull($requestResponse['cc_type']); + $this->assertNotNull($requestResponse['cc_exp_year']); + $this->assertNotNull($requestResponse['cc_exp_month']); + $this->assertNotNull($requestResponse['additional_data']); + + $this->assertEquals('checkmo', $requestResponse['method']); + } + + /** + * Retrieve masked cart ID for guest cart. + * + * @param string $cartId + * @return string + */ + protected function getMaskedCartId($cartId) + { + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + return $quoteIdMask->getMaskedId(); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved_rollback.php index 9bc73ec6d964f..098b8e746cd5b 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_address_saved_rollback.php @@ -10,3 +10,7 @@ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $quote = $objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id')->delete(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create('Magento\Quote\Model\QuoteIdMask'); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved_rollback.php index c828e4acf0c79..92d03e750c176 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved_rollback.php @@ -10,3 +10,7 @@ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $quote = $objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1_with_payment', 'reserved_order_id')->delete(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create('Magento\Quote\Model\QuoteIdMask'); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved.php index 3d410ba47f558..e917e5c33e8dd 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved.php @@ -26,3 +26,11 @@ ); $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php index 60b8a06b2dcfe..5639fc74d602e 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_simple_product_saved_rollback.php @@ -10,3 +10,7 @@ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $quote = $objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_with_simple_product_without_address', 'reserved_order_id')->delete(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create('Magento\Quote\Model\QuoteIdMask'); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address.php index f892d8e7abade..56ae6b1a7643b 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address.php @@ -52,3 +52,11 @@ ); $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php index abd211dba8b78..c87f4d43a8ac5 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_and_address_rollback.php @@ -9,3 +9,7 @@ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $quote = $objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_with_virtual_product', 'reserved_order_id')->delete(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create('Magento\Quote\Model\QuoteIdMask'); +$quoteIdMask->delete($quote->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved.php index d68124215662e..1d19150c3a3a5 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved.php @@ -19,3 +19,11 @@ ); $quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php index 4447d3cf57862..914ec199cfd33 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php @@ -10,3 +10,7 @@ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $quote = $objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_with_virtual_product_without_address', 'reserved_order_id')->delete(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = $objectManager->create('Magento\Quote\Model\QuoteIdMask'); +$quoteIdMask->delete($quote->getId()); From c662482e11b2e4fa2de95b085bb7edb7e1d1d80f Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 13:32:17 -0500 Subject: [PATCH 017/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Api functional test fixes for Cart Item repository --- .../Quote/Model/GuestCart/GuestCartItemRepository.php | 11 ----------- .../Magento/Quote/Api/GuestCartItemRepositoryTest.php | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index a8d453edb966c..35843f9188613 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -56,17 +56,6 @@ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem) return parent::save($cartItem); } - /** - * {@inheritdoc} - */ - public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) - { - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); - $cartItem->setQuoteId($quoteIdMask->getId()); - parent::delete($cartItem); - } - /** * {@inheritdoc} */ diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php index 83ee4dd569228..9a372cf87ed7d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -130,6 +130,15 @@ public function testRemoveItem() $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_item_with_items', 'reserved_order_id'); $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + $product = $this->objectManager->create('Magento\Catalog\Model\Product'); $productId = $product->getIdBySku('simple_one'); $product->load($productId); From c9d47d0b3d237c439569d6255eb0cb5de47156b3 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 14:04:22 -0500 Subject: [PATCH 018/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Remove the need to create quote masked ids because fixtures were updated --- .../Quote/Api/GuestCouponManagementTest.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php index 3e64df1e035b8..1a9ea8d79fd08 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php @@ -25,13 +25,11 @@ protected function setUp() $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } - protected function createGuestQuote($quoteId) + protected function getQuoteMaskedId($quoteId) { /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); - $quoteIdMask->setId($quoteId); - $quoteIdMask->setDataChanges(true); - $quoteIdMask->save(); + $quoteIdMask->load($quoteId); return $quoteIdMask->getMaskedId(); } @@ -44,7 +42,7 @@ public function testGet() $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $this->createGuestQuote($quote->getId()); + $cartId = $this->getQuoteMaskedId($quote->getId()); $couponCode = $quote->getCouponCode(); $serviceInfo = [ @@ -71,7 +69,7 @@ public function testDelete() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $this->createGuestQuote($quote->getId()); + $cartId = $this->getQuoteMaskedId($quote->getId()); $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons', @@ -99,7 +97,7 @@ public function testSetCouponThrowsExceptionIfCouponDoesNotExist() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $this->createGuestQuote($quote->getId()); + $cartId = $this->getQuoteMaskedId($quote->getId()); $couponCode = 'invalid_coupon_code'; @@ -132,7 +130,7 @@ public function testSetCouponSuccess() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test01', 'reserved_order_id'); - $cartId = $this->createGuestQuote($quote->getId()); + $cartId = $this->getQuoteMaskedId($quote->getId()); $salesRule = $this->objectManager->create('Magento\SalesRule\Model\Rule'); $salesRule->load('Test Coupon', 'name'); $couponCode = $salesRule->getCouponCode(); From 737e507377f4bcd2f4e07bcfb1903081f80acf15 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 14:09:29 -0500 Subject: [PATCH 019/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Code comment clean up --- .../Quote/Api/GuestCartItemRepositoryInterface.php | 3 +++ .../Magento/Quote/Api/GuestCartManagementInterface.php | 3 +++ .../Magento/Quote/Api/GuestCartRepositoryInterface.php | 5 ++++- .../Quote/Api/GuestCouponManagementInterface.php | 2 +- .../Api/GuestPaymentMethodManagementInterface.php | 2 +- .../Quote/Model/GuestCart/GuestCartItemRepository.php | 3 +++ .../Quote/Model/GuestCart/GuestCartManagement.php | 2 +- .../Quote/Model/GuestCart/GuestCartRepository.php | 10 +++++----- .../Quote/Model/GuestCart/GuestCouponManagement.php | 2 +- .../Model/GuestCart/GuestPaymentMethodManagement.php | 2 +- app/code/Magento/Quote/Model/QuoteIdMask.php | 3 +++ app/code/Magento/Quote/Setup/InstallSchema.php | 2 +- 12 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php index 782ca001af054..83d45bc157db0 100644 --- a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -5,6 +5,9 @@ */ namespace Magento\Quote\Api; +/** + * Cart Item repository interface for guest carts. + */ interface GuestCartItemRepositoryInterface extends CartItemRepositoryInterface { /** diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php index 2e9d5bcb113e6..90ba67b8a5bdb 100644 --- a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -5,6 +5,9 @@ */ namespace Magento\Quote\Api; +/** + * Cart Management interface for guest carts. + */ interface GuestCartManagementInterface extends CartManagementInterface { /** diff --git a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php index 53b256a6e8ea3..61c1457900552 100644 --- a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php @@ -5,10 +5,13 @@ */ namespace Magento\Quote\Api; +/** + * Cart Repository interface for guest carts. + */ interface GuestCartRepositoryInterface extends CartRepositoryInterface { /** - * Enables an administrative user to return information for a specified cart. + * Enables a guest user to return information for a specified cart. * * @param string $cartId * @return \Magento\Quote\Api\Data\CartInterface diff --git a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php index 64c4a308851d9..7f55ef952211c 100644 --- a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php @@ -8,7 +8,7 @@ namespace Magento\Quote\Api; /** - * Coupon management service interface. + * Coupon management interface for guest carts. */ interface GuestCouponManagementInterface extends CouponManagementInterface { diff --git a/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php index a33d00927e851..6f6daab8099ab 100644 --- a/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php @@ -6,7 +6,7 @@ namespace Magento\Quote\Api; /** - * Interface for payment method management in the cart by guest user. + * Payment method management interface for guest carts. */ interface GuestPaymentMethodManagementInterface extends PaymentMethodManagementInterface { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index 35843f9188613..b1ae3cfd06ebd 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -10,6 +10,9 @@ use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; +/** + * Cart Item repository class for guest carts. + */ class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface { /** diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 18e0389b78ba9..811ea1586ce32 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -25,7 +25,7 @@ use Magento\Store\Model\StoreManagerInterface; /** - * Class GuestCartManagement + * Cart Management class for guest carts. */ class GuestCartManagement extends QuoteManagement implements GuestCartManagementInterface { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index 73b23183c5120..33718612f3b9c 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -15,7 +15,7 @@ use Magento\Quote\Model\QuoteIdMaskFactory; /** - * Class GuestCartRepository + * Cart Repository class for guest carts. */ class GuestCartRepository extends QuoteRepository implements GuestCartRepositoryInterface { @@ -43,7 +43,7 @@ public function __construct( } /** - * @inheritdoc + * {@inheritdoc} */ public function get($cartId, array $sharedStoreIds = []) { @@ -53,7 +53,7 @@ public function get($cartId, array $sharedStoreIds = []) } /** - * @inheritdoc + * {@inheritdoc} */ public function getActive($cartId, array $sharedStoreIds = []) { @@ -63,7 +63,7 @@ public function getActive($cartId, array $sharedStoreIds = []) } /** - * @inheritdoc + * {@inheritdoc} */ public function save(Quote $quote) { @@ -76,7 +76,7 @@ public function save(Quote $quote) } /** - * @inheritdoc + * {@inheritdoc} */ public function delete(Quote $quote) { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index ba15098012d00..1a497334773b8 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -13,7 +13,7 @@ use Magento\Quote\Model\QuoteIdMaskFactory; /** - * Coupon management object for guest carts. + * Coupon management class for guest carts. */ class GuestCouponManagement extends CouponManagement implements GuestCouponManagementInterface { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php index 31244e30b9e8c..72723d0964458 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php @@ -11,7 +11,7 @@ use Magento\Quote\Model\QuoteIdMaskFactory; /** - * Class for guest cart payment method management. + * Payment method management class for guest carts. */ class GuestPaymentMethodManagement extends PaymentMethodManagement implements GuestPaymentMethodManagementInterface { diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php index 6063d89af6c17..ff9f63f64a57f 100644 --- a/app/code/Magento/Quote/Model/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -41,6 +41,9 @@ public function beforeSave() /** * Generate guid * + * Utility to generate random guid style identifiers + * Original Source: http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid + * * @return string */ protected function guidv4() diff --git a/app/code/Magento/Quote/Setup/InstallSchema.php b/app/code/Magento/Quote/Setup/InstallSchema.php index 8db3a3744c7da..14865891d74a0 100644 --- a/app/code/Magento/Quote/Setup/InstallSchema.php +++ b/app/code/Magento/Quote/Setup/InstallSchema.php @@ -1551,7 +1551,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con * Create table to store cartId and obscured UUID based cartId mapping */ /** - * Create table '' + * Create table 'quote_id_mask' */ $table = $installer->getConnection()->newTable( $installer->getTable('quote_id_mask') From 6356a3263e0942eb54049ebd10c17f94985133d9 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 14 Apr 2015 15:53:11 -0500 Subject: [PATCH 020/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed unit test \Magento\Quote\Test\Unit\Model\QuoteManagementTest --- .../Test/Unit/Model/QuoteManagementTest.php | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php index 522734a324ad9..d58adf62d675c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php @@ -86,6 +86,11 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase */ protected $customerFactoryMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -140,6 +145,15 @@ protected function setUp() '', false ); + $this->storeManagerMock = $this->getMockForAbstractClass( + 'Magento\Store\Model\StoreManagerInterface', + [], + '', + false, + true, + true, + ['getStore', 'getStoreId'] + ); $dataObjectHelper = $this->getMock('\Magento\Framework\Api\DataObjectHelper', [], [], '', false); @@ -160,6 +174,7 @@ protected function setUp() 'customerRepository' => $this->customerRepositoryMock, 'customerModelFactory' => $this->customerFactoryMock, 'dataObjectHelper' => $dataObjectHelper, + 'storeManager' => $this->storeManagerMock ] ); } @@ -171,17 +186,16 @@ public function testCreateEmptyCartAnonymous() $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->userContextMock->expects($this->once())->method('getUserType') - ->willReturn(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_GUEST); - $this->quoteRepositoryMock->expects($this->once())->method('create')->willReturn($quoteMock); $quoteMock->expects($this->any())->method('setStoreId')->with($storeId); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); - $this->assertEquals($quoteId, $this->model->createEmptyCart($storeId)); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf(); + $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + + $this->assertEquals($quoteId, $this->model->createEmptyCart()); } public function testCreateEmptyCartLoggedInUser() @@ -192,18 +206,6 @@ public function testCreateEmptyCartLoggedInUser() $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->userContextMock->expects($this->once())->method('getUserType') - ->willReturn(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER); - - $this->userContextMock->expects($this->atLeastOnce())->method('getUserId')->willReturn($userId); - - $customerMock = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface', [], [], '', false); - $this->customerRepositoryMock - ->expects($this->once()) - ->method('getById') - ->with($userId) - ->willReturn($customerMock); - $this->quoteRepositoryMock ->expects($this->once()) ->method('getActiveForCustomer') @@ -212,14 +214,15 @@ public function testCreateEmptyCartLoggedInUser() $this->quoteRepositoryMock->expects($this->once())->method('create')->willReturn($quoteMock); $quoteMock->expects($this->any())->method('setStoreId')->with($storeId); - $quoteMock->expects($this->any())->method('setCustomer')->with($customerMock); $quoteMock->expects($this->any())->method('setCustomerIsGuest')->with(0); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId); - $this->assertEquals($quoteId, $this->model->createEmptyCart($storeId)); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf(); + $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + + $this->assertEquals($quoteId, $this->model->createEmptyCart($userId)); } /** @@ -232,28 +235,18 @@ public function testCreateEmptyCartLoggedInUserException() $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->userContextMock->expects($this->once())->method('getUserType') - ->willReturn(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER); - - $this->userContextMock->expects($this->atLeastOnce())->method('getUserId')->willReturn($userId); - - $customerMock = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface', [], [], '', false); - $this->customerRepositoryMock - ->expects($this->once()) - ->method('getById') - ->with($userId) - ->willReturn($customerMock); - $this->quoteRepositoryMock ->expects($this->once()) ->method('getActiveForCustomer') ->with($userId); $this->quoteRepositoryMock->expects($this->never())->method('create')->willReturn($quoteMock); - $this->quoteRepositoryMock->expects($this->never())->method('save')->with($quoteMock); - $this->model->createEmptyCart($storeId); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf(); + $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + + $this->model->createEmptyCart($userId); } /** From ba3986441d2fb4c9e41c2787e2006dc0f52b16ab Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 14 Apr 2015 16:58:22 -0500 Subject: [PATCH 021/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Added unit test for \Magento\Quote\Model\QuoteIdMask --- .../Quote/Test/Unit/Model/QuoteIdMaskTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php new file mode 100644 index 0000000000000..9dc9aa848fc8e --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php @@ -0,0 +1,31 @@ +quoteIdMask = $helper->getObject('Magento\Quote\Model\QuoteIdMask'); + } + + public function testBeforeSave() + { + $this->quoteIdMask->beforeSave(); + $this->assertNotNull($this->quoteIdMask->getMaskedId(), 'Masked identifier is not generated.'); + } +} From cd734187531fd7dd815cb8b943a33967881afe30 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 17:58:55 -0500 Subject: [PATCH 022/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fix cart Item repository api functional test --- .../Quote/Model/GuestCart/GuestCartItemRepository.php | 8 +++++++- .../Magento/Quote/Api/GuestCartItemRepositoryTest.php | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index b1ae3cfd06ebd..c376915dcb12f 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -6,6 +6,7 @@ */ namespace Magento\Quote\Model\GuestCart; +use Magento\Quote\Api\Data\CartItemInterface; use Magento\Quote\Model\Quote\Item\Repository; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; @@ -45,7 +46,12 @@ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::getList($quoteIdMask->getId()); + $cartItemList = parent::getList($quoteIdMask->getId()); + /** @var $item CartItemInterface */ + foreach ($cartItemList as $item) { + $item->setQuoteId($quoteIdMask->getMaskedId()); + } + return $cartItemList; } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php index 9a372cf87ed7d..7287cd3020082 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -174,6 +174,15 @@ public function testUpdateItem() $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_item_with_items', 'reserved_order_id'); $cartId = $quote->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + $product = $this->objectManager->create('Magento\Catalog\Model\Product'); $productId = $product->getIdBySku('simple_one'); $product->load($productId); From 1df39402d038133976549b7c5e94b58b3c5d8365 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 14 Apr 2015 18:29:04 -0500 Subject: [PATCH 023/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed \Magento\Quote\Api\GuestCouponManagementTest by adding cleanup code --- .../Quote/Api/GuestCouponManagementTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php index 1a9ea8d79fd08..296d5d60767fb 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php @@ -12,7 +12,7 @@ class GuestCouponManagementTest extends WebapiAbstract { const SERVICE_VERSION = 'V1'; - const SERVICE_NAME = 'quoteCouponManagementV1'; + const SERVICE_NAME = 'quoteGuestCouponManagementV1'; const RESOURCE_PATH = '/V1/guest-carts/'; /** @@ -25,6 +25,20 @@ protected function setUp() $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } + public function tearDown() + { + $createdQuotes = ['test_order_1', 'test01']; + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + foreach ($createdQuotes as $quoteId) { + $quote->load($quoteId, 'reserved_order_id'); + $quote->delete(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMask'); + $quoteIdMask->delete($quote->getId()); + } + } + protected function getQuoteMaskedId($quoteId) { /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ From db7d6b60fbfab005c9e702b5a2be2475acb1ec9b Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 14 Apr 2015 18:43:18 -0500 Subject: [PATCH 024/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed \Magento\Quote\Api\CartManagementTest for SOAP --- .../Magento/Quote/Api/CartManagementTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index 9898ab28a7909..970e4998f011c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -310,14 +310,11 @@ public function testPlaceOrder() public function testGetCartForCustomer() { // get customer ID token - $serviceInfo = [ - 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH_CUSTOMER_TOKEN, - 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, - ], - ]; - $requestData = ['username' => 'customer@example.com', 'password' => 'password']; - $token = $this->_webApiCall($serviceInfo, $requestData); + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); $cart = $this->getCart('test01'); $customerId = $cart->getCustomer()->getId(); From 571fe2596e574aaa0615f11602d5afc2f95c9da6 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 18:30:45 -0500 Subject: [PATCH 025/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Add functionality for GuestCartTotalRepositoryInterface --- .../Api/GuestCartTotalRepositoryInterface.php | 19 ++ .../GuestCart/GuestCartTotalRepository.php | 56 ++++++ app/code/Magento/Quote/etc/di.xml | 1 + app/code/Magento/Quote/etc/webapi.xml | 6 + .../Api/GuestCartTotalRepositoryTest.php | 182 ++++++++++++++++++ 5 files changed, 264 insertions(+) create mode 100644 app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php diff --git a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php new file mode 100644 index 0000000000000..99d65322a092f --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php @@ -0,0 +1,19 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + parent::__construct( + $totalsFactory, + $quoteRepository, + $dataObjectHelper + ); + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index fa3a4e2a1bef2..cf4cd518a6507 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -31,4 +31,5 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 146f47ef85eee..7a153c23d9190 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -314,4 +314,10 @@ + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php new file mode 100644 index 0000000000000..87cbbbdaaf40e --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -0,0 +1,182 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->searchBuilder = $this->objectManager->create( + 'Magento\Framework\Api\SearchCriteriaBuilder' + ); + $this->filterBuilder = $this->objectManager->create( + 'Magento\Framework\Api\FilterBuilder' + ); + } + + protected function getQuoteMaskedId($quoteId) + { + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); + $quoteIdMask->load($quoteId); + return $quoteIdMask->getMaskedId(); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php + */ + public function testGetTotals() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $this->getQuoteMaskedId($quote->getId()); + + /** @var \Magento\Quote\Model\Quote\Address $shippingAddress */ + $shippingAddress = $quote->getShippingAddress(); + + $data = [ + Totals::KEY_BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), + Totals::KEY_GRAND_TOTAL => $quote->getGrandTotal(), + Totals::KEY_BASE_SUBTOTAL => $quote->getBaseSubtotal(), + Totals::KEY_SUBTOTAL => $quote->getSubtotal(), + Totals::KEY_BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), + Totals::KEY_SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), + Totals::KEY_DISCOUNT_AMOUNT => $shippingAddress->getDiscountAmount(), + Totals::KEY_BASE_DISCOUNT_AMOUNT => $shippingAddress->getBaseDiscountAmount(), + Totals::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), + Totals::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), + Totals::KEY_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getShippingDiscountAmount(), + Totals::KEY_BASE_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getBaseShippingDiscountAmount(), + Totals::KEY_TAX_AMOUNT => $shippingAddress->getTaxAmount(), + Totals::KEY_BASE_TAX_AMOUNT => $shippingAddress->getBaseTaxAmount(), + Totals::KEY_SHIPPING_TAX_AMOUNT => $shippingAddress->getShippingTaxAmount(), + Totals::KEY_BASE_SHIPPING_TAX_AMOUNT => $shippingAddress->getBaseShippingTaxAmount(), + Totals::KEY_SUBTOTAL_INCL_TAX => $shippingAddress->getSubtotalInclTax(), + Totals::KEY_BASE_SUBTOTAL_INCL_TAX => $shippingAddress->getBaseSubtotalTotalInclTax(), + Totals::KEY_SHIPPING_INCL_TAX => $shippingAddress->getShippingInclTax(), + Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), + Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), + Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), + Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], + ]; + + $requestData = ['cartId' => $cartId]; + + $data = $this->formatTotalsData($data); + + $this->assertEquals($data, $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData)); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage No such entity + */ + public function testGetTotalsWithAbsentQuote() + { + $cartId = 'unknownCart'; + $requestData = ['cartId' => $cartId]; + $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData); + } + + /** + * Get service info for totals service + * + * @param string $cartId + * @return array + */ + protected function getServiceInfoForTotalsService($cartId) + { + return [ + 'soap' => [ + 'service' => 'quoteGuestCartTotalRepositoryV1', + 'serviceVersion' => 'V1', + 'operation' => 'quoteGuestCartTotalRepositoryV1get', + ], + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId . '/totals', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + ]; + } + + /** + * Adjust response details for SOAP protocol + * + * @param array $data + * @return array + */ + protected function formatTotalsData($data) + { + foreach ($data as $key => $field) { + if (is_numeric($field)) { + $data[$key] = round($field, 1); + if ($data[$key] === null) { + $data[$key] = 0.0; + } + } + } + + unset($data[Totals::KEY_BASE_SUBTOTAL_INCL_TAX]); + + return $data; + } + + /** + * Fetch quote item totals data from quote + * + * @param \Magento\Quote\Model\Quote $quote + * @return array + */ + protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote) + { + $items = $quote->getAllItems(); + $item = array_shift($items); + + return [ + ItemTotals::KEY_PRICE => $item->getPrice(), + ItemTotals::KEY_BASE_PRICE => $item->getBasePrice(), + ItemTotals::KEY_QTY => $item->getQty(), + ItemTotals::KEY_ROW_TOTAL => $item->getRowTotal(), + ItemTotals::KEY_BASE_ROW_TOTAL => $item->getBaseRowTotal(), + ItemTotals::KEY_ROW_TOTAL_WITH_DISCOUNT => $item->getRowTotalWithDiscount(), + ItemTotals::KEY_TAX_AMOUNT => $item->getTaxAmount(), + ItemTotals::KEY_BASE_TAX_AMOUNT => $item->getBaseTaxAmount(), + ItemTotals::KEY_TAX_PERCENT => $item->getTaxPercent(), + ItemTotals::KEY_DISCOUNT_AMOUNT => $item->getDiscountAmount(), + ItemTotals::KEY_BASE_DISCOUNT_AMOUNT => $item->getBaseDiscountAmount(), + ItemTotals::KEY_DISCOUNT_PERCENT => $item->getDiscountPercent(), + ItemTotals::KEY_PRICE_INCL_TAX => $item->getPriceInclTax(), + ItemTotals::KEY_BASE_PRICE_INCL_TAX => $item->getBasePriceInclTax(), + ItemTotals::KEY_ROW_TOTAL_INCL_TAX => $item->getRowTotalInclTax(), + ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => $item->getBaseRowTotalInclTax(), + ]; + } +} From 20cfe4fd725aa782347fd243eb711e1233ac2c36 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 18:55:29 -0500 Subject: [PATCH 026/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Guest Services and APIs for Shipping Address Management --- ...uestShippingAddressManagementInterface.php | 29 ++ .../GuestShippingAddressManagement.php | 65 +++++ app/code/Magento/Quote/etc/di.xml | 1 + app/code/Magento/Quote/etc/webapi.xml | 14 + .../GuestShippingAddressManagementTest.php | 254 ++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php diff --git a/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php new file mode 100644 index 0000000000000..f4cfa80091d82 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php @@ -0,0 +1,29 @@ +quoteRepository = $quoteRepository; + $this->addressValidator = $addressValidator; + $this->logger = $logger; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritDoc} + */ + public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::assign($quoteIdMask->getId(), $address); + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($cartId); + } +} diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index cf4cd518a6507..c4eecb0523503 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -32,4 +32,5 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 7a153c23d9190..8e52696b4a04e 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -300,6 +300,20 @@ + + + + + + + + + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php new file mode 100644 index 0000000000000..dca42da770c22 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php @@ -0,0 +1,254 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + public function tearDown() + { + $createdQuotes = ['test_order_1', 'test_order_with_virtual_product']; + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + foreach ($createdQuotes as $quoteId) { + $quote->load($quoteId, 'reserved_order_id'); + $quote->delete(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMask'); + $quoteIdMask->delete($quote->getId()); + } + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetAddress() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Quote\Model\Quote\Address $address */ + $address = $quote->getShippingAddress(); + + $data = [ + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), + AddressInterface::KEY_ID => (int)$address->getId(), + AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), + AddressInterface::KEY_REGION => $address->getRegion(), + AddressInterface::KEY_REGION_ID => $address->getRegionId(), + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), + AddressInterface::KEY_STREET => $address->getStreet(), + AddressInterface::KEY_COMPANY => $address->getCompany(), + AddressInterface::KEY_TELEPHONE => $address->getTelephone(), + AddressInterface::KEY_POSTCODE => $address->getPostcode(), + AddressInterface::KEY_CITY => $address->getCity(), + AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), + AddressInterface::KEY_LASTNAME => $address->getLastname(), + AddressInterface::KEY_EMAIL => $address->getEmail() + ]; + + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $quote->getId() . '/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * + * @expectedException \Exception + * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable + */ + public function testGetAddressOfQuoteWithVirtualProduct() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $cartId = $quote->load('test_order_with_virtual_product', 'reserved_order_id')->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $quote->getId() . '/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $this->_webApiCall($serviceInfo, ["cartId" => $cartId]); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetAddress() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Assign', + ], + ]; + + $addressData = [ + 'firstname' => 'John', + 'lastname' => 'Smith', + 'email' => 'cat@dog.com', + 'company' => 'eBay Inc', + 'street' => ['Typical Street', 'Tiny House 18'], + 'city' => 'Big City', + 'region_id' => 12, + 'region' => 'California', + 'region_code' => 'CA', + 'postcode' => '0985432', + 'country_id' => 'US', + 'telephone' => '88776655', + 'fax' => '44332255', + ]; + $requestData = [ + "cartId" => $cartId, + 'address' => $addressData, + ]; + + $addressId = $this->_webApiCall($serviceInfo, $requestData); + + //reset $quote to reload data + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $address = $quote->getShippingAddress(); + $address->getRegionCode(); + $savedData = $address->getData(); + $this->assertEquals($addressId, $savedData['address_id'], 'Invalid address ID'); + $this->assertEquals(0, $savedData['same_as_billing']); + //custom checks for street, region and address_type + $this->assertEquals($addressData['street'], $quote->getShippingAddress()->getStreet()); + unset($addressData['street']); + + $this->assertEquals('shipping', $savedData['address_type']); + //check the rest of fields + foreach ($addressData as $key => $value) { + $this->assertEquals($value, $savedData[$key], 'Invalid value for ' . $key); + } + } + + /** + * Set address to quote with virtual products only + * + * @expectedException \Exception + * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ + public function testSetAddressForVirtualQuote() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_with_virtual_product', 'reserved_order_id'); + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Assign', + ], + ]; + + $addressData = [ + 'firstname' => 'John', + 'lastname' => 'Smith', + 'email' => 'cat@dog.com', + 'company' => 'eBay Inc', + 'street' => ['Typical Street', 'Tiny House 18'], + 'city' => 'Big City', + 'region_id' => 12, + 'region' => 'California', + 'region_code' => 'CA', + 'postcode' => '0985432', + 'country_id' => 'US', + 'telephone' => '88776655', + 'fax' => '44332255', + ]; + $requestData = [ + "cartId" => $cartId, + 'address' => $addressData, + ]; + + $this->_webApiCall($serviceInfo, $requestData); + } +} From ebf227a46b548796402ed521b71e804bf8a077a7 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 19:01:00 -0500 Subject: [PATCH 027/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fix instance variable and missing phpdoc for GuestCouponManagement --- .../Magento/Quote/Model/GuestCart/GuestCouponManagement.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 1a497334773b8..6a35d1b3f5b2d 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -17,10 +17,16 @@ */ class GuestCouponManagement extends CouponManagement implements GuestCouponManagementInterface { + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + /** * Constructs a coupon read service object. * * @param \Magento\Quote\Model\QuoteRepository $quoteRepository Quote repository. + * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( \Magento\Quote\Model\QuoteRepository $quoteRepository, From 1080204fb5fa721af03b2ef3121686643af035c2 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 19:06:16 -0500 Subject: [PATCH 028/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Add GuestBillingAddressManagementInterface and GuestBillingAddressManagement --- ...GuestBillingAddressManagementInterface.php | 29 ++++ .../GuestBillingAddressManagement.php | 67 ++++++++ app/code/Magento/Quote/etc/di.xml | 1 + app/code/Magento/Quote/etc/webapi.xml | 14 ++ .../Api/GuestBillingAddressManagementTest.php | 145 ++++++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php diff --git a/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php new file mode 100644 index 0000000000000..1428995d91d8a --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php @@ -0,0 +1,29 @@ +quoteIdMaskFactory = $quoteIdMaskFactory; + parent::__construct( + $quoteRepository, + $addressValidator, + $logger + ); + } + + /** + * {@inheritDoc} + */ + public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + + return parent::assign($quoteIdMask->getId(), $address); + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + + return parent::get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index c4eecb0523503..d1e74395bf52b 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -33,4 +33,5 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 8e52696b4a04e..47d9e5b150b19 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -246,6 +246,20 @@ + + + + + + + + + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php new file mode 100644 index 0000000000000..97838fe9f2639 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php @@ -0,0 +1,145 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + protected function getQuoteMaskedId($quoteId) + { + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); + $quoteIdMask->load($quoteId); + return $quoteIdMask->getMaskedId(); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetAddress() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Quote\Model\Quote\Address $address */ + $address = $quote->getBillingAddress(); + + $data = [ + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), + AddressInterface::KEY_ID => (int)$address->getId(), + AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), + AddressInterface::KEY_REGION => $address->getRegion(), + AddressInterface::KEY_REGION_ID => $address->getRegionId(), + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), + AddressInterface::KEY_STREET => $address->getStreet(), + AddressInterface::KEY_COMPANY => $address->getCompany(), + AddressInterface::KEY_TELEPHONE => $address->getTelephone(), + AddressInterface::KEY_POSTCODE => $address->getPostcode(), + AddressInterface::KEY_CITY => $address->getCity(), + AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), + AddressInterface::KEY_LASTNAME => $address->getLastname(), + AddressInterface::KEY_EMAIL => $address->getEmail() + ]; + + $cartId = $this->getQuoteMaskedId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetAddress() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $cartId = $this->getQuoteMaskedId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Assign', + ], + ]; + + $addressData = [ + 'firstname' => 'John', + 'lastname' => 'Smith', + 'email' => 'cat@dog.com', + 'company' => 'eBay Inc', + 'street' => ['Typical Street', 'Tiny House 18'], + 'city' => 'Big City', + 'region_id' => 12, + 'region' => 'California', + 'region_code' => 'CA', + 'postcode' => '0985432', + 'country_id' => 'US', + 'telephone' => '88776655', + 'fax' => '44332255', + ]; + $requestData = [ + "cartId" => $cartId, + 'address' => $addressData, + ]; + + $addressId = $this->_webApiCall($serviceInfo, $requestData); + + //reset $quote to reload data + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $address = $quote->getBillingAddress(); + $address->getRegionCode(); + $savedData = $address->getData(); + $this->assertEquals($addressId, $savedData['address_id']); + //custom checks for street, region and address_type + foreach ($addressData['street'] as $streetLine) { + $this->assertContains($streetLine, $quote->getBillingAddress()->getStreet()); + } + unset($addressData['street']); + $this->assertEquals('billing', $savedData['address_type']); + //check the rest of fields + foreach ($addressData as $key => $value) { + $this->assertEquals($value, $savedData[$key]); + } + } +} From 849a9f0a4e67403f92bfd69a4271dbba6221247e Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 14 Apr 2015 19:07:35 -0500 Subject: [PATCH 029/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Removes GuestCartTotalRepositoryInterface extending CartTotalRepositoryInterface --- .../Magento/Quote/Api/GuestCartTotalRepositoryInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php index 99d65322a092f..3ab99d4ab0f89 100644 --- a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php @@ -6,7 +6,7 @@ namespace Magento\Quote\Api; -interface GuestCartTotalRepositoryInterface extends CartTotalRepositoryInterface +interface GuestCartTotalRepositoryInterface { /** * Returns quote totals data for a specified cart. From e21f14925001a63d3cc7d01de3a45f30eb2e3064 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 19:29:45 -0500 Subject: [PATCH 030/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Guest Services and APIs for Shipping Method Management --- .../Api/GuestCartTotalRepositoryInterface.php | 2 +- ...GuestShippingMethodManagementInterface.php | 47 +++ .../GuestShippingMethodManagement.php | 86 +++++ app/code/Magento/Quote/etc/di.xml | 1 + app/code/Magento/Quote/etc/webapi.xml | 22 +- .../Api/GuestShippingMethodManagementTest.php | 334 ++++++++++++++++++ 6 files changed, 490 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php create mode 100644 app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php create mode 100644 dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingMethodManagementTest.php diff --git a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php index 3ab99d4ab0f89..19b3d2068b168 100644 --- a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php @@ -11,7 +11,7 @@ interface GuestCartTotalRepositoryInterface /** * Returns quote totals data for a specified cart. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @return \Magento\Quote\Api\Data\TotalsInterface Quote totals data. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. */ diff --git a/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php b/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php new file mode 100644 index 0000000000000..0e881009d9856 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php @@ -0,0 +1,47 @@ +quoteRepository = $quoteRepository; + $this->methodDataFactory = $methodDataFactory; + $this->converter = $converter; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::get($quoteIdMask->getId()); + } + + /** + * {@inheritDoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::getList($quoteIdMask->getId()); + } + + /** + * {@inheritDoc} + * + * @param int $cartId The shopping cart ID. + * @param string $carrierCode The carrier code. + * @param string $methodCode The shipping method code. + * @return bool + * @throws \Magento\Framework\Exception\InputException The shipping method is not valid for an empty cart. + * @throws \Magento\Framework\Exception\CouldNotSaveException The shipping method could not be saved. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart contains only virtual products and the shipping method is not applicable. + * @throws \Magento\Framework\Exception\StateException The billing or shipping address is not set. + */ + public function set($cartId, $carrierCode, $methodCode) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return parent::set($quoteIdMask->getId(), $carrierCode, $methodCode); + } +} diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index d1e74395bf52b..715e7fb3f91c0 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -33,5 +33,6 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 47d9e5b150b19..708de5e88af33 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -82,7 +82,7 @@ - + @@ -102,6 +102,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingMethodManagementTest.php new file mode 100644 index 0000000000000..54b8938765164 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingMethodManagementTest.php @@ -0,0 +1,334 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + } + + protected function getServiceInfo() + { + return [ + 'rest' => [ + 'resourcePath' => '/V1/carts/' . $this->quote->getId() . '/selected-shipping-method', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Set', + ], + ]; + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMethod() + { + $this->quote->load('test_order_1', 'reserved_order_id'); + $serviceInfo = $this->getServiceInfo(); + + $cartId = $this->quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $requestData = [ + 'cartId' => $cartId, + 'carrierCode' => 'flatrate', + 'methodCode' => 'flatrate', + ]; + $result = $this->_webApiCall($serviceInfo, $requestData); + $this->assertEquals(true, $result); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMethodWrongMethod() + { + $expectedMessage = 'Carrier with such method not found: %1, %2'; + $this->quote->load('test_order_1', 'reserved_order_id'); + $serviceInfo = $this->getServiceInfo(); + $carrierCode = 'flatrate'; + $methodCode = 'wrongMethod'; + + $cartId = $this->quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $requestData = [ + 'cartId' => $cartId, + 'carrierCode' => $carrierCode, + 'methodCode' => $methodCode, + ]; + try { + $this->_webApiCall($serviceInfo, $requestData); + } catch (\SoapFault $e) { + $this->assertContains( + $expectedMessage, + $e->getMessage(), + 'SoapFault does not contain expected message.' + ); + } catch (\Exception $e) { + $errorObj = $this->processRestExceptionResult($e); + $this->assertEquals($expectedMessage, $errorObj['message']); + $this->assertEquals([$carrierCode, $methodCode], $errorObj['parameters']); + } + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php + */ + public function testSetMethodWithoutShippingAddress() + { + $this->quote->load('test_order_with_simple_product_without_address', 'reserved_order_id'); + $serviceInfo = $this->getServiceInfo(); + + $cartId = $this->quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $requestData = [ + 'cartId' => $cartId, + 'carrierCode' => 'flatrate', + 'methodCode' => 'flatrate', + ]; + try { + $this->_webApiCall($serviceInfo, $requestData); + } catch (\SoapFault $e) { + $message = $e->getMessage(); + } catch (\Exception $e) { + $message = json_decode($e->getMessage())->message; + } + $this->assertEquals('Shipping address is not set', $message); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php + */ + public function testGetMethod() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $cartId = $quote->getId(); + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $shippingAddress = $quote->getShippingAddress(); + list($carrierCode, $methodCode) = explode('_', $shippingAddress->getShippingMethod()); + list($carrierTitle, $methodTitle) = explode(' - ', $shippingAddress->getShippingDescription()); + $data = [ + ShippingMethodInterface::KEY_CARRIER_CODE => $carrierCode, + ShippingMethodInterface::KEY_METHOD_CODE => $methodCode, + ShippingMethodInterface::KEY_CARRIER_TITLE => $carrierTitle, + ShippingMethodInterface::KEY_METHOD_TITLE => $methodTitle, + ShippingMethodInterface::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), + ShippingMethodInterface::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), + ShippingMethodInterface::KEY_AVAILABLE => true, + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($data, $this->_webApiCall($this->getSelectedMethodServiceInfo($cartId), $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + */ + public function testGetMethodOfVirtualCart() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $cartId = $quote->load('test_order_with_virtual_product', 'reserved_order_id')->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $result = $this->_webApiCall($this->getSelectedMethodServiceInfo($cartId), ["cartId" => $cartId]); + $this->assertEquals([], $result); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetMethodOfCartWithNoShippingMethod() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $cartId = $quote->load('test_order_1', 'reserved_order_id')->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $result = $this->_webApiCall($this->getSelectedMethodServiceInfo($cartId), ["cartId" => $cartId]); + $this->assertEquals([], $result); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php + * + */ + public function testGetListForVirtualCart() + { + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $cartId = $quote->load('test_order_with_virtual_product', 'reserved_order_id')->getId(); + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $this->assertEquals([], $this->_webApiCall($this->getListServiceInfo($cartId), ["cartId" => $cartId])); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetList() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + if (!$cartId) { + $this->fail('quote fixture failed'); + } + + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); + $quoteIdMask->load($cartId); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + + $quote->getShippingAddress()->collectShippingRates(); + $expectedRates = $quote->getShippingAddress()->getGroupedAllShippingRates(); + + $expectedData = $this->convertRates($expectedRates, $quote->getQuoteCurrencyCode()); + + $requestData = ["cartId" => $cartId]; + + $returnedRates = $this->_webApiCall($this->getListServiceInfo($cartId), $requestData); + $this->assertEquals($expectedData, $returnedRates); + } + + /** + * @param string $cartId + * @return array + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + protected function getSelectedMethodServiceInfo($cartId) + { + return $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-shipping-method', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + ], + ]; + } + + /** + * Service info + * + * @param int $cartId + * @return array + */ + protected function getListServiceInfo($cartId) + { + return [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/shipping-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'GetList', + ], + ]; + } + + /** + * Convert rate models array to data array + * + * @param string $currencyCode + * @param \Magento\Quote\Model\Quote\Address\Rate[] $groupedRates + * @return array + */ + protected function convertRates($groupedRates, $currencyCode) + { + $result = []; + /** @var \Magento\Quote\Model\Cart\ShippingMethodConverter $converter */ + $converter = $this->objectManager->create('\Magento\Quote\Model\Cart\ShippingMethodConverter'); + foreach ($groupedRates as $carrierRates) { + foreach ($carrierRates as $rate) { + $result[] = $converter->modelToDataObject($rate, $currencyCode)->__toArray(); + } + } + return $result; + } +} From ef85b40ca1edca12a7dbcfb736635e55d6239ea1 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 19:33:01 -0500 Subject: [PATCH 031/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed typo --- app/code/Magento/Quote/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 715e7fb3f91c0..a305a4a63284a 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -33,6 +33,6 @@ - + From 8a4e59019750cc6b907215bb4b22e2e4fa3958d1 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 19:44:31 -0500 Subject: [PATCH 032/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Removed extending Interfaces - Fixed cartId type to string for guest carts --- .../Api/GuestCartItemRepositoryInterface.php | 2 +- .../Api/GuestCartManagementInterface.php | 14 ++------- .../Api/GuestCartRepositoryInterface.php | 2 +- .../Api/GuestCouponManagementInterface.php | 31 ++++++++++++++++++- .../GuestPaymentMethodManagementInterface.php | 8 ++--- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php index 83d45bc157db0..8ad07762b83a8 100644 --- a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -8,7 +8,7 @@ /** * Cart Item repository interface for guest carts. */ -interface GuestCartItemRepositoryInterface extends CartItemRepositoryInterface +interface GuestCartItemRepositoryInterface { /** * Lists items that are assigned to a specified cart. diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php index 90ba67b8a5bdb..7fa298c2d719d 100644 --- a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -8,25 +8,15 @@ /** * Cart Management interface for guest carts. */ -interface GuestCartManagementInterface extends CartManagementInterface +interface GuestCartManagementInterface { /** * Enables an customer or guest user to create an empty cart and quote for an anonymous customer. * - * @param int|null $customerId The customer ID. * @return string Cart ID. * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. */ - public function createEmptyCart($customerId = null); - - /** - * Returns information for the cart for a specified customer. - * - * @param int $customerId The customer ID. - * @return \Magento\Quote\Api\Data\CartInterface Cart object. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer does not exist. - */ - public function getCartForCustomer($customerId); + public function createEmptyCart(); /** * Assigns a specified customer to a specified shopping cart. diff --git a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php index 61c1457900552..eb7293e15ee90 100644 --- a/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php @@ -8,7 +8,7 @@ /** * Cart Repository interface for guest carts. */ -interface GuestCartRepositoryInterface extends CartRepositoryInterface +interface GuestCartRepositoryInterface { /** * Enables a guest user to return information for a specified cart. diff --git a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php index 7f55ef952211c..14d0a1d5def59 100644 --- a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php @@ -10,6 +10,35 @@ /** * Coupon management interface for guest carts. */ -interface GuestCouponManagementInterface extends CouponManagementInterface +interface GuestCouponManagementInterface { + /** + * Returns information for a coupon in a specified cart. + * + * @param string $cartId The cart ID. + * @return string The coupon code data. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + */ + public function get($cartId); + + /** + * Adds a coupon by code to a specified cart. + * + * @param string $cartId The cart ID. + * @param string $couponCode The coupon code data. + * @return bool + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + * @throws \Magento\Framework\Exception\CouldNotSaveException The specified coupon could not be added. + */ + public function set($cartId, $couponCode); + + /** + * Deletes a coupon from a specified cart. + * + * @param string $cartId The cart ID. + * @return bool + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + * @throws \Magento\Framework\Exception\CouldNotDeleteException The specified coupon could not be deleted. + */ + public function remove($cartId); } diff --git a/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php index 6f6daab8099ab..e40142b3e2cb2 100644 --- a/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php @@ -8,12 +8,12 @@ /** * Payment method management interface for guest carts. */ -interface GuestPaymentMethodManagementInterface extends PaymentMethodManagementInterface +interface GuestPaymentMethodManagementInterface { /** * Adds a specified payment method to a specified shopping cart. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @param \Magento\Quote\Api\Data\PaymentInterface $method The payment method. * @return int Payment method ID. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. @@ -25,7 +25,7 @@ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method); /** * Returns the payment method for a specified shopping cart. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @return \Magento\Quote\Api\Data\PaymentInterface Payment method object. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. */ @@ -34,7 +34,7 @@ public function get($cartId); /** * Lists available payment methods for a specified shopping cart. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @return \Magento\Quote\Api\Data\PaymentMethodInterface[] Array of payment methods. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. */ From 6e016c6b0aa60bd1846910c89bdd26e98c39786b Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 21:56:27 -0500 Subject: [PATCH 033/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed interface reference and get method --- .../Model/GuestCart/GuestShippingAddressManagement.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index a4eddcad24388..7d585ce34d2b6 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -5,7 +5,7 @@ */ namespace Magento\Quote\Model\GuestCart; -use Magento\Quote\Api\ShippingAddressManagementInterface; +use Magento\Quote\Api\GuestShippingAddressManagementInterface; use Magento\Quote\Model\QuoteAddressValidator; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; @@ -16,7 +16,7 @@ /** * Shipping address management management class for guest carts. */ -class GuestShippingAddressManagement extends ShippingAddressManagement implements ShippingAddressManagementInterface +class GuestShippingAddressManagement extends ShippingAddressManagement implements GuestShippingAddressManagementInterface { /** * @var QuoteIdMaskFactory @@ -60,6 +60,6 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($cartId); + return parent::get($quoteIdMask->getId()); } } From b6b784ece18a4131e34465f482efd70ecd20e36f Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 22:00:19 -0500 Subject: [PATCH 034/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Removing incomplete test. Already covered by api-functional for now. --- .../GuestCart/GuestCartManagementTest.php | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php deleted file mode 100644 index 8a5ef7a3b77bb..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/GuestCart/GuestCartManagementTest.php +++ /dev/null @@ -1,26 +0,0 @@ -guestCart = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Quote\Api\GuestCartManagementInterface' - ); - } - - public function testCreateEmptyCart() - { - $cartId = $this->guestCart->createEmptyCart(); - $this->assertNotEmpty($cartId); - } -} From 3062c19e622dae57231ccd1ddf747fba32026fe0 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Tue, 14 Apr 2015 22:06:39 -0500 Subject: [PATCH 035/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed license block --- app/code/Magento/Quote/Model/QuoteIdMask.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php index ff9f63f64a57f..36bb5bbcac05b 100644 --- a/app/code/Magento/Quote/Model/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -1,9 +1,7 @@ Date: Wed, 15 Apr 2015 13:11:10 +0300 Subject: [PATCH 036/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs --- ...GuestBillingAddressManagementInterface.php | 7 +++++-- .../GuestBillingAddressManagement.php | 5 ++++- .../Model/GuestCart/GuestCartManagement.php | 19 ++++++++++++++++++- .../Model/GuestCart/GuestCartRepository.php | 6 ++++-- .../GuestCart/GuestCartTotalRepository.php | 8 ++------ .../Model/GuestCart/GuestCouponManagement.php | 4 +--- .../GuestShippingAddressManagement.php | 3 ++- .../GuestShippingMethodManagement.php | 9 --------- .../Model/Resource/Quote/QuoteIdMask.php | 2 +- .../Magento/Quote/Setup/InstallSchema.php | 15 ++++++--------- 10 files changed, 43 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php index 1428995d91d8a..0400edba25ea1 100644 --- a/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php @@ -5,12 +5,15 @@ */ namespace Magento\Quote\Api; +/** + * Billing address management interface for guest carts. + */ interface GuestBillingAddressManagementInterface { /** * Assigns a specified billing address to a specified cart. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @param \Magento\Quote\Api\Data\AddressInterface $address Billing address data. * @return int Address ID. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. @@ -21,7 +24,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres /** * Returns the billing address for a specified quote. * - * @param int $cartId The cart ID. + * @param string $cartId The cart ID. * @return \Magento\Quote\Api\Data\AddressInterface Quote billing address object. * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. */ diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php index 97b2e0ffb157a..dc2ce6805c683 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php @@ -9,11 +9,14 @@ use Magento\Quote\Api\GuestBillingAddressManagementInterface; use Magento\Quote\Model\BillingAddressManagement; use Magento\Quote\Model\QuoteAddressValidator; +use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Model\QuoteRepository; use Psr\Log\LoggerInterface as Logger; -/** Quote billing address write service object. */ +/** + * Billing address management service for guest carts. + */ class GuestBillingAddressManagement extends BillingAddressManagement implements GuestBillingAddressManagementInterface { /** diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 811ea1586ce32..14cb662148a73 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -35,6 +35,23 @@ class GuestCartManagement extends QuoteManagement implements GuestCartManagement protected $quoteIdMaskFactory; /** + * Initialize dependencies. + * + * @param EventManager $eventManager + * @param QuoteValidator $quoteValidator + * @param OrderFactory $orderFactory + * @param OrderManagement $orderManagement + * @param CustomerManagement $customerManagement + * @param ToOrderConverter $quoteAddressToOrder + * @param ToOrderAddressConverter $quoteAddressToOrderAddress + * @param ToOrderItemConverter $quoteItemToOrderItem + * @param ToOrderPaymentConverter $quotePaymentToOrderPayment + * @param UserContextInterface $userContext + * @param QuoteRepository $quoteRepository + * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @param \Magento\Customer\Model\CustomerFactory $customerModelFactory + * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param StoreManagerInterface $storeManager * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( @@ -76,7 +93,7 @@ public function __construct( } /** - * @inheritdoc + * {@inheritdoc} */ public function createEmptyCart($customerId = null) { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index 33718612f3b9c..e0619d15fc211 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -25,6 +25,8 @@ class GuestCartRepository extends QuoteRepository implements GuestCartRepository protected $quoteIdMaskFactory; /** + * Initialize dependencies. + * * @param QuoteFactory $quoteFactory * @param StoreManagerInterface $storeManager * @param \Magento\Quote\Model\Resource\Quote\Collection $quoteCollection @@ -67,7 +69,7 @@ public function getActive($cartId, array $sharedStoreIds = []) */ public function save(Quote $quote) { - if($quote->getId()) { + if ($quote->getId()) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); $quote->setId($quoteIdMask->getId()); @@ -80,7 +82,7 @@ public function save(Quote $quote) */ public function delete(Quote $quote) { - if($quote->getId()) { + if ($quote->getId()) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); $quote->setId($quoteIdMask->getId()); diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php index 65cb2da0688f0..02221d2950c3c 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php @@ -15,7 +15,7 @@ /** * Cart totals repository class for guest carts. */ -class GuestCartTotalRepository extends CartTotalRepository implements \Magento\Quote\Api\GuestCartTotalRepositoryInterface +class GuestCartTotalRepository extends CartTotalRepository implements GuestCartTotalRepositoryInterface { /** * @var QuoteIdMaskFactory @@ -37,11 +37,7 @@ public function __construct( QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct( - $totalsFactory, - $quoteRepository, - $dataObjectHelper - ); + parent::__construct($totalsFactory, $quoteRepository, $dataObjectHelper); } /** diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 6a35d1b3f5b2d..362e51f02c9f0 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -33,9 +33,7 @@ public function __construct( QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct( - $quoteRepository - ); + parent::__construct($quoteRepository); } /** diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 7d585ce34d2b6..750e1580c3b44 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -16,7 +16,8 @@ /** * Shipping address management management class for guest carts. */ -class GuestShippingAddressManagement extends ShippingAddressManagement implements GuestShippingAddressManagementInterface +class GuestShippingAddressManagement extends ShippingAddressManagement + implements GuestShippingAddressManagementInterface { /** * @var QuoteIdMaskFactory diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php index ac9a7b5d1f8b0..bd4e8672b764c 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php @@ -67,15 +67,6 @@ public function getList($cartId) /** * {@inheritDoc} - * - * @param int $cartId The shopping cart ID. - * @param string $carrierCode The carrier code. - * @param string $methodCode The shipping method code. - * @return bool - * @throws \Magento\Framework\Exception\InputException The shipping method is not valid for an empty cart. - * @throws \Magento\Framework\Exception\CouldNotSaveException The shipping method could not be saved. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart contains only virtual products and the shipping method is not applicable. - * @throws \Magento\Framework\Exception\StateException The billing or shipping address is not set. */ public function set($cartId, $carrierCode, $methodCode) { diff --git a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php index 6975b43c57976..a3c02553b16d2 100644 --- a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php @@ -19,7 +19,7 @@ class QuoteIdMask extends AbstractDb */ protected function _construct() { - $this->_init('quote_id_mask', 'entity_id'); + $this->_init('quote_id_mask', 'quote_id'); $this->_isPkAutoIncrement = false; } } diff --git a/app/code/Magento/Quote/Setup/InstallSchema.php b/app/code/Magento/Quote/Setup/InstallSchema.php index 14865891d74a0..3ae1f33543062 100644 --- a/app/code/Magento/Quote/Setup/InstallSchema.php +++ b/app/code/Magento/Quote/Setup/InstallSchema.php @@ -1550,20 +1550,17 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con /** * Create table to store cartId and obscured UUID based cartId mapping */ - /** - * Create table 'quote_id_mask' - */ $table = $installer->getConnection()->newTable( $installer->getTable('quote_id_mask') )->addColumn( - 'entity_id', + 'quote_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['identity' => true, 'unsigned' => true, 'nullable' => false], - 'Entity Id' + 'Quote ID' )->addForeignKey( - 'entity_id', - 'entity_id', + 'quote_id', + 'quote_id', $installer->getTable('quote'), 'entity_id', \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE @@ -1572,9 +1569,9 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 32, ['nullable' => 'false'], - 'Masked Id' + 'Masked ID' )->setComment( - 'Quote id and masked id mapping' + 'Quote ID and masked ID mapping' ); $installer->getConnection()->createTable($table); From 1bc4692d85f704cbca3e134164d21b0a00052ffa Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 15 Apr 2015 16:03:23 +0300 Subject: [PATCH 037/115] MAGETWO-36191: Merge and Build stabilization --- .../Model/GuestCart/GuestCartManagement.php | 2 + .../GuestShippingAddressManagement.php | 4 +- .../GuestShippingAddressManagementTest.php | 49 ++++++------------- .../_files/quote_with_check_payment.php | 1 - .../Framework/Reflection/TypeProcessor.php | 6 ++- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 14cb662148a73..16be40235df21 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -26,6 +26,8 @@ /** * Cart Management class for guest carts. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class GuestCartManagement extends QuoteManagement implements GuestCartManagementInterface { diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 750e1580c3b44..6170bca7dc7d8 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -16,8 +16,8 @@ /** * Shipping address management management class for guest carts. */ -class GuestShippingAddressManagement extends ShippingAddressManagement - implements GuestShippingAddressManagementInterface +class GuestShippingAddressManagement extends ShippingAddressManagement implements + GuestShippingAddressManagementInterface { /** * @var QuoteIdMaskFactory diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php index dca42da770c22..a1c22bf0ee869 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php @@ -39,6 +39,14 @@ public function tearDown() } } + protected function getQuoteMaskedId($quoteId) + { + /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); + $quoteIdMask->load($quoteId); + return $quoteIdMask->getMaskedId(); + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ @@ -67,18 +75,11 @@ public function testGetAddress() AddressInterface::KEY_EMAIL => $address->getEmail() ]; - $cartId = $quote->getId(); - /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ - $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Quote\Model\QuoteIdMaskFactory') - ->create(); - $quoteIdMask->load($cartId); - //Use masked cart Id - $cartId = $quoteIdMask->getMaskedId(); + $cartId = $this->getQuoteMaskedId($quote->getId()); $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $quote->getId() . '/shipping-address', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/shipping-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -101,18 +102,12 @@ public function testGetAddress() public function testGetAddressOfQuoteWithVirtualProduct() { $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); - $cartId = $quote->load('test_order_with_virtual_product', 'reserved_order_id')->getId(); - /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ - $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Quote\Model\QuoteIdMaskFactory') - ->create(); - $quoteIdMask->load($cartId); - //Use masked cart Id - $cartId = $quoteIdMask->getMaskedId(); + $quote->load('test_order_with_virtual_product', 'reserved_order_id'); + $cartId = $this->getQuoteMaskedId($quote->getId()); $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $quote->getId() . '/shipping-address', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/shipping-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -133,14 +128,7 @@ public function testSetAddress() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $quote->getId(); - /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ - $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Quote\Model\QuoteIdMaskFactory') - ->create(); - $quoteIdMask->load($cartId); - //Use masked cart Id - $cartId = $quoteIdMask->getMaskedId(); + $cartId = $this->getQuoteMaskedId($quote->getId()); $serviceInfo = [ 'rest' => [ @@ -208,14 +196,7 @@ public function testSetAddressForVirtualQuote() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_with_virtual_product', 'reserved_order_id'); - $cartId = $quote->getId(); - /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ - $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Quote\Model\QuoteIdMaskFactory') - ->create(); - $quoteIdMask->load($cartId); - //Use masked cart Id - $cartId = $quoteIdMask->getMaskedId(); + $cartId = $this->getQuoteMaskedId($quote->getId()); $serviceInfo = [ 'rest' => [ diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php index 5133094c254f3..1f0a0a45197c7 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php @@ -27,4 +27,3 @@ $quoteIdMask->setId($quote->getId()); $quoteIdMask->setDataChanges(true); $quoteIdMask->save(); - diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index a3c31c6b43db6..580be037ad206 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -12,6 +12,8 @@ /** * Type processor of config reader properties + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class TypeProcessor { @@ -108,7 +110,7 @@ public function setTypeData($typeName, $data) public function register($type) { $typeName = $this->normalizeType($type); - if (is_null($typeName)) { + if (null === $typeName) { return null; } if (!$this->isTypeSimple($typeName) && !$this->isTypeAny($typeName)) { @@ -291,7 +293,7 @@ public function getGetterReturnType($methodReflection) */ public function normalizeType($type) { - if($type == 'null') { + if ($type == 'null') { return null; } $normalizationMap = [ From dde93e0f8e266ff17c3b817c888bf439abf2e69e Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 15 Apr 2015 16:28:26 +0300 Subject: [PATCH 038/115] MAGETWO-36191: Merge and Build stabilization - L3 fix --- app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 16be40235df21..2e655a2bf39d1 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -55,6 +55,7 @@ class GuestCartManagement extends QuoteManagement implements GuestCartManagement * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper * @param StoreManagerInterface $storeManager * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( EventManager $eventManager, From 11609d1d3e35a23dc1b45eacdab1d17d3fa17af2 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Wed, 15 Apr 2015 10:35:47 -0500 Subject: [PATCH 039/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Replace implementation for masked Id generation --- app/code/Magento/Quote/Model/QuoteIdMask.php | 45 +++++++++++-------- .../Quote/Test/Unit/Model/QuoteIdMaskTest.php | 8 +++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php index 36bb5bbcac05b..2e14cc0229f31 100644 --- a/app/code/Magento/Quote/Model/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -14,6 +14,31 @@ */ class QuoteIdMask extends \Magento\Framework\Model\AbstractModel { + /** + * @var \Magento\Framework\Math\Random + */ + protected $randomDataGenerator; + + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Math\Random $randomDataGenerator + * @param \Magento\Framework\Model\Resource\AbstractResource $resource + * @param \Magento\Framework\Data\Collection\Db $resourceCollection + * @param array $data + */ + public function __construct( + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Math\Random $randomDataGenerator, + \Magento\Framework\Model\Resource\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\Db $resourceCollection = null, + array $data = []) + { + $this->randomDataGenerator = $randomDataGenerator; + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + } + /** * Initialize resource * @@ -32,25 +57,7 @@ protected function _construct() public function beforeSave() { parent::beforeSave(); - $this->setMaskedId($this->guidv4()); + $this->setMaskedId($this->randomDataGenerator->getUniqueHash()); return $this; } - - /** - * Generate guid - * - * Utility to generate random guid style identifiers - * Original Source: http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid - * - * @return string - */ - protected function guidv4() - { - $data = openssl_random_pseudo_bytes(16); - - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100 - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 - - return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); - } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php index 9dc9aa848fc8e..9bd03b6bea45e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php @@ -6,12 +6,13 @@ namespace Magento\Quote\Test\Unit\Model; +use Magento\Framework\Math\Random; + /** * Unit test for \Magento\Quote\Model\QuoteIdMask */ class QuoteIdMaskTest extends \PHPUnit_Framework_TestCase { - /** * @var \Magento\Quote\Model\QuoteIdMask */ @@ -20,7 +21,10 @@ class QuoteIdMaskTest extends \PHPUnit_Framework_TestCase protected function setUp() { $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteIdMask = $helper->getObject('Magento\Quote\Model\QuoteIdMask'); + $this->quoteIdMask = $helper->getObject( + 'Magento\Quote\Model\QuoteIdMask', + ['randomDataGenerator' => new Random()] + ); } public function testBeforeSave() From 6626381e249a050deae42294dce2d3811128f968 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Wed, 15 Apr 2015 18:45:45 +0300 Subject: [PATCH 040/115] MAGETWO-36033: Exception if trying to sort Customer Groups by Tax Class --- .../Model/Resource/GroupRepository.php | 3 + .../Model/Resource/GroupRepositoryTest.php | 94 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/app/code/Magento/Customer/Model/Resource/GroupRepository.php b/app/code/Magento/Customer/Model/Resource/GroupRepository.php index 73b59ff2dd1e5..fe0d52ca471ef 100644 --- a/app/code/Magento/Customer/Model/Resource/GroupRepository.php +++ b/app/code/Magento/Customer/Model/Resource/GroupRepository.php @@ -164,6 +164,7 @@ public function getList(SearchCriteriaInterface $searchCriteria) /** @var \Magento\Customer\Model\Resource\Group\Collection $collection */ $collection = $this->groupFactory->create()->getCollection(); + $collection->addTaxClass(); //Add filters from root filter group to the collection /** @var FilterGroup $group */ @@ -234,6 +235,8 @@ protected function translateField($field) return 'customer_group_code'; case GroupInterface::ID: return 'customer_group_id'; + case GroupInterface::TAX_CLASS_NAME: + return 'class_name'; default: return $field; } diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php index f147db9a5a5cc..905a5a9affc1d 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php @@ -7,6 +7,7 @@ namespace Magento\Customer\Model\Resource; use Magento\Customer\Api\Data\GroupInterface; +use Magento\Framework\Api\SearchCriteria; /** * Integration test for \Magento\Customer\Model\Resource\GroupRepository @@ -28,12 +29,16 @@ class GroupRepositoryTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\Api\SearchCriteriaBuilder */ private $searchCriteriaBuilder; + /** @var \Magento\Framework\Api\SortOrderBuilder */ + private $sortOrderBuilder; + protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->groupRepository = $this->objectManager->create('Magento\Customer\Api\GroupRepositoryInterface'); $this->groupFactory = $this->objectManager->create('Magento\Customer\Api\Data\GroupInterfaceFactory'); $this->searchCriteriaBuilder = $this->objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder'); + $this->sortOrderBuilder = $this->objectManager->create('Magento\Framework\Api\SortOrderBuilder'); } /** @@ -249,6 +254,95 @@ public function searchGroupsDataProvider() 3 => [GroupInterface::CODE => 'Retailer', GroupInterface::TAX_CLASS_ID => 3] ], ], + 'like_tax_name' => [ + [ + $builder->setField(GroupInterface::TAX_CLASS_NAME)->setValue('Retail Customer') + ->setConditionType('like') + ->create(), + ], + [], + [ + 0 => [GroupInterface::CODE => 'NOT LOGGED IN', GroupInterface::TAX_CLASS_ID => 3], + 1 => [GroupInterface::CODE => 'General', GroupInterface::TAX_CLASS_ID => 3], + 2 => [GroupInterface::CODE => 'Wholesale', GroupInterface::TAX_CLASS_ID => 3], + 3 => [GroupInterface::CODE => 'Retailer', GroupInterface::TAX_CLASS_ID => 3], + ], + ], + ]; + } + + /** + * @param string $field + * @param string, $direction + * @param string, $methodName + * @param array $expectedResult + * + * @dataProvider sortOrderDataProvider + */ + public function testGetListSortOrder($field, $direction, $methodName, $expectedResult) + { + /** @var \Magento\Framework\Api\SortOrder $sortOrder */ + /** @var string $direction */ + $direction = ($direction == 'ASC') ? SearchCriteria::SORT_ASC : SearchCriteria::SORT_DESC; + $sortOrder = $this->sortOrderBuilder->setField($field)->setDirection($direction)->create(); + $this->searchCriteriaBuilder->addSortOrder($sortOrder); + + $searchResults = $this->groupRepository->getList($this->searchCriteriaBuilder->create()); + + /** @var \Magento\Customer\Api\Data\GroupInterface[] $resultItems */ + $resultItems = $searchResults->getItems(); + $this->assertTrue(count($resultItems) > 0); + + $result = []; + foreach ($resultItems as $item) { + /** @var \Magento\Customer\Model\Data\Group $item */ + $result[] = $item->$methodName(); + } + $this->assertEquals($expectedResult, $result); + } + + /** + * @return array + */ + public function sortOrderDataProvider() + { + return [ + [ + GroupInterface::ID, + 'ASC', + 'getId', + [0, 1, 2, 3], + ], + [ + GroupInterface::ID, + 'DESC', + 'getId', + [3, 2, 1, 0], + ], + [ + GroupInterface::CODE, + 'ASC', + 'getCode', + ['General', 'NOT LOGGED IN', 'Retailer', 'Wholesale'], + ], + [ + GroupInterface::CODE, + 'DESC', + 'getCode', + ['Wholesale', 'Retailer', 'NOT LOGGED IN', 'General'], + ], + [ + GroupInterface::TAX_CLASS_NAME, + 'ASC', + 'getTaxClassName', + ['Retail Customer', 'Retail Customer', 'Retail Customer', 'Retail Customer'] + ], + [ + GroupInterface::TAX_CLASS_NAME, + 'DESC', + 'getTaxClassName', + ['Retail Customer', 'Retail Customer', 'Retail Customer', 'Retail Customer'] + ], ]; } } From 3f94e0c3948fef92f1c15b01250ffcadbbbda9df Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Wed, 15 Apr 2015 13:48:24 -0500 Subject: [PATCH 041/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixes for Code comment and styling --- .../Quote/Api/GuestShippingAddressManagementInterface.php | 3 +++ .../Quote/Model/GuestCart/GuestShippingAddressManagement.php | 2 +- app/code/Magento/Quote/Model/QuoteIdMask.php | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php index f4cfa80091d82..c208b9a0fe19d 100644 --- a/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php +++ b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php @@ -5,6 +5,9 @@ */ namespace Magento\Quote\Api; +/** + * Shipping address management interface for guest carts. + */ interface GuestShippingAddressManagementInterface { /** diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 6170bca7dc7d8..7d83d71ebf6b4 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -14,7 +14,7 @@ use Psr\Log\LoggerInterface as Logger; /** - * Shipping address management management class for guest carts. + * Shipping address management class for guest carts. */ class GuestShippingAddressManagement extends ShippingAddressManagement implements GuestShippingAddressManagementInterface diff --git a/app/code/Magento/Quote/Model/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php index 2e14cc0229f31..953fe1d7af87e 100644 --- a/app/code/Magento/Quote/Model/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -33,8 +33,8 @@ public function __construct( \Magento\Framework\Math\Random $randomDataGenerator, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, - array $data = []) - { + array $data = [] + ) { $this->randomDataGenerator = $randomDataGenerator; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } From b3183ccf1a4361c4758371daf6b2d06630ae3d31 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Wed, 15 Apr 2015 13:57:22 -0500 Subject: [PATCH 042/115] MAGETWO-32686: Customer-facing resources in Sales & Checkout APIs - Fixed docblock comment --- .../Magento/Quote/Api/GuestCartTotalRepositoryInterface.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php index 19b3d2068b168..6384407793a7a 100644 --- a/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php @@ -6,6 +6,9 @@ namespace Magento\Quote\Api; +/** + * Cart totals repository interface for guest carts. + */ interface GuestCartTotalRepositoryInterface { /** From 27af9d1596cdfabc63e426f674ce0ca403861dce Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Wed, 15 Apr 2015 16:46:13 -0500 Subject: [PATCH 043/115] MAGETWO-361898: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Refactor the webapi code for overriding parameters --- .../Rest/ParamOverriderCustomerId.php | 31 ++++++++++++++++ .../Rest/ParamOverriderInterface.php | 37 +++++++++++++++++++ .../Controller/Rest/ParamsOverrider.php | 21 +++++------ app/code/Magento/Webapi/etc/di.xml | 7 ++++ 4 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php create mode 100644 app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php new file mode 100644 index 0000000000000..5712dd23c087e --- /dev/null +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -0,0 +1,31 @@ +userContext = $userContext; + } + + public function getOverridenValue() { + if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { + return $this->userContext->getUserId(); + } + return null; + } +} diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php new file mode 100644 index 0000000000000..cad7f5edda3ab --- /dev/null +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php @@ -0,0 +1,37 @@ + + * %customer_id% + * + * + * Classes which implement ParamOverriderInterface would return the real value for the parameter, so a + * ParamOverriderCustomerId would return the current authenticated user's customer id. If you + * create new ParamOverriderInterface implementations, you can register new implementations by + * adding to the parameter list for ParamsOverrider's dependency injection configuration. + */ +interface ParamOverriderInterface +{ + /** + * Returns the overriden value to use. + * + * @return string|int|null + */ + public function getOverridenValue(); +} diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 140f7dcd6a3b3..584d8e1a52ca7 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -6,7 +6,6 @@ namespace Magento\Webapi\Controller\Rest; -use Magento\Authorization\Model\UserContextInterface; use Magento\Webapi\Model\Config\Converter; /** @@ -15,18 +14,19 @@ class ParamsOverrider { /** - * @var \Magento\Authorization\Model\UserContextInterface + * @var ParamOverriderInterface[] */ - protected $userContext; + private $paramsOverrider; /** * Initialize dependencies * - * @param UserContextInterface $userContext + * @param ParamOverriderInterface[] $paramOverriders */ - public function __construct(UserContextInterface $userContext) - { - $this->userContext = $userContext; + public function __construct( + array $paramsOverrider = [] + ) { + $this->paramsOverrider = $paramsOverrider; } /** @@ -41,10 +41,9 @@ public function override(array $inputData, array $parameters) foreach ($parameters as $name => $paramData) { $arrayKeys = explode('.', $name); if ($paramData[Converter::KEY_FORCE] || !$this->isNestedArrayValueSet($inputData, $arrayKeys)) { - if ($paramData[Converter::KEY_VALUE] == '%customer_id%' - && $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER - ) { - $value = $this->userContext->getUserId(); + $paramValue = $paramData[Converter::KEY_VALUE]; + if (isset($this->paramsOverrider[$paramValue])) { + $value = $this->paramsOverrider[$paramValue]->getOverridenValue(); } else { $value = $paramData[Converter::KEY_VALUE]; } diff --git a/app/code/Magento/Webapi/etc/di.xml b/app/code/Magento/Webapi/etc/di.xml index d9f47dfd67a79..10b12f754710b 100644 --- a/app/code/Magento/Webapi/etc/di.xml +++ b/app/code/Magento/Webapi/etc/di.xml @@ -30,4 +30,11 @@ + + + + Magento\Webapi\Controller\Rest\ParamOverriderCustomerId + + + From 25d468019d74ee6605d2bd35ccc075ac0af29ede Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Wed, 15 Apr 2015 17:04:08 -0500 Subject: [PATCH 044/115] MAGETWO-361898: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Add QuoteWebapi module to add ParamOverriderCartId - Dependency on both Quote module and Webapi module --- app/code/Magento/QuoteWebapi/LICENSE.txt | 48 +++++++++++++++++++ app/code/Magento/QuoteWebapi/LICENSE_AFL.txt | 48 +++++++++++++++++++ .../Model/Webapi/ParamOverriderCartId.php | 47 ++++++++++++++++++ app/code/Magento/QuoteWebapi/README.md | 3 ++ app/code/Magento/QuoteWebapi/composer.json | 24 ++++++++++ app/code/Magento/QuoteWebapi/etc/di.xml | 16 +++++++ composer.json | 1 + 7 files changed, 187 insertions(+) create mode 100644 app/code/Magento/QuoteWebapi/LICENSE.txt create mode 100644 app/code/Magento/QuoteWebapi/LICENSE_AFL.txt create mode 100644 app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php create mode 100644 app/code/Magento/QuoteWebapi/README.md create mode 100644 app/code/Magento/QuoteWebapi/composer.json create mode 100644 app/code/Magento/QuoteWebapi/etc/di.xml diff --git a/app/code/Magento/QuoteWebapi/LICENSE.txt b/app/code/Magento/QuoteWebapi/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/QuoteWebapi/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt b/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt new file mode 100644 index 0000000000000..87943b95d43a5 --- /dev/null +++ b/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php new file mode 100644 index 0000000000000..f2b3aca3970d7 --- /dev/null +++ b/app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php @@ -0,0 +1,47 @@ +userContext = $userContext; + $this->cartManagement = $cartManagement; + } + + public function getOverridenValue() { + if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { + $customerId = $this->userContext->getUserId(); + + /** @var \Magento\Quote\Api\Data\CartInterface */ + $cart = $this->cartManagement->getCartForCustomer($customerId); + if ($cart) { + return $cart->getId(); + } + } + return null; + } +} diff --git a/app/code/Magento/QuoteWebapi/README.md b/app/code/Magento/QuoteWebapi/README.md new file mode 100644 index 0000000000000..d8ff2d852faa2 --- /dev/null +++ b/app/code/Magento/QuoteWebapi/README.md @@ -0,0 +1,3 @@ +# Overview + +Provides the Quote module with some Web API specific functionality. diff --git a/app/code/Magento/QuoteWebapi/composer.json b/app/code/Magento/QuoteWebapi/composer.json new file mode 100644 index 0000000000000..46a2977ace645 --- /dev/null +++ b/app/code/Magento/QuoteWebapi/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-quote-webapi", + "description": "N/A", + "require": { + "php": "~5.5.0|~5.6.0", + "magento/module-quote": "0.74.0-beta4", + "magento/module-webapi": "0.74.0-beta4", + "magento/magento-composer-installer": "*" + }, + "type": "magento2-module", + "version": "0.74.0-beta4", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "extra": { + "map": [ + [ + "*", + "Magento/QuoteWebapi" + ] + ] + } +} diff --git a/app/code/Magento/QuoteWebapi/etc/di.xml b/app/code/Magento/QuoteWebapi/etc/di.xml new file mode 100644 index 0000000000000..d839644cd9ecd --- /dev/null +++ b/app/code/Magento/QuoteWebapi/etc/di.xml @@ -0,0 +1,16 @@ + + + + + + + Magento\QuoteWebapi\Model\Webapi\ParamOverriderCartId + + + + diff --git a/composer.json b/composer.json index c8721c87609c6..4449b63df65b5 100644 --- a/composer.json +++ b/composer.json @@ -116,6 +116,7 @@ "magento/module-persistent": "self.version", "magento/module-product-alert": "self.version", "magento/module-quote": "self.version", + "magento/module-quote-webapi": "self.version", "magento/module-reports": "self.version", "magento/module-require-js": "self.version", "magento/module-review": "self.version", From 6a4ec679f329d802e5db9afd80fc89ad0cac35ae Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Thu, 16 Apr 2015 11:14:16 -0500 Subject: [PATCH 045/115] MAGETWO-361898: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Move ParamOverriderCartId to Quote module - Remove QuoteWebapi module - Move ParamOverriderInterface to framework --- .../Model/Webapi/ParamOverriderCartId.php | 3 +- app/code/Magento/Quote/etc/di.xml | 8 ++++ app/code/Magento/QuoteWebapi/LICENSE.txt | 48 ------------------- app/code/Magento/QuoteWebapi/LICENSE_AFL.txt | 48 ------------------- app/code/Magento/QuoteWebapi/README.md | 3 -- app/code/Magento/QuoteWebapi/composer.json | 24 ---------- app/code/Magento/QuoteWebapi/etc/di.xml | 16 ------- .../Controller/Rest/ParamsOverrider.php | 1 + composer.json | 1 - .../Rest/Request}/ParamOverriderInterface.php | 2 +- 10 files changed, 12 insertions(+), 142 deletions(-) rename app/code/Magento/{QuoteWebapi => Quote}/Model/Webapi/ParamOverriderCartId.php (91%) delete mode 100644 app/code/Magento/QuoteWebapi/LICENSE.txt delete mode 100644 app/code/Magento/QuoteWebapi/LICENSE_AFL.txt delete mode 100644 app/code/Magento/QuoteWebapi/README.md delete mode 100644 app/code/Magento/QuoteWebapi/composer.json delete mode 100644 app/code/Magento/QuoteWebapi/etc/di.xml rename {app/code/Magento/Webapi/Controller/Rest => lib/internal/Magento/Framework/Webapi/Rest/Request}/ParamOverriderInterface.php (96%) diff --git a/app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php similarity index 91% rename from app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php rename to app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php index f2b3aca3970d7..24bb7afd251dd 100644 --- a/app/code/Magento/QuoteWebapi/Model/Webapi/ParamOverriderCartId.php +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -4,9 +4,10 @@ * See COPYING.txt for license details. */ -namespace Magento\QuoteWebapi\Model\Webapi; +namespace Magento\Quote\Model\Webapi; use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; use Magento\Quote\Api\CartManagementInterface; /** diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index a305a4a63284a..1e7d0691c171b 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -35,4 +35,12 @@ + + + + + Magento\QuoteWebapi\Model\Webapi\ParamOverriderCartId + + + diff --git a/app/code/Magento/QuoteWebapi/LICENSE.txt b/app/code/Magento/QuoteWebapi/LICENSE.txt deleted file mode 100644 index 49525fd99da9c..0000000000000 --- a/app/code/Magento/QuoteWebapi/LICENSE.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Open Software License ("OSL") v. 3.0 - -This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Open Software License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt b/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt deleted file mode 100644 index 87943b95d43a5..0000000000000 --- a/app/code/Magento/QuoteWebapi/LICENSE_AFL.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Academic Free License ("AFL") v. 3.0 - -This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Academic Free License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/QuoteWebapi/README.md b/app/code/Magento/QuoteWebapi/README.md deleted file mode 100644 index d8ff2d852faa2..0000000000000 --- a/app/code/Magento/QuoteWebapi/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Overview - -Provides the Quote module with some Web API specific functionality. diff --git a/app/code/Magento/QuoteWebapi/composer.json b/app/code/Magento/QuoteWebapi/composer.json deleted file mode 100644 index 46a2977ace645..0000000000000 --- a/app/code/Magento/QuoteWebapi/composer.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "magento/module-quote-webapi", - "description": "N/A", - "require": { - "php": "~5.5.0|~5.6.0", - "magento/module-quote": "0.74.0-beta4", - "magento/module-webapi": "0.74.0-beta4", - "magento/magento-composer-installer": "*" - }, - "type": "magento2-module", - "version": "0.74.0-beta4", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "extra": { - "map": [ - [ - "*", - "Magento/QuoteWebapi" - ] - ] - } -} diff --git a/app/code/Magento/QuoteWebapi/etc/di.xml b/app/code/Magento/QuoteWebapi/etc/di.xml deleted file mode 100644 index d839644cd9ecd..0000000000000 --- a/app/code/Magento/QuoteWebapi/etc/di.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - Magento\QuoteWebapi\Model\Webapi\ParamOverriderCartId - - - - diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 584d8e1a52ca7..8ed795f7fa603 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -6,6 +6,7 @@ namespace Magento\Webapi\Controller\Rest; +use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; use Magento\Webapi\Model\Config\Converter; /** diff --git a/composer.json b/composer.json index 4449b63df65b5..c8721c87609c6 100644 --- a/composer.json +++ b/composer.json @@ -116,7 +116,6 @@ "magento/module-persistent": "self.version", "magento/module-product-alert": "self.version", "magento/module-quote": "self.version", - "magento/module-quote-webapi": "self.version", "magento/module-reports": "self.version", "magento/module-require-js": "self.version", "magento/module-review": "self.version", diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php similarity index 96% rename from app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php rename to lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php index cad7f5edda3ab..0403973a58ffc 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderInterface.php +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Webapi\Controller\Rest; +namespace Magento\Framework\Webapi\Rest\Request; /** * Override parameter values From ffc46d370e50dbbabbf8c71816c3cb5015caeef1 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Thu, 16 Apr 2015 11:23:59 -0500 Subject: [PATCH 046/115] MAGETWO-361898: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Remove QuoteWebapi di.xml reference - Add use statement for ParamOverriderCustomerId --- app/code/Magento/Quote/etc/di.xml | 2 +- .../Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 1e7d0691c171b..16b5d7f916ba9 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -39,7 +39,7 @@ - Magento\QuoteWebapi\Model\Webapi\ParamOverriderCartId + Magento\Quote\Model\Webapi\ParamOverriderCartId diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php index 5712dd23c087e..3add052abcb4d 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -7,6 +7,7 @@ namespace Magento\Webapi\Controller\Rest; use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; /** * Replaces a "%customer_id%" value with the real customer id From 417d736e6734760d2860214a2a4eab6e5dda326e Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Thu, 16 Apr 2015 12:47:47 -0500 Subject: [PATCH 047/115] MAGETWO-36273: Create /mine API for ShippingAddressManagement - add /mine endpoints to webapi.xml - create corresponding api-functional test --- app/code/Magento/Quote/etc/webapi.xml | 20 +++++++ .../Api/ShippingAddressManagementTest.php | 56 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 708de5e88af33..fa9b4dd66e74c 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -348,6 +348,26 @@ + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php index ff9c032601f88..9f14c678e101e 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php @@ -207,4 +207,60 @@ public function testSetAddressForVirtualQuote() $this->_webApiCall($serviceInfo, $requestData); } + + /** + * Test getting shipping address based on the customer's authentication token. + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetMyAddress() + { + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Quote\Model\Quote\Address $address */ + $address = $quote->getShippingAddress(); + + $addressData = [ + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), + AddressInterface::KEY_ID => (int)$address->getId(), + AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), + AddressInterface::KEY_REGION => $address->getRegion(), + AddressInterface::KEY_REGION_ID => $address->getRegionId(), + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), + AddressInterface::KEY_STREET => $address->getStreet(), + AddressInterface::KEY_COMPANY => $address->getCompany(), + AddressInterface::KEY_TELEPHONE => $address->getTelephone(), + AddressInterface::KEY_POSTCODE => $address->getPostcode(), + AddressInterface::KEY_CITY => $address->getCity(), + AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), + AddressInterface::KEY_LASTNAME => $address->getLastname(), + AddressInterface::KEY_EMAIL => $address->getEmail() + ]; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + 'token' => $token + ], + ]; + + $requestData = ['cartId' => $quote->getId()]; + $this->assertEquals($addressData, $this->_webApiCall($serviceInfo, $requestData)); + } } From 3b0ba3007a4471e4645098be1780597e27072cf9 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Thu, 16 Apr 2015 12:52:53 -0500 Subject: [PATCH 048/115] MAGETWO-36273: Create /mine API for ShippingAddressManagement - create api-functional test for assign method --- .../Api/ShippingAddressManagementTest.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php index 9f14c678e101e..91afb9cd08054 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php @@ -263,4 +263,77 @@ public function testGetMyAddress() $requestData = ['cartId' => $quote->getId()]; $this->assertEquals($addressData, $this->_webApiCall($serviceInfo, $requestData)); } + + /** + * Test setting shipping address based on the customer's authentication token. + * + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMyAddress() + { + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + 'token' => $token + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Assign', + 'token' => $token + ], + ]; + + $addressData = [ + 'firstname' => 'John', + 'lastname' => 'Smith', + 'email' => 'cat@dog.com', + 'company' => 'eBay Inc', + 'street' => ['Typical Street', 'Tiny House 18'], + 'city' => 'Big City', + 'region_id' => 12, + 'region' => 'California', + 'region_code' => 'CA', + 'postcode' => '0985432', + 'country_id' => 'US', + 'telephone' => '88776655', + 'fax' => '44332255', + ]; + $requestData = [ + "cartId" => $quote->getId(), + 'address' => $addressData, + ]; + + $addressId = $this->_webApiCall($serviceInfo, $requestData); + + //reset $quote to reload data + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $address = $quote->getShippingAddress(); + $address->getRegionCode(); + $savedData = $address->getData(); + $this->assertEquals($addressId, $savedData['address_id'], 'Invalid address ID'); + $this->assertEquals(0, $savedData['same_as_billing']); + //custom checks for street, region and address_type + $this->assertEquals($addressData['street'], $quote->getShippingAddress()->getStreet()); + unset($addressData['street']); + + $this->assertEquals('shipping', $savedData['address_type']); + //check the rest of fields + foreach ($addressData as $key => $value) { + $this->assertEquals($value, $savedData[$key], 'Invalid value for ' . $key); + } + } } From 0c20fe80914097473afa1d60073269800cc333d8 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Thu, 16 Apr 2015 13:59:36 -0500 Subject: [PATCH 049/115] MAGETWO-36275: Create /mine API for BillingAddressManagement - add /mine URLs to webapi.xml for billing address get & assign - create corresponding api-functional tests --- app/code/Magento/Quote/etc/webapi.xml | 22 ++- .../Api/BillingAddressManagementTest.php | 126 ++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index fa9b4dd66e74c..80a4ad3928158 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -266,7 +266,7 @@ - + @@ -280,6 +280,26 @@ + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php index f78abc4a896ad..37afd5e0e1064 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php @@ -132,4 +132,130 @@ public function testSetAddress() $this->assertEquals($value, $savedData[$key]); } } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetMyAddress() + { + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Quote\Model\Quote\Address $address */ + $address = $quote->getBillingAddress(); + + $data = [ + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), + AddressInterface::KEY_ID => (int)$address->getId(), + AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), + AddressInterface::KEY_REGION => $address->getRegion(), + AddressInterface::KEY_REGION_ID => $address->getRegionId(), + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), + AddressInterface::KEY_STREET => $address->getStreet(), + AddressInterface::KEY_COMPANY => $address->getCompany(), + AddressInterface::KEY_TELEPHONE => $address->getTelephone(), + AddressInterface::KEY_POSTCODE => $address->getPostcode(), + AddressInterface::KEY_CITY => $address->getCity(), + AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), + AddressInterface::KEY_LASTNAME => $address->getLastname(), + AddressInterface::KEY_EMAIL => $address->getEmail() + ]; + + $cartId = $quote->getId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Get', + 'token' => $token + ], + ]; + + $requestData = ["cartId" => $cartId]; + $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMyAddress() + { + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + 'token' => $token + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Assign', + 'token' => $token + ], + ]; + + $addressData = [ + 'firstname' => 'John', + 'lastname' => 'Smith', + 'email' => 'cat@dog.com', + 'company' => 'eBay Inc', + 'street' => ['Typical Street', 'Tiny House 18'], + 'city' => 'Big City', + 'region_id' => 12, + 'region' => 'California', + 'region_code' => 'CA', + 'postcode' => '0985432', + 'country_id' => 'US', + 'telephone' => '88776655', + 'fax' => '44332255', + ]; + $requestData = [ + "cartId" => $quote->getId(), + 'address' => $addressData, + ]; + + $addressId = $this->_webApiCall($serviceInfo, $requestData); + + //reset $quote to reload data + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $address = $quote->getBillingAddress(); + $address->getRegionCode(); + $savedData = $address->getData(); + $this->assertEquals($addressId, $savedData['address_id']); + //custom checks for street, region and address_type + foreach ($addressData['street'] as $streetLine) { + $this->assertContains($streetLine, $quote->getBillingAddress()->getStreet()); + } + unset($addressData['street']); + $this->assertEquals('billing', $savedData['address_type']); + //check the rest of fields + foreach ($addressData as $key => $value) { + $this->assertEquals($value, $savedData[$key]); + } + } } From a12988ea7575bc37f9b5dc1d23f00076d3709edd Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Thu, 16 Apr 2015 22:15:46 +0300 Subject: [PATCH 050/115] MAGETWO-36272: Create /mine API for PaymentMethodManagement --- app/code/Magento/Quote/etc/webapi.xml | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 80a4ad3928158..cb2da75eea5b6 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -252,6 +252,35 @@ + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + From 2aca647053d612279cf3292ef999d807023c9611 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Thu, 16 Apr 2015 14:55:45 -0500 Subject: [PATCH 051/115] MAGETWO-36276: Create /mine API for CartTotalRepository - added /mine URLs to webapi.xml for getting cart total - created corresponding api-functional tests --- app/code/Magento/Quote/etc/webapi.xml | 14 ++++ .../Quote/Api/CartTotalRepositoryTest.php | 67 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index cb2da75eea5b6..7016d40d1d461 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -424,6 +424,8 @@ + + @@ -431,10 +433,22 @@ + + + + + + + + + + %cart_id% + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php index 257cd01237d94..ed2fa5268aa30 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php @@ -171,4 +171,71 @@ protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote) ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => $item->getBaseRowTotalInclTax(), ]; } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php + */ + public function testGetMyTotals() + { + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + + $serviceInfo = [ + 'soap' => [ + 'service' => 'quoteCartTotalRepositoryV1', + 'serviceVersion' => 'V1', + 'operation' => 'quoteCartTotalRepositoryV1get', + 'token' => $token + ], + 'rest' => [ + 'resourcePath' => '/V1/carts/mine/totals', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ], + ]; + + /** @var \Magento\Quote\Model\Quote\Address $shippingAddress */ + $shippingAddress = $quote->getShippingAddress(); + + $data = [ + Totals::KEY_BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), + Totals::KEY_GRAND_TOTAL => $quote->getGrandTotal(), + Totals::KEY_BASE_SUBTOTAL => $quote->getBaseSubtotal(), + Totals::KEY_SUBTOTAL => $quote->getSubtotal(), + Totals::KEY_BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), + Totals::KEY_SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), + Totals::KEY_DISCOUNT_AMOUNT => $shippingAddress->getDiscountAmount(), + Totals::KEY_BASE_DISCOUNT_AMOUNT => $shippingAddress->getBaseDiscountAmount(), + Totals::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), + Totals::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), + Totals::KEY_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getShippingDiscountAmount(), + Totals::KEY_BASE_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getBaseShippingDiscountAmount(), + Totals::KEY_TAX_AMOUNT => $shippingAddress->getTaxAmount(), + Totals::KEY_BASE_TAX_AMOUNT => $shippingAddress->getBaseTaxAmount(), + Totals::KEY_SHIPPING_TAX_AMOUNT => $shippingAddress->getShippingTaxAmount(), + Totals::KEY_BASE_SHIPPING_TAX_AMOUNT => $shippingAddress->getBaseShippingTaxAmount(), + Totals::KEY_SUBTOTAL_INCL_TAX => $shippingAddress->getSubtotalInclTax(), + Totals::KEY_BASE_SUBTOTAL_INCL_TAX => $shippingAddress->getBaseSubtotalTotalInclTax(), + Totals::KEY_SHIPPING_INCL_TAX => $shippingAddress->getShippingInclTax(), + Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), + Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), + Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), + Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], + ]; + + $requestData = ['cartId' => $cartId]; + + $data = $this->formatTotalsData($data); + + $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + } } From 23061108733aa9ab3ca370d13baa4f9983beca80 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Thu, 16 Apr 2015 18:09:59 -0500 Subject: [PATCH 052/115] MAGETWO-36269: Create /mine APIs for CartManagement - Added/updated /mine URLs to webapi.xml for cart management - Added new method createEmptyCartForCustomer for CartManagementInterface to take responsibility of creating empty cart for logged in customer - Added/updated api-functional tests --- .../Quote/Api/CartManagementInterface.php | 14 +++- .../Model/GuestCart/GuestCartManagement.php | 4 +- .../Magento/Quote/Model/QuoteManagement.php | 22 ++++- .../Test/Unit/Model/QuoteManagementTest.php | 8 +- app/code/Magento/Quote/etc/webapi.xml | 10 ++- .../Magento/Quote/Api/CartManagementTest.php | 83 +++++++++++++++++-- 6 files changed, 118 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Quote/Api/CartManagementInterface.php b/app/code/Magento/Quote/Api/CartManagementInterface.php index 5dff50e9b3a56..fdc0d18085cf0 100644 --- a/app/code/Magento/Quote/Api/CartManagementInterface.php +++ b/app/code/Magento/Quote/Api/CartManagementInterface.php @@ -8,13 +8,21 @@ interface CartManagementInterface { /** - * Enables an customer or guest user to create an empty cart and quote for an anonymous customer. + * Creates an empty cart and quote for a guest. * - * @param int|null $customerId The customer ID. * @return int Cart ID. * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. */ - public function createEmptyCart($customerId = null); + public function createEmptyCart(); + + /** + * Creates an empty cart and quote for a specified customer. + * + * @param int $customerId The customer ID. + * @return int Cart ID. + * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. + */ + public function createEmptyCartForCustomer($customerId); /** * Returns information for the cart for a specified customer. diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 2e655a2bf39d1..a64521c8d6c87 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -98,11 +98,11 @@ public function __construct( /** * {@inheritdoc} */ - public function createEmptyCart($customerId = null) + public function createEmptyCart() { /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create(); - $cartId = parent::createEmptyCart($customerId); + $cartId = parent::createEmptyCart(); $quoteIdMask->setId($cartId)->save(); return $quoteIdMask->getMaskedId(); } diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 4cfc07b3a318e..c09a32964aa3f 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -156,12 +156,26 @@ public function __construct( /** * {@inheritdoc} */ - public function createEmptyCart($customerId = null) + public function createEmptyCart() { $storeId = $this->storeManager->getStore()->getStoreId(); - $quote = $customerId - ? $this->createCustomerCart($customerId, $storeId) - : $this->createAnonymousCart($storeId); + $quote = $this->createAnonymousCart($storeId); + + try { + $this->quoteRepository->save($quote); + } catch (\Exception $e) { + throw new CouldNotSaveException(__('Cannot create quote')); + } + return $quote->getId(); + } + + /** + * {@inheritdoc} + */ + public function createEmptyCartForCustomer($customerId) + { + $storeId = $this->storeManager->getStore()->getStoreId(); + $quote = $this->createCustomerCart($customerId, $storeId); try { $this->quoteRepository->save($quote); diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php index d58adf62d675c..12c4248d82c81 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php @@ -198,7 +198,7 @@ public function testCreateEmptyCartAnonymous() $this->assertEquals($quoteId, $this->model->createEmptyCart()); } - public function testCreateEmptyCartLoggedInUser() + public function testCreateEmptyCartForCustomer() { $storeId = 345; $quoteId = 2311; @@ -222,13 +222,13 @@ public function testCreateEmptyCartLoggedInUser() $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf(); $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId); - $this->assertEquals($quoteId, $this->model->createEmptyCart($userId)); + $this->assertEquals($quoteId, $this->model->createEmptyCartForCustomer($userId)); } /** * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ - public function testCreateEmptyCartLoggedInUserException() + public function testCreateEmptyCartForCustomerException() { $storeId = 345; $userId = 567; @@ -246,7 +246,7 @@ public function testCreateEmptyCartLoggedInUserException() $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf(); $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId); - $this->model->createEmptyCart($userId); + $this->model->createEmptyCartForCustomer($userId); } /** diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 7016d40d1d461..714843ca8e9fd 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -24,7 +24,13 @@ - + + + + + + + @@ -36,7 +42,7 @@ - + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index 970e4998f011c..536bf90112161 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -27,7 +27,17 @@ protected function setUp() $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } - public function testCreate() + public function tearDown() + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + foreach ($this->createdQuotes as $quoteId) { + $quote->load($quoteId); + $quote->delete(); + } + } + + public function testCreateEmptyCartForGuest() { $serviceInfo = [ 'rest' => [ @@ -47,14 +57,71 @@ public function testCreate() $this->createdQuotes[] = $quoteId; } - public function tearDown() + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testCreateEmptyCartForCustomer() { - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); - foreach ($this->createdQuotes as $quoteId) { - $quote->load($quoteId); - $quote->delete(); - } + /** @var $repository \Magento\Customer\Api\CustomerRepositoryInterface */ + $repository = $this->objectManager->create('Magento\Customer\Api\CustomerRepositoryInterface'); + /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */ + $customer = $repository->getById(1); + $customerId = $customer->getId(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/customers/' . $customerId . '/carts', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'CreateEmptyCartForCustomer', + ], + ]; + + $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]); + $this->assertGreaterThan(0, $quoteId); + $this->createdQuotes[] = $quoteId; + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + */ + public function testCreateEmptyCartAndGetCartForCustomer() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + 'token' => $token + ] + ]; + + $quoteId = $this->_webApiCall($serviceInfo, ['customerId' => 999]); // customerId 999 will get overridden + $this->assertGreaterThan(0, $quoteId); + $this->createdQuotes[] = $quoteId; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ] + ]; + + /** @var \Magento\Quote\Api\Data\CartInterface $cart */ + $cart = $this->_webApiCall($serviceInfo, ['customerId' => 999]); // customerId 999 will get overridden + $this->assertEquals($quoteId, $cart['id']); } /** From 1637a227752cb21db8e39eac22cfbd1cf63e6850 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 14:19:32 +0300 Subject: [PATCH 053/115] MAGETWO-36272: Create /mine API for PaymentMethodManagement - added Api-functional tests --- .../Quote/Api/PaymentMethodManagementTest.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php index 8288f1f9b5d87..fae12ec93147f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php @@ -284,4 +284,123 @@ public function testGet() $this->assertEquals('checkmo', $requestResponse['method']); } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetListMine() + { + $this->_markTestAsRestOnly(); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $this->getCustomerToken() + ] + ]; + + $requestResponse = $this->_webApiCall($serviceInfo); + + $expectedResponse = [ + 'code' => 'checkmo', + 'title' => 'Check / Money order', + ]; + + $this->assertGreaterThan(0, count($requestResponse)); + $this->assertContains($expectedResponse, $requestResponse); + } + + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php + */ + public function testGetMine() + { + $this->_markTestAsRestOnly(); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1_with_payment', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $this->getCustomerToken() + ] + ]; + + $requestResponse = $this->_webApiCall($serviceInfo); + + $this->assertArrayHasKey('method', $requestResponse); + $this->assertArrayHasKey('po_number', $requestResponse); + $this->assertArrayHasKey('cc_owner', $requestResponse); + $this->assertArrayHasKey('cc_type', $requestResponse); + $this->assertArrayHasKey('cc_exp_year', $requestResponse); + $this->assertArrayHasKey('cc_exp_month', $requestResponse); + $this->assertArrayHasKey('additional_data', $requestResponse); + + $this->assertNotNull($requestResponse['method']); + $this->assertNotNull($requestResponse['po_number']); + $this->assertNotNull($requestResponse['cc_owner']); + $this->assertNotNull($requestResponse['cc_type']); + $this->assertNotNull($requestResponse['cc_exp_year']); + $this->assertNotNull($requestResponse['cc_exp_month']); + $this->assertNotNull($requestResponse['additional_data']); + + $this->assertEquals('checkmo', $requestResponse['method']); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetPaymentWithSimpleProductMine() + { + $this->_markTestAsRestOnly(); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'token' => $this->getCustomerToken() + ] + ]; + + $requestData = [ + "method" => [ + 'method' => 'checkmo', + 'po_number' => '200', + 'cc_owner' => 'tester', + 'cc_type' => 'test', + 'cc_exp_year' => '2014', + 'cc_exp_month' => '1', + ], + ]; + + $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * Get customer ID token + * + * @return string + */ + protected function getCustomerToken() + { + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + return $token; + } } From 7fad6e575419d50edce7fbbf8ca4b48fd6cd2c68 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 16:47:53 +0300 Subject: [PATCH 054/115] MAGETWO-36377: Magento\Quote\Api\GuestCartRepositoryInterface - added unit tests - fixed GuestCartRepository (removed method getActive) --- .../Model/GuestCart/GuestCartRepository.php | 10 - .../GuestCart/GuestCartRepositoryTest.php | 179 ++++++++++++++++++ 2 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index e0619d15fc211..1768b727aeb30 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -54,16 +54,6 @@ public function get($cartId, array $sharedStoreIds = []) return parent::get($quoteIdMask->getId(), $sharedStoreIds); } - /** - * {@inheritdoc} - */ - public function getActive($cartId, array $sharedStoreIds = []) - { - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::getActive($quoteIdMask->getId(), $sharedStoreIds); - } - /** * {@inheritdoc} */ diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php new file mode 100644 index 0000000000000..7e3ca674fb58d --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -0,0 +1,179 @@ +quoteFactoryMock = $this->getMock('Magento\Quote\Model\QuoteFactory', ['create'], [], '', false); + $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface'); + $this->quoteMock = $this->getMock( + 'Magento\Quote\Model\Quote', + ['load', 'getId', 'save', 'delete', 'getCustomerId'], + [], + '', + false + ); + $this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); + $this->searchResultsDataFactory = $this->getMock( + 'Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory', + ['create'], + [], + '', + false + ); + + $this->quoteCollectionMock = $this->getMock('Magento\Quote\Model\Resource\Quote\Collection', [], [], '', false); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->model = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestCartRepository', + [ + 'quoteFactory' => $this->quoteFactoryMock, + 'storeManager' => $this->storeManagerMock, + 'searchResultsDataFactory' => $this->searchResultsDataFactory, + 'quoteCollection' => $this->quoteCollectionMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGet() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 15; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); + $this->storeMock->expects($this->once())->method('getId')->willReturn($this->storeMock); + $this->quoteMock->expects($this->never())->method('setSharedStoreIds'); + $this->quoteMock->expects($this->once()) + ->method('load') + ->with($cartId) + ->willReturn($this->storeMock); + $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); + + $this->assertEquals($this->quoteMock, $this->model->get($maskedCartId)); + } + + public function testSaveEdited() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 1; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($cartId); + + + $this->quoteMock->expects($this->once()) + ->method('save'); + $this->quoteMock->expects($this->exactly(3))->method('getId')->willReturn($maskedCartId); + $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); + + $this->model->save($this->quoteMock); + } + + public function testSaveNew() + { + $cartId = 1; + + $this->quoteIdMaskFactoryMock->expects($this->never())->method('create'); + $this->quoteMock->expects($this->at(0))->method('getId')->willReturn(false); + + $this->quoteMock->expects($this->once()) + ->method('save'); + $this->quoteMock->expects($this->at(1))->method('getId')->willReturn($cartId); + $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); + + $this->model->save($this->quoteMock); + } + + public function testDelete() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 1; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($cartId); + + $this->quoteMock->expects($this->once()) + ->method('delete'); + $this->quoteMock->expects($this->exactly(3))->method('getId')->willReturn($maskedCartId); + $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); + + $this->model->delete($this->quoteMock); + } +} From 08bbc9af08521f1f27dff00500a97913debd3bbc Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 17:17:13 +0300 Subject: [PATCH 055/115] MAGETWO-36380: Magento\Quote\Api\GuestPaymentMethodManagement - added unit tests --- .../GuestPaymentMethodManagementTest.php | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php new file mode 100644 index 0000000000000..f1aff58ed6265 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -0,0 +1,199 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->methodListMock = $this->getMock('Magento\Payment\Model\MethodList', [], [], '', false); + $this->zeroTotalMock = $this->getMock('Magento\Payment\Model\Checks\ZeroTotal', [], [], '', false); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->model = $this->objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement', + [ + 'quoteRepository' => $this->quoteRepositoryMock, + 'methodList' => $this->methodListMock, + 'zeroTotalValidator' => $this->zeroTotalMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGetPaymentSuccess() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 11; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $paymentMock = $this->getMock('Magento\Quote\Model\Quote\Payment', [], [], '', false); + $paymentMock->expects($this->once())->method('getId')->will($this->returnValue(1)); + + $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); + $quoteMock->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock)); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + $this->assertEquals($paymentMock, $this->model->get($maskedCartId)); + } + + public function testGetList() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 10; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + + $paymentMethod = $this->getMock('Magento\Quote\Api\Data\PaymentMethodInterface'); + $this->methodListMock->expects($this->once()) + ->method('getAvailableMethods') + ->with($quoteMock) + ->will($this->returnValue([$paymentMethod])); + $this->assertEquals([$paymentMethod], $this->model->getList($maskedCartId)); + } + + public function testSetSimpleProduct() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 100; + $paymentId = 20; + $methodData = ['method' => 'data']; + $paymentMethod = 'checkmo'; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock( + '\Magento\Quote\Model\Quote', + ['getPayment', 'isVirtual', 'getShippingAddress', 'setTotalsCollectedFlag', 'collectTotals', 'save'], + [], + '', + false + ); + $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($quoteMock); + + $methodMock = $this->getMock('Magento\Quote\Model\Quote\Payment', ['setChecks', 'getData'], [], '', false); + $methodMock->expects($this->once()) + ->method('setChecks') + ->with([ + \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, + \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, + \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, + \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, + ]) + ->willReturnSelf(); + $methodMock->expects($this->once())->method('getData')->willReturn($methodData); + + $paymentMock = $this->getMock( + 'Magento\Quote\Model\Quote\Payment', + ['importData', 'getMethod', 'getMethodInstance', 'getId'], + [], + '', + false + ); + $paymentMock->expects($this->once())->method('importData')->with($methodData)->willReturnSelf(); + $paymentMock->expects($this->once())->method('getMethod')->willReturn($paymentMethod); + + $shippingAddressMock = $this->getMock( + 'Magento\Quote\Model\Quote\Address', + ['getCountryId', 'setPaymentMethod'], + [], + '', + false + ); + $shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(100); + $shippingAddressMock->expects($this->once()) + ->method('setPaymentMethod') + ->with($paymentMethod) + ->willReturnSelf(); + + $quoteMock->expects($this->exactly(2))->method('getPayment')->willReturn($paymentMock); + $quoteMock->expects($this->exactly(2))->method('isVirtual')->willReturn(false); + $quoteMock->expects($this->exactly(4))->method('getShippingAddress')->willReturn($shippingAddressMock); + + $methodInstance = $this->getMock('\Magento\Payment\Model\Checks\PaymentMethodChecksInterface'); + $paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInstance); + + $this->zeroTotalMock->expects($this->once()) + ->method('isApplicable') + ->with($methodInstance, $quoteMock) + ->willReturn(true); + + $quoteMock->expects($this->once())->method('setTotalsCollectedFlag')->with(false)->willReturnSelf(); + $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); + $quoteMock->expects($this->once())->method('save')->willReturnSelf(); + + $paymentMock->expects($this->once())->method('getId')->willReturn($paymentId); + $this->assertEquals($paymentId, $this->model->set($maskedCartId, $methodMock)); + } +} From 0f1f9f34e615ba44e2c221b6190d3c07309e9593 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 17 Apr 2015 09:23:08 -0500 Subject: [PATCH 056/115] MAGETWO-36273: Create /mine API for ShippingAddressManagement - update test to mark as REST only and remove cartId from request data --- .../Api/ShippingAddressManagementTest.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php index 91afb9cd08054..9a8db29b15a7a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingAddressManagementTest.php @@ -215,6 +215,8 @@ public function testSetAddressForVirtualQuote() */ public function testGetMyAddress() { + $this->_markTestAsRestOnly(); + // get customer ID token /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( @@ -252,15 +254,9 @@ public function testGetMyAddress() 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $token ], - 'soap' => [ - 'service' => self::SERVICE_NAME, - 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Get', - 'token' => $token - ], ]; - $requestData = ['cartId' => $quote->getId()]; + $requestData = []; $this->assertEquals($addressData, $this->_webApiCall($serviceInfo, $requestData)); } @@ -271,6 +267,8 @@ public function testGetMyAddress() */ public function testSetMyAddress() { + $this->_markTestAsRestOnly(); + // get customer ID token /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( @@ -288,12 +286,6 @@ public function testSetMyAddress() 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, 'token' => $token ], - 'soap' => [ - 'service' => self::SERVICE_NAME, - 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Assign', - 'token' => $token - ], ]; $addressData = [ @@ -312,7 +304,6 @@ public function testSetMyAddress() 'fax' => '44332255', ]; $requestData = [ - "cartId" => $quote->getId(), 'address' => $addressData, ]; From 3ea93723d84ddd40e732213c9acbe898763f202d Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 17:23:45 +0300 Subject: [PATCH 057/115] MAGETWO-36380: Magento\Quote\Api\GuestPaymentMethodManagement - fixed param --- .../Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php index f1aff58ed6265..8836a93a5e569 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -8,7 +8,7 @@ class GuestPaymentMethodManagementTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Quote\Model\PaymentMethodManagement + * @var \Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement */ protected $model; From 4345dd44ac6538c121a0694e70a708f50b6ac1de Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 17:25:19 +0300 Subject: [PATCH 058/115] MAGETWO-36377: Magento\Quote\Api\GuestCartRepositoryInterface - fixed param --- .../Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php index 7e3ca674fb58d..406c1e9e46308 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -7,12 +7,10 @@ namespace Magento\Quote\Test\Unit\Model\GuestCart; -use \Magento\Quote\Model\QuoteRepository; - class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase { /** - * @var QuoteRepository + * @var \Magento\Quote\Model\GuestCart\GuestCartRepository */ protected $model; From 6eca190d4d2fb84e815f464089f49236706faf93 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 17:48:03 +0300 Subject: [PATCH 059/115] MAGETWO-36426: Magento\Quote\Api\GuestCartTotalRepository - added unit tests --- .../GuestCartTotalRepositoryTest.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php new file mode 100644 index 0000000000000..539cd524afc0c --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php @@ -0,0 +1,116 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->totalsFactoryMock = $this->getMock( + 'Magento\Quote\Api\Data\TotalsInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); + $this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper') + ->disableOriginalConstructor() + ->getMock(); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->model = $this->objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestCartTotalRepository', + [ + 'totalsFactory' => $this->totalsFactoryMock, + 'quoteRepository' => $this->quoteRepositoryMock, + 'dataObjectHelper' => $this->dataObjectHelperMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGetTotals() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 12; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId) + ->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock); + $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']); + $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']); + + $item = $this->getMock('Magento\Quote\Model\Quote\Item', [], [], '', false); + $this->quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$item])); + + $totals = $this->getMock('Magento\Quote\Model\Cart\Totals', ['setItems'], [], '', false); + $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totals); + $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); + $totals->expects($this->once())->method('setItems'); + + $this->model->get($maskedCartId); + } +} From d9426d061e19ac9025f20f1b03e707212558d2d6 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 17 Apr 2015 17:49:10 +0300 Subject: [PATCH 060/115] MAGETWO-36380: Magento\Quote\Api\GuestPaymentMethodManagement - code style fix --- .../Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php index 8836a93a5e569..975777704ef85 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -16,6 +16,7 @@ class GuestPaymentMethodManagementTest extends \PHPUnit_Framework_TestCase * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ protected $objectManager; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ From 4a3a30aaf3c15fddfbc24b61140bb35fba4b806c Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 17 Apr 2015 09:55:07 -0500 Subject: [PATCH 061/115] MAGETWO-36275: Create /mine API for BillingAddressManagement - update test to mark as REST only and remove cartId from request data --- .../Api/BillingAddressManagementTest.php | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php index 37afd5e0e1064..6069e754863aa 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php @@ -138,6 +138,8 @@ public function testSetAddress() */ public function testGetMyAddress() { + $this->_markTestAsRestOnly(); + // get customer ID token /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( @@ -176,16 +178,9 @@ public function testGetMyAddress() 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $token ], - 'soap' => [ - 'service' => self::SERVICE_NAME, - 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Get', - 'token' => $token - ], ]; - $requestData = ["cartId" => $cartId]; - $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + $this->assertEquals($data, $this->_webApiCall($serviceInfo)); } /** @@ -193,6 +188,8 @@ public function testGetMyAddress() */ public function testSetMyAddress() { + $this->_markTestAsRestOnly(); + // get customer ID token /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( @@ -210,12 +207,6 @@ public function testSetMyAddress() 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, 'token' => $token ], - 'soap' => [ - 'service' => self::SERVICE_NAME, - 'serviceVersion' => self::SERVICE_VERSION, - 'operation' => self::SERVICE_NAME . 'Assign', - 'token' => $token - ], ]; $addressData = [ @@ -234,7 +225,6 @@ public function testSetMyAddress() 'fax' => '44332255', ]; $requestData = [ - "cartId" => $quote->getId(), 'address' => $addressData, ]; From 57247e2b526215bbae71d777af3c673927871b4c Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 17 Apr 2015 10:17:32 -0500 Subject: [PATCH 062/115] MAGETWO-36275: Create /mine API for BillingAddressManagement - removed unused local variable --- .../Magento/Quote/Api/BillingAddressManagementTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php index 6069e754863aa..d7dfd3e938c7e 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php @@ -170,8 +170,6 @@ public function testGetMyAddress() AddressInterface::KEY_EMAIL => $address->getEmail() ]; - $cartId = $quote->getId(); - $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', From 1442d3345aba2bcc80768de62c32faf2579453b5 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 17 Apr 2015 10:35:52 -0500 Subject: [PATCH 063/115] MAGETWO-36276: Create /mine API for CartTotalRepository - update test to mark as REST only and remove cartId from request data --- .../Magento/Quote/Api/CartTotalRepositoryTest.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php index ed2fa5268aa30..c2777f4e716e0 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php @@ -177,6 +177,8 @@ protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote) */ public function testGetMyTotals() { + $this->_markTestAsRestOnly(); + // get customer ID token /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( @@ -190,12 +192,6 @@ public function testGetMyTotals() $cartId = $quote->getId(); $serviceInfo = [ - 'soap' => [ - 'service' => 'quoteCartTotalRepositoryV1', - 'serviceVersion' => 'V1', - 'operation' => 'quoteCartTotalRepositoryV1get', - 'token' => $token - ], 'rest' => [ 'resourcePath' => '/V1/carts/mine/totals', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, @@ -232,10 +228,8 @@ public function testGetMyTotals() Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)], ]; - $requestData = ['cartId' => $cartId]; - $data = $this->formatTotalsData($data); - $this->assertEquals($data, $this->_webApiCall($serviceInfo, $requestData)); + $this->assertEquals($data, $this->_webApiCall($serviceInfo)); } } From 67cbd1f2a1f67a2db845a441826882e8bcf45930 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Fri, 17 Apr 2015 19:58:48 +0300 Subject: [PATCH 064/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart --- .../Wishlist/Controller/Index/Cart.php | 27 ++++++++++++++++--- .../view/frontend/templates/view.phtml | 8 ------ .../Wishlist/view/frontend/web/wishlist.js | 3 +-- .../Fixture/GroupedProduct/Associated.php | 6 ++--- ...CartFromCustomerWishlistOnFrontendTest.php | 16 ++++++++--- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Index/Cart.php b/app/code/Magento/Wishlist/Controller/Index/Cart.php index ed155aa60585b..de5e3e2dc0f96 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Index/Cart.php @@ -36,6 +36,16 @@ class Cart extends Action\Action implements IndexInterface */ protected $cart; + /** + * @var \Magento\Checkout\Helper\Cart + */ + protected $cartHelper; + + /** + * @var \Magento\Framework\Json\Helper\Data + */ + protected $jsonHelper; + /** * @var \Magento\Wishlist\Model\Item\OptionFactory */ @@ -76,7 +86,9 @@ public function __construct( \Magento\Wishlist\Model\Item\OptionFactory $optionFactory, \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, - \Magento\Wishlist\Helper\Data $helper + \Magento\Wishlist\Helper\Data $helper, + \Magento\Checkout\Helper\Cart $cartHelper, + \Magento\Framework\Json\Helper\Data $jsonHelper ) { $this->wishlistProvider = $wishlistProvider; $this->quantityProcessor = $quantityProcessor; @@ -86,6 +98,8 @@ public function __construct( $this->productHelper = $productHelper; $this->escaper = $escaper; $this->helper = $helper; + $this->cartHelper = $cartHelper; + $this->jsonHelper = $jsonHelper; parent::__construct($context); } @@ -159,8 +173,8 @@ public function execute() $this->messageManager->addSuccess($message); } - if ($this->cart->getShouldRedirectToCart()) { - $redirectUrl = $this->cart->getCartUrl(); + if ($this->cartHelper->getShouldRedirectToCart()) { + $redirectUrl = $this->cartHelper->getCartUrl(); } else { $refererUrl = $this->_redirect->getRefererUrl(); if ($refererUrl && $refererUrl != $configureUrl) { @@ -178,6 +192,13 @@ public function execute() $this->helper->calculate(); + if ($this->getRequest()->isAjax()) { + $this->getResponse()->representJson( + $this->jsonHelper->jsonEncode(['backUrl' => $redirectUrl]) + ); + return; + } + return $this->getResponse()->setRedirect($redirectUrl); } } diff --git a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml index 035364489f3ca..624a320f30a7e 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml @@ -13,14 +13,6 @@ getChildHtml('wishlist.rss.link'));?>
= 0) ? '&' : '?'; url += separator + inputName + '=' + encodeURIComponent(inputValue); this._validateAndRedirect(url); } - }, /** diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php index 00e3a4896a7fd..427bc6c11cd4e 100644 --- a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php @@ -198,19 +198,19 @@ protected function getPreset($name) 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 17, + 'qty' => 3, ], [ 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 36, + 'qty' => 1, ], [ 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 20, + 'qty' => 2, ], ], 'products' => [ diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php index 64ec7938f66cd..1f866500e574a 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php @@ -33,6 +33,19 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli const DOMAIN = 'CS'; /* end tags */ + /** + * Prepare data for test + * + * @param Customer $customer + * @return array + */ + public function __prepare(Customer $customer) + { + $customer->persist(); + + return ['customer' => $customer]; + } + /** * Run suggest searching result test. * @@ -43,9 +56,6 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli */ public function test(Customer $customer, $products, $qty) { - $this->markTestIncomplete('Bug: MAGETWO-34757'); - // Preconditions - $customer->persist(); $this->loginCustomer($customer); $products = $this->createProducts($products); $this->addToWishlist($products); From 7b7504d5130bd91172a7aa1e602a1a1fae0bd96d Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Fri, 17 Apr 2015 20:17:03 +0300 Subject: [PATCH 065/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart --- .../Test/Unit/Controller/Index/CartTest.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php index fd7c06e7336d0..e965b07ba632e 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php @@ -96,6 +96,16 @@ class CartTest extends \PHPUnit_Framework_TestCase */ protected $urlMock; + /** + * @var \Magento\Checkout\Helper\Cart|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cartHelperMock; + + /** + * @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + */ + protected $jsonHelperMock; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -139,7 +149,7 @@ protected function setUp() $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') ->disableOriginalConstructor() - ->setMethods(['getParams', 'getParam']) + ->setMethods(['getParams', 'getParam', 'isAjax']) ->getMockForAbstractClass(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') @@ -187,6 +197,14 @@ protected function setUp() ->method('getUrl') ->will($this->returnValue($this->urlMock)); + $this->cartHelperMock = $this->getMockBuilder('Magento\Checkout\Helper\Cart') + ->disableOriginalConstructor() + ->getMock(); + + $this->jsonHelperMock = $this->getMockBuilder('Magento\Framework\Json\Helper\Data') + ->disableOriginalConstructor() + ->getMock(); + $this->model = new Cart( $this->contextMock, $this->wishlistProviderMock, @@ -196,7 +214,9 @@ protected function setUp() $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, - $this->helperMock + $this->helperMock, + $this->cartHelperMock, + $this->jsonHelperMock ); } @@ -397,6 +417,9 @@ public function testExecuteWithQuantityArray() $this->requestMock->expects($this->once()) ->method('getParams') ->willReturn($params); + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn(false); $buyRequestMock = $this->getMockBuilder('Magento\Framework\Object') ->disableOriginalConstructor() @@ -467,7 +490,7 @@ public function testExecuteWithQuantityArray() ->with('You added ' . $productName . ' to your shopping cart.', null) ->willReturnSelf(); - $this->checkoutCartMock->expects($this->once()) + $this->cartHelperMock->expects($this->once()) ->method('getShouldRedirectToCart') ->willReturn(false); From f4b5d22c83fb6a033df9849ec3f506b0dbf82427 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Fri, 17 Apr 2015 21:36:03 +0300 Subject: [PATCH 066/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart --- .../Wishlist/Controller/Index/Cart.php | 4 +++ .../Test/Unit/Controller/Index/CartTest.php | 35 ++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Index/Cart.php b/app/code/Magento/Wishlist/Controller/Index/Cart.php index de5e3e2dc0f96..61a80f8ca58ee 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Index/Cart.php @@ -76,6 +76,10 @@ class Cart extends Action\Action implements IndexInterface * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper * @param \Magento\Wishlist\Helper\Data $helper + * @param \Magento\Checkout\Helper\Cart $cartHelper + * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Action\Context $context, diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php index e965b07ba632e..fcfec1f1071a8 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php @@ -154,7 +154,7 @@ protected function setUp() $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') ->disableOriginalConstructor() - ->setMethods(['setRedirect']) + ->setMethods(['setRedirect', 'representJson']) ->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface') @@ -295,9 +295,13 @@ public function testExecuteWithNoWishlist() } /** + * @param bool $isAjax + * + * @dataProvider dataProviderExecuteWithQuantityArray + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testExecuteWithQuantityArray() + public function testExecuteWithQuantityArray($isAjax) { $itemId = 2; $wishlistId = 1; @@ -419,7 +423,7 @@ public function testExecuteWithQuantityArray() ->willReturn($params); $this->requestMock->expects($this->once()) ->method('isAjax') - ->willReturn(false); + ->willReturn($isAjax); $buyRequestMock = $this->getMockBuilder('Magento\Framework\Object') ->disableOriginalConstructor() @@ -502,12 +506,33 @@ public function testExecuteWithQuantityArray() ->method('calculate') ->willReturnSelf(); - $this->responseMock->expects($this->once()) + $this->jsonHelperMock->expects($this->any()) + ->method('jsonEncode') + ->with(['backUrl' => $refererUrl]) + ->willReturn('{"backUrl":"' . $refererUrl . '"}'); + + $this->responseMock->expects($this->any()) ->method('setRedirect') ->with($refererUrl) ->willReturn($this->responseMock); + $this->responseMock->expects($this->any()) + ->method('representJson') + ->with('{"backUrl":"' . $refererUrl . '"}') + ->willReturnSelf(); - $this->assertEquals($this->responseMock, $this->model->execute()); + $expectedResult = ($isAjax ? null : $this->responseMock); + $this->assertEquals($expectedResult, $this->model->execute()); + } + + /** + * @return array + */ + public function dataProviderExecuteWithQuantityArray() + { + return [ + ['isAjax' => false], + ['isAjax' => true], + ]; } /** From 7d359bae94522964c698268b1a59b6d4fcfae7db Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 17 Apr 2015 14:50:04 -0500 Subject: [PATCH 067/115] MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository - created unit tests --- .../GuestCart/GuestCartItemRepositoryTest.php | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php new file mode 100644 index 0000000000000..69f86e7754d36 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php @@ -0,0 +1,240 @@ +quoteRepositoryMock = + $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->productRepositoryMock = + $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface', [], [], '', false); + $this->itemDataFactoryMock = + $this->getMock('Magento\Quote\Api\Data\CartItemInterfaceFactory', ['create'], [], '', false); + $this->dataMock = $this->getMock('Magento\Quote\Api\Data\CartItemInterface'); + $this->quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); + $this->productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $this->quoteItemMock = + $this->getMock('Magento\Quote\Model\Quote\Item', ['getId', 'getSku', 'setData', '__wakeUp'], [], '', false); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->repository = new GuestCartItemRepository( + $this->quoteRepositoryMock, + $this->productRepositoryMock, + $this->itemDataFactoryMock, + $this->quoteIdMaskFactoryMock + ); + } + + /** + * @return void + */ + public function testSave() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 13; + $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('getId') + ->willReturn($cartId); + + $this->dataMock->expects($this->at(0))->method('getQuoteId')->willReturn($maskedCartId); + $this->dataMock->expects($this->once())->method('setQuoteId')->with($cartId); + $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); + $this->dataMock->expects($this->at(3))->method('getQuoteId')->willReturn($cartId); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->productRepositoryMock->expects($this->once()) + ->method('get') + ->will($this->returnValue($this->productMock)); + $this->dataMock->expects($this->once())->method('getSku'); + $this->quoteMock->expects($this->once())->method('addProduct')->with($this->productMock, 12); + $this->quoteMock->expects($this->never())->method('getItemById'); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quoteMock + ->expects($this->once()) + ->method('getItemByProduct') + ->with($this->productMock) + ->will($this->returnValue($this->quoteItemMock)); + $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); + $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + } + + /** + * @return void + */ + public function testUpdateItem() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 13; + $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('getId') + ->willReturn($cartId); + + $itemId = 5; + $productSku = 'product_sku'; + $this->dataMock->expects($this->at(0))->method('getQuoteId')->willReturn($maskedCartId); + $this->dataMock->expects($this->once())->method('setQuoteId')->with($cartId); + $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); + $this->dataMock->expects($this->at(3))->method('getQuoteId')->willReturn($cartId); + $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once()) + ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + $this->quoteItemMock->expects($this->once())->method('setData')->with('qty', 12); + $this->quoteItemMock->expects($this->once())->method('getSku')->willReturn($productSku); + $this->productRepositoryMock + ->expects($this->once()) + ->method('get') + ->with($productSku) + ->willReturn($this->productMock); + $this->quoteItemMock->expects($this->never())->method('addProduct'); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quoteMock + ->expects($this->once()) + ->method('getItemByProduct') + ->with($this->productMock) + ->willReturn($this->quoteItemMock); + $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + } + + /** + * @return void + */ + public function testGetList() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 33; + $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once())->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + $itemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false); + $quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); + + $this->assertEquals([$itemMock], $this->repository->getList($maskedCartId)); + } + + /** + * @return void + */ + public function testDeleteById() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 33; + $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->any()) + ->method('getId') + ->willReturn($cartId); + + $itemId = 5; + $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('setQuoteId') + ->with($cartId)->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('setItemId') + ->with($itemId)->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); + $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once()) + ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + $this->quoteMock->expects($this->once())->method('removeItem'); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + + $this->assertTrue($this->repository->deleteById($maskedCartId, $itemId)); + } +} From c6d8407ddd857efdd51b768bed1f7e931ad11c27 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Fri, 17 Apr 2015 15:09:32 -0500 Subject: [PATCH 068/115] MAGETWO-36274: Create /mine API for ShippingMethodManagement - Added /mine URLs to webapi.xml for shipping method management - Added api-functional test cases to cover newly added endpoints --- app/code/Magento/Quote/etc/webapi.xml | 29 ++++ .../Api/ShippingMethodManagementTest.php | 130 ++++++++++++++++++ 2 files changed, 159 insertions(+) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 714843ca8e9fd..1fde612d9974c 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -108,6 +108,35 @@ + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php index 6217cc99b088f..3eea4fd590c1c 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php @@ -117,6 +117,50 @@ public function testSetMethodWithoutShippingAddress() $this->assertEquals('Shipping address is not set', $message); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMethodForMyCart() + { + $this->_markTestAsRestOnly(); + + $this->quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine/selected-shipping-method', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'token' => $token + ] + ]; + + $requestData = [ + 'cartId' => 999, + 'carrierCode' => 'flatrate', + 'methodCode' => 'flatrate', + ]; // cartId 999 will be overridden + + $result = $this->_webApiCall($serviceInfo, $requestData); + $this->assertEquals(true, $result); + + /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */ + $ShippingMethodManagementService = $this->objectManager->create( + 'Magento\Quote\Api\ShippingMethodManagementInterface' + ); + $shippingMethod = $ShippingMethodManagementService->get($this->quote->getId()); + + $this->assertNotNull($shippingMethod); + $this->assertEquals('flatrate', $shippingMethod->getCarrierCode()); + $this->assertEquals('flatrate', $shippingMethod->getMethodCode()); + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php */ @@ -169,6 +213,41 @@ public function testGetMethodOfCartWithNoShippingMethod() $this->assertEquals([], $result); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetMethodForMyCart() + { + $this->_markTestAsRestOnly(); + + $this->quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ + $shippingMethodManagementService = $this->objectManager->create( + 'Magento\Quote\Api\ShippingMethodManagementInterface' + ); + $shippingMethodManagementService->set($this->quote->getId(), 'flatrate', 'flatrate'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine/selected-shipping-method', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ] + ]; + + $result = $this->_webApiCall($serviceInfo, []); + $this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_CARRIER_CODE]); + $this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_METHOD_CODE]); + } + /** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php * @@ -204,6 +283,57 @@ public function testGetList() $this->assertEquals($expectedData, $returnedRates); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetListForMyCart() + { + $this->_markTestAsRestOnly(); + + $this->quote->load('test_order_1', 'reserved_order_id'); + + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ + $shippingMethodManagementService = $this->objectManager->create( + 'Magento\Quote\Api\ShippingMethodManagementInterface' + ); + $shippingMethodManagementService->set($this->quote->getId(), 'flatrate', 'flatrate'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine/shipping-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ] + ]; + + $result = $this->_webApiCall($serviceInfo, []); + $this->assertNotEmpty($result); + + /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */ + $ShippingMethodManagementService = $this->objectManager->create( + 'Magento\Quote\Api\ShippingMethodManagementInterface' + ); + $shippingMethod = $ShippingMethodManagementService->get($this->quote->getId()); + $expectedData = [ + ShippingMethodInterface::KEY_CARRIER_CODE => $shippingMethod->getCarrierCode(), + ShippingMethodInterface::KEY_METHOD_CODE => $shippingMethod->getMethodCode(), + ShippingMethodInterface::KEY_CARRIER_TITLE => $shippingMethod->getCarrierTitle(), + ShippingMethodInterface::KEY_METHOD_TITLE => $shippingMethod->getMethodTitle(), + ShippingMethodInterface::KEY_SHIPPING_AMOUNT => $shippingMethod->getAmount(), + ShippingMethodInterface::KEY_BASE_SHIPPING_AMOUNT => $shippingMethod->getBaseAmount(), + ShippingMethodInterface::KEY_AVAILABLE => $shippingMethod->getAvailable(), + ]; + + $this->assertEquals($expectedData, $result[0]); + } + /** * @param string $cartId * @return array From 7f65d587a0e5a22134ddb5129ee5616f9b935fc1 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Fri, 17 Apr 2015 16:54:51 -0500 Subject: [PATCH 069/115] MAGETWO-36269: Create /mine APIs for CartManagement - Added /mine endpoint for placeOrder - Added api-functional test case to cover this endpoint --- app/code/Magento/Quote/etc/webapi.xml | 9 +++++ .../Magento/Quote/Api/CartManagementTest.php | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 1fde612d9974c..40d78a43533d8 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -59,6 +59,15 @@ %customer_id% + + + + + + + %cart_id% + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index 536bf90112161..3393c28e0a579 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -369,6 +369,41 @@ public function testPlaceOrder() $quote->delete(); } + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_check_payment.php + */ + public function testPlaceOrderForMyCart() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var $quote \Magento\Quote\Model\Quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test_order_1', 'reserved_order_id'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/carts/mine/order', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'token' => $token + ], + ]; + + $orderId = $this->_webApiCall($serviceInfo, []); + + /** @var \Magento\Sales\Model\Order $order */ + $order = $this->objectManager->create('Magento\Sales\Model\Order')->load($orderId); + $items = $order->getAllItems(); + $this->assertCount(1, $items); + $this->assertEquals('Simple Product', $items[0]->getName()); + $quote->delete(); + } + /** * Test to get my cart based on customer authentication token or session * From fe686ca0a32188eafdb957583a5f11f6de2ca7ba Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Mon, 20 Apr 2015 14:27:42 +0300 Subject: [PATCH 070/115] MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement - added unit tests --- .../GuestShippingAddressManagementTest.php | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php new file mode 100644 index 0000000000000..3665a0472e1bf --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php @@ -0,0 +1,127 @@ +quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->quoteAddressMock = $this->getMock( '\Magento\Quote\Model\Quote\Address', [], [], '', false); + $this->validatorMock = $this->getMock( 'Magento\Quote\Model\QuoteAddressValidator', [], [], '', false); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $this->model = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestShippingAddressManagement', + [ + 'quoteRepository' => $this->quoteRepositoryMock, + 'addressValidator' => $this->validatorMock, + 'logger' => $this->getMock('\Psr\Log\LoggerInterface'), + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testAssignAddress() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 867; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + + + $this->validatorMock->expects($this->once())->method('validate') + ->with($this->quoteAddressMock) + ->will($this->returnValue(true)); + + $quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock); + $quoteMock->expects($this->once())->method('setDataChanges')->with(true); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); + + $addressId = 1; + $shippingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); + $shippingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); + $quoteMock->expects($this->once())->method('getShippingAddress') + ->will($this->returnValue($shippingAddressMock)); + + $this->assertEquals($addressId, $this->model->assign($maskedCartId, $this->quoteAddressMock)); + } + + public function testGetAddress() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 867; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will( + $this->returnValue($quoteMock) + ); + + $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); + $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($addressMock)); + $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(false)); + $this->assertEquals($addressMock, $this->model->get($maskedCartId)); + } +} From 9e70be75498f0cb55b9a5a84de6f0c232aa7b9db Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Mon, 20 Apr 2015 14:29:22 +0300 Subject: [PATCH 071/115] MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement - removed excessive line --- .../Unit/Model/GuestCart/GuestShippingAddressManagementTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php index 3665a0472e1bf..8ce3ae28fcd00 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php @@ -5,8 +5,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Quote\Test\Unit\Model\GuestCart; class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase From 1f7b5d83ee948cc4c750552c0269a13b65b2ee9d Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Mon, 20 Apr 2015 15:20:11 +0300 Subject: [PATCH 072/115] MAGETWO-36379: Magento\Quote\Api\GuestCouponManagement - added unit tests --- .../GuestCart/GuestCouponManagementTest.php | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php new file mode 100644 index 0000000000000..9fe52d31876d4 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php @@ -0,0 +1,165 @@ +quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->quoteMock = $this->getMock( + 'Magento\Quote\Model\Quote', + [ + 'getItemsCount', + 'setCouponCode', + 'collectTotals', + 'save', + 'getShippingAddress', + 'getCouponCode' + ], + [], + '', + false + ); + $this->quoteAddressMock = $this->getMock( + 'Magento\Quote\Model\Quote\Address', + [ + 'setCollectShippingRates' + ], + [], + '', + false); + + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->model = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestCouponManagement', + [ + 'quoteRepository' => $this->quoteRepositoryMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGetCoupon() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 11; + $couponCode = 'test_coupon_code'; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $quoteMock = $this->getMock('Magento\Quote\Model\Quote', ['getCouponCode', '__wakeup'], [], '', false); + $quoteMock->expects($this->any())->method('getCouponCode')->will($this->returnValue($couponCode)); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + + $this->assertEquals($couponCode, $this->model->get($maskedCartId)); + } + + public function testSet() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 33; + $couponCode = '153a-ABC'; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12)); + $this->quoteMock->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock)); + $this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true); + $this->quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue($couponCode)); + + $this->assertTrue($this->model->set($maskedCartId, $couponCode)); + } + + public function testDelete() + { + $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $cartId = 65; + + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($cartId); + + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12)); + $this->quoteMock->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock)); + $this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true); + $this->quoteMock->expects($this->once())->method('setCouponCode')->with(''); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue('')); + + $this->assertTrue($this->model->remove($maskedCartId)); + } +} From d831265645d7f0aace4c2ee8ac013aeee20d5373 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Mon, 20 Apr 2015 16:28:22 +0300 Subject: [PATCH 073/115] MAGETWO-36272: Create /mine API for PaymentMethodManagement - code style fix/ removed exessive whitespaces - renamed api url to more appropriate - refactored code to use foreach --- app/code/Magento/Quote/etc/webapi.xml | 12 ++-- .../Api/GuestPaymentMethodManagementTest.php | 39 +++++------ .../Quote/Api/PaymentMethodManagementTest.php | 67 +++++++------------ 3 files changed, 50 insertions(+), 68 deletions(-) diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 40d78a43533d8..aee67ad80a34f 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -257,13 +257,13 @@ - + - + @@ -277,13 +277,13 @@ - + - + @@ -297,7 +297,7 @@ - + @@ -306,7 +306,7 @@ %cart_id% - + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php index a1eba522ea594..40579922f1896 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php @@ -66,7 +66,7 @@ public function testReSetPayment() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -103,7 +103,7 @@ public function testSetPaymentWithVirtualProduct() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -139,7 +139,7 @@ public function testSetPaymentWithSimpleProduct() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -178,7 +178,7 @@ public function testSetPaymentWithVirtualProductWithoutAddress() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -216,7 +216,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -286,7 +286,7 @@ public function testGet() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -299,25 +299,22 @@ public function testGet() $requestData = ["cartId" => $cartId]; $requestResponse = $this->_webApiCall($serviceInfo, $requestData); - $this->assertArrayHasKey('method', $requestResponse); - $this->assertArrayHasKey('po_number', $requestResponse); - $this->assertArrayHasKey('cc_owner', $requestResponse); - $this->assertArrayHasKey('cc_type', $requestResponse); - $this->assertArrayHasKey('cc_exp_year', $requestResponse); - $this->assertArrayHasKey('cc_exp_month', $requestResponse); - $this->assertArrayHasKey('additional_data', $requestResponse); - - $this->assertNotNull($requestResponse['method']); - $this->assertNotNull($requestResponse['po_number']); - $this->assertNotNull($requestResponse['cc_owner']); - $this->assertNotNull($requestResponse['cc_type']); - $this->assertNotNull($requestResponse['cc_exp_year']); - $this->assertNotNull($requestResponse['cc_exp_month']); - $this->assertNotNull($requestResponse['additional_data']); + foreach ($this->getPaymentMethodFieldsForAssert() as $field) { + $this->assertArrayHasKey($field, $requestResponse); + $this->assertNotNull($requestResponse[$field]); + } $this->assertEquals('checkmo', $requestResponse['method']); } + /** + * @return array + */ + protected function getPaymentMethodFieldsForAssert() + { + return ['method', 'po_number', 'cc_owner', 'cc_type', 'cc_exp_year', 'cc_exp_month', 'additional_data']; + } + /** * Retrieve masked cart ID for guest cart. * diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php index fae12ec93147f..b4aa67ab9fa7d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/PaymentMethodManagementTest.php @@ -33,7 +33,7 @@ public function testReSetPayment() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -70,7 +70,7 @@ public function testSetPaymentWithVirtualProduct() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -106,7 +106,7 @@ public function testSetPaymentWithSimpleProduct() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -145,7 +145,7 @@ public function testSetPaymentWithVirtualProductWithoutAddress() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -183,7 +183,7 @@ public function testSetPaymentWithSimpleProductWithoutAddress() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -253,7 +253,7 @@ public function testGet() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -266,21 +266,10 @@ public function testGet() $requestData = ["cartId" => $cartId]; $requestResponse = $this->_webApiCall($serviceInfo, $requestData); - $this->assertArrayHasKey('method', $requestResponse); - $this->assertArrayHasKey('po_number', $requestResponse); - $this->assertArrayHasKey('cc_owner', $requestResponse); - $this->assertArrayHasKey('cc_type', $requestResponse); - $this->assertArrayHasKey('cc_exp_year', $requestResponse); - $this->assertArrayHasKey('cc_exp_month', $requestResponse); - $this->assertArrayHasKey('additional_data', $requestResponse); - - $this->assertNotNull($requestResponse['method']); - $this->assertNotNull($requestResponse['po_number']); - $this->assertNotNull($requestResponse['cc_owner']); - $this->assertNotNull($requestResponse['cc_type']); - $this->assertNotNull($requestResponse['cc_exp_year']); - $this->assertNotNull($requestResponse['cc_exp_month']); - $this->assertNotNull($requestResponse['additional_data']); + foreach ($this->getPaymentMethodFieldsForAssert() as $field) { + $this->assertArrayHasKey($field, $requestResponse); + $this->assertNotNull($requestResponse[$field]); + } $this->assertEquals('checkmo', $requestResponse['method']); } @@ -292,7 +281,7 @@ public function testGetListMine() { $this->_markTestAsRestOnly(); - /** @var \Magento\Quote\Model\Quote $quote */ + /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); @@ -329,7 +318,7 @@ public function testGetMine() $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $this->getCustomerToken() ] @@ -337,22 +326,10 @@ public function testGetMine() $requestResponse = $this->_webApiCall($serviceInfo); - $this->assertArrayHasKey('method', $requestResponse); - $this->assertArrayHasKey('po_number', $requestResponse); - $this->assertArrayHasKey('cc_owner', $requestResponse); - $this->assertArrayHasKey('cc_type', $requestResponse); - $this->assertArrayHasKey('cc_exp_year', $requestResponse); - $this->assertArrayHasKey('cc_exp_month', $requestResponse); - $this->assertArrayHasKey('additional_data', $requestResponse); - - $this->assertNotNull($requestResponse['method']); - $this->assertNotNull($requestResponse['po_number']); - $this->assertNotNull($requestResponse['cc_owner']); - $this->assertNotNull($requestResponse['cc_type']); - $this->assertNotNull($requestResponse['cc_exp_year']); - $this->assertNotNull($requestResponse['cc_exp_month']); - $this->assertNotNull($requestResponse['additional_data']); - + foreach ($this->getPaymentMethodFieldsForAssert() as $field) { + $this->assertArrayHasKey($field, $requestResponse); + $this->assertNotNull($requestResponse[$field]); + } $this->assertEquals('checkmo', $requestResponse['method']); } @@ -363,13 +340,13 @@ public function testSetPaymentWithSimpleProductMine() { $this->_markTestAsRestOnly(); - /** @var \Magento\Quote\Model\Quote $quote */ + /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('\Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-methods', + 'resourcePath' => self::RESOURCE_PATH . 'mine/selected-payment-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, 'token' => $this->getCustomerToken() ] @@ -389,6 +366,14 @@ public function testSetPaymentWithSimpleProductMine() $this->assertNotNull($this->_webApiCall($serviceInfo, $requestData)); } + /** + * @return array + */ + protected function getPaymentMethodFieldsForAssert() + { + return ['method', 'po_number', 'cc_owner', 'cc_type', 'cc_exp_year', 'cc_exp_month', 'additional_data']; + } + /** * Get customer ID token * From c47778113811b974b53eeb77eaf37af4efbe09ca Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Mon, 20 Apr 2015 08:41:34 -0500 Subject: [PATCH 074/115] MAGETWO-36275: Create /mine API for BillingAddressManagement - removed excessive whitespace --- .../Magento/Quote/Api/BillingAddressManagementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php index d7dfd3e938c7e..8d6c238db91f5 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/BillingAddressManagementTest.php @@ -233,7 +233,7 @@ public function testSetMyAddress() $quote->load('test_order_1', 'reserved_order_id'); $address = $quote->getBillingAddress(); $address->getRegionCode(); - $savedData = $address->getData(); + $savedData = $address->getData(); $this->assertEquals($addressId, $savedData['address_id']); //custom checks for street, region and address_type foreach ($addressData['street'] as $streetLine) { From a40b6e977dd0810cc9701d86d7c5e285a67bd47d Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Mon, 20 Apr 2015 17:29:39 +0300 Subject: [PATCH 075/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart --- .../AddProductsToCartFromCustomerWishlistOnFrontendTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php index 8d6ee4f4df8e1..3b904100aa510 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php @@ -54,7 +54,6 @@ public function __prepare(Customer $customer) */ public function test(Customer $customer, $products, $qty) { - $this->markTestIncomplete('Bug: MAGETWO-34757'); // Preconditions $customer->persist(); $this->loginCustomer($customer); From 9fde4432130805ffeb8857d8abba1a9e60b8a311 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 09:45:31 -0500 Subject: [PATCH 076/115] MAGETWO-36189: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Fix for code review comments --- .../Quote/Model/Webapi/ParamOverriderCartId.php | 3 ++- app/code/Magento/Quote/etc/di.xml | 2 +- .../Controller/Rest/ParamOverriderCustomerId.php | 6 ++++-- .../Magento/Webapi/Controller/Rest/ParamsOverrider.php | 10 +++++----- app/code/Magento/Webapi/etc/di.xml | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php index 24bb7afd251dd..7fc6fad77df1c 100644 --- a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -33,7 +33,8 @@ public function __construct( $this->cartManagement = $cartManagement; } - public function getOverridenValue() { + public function getOverridenValue() + { if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { $customerId = $this->userContext->getUserId(); diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 16b5d7f916ba9..4eeb1ff2b61a7 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -38,7 +38,7 @@ - + Magento\Quote\Model\Webapi\ParamOverriderCartId diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php index 3add052abcb4d..15bd8bee64c18 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -19,11 +19,13 @@ class ParamOverriderCustomerId implements ParamOverriderInterface */ private $userContext; - public function __construct(UserContextInterface $userContext) { + public function __construct(UserContextInterface $userContext) + { $this->userContext = $userContext; } - public function getOverridenValue() { + public function getOverridenValue() + { if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { return $this->userContext->getUserId(); } diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 8ed795f7fa603..862235a1cd873 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -17,7 +17,7 @@ class ParamsOverrider /** * @var ParamOverriderInterface[] */ - private $paramsOverrider; + private $paramOverriders; /** * Initialize dependencies @@ -25,9 +25,9 @@ class ParamsOverrider * @param ParamOverriderInterface[] $paramOverriders */ public function __construct( - array $paramsOverrider = [] + array $paramOverriders = [] ) { - $this->paramsOverrider = $paramsOverrider; + $this->paramOverriders = $paramOverriders; } /** @@ -43,8 +43,8 @@ public function override(array $inputData, array $parameters) $arrayKeys = explode('.', $name); if ($paramData[Converter::KEY_FORCE] || !$this->isNestedArrayValueSet($inputData, $arrayKeys)) { $paramValue = $paramData[Converter::KEY_VALUE]; - if (isset($this->paramsOverrider[$paramValue])) { - $value = $this->paramsOverrider[$paramValue]->getOverridenValue(); + if (isset($this->paramOverrider[$paramValue])) { + $value = $this->paramOverrider[$paramValue]->getOverridenValue(); } else { $value = $paramData[Converter::KEY_VALUE]; } diff --git a/app/code/Magento/Webapi/etc/di.xml b/app/code/Magento/Webapi/etc/di.xml index 10b12f754710b..12b661f639c42 100644 --- a/app/code/Magento/Webapi/etc/di.xml +++ b/app/code/Magento/Webapi/etc/di.xml @@ -32,7 +32,7 @@ - + Magento\Webapi\Controller\Rest\ParamOverriderCustomerId From f3cd41a481afba56b9f0b3fdadcaf776dcfd92c8 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 10:37:09 -0500 Subject: [PATCH 077/115] MAGETWO-36189: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Fix for code review --- app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 862235a1cd873..5a998602fc9c5 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -43,8 +43,8 @@ public function override(array $inputData, array $parameters) $arrayKeys = explode('.', $name); if ($paramData[Converter::KEY_FORCE] || !$this->isNestedArrayValueSet($inputData, $arrayKeys)) { $paramValue = $paramData[Converter::KEY_VALUE]; - if (isset($this->paramOverrider[$paramValue])) { - $value = $this->paramOverrider[$paramValue]->getOverridenValue(); + if (isset($this->paramOverriders[$paramValue])) { + $value = $this->paramOverriders[$paramValue]->getOverridenValue(); } else { $value = $paramData[Converter::KEY_VALUE]; } From f1678582288fdbe4ef5b71f06c8b7caec5acdd75 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Mon, 20 Apr 2015 11:04:39 -0500 Subject: [PATCH 078/115] MAGETWO-36274: Create /mine API for ShippingMethodManagement - CR changes --- .../Quote/Api/ShippingMethodManagementTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php index 3eea4fd590c1c..60865f081c99f 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/ShippingMethodManagementTest.php @@ -150,11 +150,11 @@ public function testSetMethodForMyCart() $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertEquals(true, $result); - /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */ - $ShippingMethodManagementService = $this->objectManager->create( + /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ + $shippingMethodManagementService = $this->objectManager->create( 'Magento\Quote\Api\ShippingMethodManagementInterface' ); - $shippingMethod = $ShippingMethodManagementService->get($this->quote->getId()); + $shippingMethod = $shippingMethodManagementService->get($this->quote->getId()); $this->assertNotNull($shippingMethod); $this->assertEquals('flatrate', $shippingMethod->getCarrierCode()); @@ -315,12 +315,9 @@ public function testGetListForMyCart() $result = $this->_webApiCall($serviceInfo, []); $this->assertNotEmpty($result); + $this->assertCount(1, $result); - /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $ShippingMethodManagementService */ - $ShippingMethodManagementService = $this->objectManager->create( - 'Magento\Quote\Api\ShippingMethodManagementInterface' - ); - $shippingMethod = $ShippingMethodManagementService->get($this->quote->getId()); + $shippingMethod = $shippingMethodManagementService->get($this->quote->getId()); $expectedData = [ ShippingMethodInterface::KEY_CARRIER_CODE => $shippingMethod->getCarrierCode(), ShippingMethodInterface::KEY_METHOD_CODE => $shippingMethod->getMethodCode(), From 9e4d9e6218621dd7c1d4f5454944707a69f1a9c9 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 11:28:43 -0500 Subject: [PATCH 079/115] MAGETWO-36271: Create /mine API for CouponManagement - Add mine URLs for CouponManagement --- app/code/Magento/Quote/etc/webapi.xml | 29 ++++ .../Quote/Api/CouponManagementTest.php | 150 ++++++++++++++++++ .../discount_10percent_generalusers.php | 28 ++++ ...scount_10percent_generalusers_rollback.php | 12 ++ .../_files/discount_10percent_rollback.php | 12 ++ 5 files changed, 231 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_rollback.php diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index aee67ad80a34f..9540a2d3b88aa 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -413,6 +413,35 @@ + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + + + + + + + %cart_id% + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php index f6f2a4655c0bc..b2370e3661d8e 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php @@ -148,4 +148,154 @@ public function testSetCouponSuccess() $this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode); } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php + */ + public function testGetMyCoupon() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + $couponCode = $quote->getCouponCode(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/coupons' , + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token, + ], + ]; + + $requestData = []; + $this->assertEquals($couponCode, $this->_webApiCall($serviceInfo, $requestData)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php + */ + public function testDeleteMyCoupon() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/coupons', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE, + 'token' => $token, + ], + ]; + $requestData = []; + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + $quote->load('test_order_1', 'reserved_order_id'); + $this->assertEquals('', $quote->getCouponCode()); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + * @expectedException \Exception + * @expectedExceptionMessage Coupon code is not valid + */ + public function testSetMyCouponThrowsExceptionIfCouponDoesNotExist() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_1', 'reserved_order_id'); + $cartId = $quote->getId(); + + $couponCode = 'invalid_coupon_code'; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/coupons/' . $couponCode, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'token' => $token, + ], + ]; + + $requestData = [ + "couponCode" => $couponCode, + ]; + + $this->_webApiCall($serviceInfo, $requestData); + } + + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Sales/_files/quote.php + * @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.php + */ + public function testSetMyCouponSuccess() + { + $this->_markTestAsRestOnly(); + + // get customer ID token + /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */ + $customerTokenService = $this->objectManager->create( + 'Magento\Integration\Service\V1\CustomerTokenServiceInterface' + ); + $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test01', 'reserved_order_id'); + $cartId = $quote->getId(); + $salesRule = $this->objectManager->create('Magento\SalesRule\Model\Rule'); + $salesRule->load('Test Coupon for General', 'name'); + $couponCode = $salesRule->getCouponCode(); + + /* Since this isn't a full quote fixture, need to assign it to the right customer */ + $cartManagementService = $this->objectManager->create( + 'Magento\Quote\Api\CartManagementInterface' + ); + $cartManagementService->assignCustomer($cartId, 1, 1); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/coupons/' . $couponCode, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + 'token' => $token, + ], + ]; + + $requestData = [ + "couponCode" => $couponCode, + ]; + + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + + $quoteWithCoupon = $this->objectManager->create('Magento\Quote\Model\Quote'); + $quoteWithCoupon->load('test01', 'reserved_order_id'); + + $this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode); + } } diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers.php new file mode 100644 index 0000000000000..c66670aa8719a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers.php @@ -0,0 +1,28 @@ +create('Magento\SalesRule\Model\Rule'); + +$data = [ + 'name' => 'Test Coupon for General', + 'is_active' => true, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getStore()->getWebsiteId() + ], + 'customer_group_ids' => [1], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC, + 'coupon_code' => uniqid(), + 'simple_action' => \Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION, + 'discount_amount' => 10, + 'discount_step' => 1 +]; + +$salesRule->loadPost($data)->setUseAutoGeneration(false)->save(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers_rollback.php new file mode 100644 index 0000000000000..a6f462f767443 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers_rollback.php @@ -0,0 +1,12 @@ +create('Magento\SalesRule\Model\Rule'); +$salesRule->load('Test Coupon for General', 'name'); +$salesRule->delete(); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_rollback.php new file mode 100644 index 0000000000000..53c90ee1778f1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_rollback.php @@ -0,0 +1,12 @@ +create('Magento\SalesRule\Model\Rule'); +$salesRule->load('Test Coupon', 'name'); +$salesRule->delete(); From 790182cbfe37840519921b3e4f63c31dd10e78f0 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 14:09:26 -0500 Subject: [PATCH 080/115] MAGETWO-36427: Magento\Quote\Api\GuestShippingMethodManagement - Use composition instead of inheritance for GuestShippingMethodManagement - Add unit tests for GuestShippingMethodManagement --- .../GuestShippingMethodManagement.php | 33 +++-- .../GuestShippingMethodManagementTest.php | 113 ++++++++++++++++++ 2 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php index bd4e8672b764c..e847e1bd36051 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php @@ -4,44 +4,39 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestShippingMethodManagementInterface; -use Magento\Quote\Model\Cart\ShippingMethodConverter; +use Magento\Quote\Api\ShippingMethodManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Quote\Model\QuoteRepository; -use Magento\Quote\Model\ShippingMethodManagement; /** * Shipping method management class for guest carts. */ -class GuestShippingMethodManagement extends ShippingMethodManagement implements GuestShippingMethodManagementInterface +class GuestShippingMethodManagement implements GuestShippingMethodManagementInterface { + /** + * @var ShippingMethodManagementInterface + */ + private $shippingMethodManagement; + /** * @var QuoteIdMaskFactory */ - protected $quoteIdMaskFactory; + private $quoteIdMaskFactory; /** * Constructs a shipping method read service object. * - * @param QuoteRepository $quoteRepository Quote repository. - * @param \Magento\Quote\Api\Data\ShippingMethodInterfaceFactory $methodDataFactory Shipping method factory. - * @param ShippingMethodConverter $converter Shipping method converter. + * @param ShippingMethodManagementInterface $shippingMethodManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - QuoteRepository $quoteRepository, - \Magento\Quote\Api\Data\ShippingMethodInterfaceFactory $methodDataFactory, - ShippingMethodConverter $converter, + ShippingMethodManagementInterface $shippingMethodManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { - $this->quoteRepository = $quoteRepository; - $this->methodDataFactory = $methodDataFactory; - $this->converter = $converter; + $this->shippingMethodManagement = $shippingMethodManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; } @@ -52,7 +47,7 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId()); + return $this->shippingMethodManagement->get($quoteIdMask->getId()); } /** @@ -62,7 +57,7 @@ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::getList($quoteIdMask->getId()); + return $this->shippingMethodManagement->getList($quoteIdMask->getId()); } /** @@ -72,6 +67,6 @@ public function set($cartId, $carrierCode, $methodCode) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::set($quoteIdMask->getId(), $carrierCode, $methodCode); + return $this->shippingMethodManagement->set($quoteIdMask->getId(), $carrierCode, $methodCode); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php new file mode 100644 index 0000000000000..07a83b5e281e6 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php @@ -0,0 +1,113 @@ +shippingMethodManagementMock = + $this->getMockBuilder('Magento\Quote\Api\ShippingMethodManagementInterface') + ->getMockForAbstractClass(); + $this->quoteIdMaskFactoryMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMaskFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->quoteIdMaskMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMask') + ->disableOriginalConstructor() + ->getMock(); + $this->model = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestShippingMethodManagement', + [ + 'shippingMethodManagement' => $this->shippingMethodManagementMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + ] + ); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 867; + + $this->quoteIdMaskFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('load') + ->with($this->maskedCartId, 'masked_id') + ->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskMock->expects($this->once()) + ->method('getId') + ->willReturn($this->cartId); + } + + public function testSet() + { + $carrierCode = 'carrierCode'; + $methodCode = 'methodCode'; + + $retValue = 'retValue'; + $this->shippingMethodManagementMock->expects($this->once()) + ->method('set') + ->with($this->cartId, $carrierCode, $methodCode) + ->will($this->returnValue($retValue)); + + $this->assertEquals($retValue, $this->model->set($this->maskedCartId, $carrierCode, $methodCode)); + } + + public function testGetList() + { + $retValue = 'retValue'; + $this->shippingMethodManagementMock->expects($this->once()) + ->method('getList') + ->with($this->cartId) + ->will($this->returnValue($retValue)); + + $this->assertEquals($retValue, $this->model->getList($this->maskedCartId)); + } + + public function testGet() + { + $retValue = 'retValue'; + $this->shippingMethodManagementMock->expects($this->once()) + ->method('get') + ->with($this->cartId) + ->will($this->returnValue($retValue)); + + $this->assertEquals($retValue, $this->model->get($this->maskedCartId)); + } +} From b1631e63fdc695b3a15f6cfb9cd7335227fc5be6 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 14:23:15 -0500 Subject: [PATCH 081/115] MAGETWO-36430: Magento\Quote\Model\Resource\Quote\QuoteIdMask - @codeCoverageIgnore QuoteIdMask --- app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php index a3c02553b16d2..8fa2507073a2e 100644 --- a/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php +++ b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php @@ -9,6 +9,7 @@ /** * QuoteIdMask Resource model + * @codeCoverageIgnore */ class QuoteIdMask extends AbstractDb { From 860a9f0e748c23016e5b870c511e8b65451716d9 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Mon, 20 Apr 2015 14:25:46 -0500 Subject: [PATCH 082/115] MAGETWO-36428: Magento\Quote\Model\Quote\Item\Repository - added "ForCustomer" test cases --- .../Unit/Model/Quote/Item/RepositoryTest.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php index b90d93933827c..754c1bd1e467d 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php @@ -160,6 +160,38 @@ public function testSave() $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); } + /** + * @return void + */ + public function testSaveForCustomer() + { + $customerId = 1; + $cartId = 13; + $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer') + ->with($customerId) + ->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); + $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); + $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->productRepositoryMock->expects($this->once()) + ->method('get') + ->will($this->returnValue($this->productMock)); + $this->dataMock->expects($this->once())->method('getSku'); + $this->quoteMock->expects($this->once())->method('addProduct')->with($this->productMock, 12); + $this->quoteMock->expects($this->never())->method('getItemById'); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quoteMock + ->expects($this->once()) + ->method('getItemByProduct') + ->with($this->productMock) + ->will($this->returnValue($this->quoteItemMock)); + $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); + $this->assertEquals($this->quoteItemMock, $this->repository->saveForCustomer($customerId, $this->dataMock)); + } + /** * @return void * @expectedException \Magento\Framework\Exception\NoSuchEntityException @@ -319,6 +351,36 @@ public function testDelete() $this->repository->delete($this->dataMock); } + /** + * @return void + */ + public function testDeleteByIdForCustomer() + { + $customerId = 1; + $cartId = 11; + $itemId = 5; + $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer') + ->with($customerId) + ->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); + $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('setQuoteId') + ->with($cartId)->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('setItemId') + ->with($itemId)->willReturn($this->dataMock); + $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); + $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); + $this->quoteMock->expects($this->once()) + ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); + $this->quoteMock->expects($this->once())->method('removeItem'); + $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + + $this->assertTrue($this->repository->deleteByIdForCustomer($customerId, $itemId)); + } + /** * @return void */ @@ -334,6 +396,27 @@ public function testGetList() $this->assertEquals([$itemMock], $this->repository->getList(33)); } + /** + * @return void + */ + public function testGetListForCustomer() + { + $cartId = 1; + $customerId = 33; + $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer') + ->with($customerId) + ->will($this->returnValue($quoteMock)); + $quoteMock->expects($this->once())->method('getId')->willReturn($cartId); + $this->quoteRepositoryMock->expects($this->once())->method('getActive') + ->with($cartId) + ->will($this->returnValue($quoteMock)); + $itemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false); + $quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); + + $this->assertEquals([$itemMock], $this->repository->getListForCustomer($customerId)); + } + /** * @return void */ From f446b5f1fdfc4f7dbf5e14e78377574e42abd06f Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 14:27:51 -0500 Subject: [PATCH 083/115] MAGETWO-36271: Create /mine API for CouponManagement - Remove unused code in api-functional tests --- .../testsuite/Magento/Quote/Api/CouponManagementTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php index b2370e3661d8e..e6c8a97b918c4 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CouponManagementTest.php @@ -166,7 +166,6 @@ public function testGetMyCoupon() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $quote->getId(); $couponCode = $quote->getCouponCode(); $serviceInfo = [ 'rest' => [ @@ -197,7 +196,6 @@ public function testDeleteMyCoupon() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $quote->getId(); $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . 'mine/coupons', @@ -227,11 +225,6 @@ public function testSetMyCouponThrowsExceptionIfCouponDoesNotExist() ); $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); - $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $quote->getId(); - $couponCode = 'invalid_coupon_code'; $serviceInfo = [ From 6c795cf284df52c4b7f6118a1e1642749bbd262f Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 14:55:13 -0500 Subject: [PATCH 084/115] MAGETWO-36189: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Add unit tests for ParamOverriders - Fix behavior for ParamOverriderCartId if NoSuchEntityException is thrown --- .../Model/Webapi/ParamOverriderCartId.php | 17 ++- .../Model/Webapi/ParamOverriderCartIdTest.php | 122 ++++++++++++++++++ .../Rest/ParamOverriderCustomerIdTest.php | 59 +++++++++ .../Controller/Rest/ParamsOverriderTest.php | 9 +- 4 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php create mode 100644 app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php diff --git a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php index 7fc6fad77df1c..7034e078d99f6 100644 --- a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -8,6 +8,7 @@ use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Api\CartManagementInterface; /** @@ -35,14 +36,18 @@ public function __construct( public function getOverridenValue() { - if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { - $customerId = $this->userContext->getUserId(); + try { + if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { + $customerId = $this->userContext->getUserId(); - /** @var \Magento\Quote\Api\Data\CartInterface */ - $cart = $this->cartManagement->getCartForCustomer($customerId); - if ($cart) { - return $cart->getId(); + /** @var \Magento\Quote\Api\Data\CartInterface */ + $cart = $this->cartManagement->getCartForCustomer($customerId); + if ($cart) { + return $cart->getId(); + } } + } catch (NoSuchEntityException $e) { + /* do nothing and just return null */ } return null; } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php new file mode 100644 index 0000000000000..b70dac7130076 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php @@ -0,0 +1,122 @@ +userContext = $this->getMockBuilder('Magento\Authorization\Model\UserContextInterface') + ->getMockForAbstractClass(); + $this->cartManagement = $this->getMockBuilder('Magento\Quote\Api\CartManagementInterface') + ->getMockForAbstractClass(); + $this->model = (new ObjectManager($this))->getObject( + 'Magento\Quote\Model\Webapi\ParamOverriderCartId', + [ + 'userContext' => $this->userContext, + 'cartManagement' => $this->cartManagement, + ] + ); + } + + public function testGetOverridenValueIsCustomerAndCartExists() + { + $retValue = 'retValue'; + $customerId = 1; + + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER)); + $this->userContext->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($customerId)); + + $cart = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface') + ->getMockForAbstractClass(); + $this->cartManagement->expects($this->once()) + ->method('getCartForCustomer') + ->with($customerId) + ->will($this->returnValue($cart)); + $cart->expects($this->once()) + ->method('getId') + ->will($this->returnValue($retValue)); + + $this->assertSame($retValue, $this->model->getOverridenValue()); + } + + public function testGetOverridenValueIsCustomerAndCartDoesNotExist() + { + $retValue = 'retValue'; + $customerId = 1; + + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER)); + $this->userContext->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($customerId)); + + $cart = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface') + ->getMockForAbstractClass(); + $this->cartManagement->expects($this->once()) + ->method('getCartForCustomer') + ->with($customerId) + ->will($this->throwException(new NoSuchEntityException())); + + $this->assertNull($this->model->getOverridenValue()); + } + + public function testGetOverridenValueIsCustomerAndCartIsNull() + { + $retValue = 'retValue'; + $customerId = 1; + + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER)); + $this->userContext->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($customerId)); + + $cart = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface') + ->getMockForAbstractClass(); + $this->cartManagement->expects($this->once()) + ->method('getCartForCustomer') + ->with($customerId) + ->will($this->returnValue(null)); + + $this->assertNull($this->model->getOverridenValue()); + } + + public function testGetOverridenValueIsNotCustomer() + { + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); + + $this->assertNull($this->model->getOverridenValue()); + } +} diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php new file mode 100644 index 0000000000000..94d9ff013295e --- /dev/null +++ b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php @@ -0,0 +1,59 @@ +userContext = $this->getMockBuilder('Magento\Authorization\Model\UserContextInterface') + ->getMockForAbstractClass(); + $this->model = (new ObjectManager($this))->getObject( + 'Magento\Webapi\Controller\Rest\ParamOverriderCustomerId', + [ + 'userContext' => $this->userContext + ] + ); + } + + public function testGetOverridenValueIsCustomer() + { + $retValue = 'retValue'; + + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER)); + $this->userContext->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($retValue)); + + $this->assertSame($retValue, $this->model->getOverridenValue()); + } + + public function testGetOverridenValueIsNotCustomer() + { + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); + + $this->assertNull($this->model->getOverridenValue()); + } +} diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamsOverriderTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamsOverriderTest.php index 2cfe94f7d07ce..f5aa363b8b9c2 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamsOverriderTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamsOverriderTest.php @@ -31,10 +31,15 @@ public function testOverrideParams($requestData, $parameters, $expectedOverridde $userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId)); $userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType)); + $paramOverriderCustomerId = $objectManager->getObject( + 'Magento\Webapi\Controller\Rest\ParamOverriderCustomerId', + ['userContext' => $userContextMock] + ); + /** @var \Magento\Webapi\Controller\Rest\ParamsOverrider $paramsOverrider */ $paramsOverrider = $objectManager->getObject( 'Magento\Webapi\Controller\Rest\ParamsOverrider', - ['userContext' => $userContextMock] + ['paramOverriders' => ['%customer_id%' => $paramOverriderCustomerId ]] ); $this->assertEquals($expectedOverriddenParams, $paramsOverrider->override($requestData, $parameters)); @@ -84,7 +89,7 @@ public function overrideParamsDataProvider() 'force true, value present, override value is %customer_id%, not a customer' => [ ['Name1' => 'valueIn'], ['Name1' => ['force' => true, 'value' => '%customer_id%']], - ['Name1' => '%customer_id%'], + ['Name1' => null], 1234, UserContextInterface::USER_TYPE_INTEGRATION, ], From d8b75a0c06c1a51a7810bca04d1f1e90baf4630b Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Mon, 20 Apr 2015 16:02:51 -0500 Subject: [PATCH 085/115] MAGETWO-36378: Magento\Quote\Api\GuestCartManagement - Use composition instead of inheritance fro GuestCartManagement - Add unit tests for GuestCartManagement --- .../Model/GuestCart/GuestCartManagement.php | 80 +++-------- .../GuestCart/GuestCartManagementTest.php | 132 ++++++++++++++++++ 2 files changed, 151 insertions(+), 61 deletions(-) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 2e655a2bf39d1..62966b0c86f88 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -6,31 +6,30 @@ namespace Magento\Quote\Model\GuestCart; -use Magento\Authorization\Model\UserContextInterface; -use Magento\Framework\Event\ManagerInterface as EventManager; use Magento\Quote\Api\GuestCartManagementInterface; -use Magento\Quote\Model\CustomerManagement; -use Magento\Quote\Model\Quote as QuoteEntity; -use Magento\Quote\Model\Quote\Address\ToOrder as ToOrderConverter; -use Magento\Quote\Model\Quote\Address\ToOrderAddress as ToOrderAddressConverter; -use Magento\Quote\Model\Quote\Item\ToOrderItem as ToOrderItemConverter; -use Magento\Quote\Model\Quote\Payment\ToOrderPayment as ToOrderPaymentConverter; +use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Model\QuoteManagement; use Magento\Quote\Model\QuoteRepository; -use Magento\Quote\Model\QuoteValidator; -use Magento\Sales\Api\Data\OrderInterfaceFactory as OrderFactory; -use Magento\Sales\Api\OrderManagementInterface as OrderManagement; -use Magento\Store\Model\StoreManagerInterface; /** * Cart Management class for guest carts. * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class GuestCartManagement extends QuoteManagement implements GuestCartManagementInterface +class GuestCartManagement implements GuestCartManagementInterface { + /** + * @var CartManagementInterface + */ + protected $quoteManagement; + + /** + * @var QuoteRepository + */ + protected $quoteRepository; + /** * @var QuoteIdMaskFactory */ @@ -39,60 +38,19 @@ class GuestCartManagement extends QuoteManagement implements GuestCartManagement /** * Initialize dependencies. * - * @param EventManager $eventManager - * @param QuoteValidator $quoteValidator - * @param OrderFactory $orderFactory - * @param OrderManagement $orderManagement - * @param CustomerManagement $customerManagement - * @param ToOrderConverter $quoteAddressToOrder - * @param ToOrderAddressConverter $quoteAddressToOrderAddress - * @param ToOrderItemConverter $quoteItemToOrderItem - * @param ToOrderPaymentConverter $quotePaymentToOrderPayment - * @param UserContextInterface $userContext + * @param CartManagementInterface $quoteManagement * @param QuoteRepository $quoteRepository - * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository - * @param \Magento\Customer\Model\CustomerFactory $customerModelFactory - * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper - * @param StoreManagerInterface $storeManager * @param QuoteIdMaskFactory $quoteIdMaskFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - EventManager $eventManager, - QuoteValidator $quoteValidator, - OrderFactory $orderFactory, - OrderManagement $orderManagement, - CustomerManagement $customerManagement, - ToOrderConverter $quoteAddressToOrder, - ToOrderAddressConverter $quoteAddressToOrderAddress, - ToOrderItemConverter $quoteItemToOrderItem, - ToOrderPaymentConverter $quotePaymentToOrderPayment, - UserContextInterface $userContext, + CartManagementInterface $quoteManagement, QuoteRepository $quoteRepository, - \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, - \Magento\Customer\Model\CustomerFactory $customerModelFactory, - \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, - StoreManagerInterface $storeManager, QuoteIdMaskFactory $quoteIdMaskFactory ) { + $this->quoteManagement = $quoteManagement; + $this->quoteRepository = $quoteRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct( - $eventManager, - $quoteValidator, - $orderFactory, - $orderManagement, - $customerManagement, - $quoteAddressToOrder, - $quoteAddressToOrderAddress, - $quoteItemToOrderItem, - $quotePaymentToOrderPayment, - $userContext, - $quoteRepository, - $customerRepository, - $customerModelFactory, - $dataObjectHelper, - $storeManager - ); } /** @@ -102,7 +60,7 @@ public function createEmptyCart($customerId = null) { /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create(); - $cartId = parent::createEmptyCart($customerId); + $cartId = $this->quoteManagement->createEmptyCart($customerId); $quoteIdMask->setId($cartId)->save(); return $quoteIdMask->getMaskedId(); } @@ -114,7 +72,7 @@ public function assignCustomer($cartId, $customerId, $storeId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::assignCustomer($quoteIdMask->getId(), $customerId, $storeId); + return $this->quoteManagement->assignCustomer($quoteIdMask->getId(), $customerId, $storeId); } /** @@ -124,7 +82,7 @@ public function placeOrder($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::placeOrder($quoteIdMask->getId()); + return $this->quoteManagement->placeOrder($quoteIdMask->getId()); } /** diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php new file mode 100644 index 0000000000000..cc567b0262f78 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php @@ -0,0 +1,132 @@ +quoteManagementMock = $this->getMockForAbstractClass( + 'Magento\Quote\Api\CartManagementInterface', + [], + '', + false, + true, + true, + [] + ); + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->quoteIdMaskFactoryMock = $this->getMock( + 'Magento\Quote\Model\QuoteIdMaskFactory', + ['create'], + [], + '', + false + ); + $this->quoteIdMaskMock = $this->getMock( + 'Magento\Quote\Model\QuoteIdMask', + ['getId', 'getMaskedId', 'load', 'save', 'setId'], + [], + '', + false + ); + + $this->guestCartManagement = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestCartManagement', + [ + 'quoteManagement' => $this->quoteManagementMock, + 'quoteRepository' => $this->quoteRepositoryMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testCreateEmptyCart() + { + $maskedCartId = 'masked1cart2id3'; + $cartId = 1; + + $this->quoteIdMaskMock->expects($this->once())->method('setId')->with($cartId)->willReturnSelf(); + $this->quoteIdMaskMock->expects($this->once())->method('save')->willReturnSelf(); + $this->quoteIdMaskMock->expects($this->once())->method('getMaskedId')->willreturn($maskedCartId); + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($cartId); + + $this->assertEquals($maskedCartId, $this->guestCartManagement->createEmptyCart()); + } + + public function testAssignCustomer() + { + $maskedCartId = 'masked1cart2id3'; + $cartId = 1; + $customerId = 1; + $storeId = 1; + + $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf(); + $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId); + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteManagementMock->expects($this->once())->method('assignCustomer')->willReturn(true); + + $this->assertEquals(true, $this->guestCartManagement->assignCustomer($cartId, $customerId, $storeId)); + } + + public function testPlaceOrder() + { + $maskedCartId = 'masked1cart2id3'; + $cartId = 1; + $orderId = 1; + + $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf(); + $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId); + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId); + + $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); + } + + public function testGetCartForCustomer() + { + $maskedCartId = 'masked1cart2id3'; + $cartId = 1; + $orderId = 1; + + $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf(); + $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId); + $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId); + + $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); + } +} From 709ae39c17e7d5aa2a696f4b8e8cb3dbba0928fd Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Mon, 20 Apr 2015 16:37:34 -0500 Subject: [PATCH 086/115] MAGETWO-36426: Magento\Quote\Api\GuestCartTotalRepository - Refactor GuestCartTotalRepository to use composition instead of inheritance - Modify unit test to match changes --- .../GuestCart/GuestCartTotalRepository.php | 22 ++--- .../GuestCartTotalRepositoryTest.php | 88 +++++++------------ 2 files changed, 42 insertions(+), 68 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php index 02221d2950c3c..1ab5f5eeb8c43 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php @@ -6,38 +6,38 @@ namespace Magento\Quote\Model\GuestCart; +use Magento\Quote\Api\CartTotalRepositoryInterface; use Magento\Quote\Api\GuestCartTotalRepositoryInterface; -use Magento\Quote\Model\Cart\CartTotalRepository; -use Magento\Quote\Model\QuoteRepository; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; /** * Cart totals repository class for guest carts. */ -class GuestCartTotalRepository extends CartTotalRepository implements GuestCartTotalRepositoryInterface +class GuestCartTotalRepository implements GuestCartTotalRepositoryInterface { /** * @var QuoteIdMaskFactory */ private $quoteIdMaskFactory; + /** + * @var CartTotalRepositoryInterface + */ + private $cartTotalRepository; + /** * Constructs a cart totals data object. * - * @param \Magento\Quote\Api\Data\TotalsInterfaceFactory $totalsFactory Cart totals factory. - * @param QuoteRepository $quoteRepository Quote repository. - * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param CartTotalRepositoryInterface $cartTotalRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - \Magento\Quote\Api\Data\TotalsInterfaceFactory $totalsFactory, - QuoteRepository $quoteRepository, - \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, + CartTotalRepositoryInterface $cartTotalRepository, QuoteIdMaskFactory $quoteIdMaskFactory ) { + $this->cartTotalRepository = $cartTotalRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct($totalsFactory, $quoteRepository, $dataObjectHelper); } /** @@ -47,6 +47,6 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId()); + return $this->cartTotalRepository->get($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php index 539cd524afc0c..4d39e8edeea32 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php @@ -21,96 +21,70 @@ class GuestCartTotalRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $quoteRepositoryMock; + protected $cartTotalRepository; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $quoteMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $totalsFactoryMock; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $addressMock; - - /** - * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject - */ - private $dataObjectHelperMock; + protected $quoteIdMaskMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $quoteIdMaskFactoryMock; + protected $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var int */ - protected $quoteIdMaskMock; + protected $cartId = 12; public function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->totalsFactoryMock = $this->getMock( - 'Magento\Quote\Api\Data\TotalsInterfaceFactory', - ['create'], - [], - '', - false - ); - $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); - $this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper') + + $this->quoteIdMaskFactoryMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMaskFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->quoteIdMaskMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMask') + ->disableOriginalConstructor() + ->getMock(); + $this->cartTotalRepository = $this->getMockBuilder('Magento\Quote\Api\CartTotalRepositoryInterface') ->disableOriginalConstructor() ->getMock(); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); $this->model = $this->objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestCartTotalRepository', [ - 'totalsFactory' => $this->totalsFactoryMock, - 'quoteRepository' => $this->quoteRepositoryMock, - 'dataObjectHelper' => $this->dataObjectHelperMock, - 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + 'cartTotalRepository' => $this->cartTotalRepository, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, ] ); - } - - public function testGetTotals() - { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 12; - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); + $this->quoteIdMaskFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->quoteIdMaskMock); $this->quoteIdMaskMock->expects($this->once()) ->method('load') - ->with($maskedCartId, 'masked_id') + ->with($this->maskedCartId, 'masked_id') ->willReturn($this->quoteIdMaskMock); $this->quoteIdMaskMock->expects($this->once()) ->method('getId') - ->willReturn($cartId); - - $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId) - ->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($this->addressMock); - $this->addressMock->expects($this->once())->method('getData')->willReturn(['addressData']); - $this->quoteMock->expects($this->once())->method('getData')->willReturn(['quoteData']); - - $item = $this->getMock('Magento\Quote\Model\Quote\Item', [], [], '', false); - $this->quoteMock->expects($this->once())->method('getAllItems')->will($this->returnValue([$item])); + ->willReturn($this->cartId); + } - $totals = $this->getMock('Magento\Quote\Model\Cart\Totals', ['setItems'], [], '', false); - $this->totalsFactoryMock->expects($this->once())->method('create')->willReturn($totals); - $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray'); - $totals->expects($this->once())->method('setItems'); + public function testGetTotals() + { + $retValue = 'retValue'; - $this->model->get($maskedCartId); + $this->cartTotalRepository->expects($this->once()) + ->method('get') + ->with($this->cartId) + ->will($this->returnValue($retValue)); + $this->assertSame($retValue, $this->model->get($this->maskedCartId)); } } From f0c3b5c48ea722d08f59e6c3db12e41748bf015a Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 15:25:56 +0300 Subject: [PATCH 087/115] MAGETWO-36382: Magento\Quote\Api\GuestBillingAddressManagement - added unit tests - refactored code to use mock helper --- .../GuestBillingAddressManagementTest.php | 123 ++++++++++++++++++ .../Model/GuestCart/GuestCartTestHelper.php | 57 ++++++++ 2 files changed, 180 insertions(+) create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php create mode 100644 app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php new file mode 100644 index 0000000000000..e5ec964a0c658 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php @@ -0,0 +1,123 @@ +quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->validatorMock = $this->getMock('\Magento\Quote\Model\QuoteAddressValidator', [], [], '', false); + $logger = $this->getMock('\Psr\Log\LoggerInterface'); + $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 11; + + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); + + $this->model = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestBillingAddressManagement', + [ + 'quoteRepository' => $this->quoteRepositoryMock, + 'addressValidator' => $this->validatorMock, + 'logger' => $logger, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + /** + * @return void + */ + public function testGetAddress() + { + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once())->method('getActive') + ->with($this->cartId )->will($this->returnValue($quoteMock)); + + $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); + $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); + + $this->assertEquals($addressMock, $this->model->get($this->maskedCartId )); + } + + /** + * @return void + */ + public function testAssingAddress() + { + $address = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); + + $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); + $this->quoteRepositoryMock->expects($this->once()) + ->method('getActive') + ->with($this->cartId ) + ->will($this->returnValue($quoteMock)); + + $this->validatorMock->expects($this->once())->method('validate') + ->with($address) + ->will($this->returnValue(true)); + + $quoteMock->expects($this->once())->method('setBillingAddress')->with($address); + $quoteMock->expects($this->once())->method('setDataChanges')->with(true); + $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); + $addressId = 1; + $billingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); + $billingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); + $quoteMock->expects($this->once())->method('getBillingAddress') + ->will($this->returnValue($billingAddressMock)); + + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId , $address)); + } +} diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php new file mode 100644 index 0000000000000..f0ea57a50a50d --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -0,0 +1,57 @@ +testCase = $testCase; + } + + /** + * Return mocks with expected invokes + * + * @param $maskedCartId + * @param $cartId + * @return array + */ + public function mockQuoteIdMask( + $maskedCartId, + $cartId + ) { + $quoteIdMaskMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $quoteIdMaskFactoryMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); + + $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn( + $quoteIdMaskMock + ); + $quoteIdMaskMock->expects($this->testCase->once()) + ->method('load') + ->with($maskedCartId, 'masked_id') + ->willReturn($quoteIdMaskMock); + $quoteIdMaskMock->expects($this->testCase->once()) + ->method('getId') + ->willReturn($cartId); + + return [$quoteIdMaskFactoryMock,$quoteIdMaskMock]; + } +} From ce1f336678adbaaf8782dd97200f4145478eff10 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 16:34:20 +0300 Subject: [PATCH 088/115] MAGETWO-36377: Magento\Quote\Api\GuestCartRepositoryInterface - replaced inheritance with composition --- .../Model/GuestCart/GuestCartRepository.php | 52 ++----- .../GuestCart/GuestCartRepositoryTest.php | 141 +++--------------- .../Model/GuestCart/GuestCartTestHelper.php | 25 +--- 3 files changed, 39 insertions(+), 179 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index 1768b727aeb30..50794238946d6 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -7,76 +7,46 @@ namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCartRepositoryInterface; -use Magento\Quote\Model\Quote; -use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteRepository; -use Magento\Store\Model\StoreManagerInterface; use Magento\Quote\Model\QuoteIdMaskFactory; /** * Cart Repository class for guest carts. */ -class GuestCartRepository extends QuoteRepository implements GuestCartRepositoryInterface +class GuestCartRepository implements GuestCartRepositoryInterface { /** * @var QuoteIdMaskFactory */ protected $quoteIdMaskFactory; + /** + * @var QuoteRepository + */ + protected $quoteRepository; + /** * Initialize dependencies. * - * @param QuoteFactory $quoteFactory - * @param StoreManagerInterface $storeManager - * @param \Magento\Quote\Model\Resource\Quote\Collection $quoteCollection - * @param \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory + * @param QuoteRepository $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - QuoteFactory $quoteFactory, - StoreManagerInterface $storeManager, - \Magento\Quote\Model\Resource\Quote\Collection $quoteCollection, - \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory, + QuoteRepository $quoteRepository, QuoteIdMaskFactory $quoteIdMaskFactory ) { - parent::__construct($quoteFactory, $storeManager, $quoteCollection, $searchResultsDataFactory); $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->quoteRepository = $quoteRepository; } /** * {@inheritdoc} */ - public function get($cartId, array $sharedStoreIds = []) + public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId(), $sharedStoreIds); - } - - /** - * {@inheritdoc} - */ - public function save(Quote $quote) - { - if ($quote->getId()) { - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); - $quote->setId($quoteIdMask->getId()); - } - parent::save($quote); - } - - /** - * {@inheritdoc} - */ - public function delete(Quote $quote) - { - if ($quote->getId()) { - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quote->getId(), 'masked_id'); - $quote->setId($quoteIdMask->getId()); - } - parent::delete($quote); + return $this->quoteRepository->get($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php index 406c1e9e46308..cc2b21cf28c65 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -17,76 +17,52 @@ class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteFactoryMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $storeManagerMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $storeMock; + protected $quoteMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteMock; + protected $quoteRepositoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $searchResultsDataFactory; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteCollectionMock; + protected $quoteIdMaskMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $quoteIdMaskFactoryMock; + protected $maskedCartId; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var int */ - protected $quoteIdMaskMock; + protected $cartId; protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->quoteRepositoryMock = $this->getMock( 'Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteFactoryMock = $this->getMock('Magento\Quote\Model\QuoteFactory', ['create'], [], '', false); - $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface'); - $this->quoteMock = $this->getMock( - 'Magento\Quote\Model\Quote', - ['load', 'getId', 'save', 'delete', 'getCustomerId'], - [], - '', - false - ); - $this->storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false); - $this->searchResultsDataFactory = $this->getMock( - 'Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory', - ['create'], - [], - '', - false - ); + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 123; - $this->quoteCollectionMock = $this->getMock('Magento\Quote\Model\Resource\Quote\Collection', [], [], '', false); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestCartRepository', [ - 'quoteFactory' => $this->quoteFactoryMock, - 'storeManager' => $this->storeManagerMock, - 'searchResultsDataFactory' => $this->searchResultsDataFactory, - 'quoteCollection' => $this->quoteCollectionMock, + 'quoteRepository' => $this->quoteRepositoryMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); @@ -94,84 +70,7 @@ protected function setUp() public function testGet() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 15; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock); - $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock); - $this->storeMock->expects($this->once())->method('getId')->willReturn($this->storeMock); - $this->quoteMock->expects($this->never())->method('setSharedStoreIds'); - $this->quoteMock->expects($this->once()) - ->method('load') - ->with($cartId) - ->willReturn($this->storeMock); - $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - - $this->assertEquals($this->quoteMock, $this->model->get($maskedCartId)); - } - - public function testSaveEdited() - { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 1; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($cartId); - - - $this->quoteMock->expects($this->once()) - ->method('save'); - $this->quoteMock->expects($this->exactly(3))->method('getId')->willReturn($maskedCartId); - $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); - - $this->model->save($this->quoteMock); - } - - public function testSaveNew() - { - $cartId = 1; - - $this->quoteIdMaskFactoryMock->expects($this->never())->method('create'); - $this->quoteMock->expects($this->at(0))->method('getId')->willReturn(false); - - $this->quoteMock->expects($this->once()) - ->method('save'); - $this->quoteMock->expects($this->at(1))->method('getId')->willReturn($cartId); - $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); - - $this->model->save($this->quoteMock); - } - - public function testDelete() - { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 1; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($cartId); - - $this->quoteMock->expects($this->once()) - ->method('delete'); - $this->quoteMock->expects($this->exactly(3))->method('getId')->willReturn($maskedCartId); - $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2); - - $this->model->delete($this->quoteMock); + $this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($this->quoteMock); + $this->assertEquals($this->quoteMock, $this->model->get($this->maskedCartId)); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php index f0ea57a50a50d..679c4e11fd748 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -30,28 +30,19 @@ public function __construct(\PHPUnit_Framework_TestCase $testCase) /** * Return mocks with expected invokes * + * First element is quoteIdMaskFactoryMock, second one is quoteIdMaskMock + * * @param $maskedCartId * @param $cartId * @return array */ - public function mockQuoteIdMask( - $maskedCartId, - $cartId - ) { + public function mockQuoteIdMask( $maskedCartId, $cartId) + { $quoteIdMaskMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); $quoteIdMaskFactoryMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - - $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn( - $quoteIdMaskMock - ); - $quoteIdMaskMock->expects($this->testCase->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($quoteIdMaskMock); - $quoteIdMaskMock->expects($this->testCase->once()) - ->method('getId') - ->willReturn($cartId); - - return [$quoteIdMaskFactoryMock,$quoteIdMaskMock]; + $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock); + $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf(); + $quoteIdMaskMock->expects($this->testCase->once())->method('getId')->willReturn($cartId); + return [$quoteIdMaskFactoryMock, $quoteIdMaskMock]; } } From 70282e6ab3e1a7ede2f402ba4823eb8051fcf081 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 16:57:35 +0300 Subject: [PATCH 089/115] MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement - replaced inheritance with composition --- .../GuestShippingAddressManagement.php | 27 ++--- .../GuestShippingAddressManagementTest.php | 107 ++++++------------ 2 files changed, 48 insertions(+), 86 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 7d83d71ebf6b4..1ef09d849ff57 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -6,41 +6,36 @@ namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestShippingAddressManagementInterface; -use Magento\Quote\Model\QuoteAddressValidator; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Quote\Model\QuoteRepository; use Magento\Quote\Model\ShippingAddressManagement; -use Psr\Log\LoggerInterface as Logger; /** * Shipping address management class for guest carts. */ -class GuestShippingAddressManagement extends ShippingAddressManagement implements - GuestShippingAddressManagementInterface +class GuestShippingAddressManagement implements GuestShippingAddressManagementInterface { /** * @var QuoteIdMaskFactory */ protected $quoteIdMaskFactory; + /** + * @var ShippingAddressManagement + */ + protected $shippingAddressManagement; + /** * Constructs a quote shipping address write service object. * - * @param QuoteRepository $quoteRepository - * @param QuoteAddressValidator $addressValidator - * @param Logger $logger + * @param ShippingAddressManagement $shippingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - \Magento\Quote\Model\QuoteRepository $quoteRepository, - QuoteAddressValidator $addressValidator, - Logger $logger, + ShippingAddressManagement $shippingAddressManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { - $this->quoteRepository = $quoteRepository; - $this->addressValidator = $addressValidator; - $this->logger = $logger; + $this->shippingAddressManagement = $shippingAddressManagement; $this->quoteIdMaskFactory = $quoteIdMaskFactory; } @@ -51,7 +46,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::assign($quoteIdMask->getId(), $address); + return $this->shippingAddressManagement->assign($quoteIdMask->getId(), $address); } /** @@ -61,6 +56,6 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId()); + return $this->shippingAddressManagement->get($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php index 8ce3ae28fcd00..e4c9d4beadde5 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php @@ -17,109 +17,76 @@ class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $quoteAddressMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteAddressMock; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $validatorMock; + protected $quoteIdMaskMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteIdMaskFactoryMock; + protected $shippingAddressManagementMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $quoteIdMaskMock; + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->quoteAddressMock = $this->getMock( '\Magento\Quote\Model\Quote\Address', [], [], '', false); - $this->validatorMock = $this->getMock( 'Magento\Quote\Model\QuoteAddressValidator', [], [], '', false); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $this->shippingAddressManagementMock = $this->getMock( + 'Magento\Quote\Model\ShippingAddressManagement', + [], + [], + '', + false + ); + $this->quoteAddressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 123; + + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); + $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestShippingAddressManagement', [ - 'quoteRepository' => $this->quoteRepositoryMock, - 'addressValidator' => $this->validatorMock, - 'logger' => $this->getMock('\Psr\Log\LoggerInterface'), + 'shippingAddressManagement' => $this->shippingAddressManagementMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); } - public function testAssignAddress() + public function testAssign() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 867; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->will($this->returnValue($quoteMock)); - $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - - - $this->validatorMock->expects($this->once())->method('validate') - ->with($this->quoteAddressMock) - ->will($this->returnValue(true)); - - $quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); - $addressId = 1; - $shippingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); - $shippingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); - $quoteMock->expects($this->once())->method('getShippingAddress') - ->will($this->returnValue($shippingAddressMock)); - - $this->assertEquals($addressId, $this->model->assign($maskedCartId, $this->quoteAddressMock)); + $this->shippingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId); + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->quoteAddressMock)); } - public function testGetAddress() + public function testGet() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 867; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->will( - $this->returnValue($quoteMock) + $this->shippingAddressManagementMock->expects($this->once())->method('get')->willReturn( + $this->quoteAddressMock ); - - $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); - $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($addressMock)); - $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(false)); - $this->assertEquals($addressMock, $this->model->get($maskedCartId)); + $this->assertEquals($this->quoteAddressMock, $this->model->get($this->maskedCartId)); } } From 75c16ec86651068b3d0f766df352f231471cf7cb Mon Sep 17 00:00:00 2001 From: vsevostianov Date: Tue, 21 Apr 2015 17:38:22 +0300 Subject: [PATCH 090/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart - Functional test fix --- ...uctsToCartFromCustomerWishlistOnFrontendTest.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php index 3b904100aa510..227831ea819ea 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php @@ -31,19 +31,6 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli const DOMAIN = 'CS'; /* end tags */ - /** - * Prepare data for test - * - * @param Customer $customer - * @return array - */ - public function __prepare(Customer $customer) - { - $customer->persist(); - - return ['customer' => $customer]; - } - /** * Run suggest searching result test. * From c30e6de211b16e2e7a6a09042c6af07dedd338fc Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 18:17:53 +0300 Subject: [PATCH 091/115] MAGETWO-36382: Magento\Quote\Api\GuestBillingAddressManagement - replaced inheritance with composition --- .../GuestBillingAddressManagement.php | 30 +++----- .../GuestBillingAddressManagementTest.php | 68 ++++++------------- 2 files changed, 32 insertions(+), 66 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php index dc2ce6805c683..8679ad781d8d7 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php @@ -8,42 +8,36 @@ use Magento\Quote\Api\GuestBillingAddressManagementInterface; use Magento\Quote\Model\BillingAddressManagement; -use Magento\Quote\Model\QuoteAddressValidator; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Quote\Model\QuoteRepository; -use Psr\Log\LoggerInterface as Logger; /** * Billing address management service for guest carts. */ -class GuestBillingAddressManagement extends BillingAddressManagement implements GuestBillingAddressManagementInterface +class GuestBillingAddressManagement implements GuestBillingAddressManagementInterface { /** * @var QuoteIdMaskFactory */ private $quoteIdMaskFactory; + /** + * @var BillingAddressManagement + */ + private $billingAddressManagement; + /** * Constructs a quote billing address service object. * - * @param QuoteRepository $quoteRepository Quote repository. - * @param QuoteAddressValidator $addressValidator Address validator. - * @param Logger $logger Logger. + * @param BillingAddressManagement $billingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - QuoteRepository $quoteRepository, - QuoteAddressValidator $addressValidator, - Logger $logger, + BillingAddressManagement $billingAddressManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct( - $quoteRepository, - $addressValidator, - $logger - ); + $this->billingAddressManagement = $billingAddressManagement; } /** @@ -53,8 +47,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - - return parent::assign($quoteIdMask->getId(), $address); + return $this->billingAddressManagement->assign($quoteIdMask->getId(), $address); } /** @@ -64,7 +57,6 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - - return parent::get($quoteIdMask->getId()); + return $this->billingAddressManagement->get($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php index e5ec964a0c658..d18203bf75139 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php @@ -6,8 +6,6 @@ */ namespace Magento\Quote\Test\Unit\Model\GuestCart; -use Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper; - class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase { /** @@ -18,22 +16,22 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $validatorMock; + protected $quoteIdMaskMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteIdMaskFactoryMock; + protected $billingAddressManagementMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteIdMaskMock; + protected $addressMock; /** * @var string @@ -51,14 +49,17 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->validatorMock = $this->getMock('\Magento\Quote\Model\QuoteAddressValidator', [], [], '', false); - $logger = $this->getMock('\Psr\Log\LoggerInterface'); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $this->addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); + $this->billingAddressManagementMock = $this->getMock( + 'Magento\Quote\Model\BillingAddressManagement', + [], + [], + '', + false + ); $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $this->cartId = 11; + $this->cartId = 123; $guestCartTestHelper = new GuestCartTestHelper($this); list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( @@ -69,10 +70,8 @@ protected function setUp() $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestBillingAddressManagement', [ - 'quoteRepository' => $this->quoteRepositoryMock, - 'addressValidator' => $this->validatorMock, - 'logger' => $logger, - 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + 'billingAddressManagement' => $this->billingAddressManagementMock ] ); } @@ -80,44 +79,19 @@ protected function setUp() /** * @return void */ - public function testGetAddress() + public function testGet() { - $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once())->method('getActive') - ->with($this->cartId )->will($this->returnValue($quoteMock)); - - $addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); - $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); - - $this->assertEquals($addressMock, $this->model->get($this->maskedCartId )); + $this->billingAddressManagementMock->expects($this->once())->method('get')->willReturn($this->addressMock); + $this->assertEquals($this->addressMock, $this->model->get($this->maskedCartId)); } /** * @return void */ - public function testAssingAddress() + public function testAssing() { - $address = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); - - $quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($this->cartId ) - ->will($this->returnValue($quoteMock)); - - $this->validatorMock->expects($this->once())->method('validate') - ->with($address) - ->will($this->returnValue(true)); - - $quoteMock->expects($this->once())->method('setBillingAddress')->with($address); - $quoteMock->expects($this->once())->method('setDataChanges')->with(true); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $addressId = 1; - $billingAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); - $billingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId)); - $quoteMock->expects($this->once())->method('getBillingAddress') - ->will($this->returnValue($billingAddressMock)); - - $this->assertEquals($addressId, $this->model->assign($this->maskedCartId , $address)); + $this->billingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId); + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->addressMock)); } } From 9a6b9e149e47b0690637cdf57b93a9457528da87 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 18:47:16 +0300 Subject: [PATCH 092/115] MAGETWO-36379: Magento\Quote\Api\GuestCouponManagement - replaced inheritance with composition --- .../Model/GuestCart/GuestCouponManagement.php | 19 ++- .../GuestCart/GuestCouponManagementTest.php | 137 ++++-------------- 2 files changed, 42 insertions(+), 114 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 362e51f02c9f0..6ec630e25e52e 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -15,25 +15,30 @@ /** * Coupon management class for guest carts. */ -class GuestCouponManagement extends CouponManagement implements GuestCouponManagementInterface +class GuestCouponManagement implements GuestCouponManagementInterface { /** * @var QuoteIdMaskFactory */ private $quoteIdMaskFactory; + /** + * @var CouponManagement + */ + private $couponManagement; + /** * Constructs a coupon read service object. * - * @param \Magento\Quote\Model\QuoteRepository $quoteRepository Quote repository. + * @param CouponManagement $couponManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - \Magento\Quote\Model\QuoteRepository $quoteRepository, + CouponManagement $couponManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct($quoteRepository); + $this->couponManagement = $couponManagement; } /** @@ -43,7 +48,7 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId()); + return $this->couponManagement->get($quoteIdMask->getId()); } /** @@ -53,7 +58,7 @@ public function set($cartId, $couponCode) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::set($quoteIdMask->getId(), $couponCode); + return $this->couponManagement->set($quoteIdMask->getId(), $couponCode); } /** @@ -63,6 +68,6 @@ public function remove($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::remove($quoteIdMask->getId()); + return $this->couponManagement->remove($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php index 9fe52d31876d4..e3b93363b237b 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php @@ -17,149 +17,72 @@ class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteMock; + protected $quoteIdMaskMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteAddressMock; + protected $couponManagementMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $quoteIdMaskFactoryMock; + protected $maskedCartId; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var int */ - protected $quoteIdMaskMock; + protected $cartId; + + /** + * @var string + */ + protected $couponCode; protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->couponManagementMock = $this->getMock( 'Magento\Quote\Model\CouponManagement', [], [], '', false); - $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->quoteMock = $this->getMock( - 'Magento\Quote\Model\Quote', - [ - 'getItemsCount', - 'setCouponCode', - 'collectTotals', - 'save', - 'getShippingAddress', - 'getCouponCode' - ], - [], - '', - false - ); - $this->quoteAddressMock = $this->getMock( - 'Magento\Quote\Model\Quote\Address', - [ - 'setCollectShippingRates' - ], - [], - '', - false); + $this->couponCode = 'test_coupon_code'; + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 123; - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestCouponManagement', [ - 'quoteRepository' => $this->quoteRepositoryMock, + 'couponManagement' => $this->couponManagementMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); } - public function testGetCoupon() + public function testGet() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 11; - $couponCode = 'test_coupon_code'; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', ['getCouponCode', '__wakeup'], [], '', false); - $quoteMock->expects($this->any())->method('getCouponCode')->will($this->returnValue($couponCode)); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->will($this->returnValue($quoteMock)); - - $this->assertEquals($couponCode, $this->model->get($maskedCartId)); + $this->couponManagementMock->expects($this->once())->method('get')->willReturn($this->couponCode); + $this->assertEquals($this->couponCode, $this->model->get($this->maskedCartId)); } public function testSet() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 33; - $couponCode = '153a-ABC'; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock)); - $this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true); - $this->quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue($couponCode)); - - $this->assertTrue($this->model->set($maskedCartId, $couponCode)); + $this->couponManagementMock->expects($this->once())->method('set')->willReturn(true); + $this->assertTrue($this->model->set($this->maskedCartId, $this->couponCode)); } - public function testDelete() + public function testRemove() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 65; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock)); - $this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true); - $this->quoteMock->expects($this->once())->method('setCouponCode')->with(''); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue('')); - - $this->assertTrue($this->model->remove($maskedCartId)); + $this->couponManagementMock->expects($this->once())->method('remove')->willReturn(true); + $this->assertTrue($this->model->remove($this->maskedCartId)); } } From 98c56cf0a3efa53ce756b1ac8df7f1b0e383b471 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:10:43 +0300 Subject: [PATCH 093/115] MAGETWO-36272: Create /mine API for PaymentMethodManagement - replaced inheritance with composition --- .../GuestPaymentMethodManagement.php | 23 +-- .../GuestPaymentMethodManagementTest.php | 180 ++++-------------- 2 files changed, 49 insertions(+), 154 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php index 72723d0964458..3b65d502b3cd4 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php @@ -13,29 +13,30 @@ /** * Payment method management class for guest carts. */ -class GuestPaymentMethodManagement extends PaymentMethodManagement implements GuestPaymentMethodManagementInterface +class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterface { /** * @var QuoteIdMaskFactory */ protected $quoteIdMaskFactory; + /** + * @var PaymentMethodManagement + */ + protected $paymentMethodManagement; + /** * Initialize dependencies. * - * @param \Magento\Quote\Model\QuoteRepository $quoteRepository - * @param \Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator - * @param \Magento\Payment\Model\MethodList $methodList + * @param PaymentMethodManagement $paymentMethodManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - \Magento\Quote\Model\QuoteRepository $quoteRepository, - \Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator, - \Magento\Payment\Model\MethodList $methodList, + PaymentMethodManagement $paymentMethodManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { - parent::__construct($quoteRepository, $zeroTotalValidator, $methodList); $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->paymentMethodManagement = $paymentMethodManagement; } /** @@ -45,7 +46,7 @@ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::set($quoteIdMask->getId(), $method); + return $this->paymentMethodManagement->set($quoteIdMask->getId(), $method); } /** @@ -55,7 +56,7 @@ public function get($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::get($quoteIdMask->getId()); + return $this->paymentMethodManagement->get($quoteIdMask->getId()); } /** @@ -65,6 +66,6 @@ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::getList($quoteIdMask->getId()); + return $this->paymentMethodManagement->getList($quoteIdMask->getId()); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php index 975777704ef85..54f23a8904fc1 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -13,188 +13,82 @@ class GuestPaymentMethodManagementTest extends \PHPUnit_Framework_TestCase protected $model; /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $objectManager; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $quoteIdMaskMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $methodListMock; + protected $paymentMethodManagementMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $zeroTotalMock; + protected $paymentMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $quoteIdMaskFactoryMock; + protected $maskedCartId; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var int */ - protected $quoteIdMaskMock; + protected $cartId; protected function setUp() { - $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->methodListMock = $this->getMock('Magento\Payment\Model\MethodList', [], [], '', false); - $this->zeroTotalMock = $this->getMock('Magento\Payment\Model\Checks\ZeroTotal', [], [], '', false); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->paymentMethodManagementMock = $this->getMock( + 'Magento\Quote\Model\PaymentMethodManagement', + [], + [], + '', + false + ); + $this->paymentMock = $this->getMock('Magento\Quote\Model\Quote\Payment', [], [], '', false); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 11; + + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); - $this->model = $this->objectManager->getObject( + $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement', [ - 'quoteRepository' => $this->quoteRepositoryMock, - 'methodList' => $this->methodListMock, - 'zeroTotalValidator' => $this->zeroTotalMock, + 'paymentMethodManagement' => $this->paymentMethodManagementMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); } - public function testGetPaymentSuccess() + public function testGet() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 11; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $paymentMock = $this->getMock('Magento\Quote\Model\Quote\Payment', [], [], '', false); - $paymentMock->expects($this->once())->method('getId')->will($this->returnValue(1)); - - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $quoteMock->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock)); - - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->will($this->returnValue($quoteMock)); - $this->assertEquals($paymentMock, $this->model->get($maskedCartId)); + $this->paymentMethodManagementMock->expects($this->once())->method('get')->willReturn($this->paymentMock); + $this->assertEquals($this->paymentMock, $this->model->get($this->maskedCartId)); } public function testGetList() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 10; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive') - ->with($cartId) - ->will($this->returnValue($quoteMock)); - - $paymentMethod = $this->getMock('Magento\Quote\Api\Data\PaymentMethodInterface'); - $this->methodListMock->expects($this->once()) - ->method('getAvailableMethods') - ->with($quoteMock) - ->will($this->returnValue([$paymentMethod])); - $this->assertEquals([$paymentMethod], $this->model->getList($maskedCartId)); + $paymentMethod = $this->getMock('Magento\Quote\Api\Data\PaymentMethodInterface', [], [], '', false); + $this->paymentMethodManagementMock->expects($this->once())->method('getList')->willReturn([$paymentMethod]); + $this->assertEquals([$paymentMethod], $this->model->getList($this->maskedCartId)); } public function testSetSimpleProduct() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 100; $paymentId = 20; - $methodData = ['method' => 'data']; - $paymentMethod = 'checkmo'; - - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock( - '\Magento\Quote\Model\Quote', - ['getPayment', 'isVirtual', 'getShippingAddress', 'setTotalsCollectedFlag', 'collectTotals', 'save'], - [], - '', - false - ); - $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($quoteMock); - - $methodMock = $this->getMock('Magento\Quote\Model\Quote\Payment', ['setChecks', 'getData'], [], '', false); - $methodMock->expects($this->once()) - ->method('setChecks') - ->with([ - \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, - \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, - ]) - ->willReturnSelf(); - $methodMock->expects($this->once())->method('getData')->willReturn($methodData); - - $paymentMock = $this->getMock( - 'Magento\Quote\Model\Quote\Payment', - ['importData', 'getMethod', 'getMethodInstance', 'getId'], - [], - '', - false - ); - $paymentMock->expects($this->once())->method('importData')->with($methodData)->willReturnSelf(); - $paymentMock->expects($this->once())->method('getMethod')->willReturn($paymentMethod); - - $shippingAddressMock = $this->getMock( - 'Magento\Quote\Model\Quote\Address', - ['getCountryId', 'setPaymentMethod'], - [], - '', - false - ); - $shippingAddressMock->expects($this->once())->method('getCountryId')->willReturn(100); - $shippingAddressMock->expects($this->once()) - ->method('setPaymentMethod') - ->with($paymentMethod) - ->willReturnSelf(); - - $quoteMock->expects($this->exactly(2))->method('getPayment')->willReturn($paymentMock); - $quoteMock->expects($this->exactly(2))->method('isVirtual')->willReturn(false); - $quoteMock->expects($this->exactly(4))->method('getShippingAddress')->willReturn($shippingAddressMock); - - $methodInstance = $this->getMock('\Magento\Payment\Model\Checks\PaymentMethodChecksInterface'); - $paymentMock->expects($this->once())->method('getMethodInstance')->willReturn($methodInstance); - - $this->zeroTotalMock->expects($this->once()) - ->method('isApplicable') - ->with($methodInstance, $quoteMock) - ->willReturn(true); - - $quoteMock->expects($this->once())->method('setTotalsCollectedFlag')->with(false)->willReturnSelf(); - $quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf(); - $quoteMock->expects($this->once())->method('save')->willReturnSelf(); - - $paymentMock->expects($this->once())->method('getId')->willReturn($paymentId); - $this->assertEquals($paymentId, $this->model->set($maskedCartId, $methodMock)); + $this->paymentMethodManagementMock->expects($this->once())->method('set')->willReturn($paymentId); + $this->assertEquals($paymentId, $this->model->set($this->maskedCartId, $this->paymentMock)); } } From ede37488463d9debafa75731b552def1906b60f1 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Tue, 21 Apr 2015 11:12:32 -0500 Subject: [PATCH 094/115] MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository - refactor GuestCartItemRepository to use composition instead of inheritance - updated unit tests - removed saveForCustomer from guest interface and implementation - updated GuestCartTestHelper to allow magic method to be mocked --- .../Api/GuestCartItemRepositoryInterface.php | 12 - .../GuestCart/GuestCartItemRepository.php | 27 +- .../GuestCart/GuestCartItemRepositoryTest.php | 244 ++++++------------ .../Model/GuestCart/GuestCartTestHelper.php | 7 +- 4 files changed, 93 insertions(+), 197 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php index 8ad07762b83a8..1e327884d7bed 100644 --- a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -49,16 +49,4 @@ public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem); * @throws \Magento\Framework\Exception\CouldNotSaveException The item could not be removed. */ public function deleteById($cartId, $itemId); - - /** - * Adds the specified item to the specified cart. - * - * @param int $customerId Customer ID. - * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem The item. - * @return \Magento\Quote\Api\Data\CartItemInterface Item. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. - * @throws \Magento\Framework\Exception\CouldNotSaveException The specified item could not be saved to the cart. - * @throws \Magento\Framework\Exception\InputException The specified item or cart is not valid. - */ - public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem); } diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index c376915dcb12f..ce6a2d24d269e 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -14,8 +14,13 @@ /** * Cart Item repository class for guest carts. */ -class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface +class GuestCartItemRepository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface { + /** + * @var Repository + */ + protected $repository; + /** * @var QuoteIdMaskFactory */ @@ -24,19 +29,15 @@ class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\G /** * Constructs a read service object. * - * @param \Magento\Quote\Model\QuoteRepository $quoteRepository - * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository - * @param \Magento\Quote\Api\Data\CartItemInterfaceFactory $itemDataFactory + * @param \Magento\Quote\Model\Quote\Item\Repository $repository * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - \Magento\Quote\Model\QuoteRepository $quoteRepository, - \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, - \Magento\Quote\Api\Data\CartItemInterfaceFactory $itemDataFactory, + \Magento\Quote\Model\Quote\Item\Repository $repository, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; - parent::__construct($quoteRepository, $productRepository, $itemDataFactory); + $this->repository = $repository; } /** @@ -46,7 +47,7 @@ public function getList($cartId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - $cartItemList = parent::getList($quoteIdMask->getId()); + $cartItemList = $this->repository->getList($quoteIdMask->getId()); /** @var $item CartItemInterface */ foreach ($cartItemList as $item) { $item->setQuoteId($quoteIdMask->getMaskedId()); @@ -62,7 +63,7 @@ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem) /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); $cartItem->setQuoteId($quoteIdMask->getId()); - return parent::save($cartItem); + return $this->repository->save($cartItem); } /** @@ -72,17 +73,17 @@ public function deleteById($cartId, $itemId) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - return parent::deleteById($quoteIdMask->getId(), $itemId); + return $this->repository->deleteById($quoteIdMask->getId(), $itemId); } /** * {@inheritdoc} */ - public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem) + public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) { /** @var $quoteIdMask QuoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); $cartItem->setQuoteId($quoteIdMask->getId()); - return parent::saveForCustomer($customerId, $cartItem); + return $this->repository->delete($cartItem); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php index 69f86e7754d36..f1b0763559973 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php @@ -7,44 +7,27 @@ namespace Magento\Quote\Test\Unit\Model\Quote\Item; -use JsonSchema\Constraints\Object; -use Magento\Framework\App\ObjectManager; -use Magento\Quote\Model\GuestCart\GuestCartItemRepository; -use Magento\Quote\Model\QuoteIdMaskFactory; - -class GuestCartItemRepositoryTest -// extends RepositoryTest -extends \PHPUnit_Framework_TestCase +class GuestCartItemRepositoryTest extends \PHPUnit_Framework_TestCase { /** - * @var GuestCartItemRepository + * @var \Magento\Quote\Model\GuestCart\GuestCartItemRepository */ - protected $repository; + protected $guestCartItemRepository; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $cartItemRepositoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $productRepositoryMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $dataMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $quoteMock; + protected $quoteIdMaskFactoryMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $productMock; + protected $quoteIdMaskMock; /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -52,44 +35,56 @@ class GuestCartItemRepositoryTest protected $quoteItemMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var string */ - protected $itemDataFactoryMock; + protected $maskedCartId; /** - * @var \Magento\Quote\Model\QuoteIdMaskFactory + * @var string */ - protected $quoteIdMaskFactoryMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $quoteIdMaskMock; + protected $cartId; /** * @return void */ protected function setUp() { - $this->quoteRepositoryMock = - $this->getMock('\Magento\Quote\Model\QuoteRepository', [], [], '', false); - $this->productRepositoryMock = - $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface', [], [], '', false); - $this->itemDataFactoryMock = - $this->getMock('Magento\Quote\Api\Data\CartItemInterfaceFactory', ['create'], [], '', false); - $this->dataMock = $this->getMock('Magento\Quote\Api\Data\CartItemInterface'); - $this->quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false); - $this->productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); - $this->quoteItemMock = - $this->getMock('Magento\Quote\Model\Quote\Item', ['getId', 'getSku', 'setData', '__wakeUp'], [], '', false); - $this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); - $this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); - - $this->repository = new GuestCartItemRepository( - $this->quoteRepositoryMock, - $this->productRepositoryMock, - $this->itemDataFactoryMock, - $this->quoteIdMaskFactoryMock + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 33; + + /** + * @var \Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper + */ + $guestCartTestHelper = new \Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); + + $this->quoteIdMaskMock->expects($this->any()) + ->method('getMaskedId') + ->willReturn($this->maskedCartId); + + $this->quoteItemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false); + $this->quoteItemMock->expects($this->any()) + ->method('getItemId') + ->willReturn($this->maskedCartId); + $this->quoteItemMock->expects($this->any()) + ->method('getQuoteId') + ->willReturn($this->maskedCartId); + $this->quoteItemMock->expects($this->any()) + ->method('setQuoteId') + ->with($this->cartId); + + $this->cartItemRepositoryMock = $this->getMock('\Magento\Quote\Model\Quote\Item\Repository', [], [], '', false); + $this->guestCartItemRepository = + $objectManager->getObject('Magento\Quote\Model\GuestCart\GuestCartItemRepository', + [ + 'repository' => $this->cartItemRepositoryMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + ] ); } @@ -98,143 +93,50 @@ protected function setUp() */ public function testSave() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 13; - $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('getId') - ->willReturn($cartId); - - $this->dataMock->expects($this->at(0))->method('getQuoteId')->willReturn($maskedCartId); - $this->dataMock->expects($this->once())->method('setQuoteId')->with($cartId); - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->at(3))->method('getQuoteId')->willReturn($cartId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->productRepositoryMock->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->productMock)); - $this->dataMock->expects($this->once())->method('getSku'); - $this->quoteMock->expects($this->once())->method('addProduct')->with($this->productMock, 12); - $this->quoteMock->expects($this->never())->method('getItemById'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getItemByProduct') - ->with($this->productMock) - ->will($this->returnValue($this->quoteItemMock)); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue(null)); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + $expectedValue = 'expected value'; + $this->cartItemRepositoryMock->expects($this->once()) + ->method('save') + ->willReturn($expectedValue); + $this->assertEquals($expectedValue, $this->guestCartItemRepository->save($this->quoteItemMock)); } /** * @return void */ - public function testUpdateItem() + public function testGetList() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 13; - $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('getId') - ->willReturn($cartId); - - $itemId = 5; - $productSku = 'product_sku'; - $this->dataMock->expects($this->at(0))->method('getQuoteId')->willReturn($maskedCartId); - $this->dataMock->expects($this->once())->method('setQuoteId')->with($cartId); - $this->dataMock->expects($this->once())->method('getQty')->will($this->returnValue(12)); - $this->dataMock->expects($this->at(3))->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->will($this->returnValue($itemId)); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteItemMock->expects($this->once())->method('setData')->with('qty', 12); - $this->quoteItemMock->expects($this->once())->method('getSku')->willReturn($productSku); - $this->productRepositoryMock - ->expects($this->once()) - ->method('get') - ->with($productSku) - ->willReturn($this->productMock); - $this->quoteItemMock->expects($this->never())->method('addProduct'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - $this->quoteMock - ->expects($this->once()) - ->method('getItemByProduct') - ->with($this->productMock) - ->willReturn($this->quoteItemMock); - $this->assertEquals($this->quoteItemMock, $this->repository->save($this->dataMock)); + $itemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false); + $itemMock->expects($this->any()) + ->method('setQuoteId') + ->with($this->maskedCartId); + $this->cartItemRepositoryMock->expects($this->once()) + ->method('getList') + ->with($this->cartId) + ->will($this->returnValue([$itemMock])); + $this->assertEquals([$itemMock], $this->guestCartItemRepository->getList($this->maskedCartId)); } /** * @return void */ - public function testGetList() + public function testDeleteById() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 33; - $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('getId') - ->willReturn($cartId); - - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $this->quoteRepositoryMock->expects($this->once())->method('getActive') - ->with($cartId) - ->will($this->returnValue($quoteMock)); - $itemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false); - $quoteMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); - - $this->assertEquals([$itemMock], $this->repository->getList($maskedCartId)); + $itemId = 5; + $this->cartItemRepositoryMock->expects($this->once()) + ->method('deleteById') + ->with($this->cartId, $itemId) + ->willReturn(true); + $this->assertTrue($this->guestCartItemRepository->deleteById($this->maskedCartId, $itemId)); } /** * @return void */ - public function testDeleteById() + public function testDelete() { - $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $cartId = 33; - $this->quoteIdMaskFactoryMock->expects($this->any())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('load') - ->with($maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->any()) - ->method('getId') - ->willReturn($cartId); - - $itemId = 5; - $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setQuoteId') - ->with($cartId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setItemId') - ->with($itemId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteMock->expects($this->once())->method('removeItem'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - - $this->assertTrue($this->repository->deleteById($maskedCartId, $itemId)); + $this->cartItemRepositoryMock->expects($this->once()) + ->method('delete') + ->with($this->quoteItemMock); + $this->guestCartItemRepository->delete($this->quoteItemMock); } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php index 679c4e11fd748..fa878c0594ee7 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -38,7 +38,12 @@ public function __construct(\PHPUnit_Framework_TestCase $testCase) */ public function mockQuoteIdMask( $maskedCartId, $cartId) { - $quoteIdMaskMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false); + $quoteIdMaskMock = $this->testCase->getMock( + 'Magento\Quote\Model\QuoteIdMask', + ['load', 'getId', 'getMaskedId'], + [], + '', + false); $quoteIdMaskFactoryMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock); $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf(); From 716c9379f7965710bd447fc69f11a09e5daf93a0 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:28:05 +0300 Subject: [PATCH 095/115] MAGETWO-36382: Magento\Quote\Api\GuestBillingAddressManagement - usage of interface --- .../Model/GuestCart/GuestBillingAddressManagement.php | 9 ++++----- .../GuestCart/GuestBillingAddressManagementTest.php | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php index 8679ad781d8d7..61788f4920def 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php @@ -3,11 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestBillingAddressManagementInterface; -use Magento\Quote\Model\BillingAddressManagement; +use Magento\Quote\Api\BillingAddressManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; @@ -22,18 +21,18 @@ class GuestBillingAddressManagement implements GuestBillingAddressManagementInte private $quoteIdMaskFactory; /** - * @var BillingAddressManagement + * @var BillingAddressManagementInterface */ private $billingAddressManagement; /** * Constructs a quote billing address service object. * - * @param BillingAddressManagement $billingAddressManagement + * @param BillingAddressManagementInterface $billingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - BillingAddressManagement $billingAddressManagement, + BillingAddressManagementInterface $billingAddressManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php index d18203bf75139..52e611b25bde3 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php @@ -51,7 +51,7 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->addressMock = $this->getMock('\Magento\Quote\Model\Quote\Address', [], [], '', false); $this->billingAddressManagementMock = $this->getMock( - 'Magento\Quote\Model\BillingAddressManagement', + 'Magento\Quote\Api\BillingAddressManagementInterface', [], [], '', From 9d988a115a5dac0d453056929bb8748635d37ad6 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:31:10 +0300 Subject: [PATCH 096/115] MAGETWO-36377: Magento\Quote\Api\GuestCartRepositoryInterface - replaced concrete usage with interface --- .../Quote/Model/GuestCart/GuestCartRepository.php | 9 ++++----- .../Unit/Model/GuestCart/GuestCartRepositoryTest.php | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php index 50794238946d6..577f2b2a76b03 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -3,12 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCartRepositoryInterface; use Magento\Quote\Model\QuoteIdMask; -use Magento\Quote\Model\QuoteRepository; +use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\QuoteIdMaskFactory; /** @@ -22,18 +21,18 @@ class GuestCartRepository implements GuestCartRepositoryInterface protected $quoteIdMaskFactory; /** - * @var QuoteRepository + * @var CartRepositoryInterface */ protected $quoteRepository; /** * Initialize dependencies. * - * @param QuoteRepository $quoteRepository + * @param CartRepositoryInterface $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - QuoteRepository $quoteRepository, + CartRepositoryInterface $quoteRepository, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php index cc2b21cf28c65..28096160fc0b4 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -4,7 +4,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Test\Unit\Model\GuestCart; class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase @@ -47,7 +46,7 @@ class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock( 'Magento\Quote\Model\QuoteRepository', [], [], '', false); + $this->quoteRepositoryMock = $this->getMock( 'Magento\Quote\Api\CartRepositoryInterface', [], [], '', false); $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; From 385a6354962b279fc152a773a437e0a0e3867035 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:33:51 +0300 Subject: [PATCH 097/115] MAGETWO-36379: Magento\Quote\Api\GuestCouponManagement - replaced concrete usage with interface --- .../Quote/Model/GuestCart/GuestCouponManagement.php | 9 ++++----- .../Unit/Model/GuestCart/GuestCouponManagementTest.php | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 6ec630e25e52e..7f4d098594312 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -4,11 +4,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Model\GuestCart; use Magento\Quote\Api\GuestCouponManagementInterface; -use Magento\Quote\Model\CouponManagement; +use Magento\Quote\Api\CouponManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; @@ -23,18 +22,18 @@ class GuestCouponManagement implements GuestCouponManagementInterface private $quoteIdMaskFactory; /** - * @var CouponManagement + * @var CouponManagementInterface */ private $couponManagement; /** * Constructs a coupon read service object. * - * @param CouponManagement $couponManagement + * @param CouponManagementInterface $couponManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - CouponManagement $couponManagement, + CouponManagementInterface $couponManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php index e3b93363b237b..b1b1d1647485f 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php @@ -4,7 +4,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Test\Unit\Model\GuestCart; class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase @@ -47,7 +46,7 @@ class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->couponManagementMock = $this->getMock( 'Magento\Quote\Model\CouponManagement', [], [], '', false); + $this->couponManagementMock = $this->getMock( 'Magento\Quote\Api\CouponManagementInterface', [], [], '', false); $this->couponCode = 'test_coupon_code'; $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; From 707d616b4955b922d87def8432eb51e11dea0c97 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:42:02 +0300 Subject: [PATCH 098/115] MAGETWO-36381: Magento\Quote\Api\GuestShippingAddressManagement - replaced concrete usage with interface --- .../Model/GuestCart/GuestShippingAddressManagement.php | 9 ++++----- .../GuestCart/GuestShippingAddressManagementTest.php | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 1ef09d849ff57..11d4db9c51615 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -8,8 +8,7 @@ use Magento\Quote\Api\GuestShippingAddressManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Quote\Model\ShippingAddressManagement; - +use Magento\Quote\Api\ShippingAddressManagementInterface; /** * Shipping address management class for guest carts. */ @@ -21,18 +20,18 @@ class GuestShippingAddressManagement implements GuestShippingAddressManagementIn protected $quoteIdMaskFactory; /** - * @var ShippingAddressManagement + * @var ShippingAddressManagementInterface */ protected $shippingAddressManagement; /** * Constructs a quote shipping address write service object. * - * @param ShippingAddressManagement $shippingAddressManagement + * @param ShippingAddressManagementInterface $shippingAddressManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - ShippingAddressManagement $shippingAddressManagement, + ShippingAddressManagementInterface $shippingAddressManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->shippingAddressManagement = $shippingAddressManagement; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php index e4c9d4beadde5..67e35a93bf73c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php @@ -4,7 +4,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Quote\Test\Unit\Model\GuestCart; class GuestShippingAddressManagementTest extends \PHPUnit_Framework_TestCase @@ -49,7 +48,7 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->shippingAddressManagementMock = $this->getMock( - 'Magento\Quote\Model\ShippingAddressManagement', + 'Magento\Quote\Api\ShippingAddressManagementInterface', [], [], '', From 300d8db01ae93feae438d614be5fbf36ae244ff7 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 21 Apr 2015 19:42:37 +0300 Subject: [PATCH 099/115] MAGETWO-36380: Magento\Quote\Api\GuestPaymentMethodManagement - replaced concrete usage with interface --- .../Model/GuestCart/GuestPaymentMethodManagement.php | 8 ++++---- .../Model/GuestCart/GuestPaymentMethodManagementTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php index 3b65d502b3cd4..b0b99599ef14d 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php @@ -5,7 +5,7 @@ */ namespace Magento\Quote\Model\GuestCart; -use Magento\Quote\Model\PaymentMethodManagement; +use Magento\Quote\Api\PaymentMethodManagementInterface; use Magento\Quote\Api\GuestPaymentMethodManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; @@ -21,18 +21,18 @@ class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterf protected $quoteIdMaskFactory; /** - * @var PaymentMethodManagement + * @var PaymentMethodManagementInterface */ protected $paymentMethodManagement; /** * Initialize dependencies. * - * @param PaymentMethodManagement $paymentMethodManagement + * @param PaymentMethodManagementInterface $paymentMethodManagement * @param QuoteIdMaskFactory $quoteIdMaskFactory */ public function __construct( - PaymentMethodManagement $paymentMethodManagement, + PaymentMethodManagementInterface $paymentMethodManagement, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php index 54f23a8904fc1..ebde097f89bd4 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -46,7 +46,7 @@ protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->paymentMethodManagementMock = $this->getMock( - 'Magento\Quote\Model\PaymentMethodManagement', + 'Magento\Quote\Api\PaymentMethodManagementInterface', [], [], '', From 453c4950b16f2e6b34efc28fe403c318c6afd866 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Tue, 21 Apr 2015 13:57:10 -0500 Subject: [PATCH 100/115] MAGETWO-36514: Fix builds - added phpdoc - removed unused variables in tests --- .../Magento/Quote/Model/Webapi/ParamOverriderCartId.php | 9 +++++++++ .../Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php | 6 ------ .../Webapi/Controller/Rest/ParamOverriderCustomerId.php | 8 ++++++++ .../Magento/Quote/Api/CartTotalRepositoryTest.php | 1 - 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php index 7034e078d99f6..8bb62f55c5246 100644 --- a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -26,6 +26,12 @@ class ParamOverriderCartId implements ParamOverriderInterface */ private $cartManagement; + /** + * Constructs an object to override the cart ID parameter on a request. + * + * @param UserContextInterface $userContext + * @param CartManagementInterface $cartManagement + */ public function __construct( UserContextInterface $userContext, CartManagementInterface $cartManagement @@ -34,6 +40,9 @@ public function __construct( $this->cartManagement = $cartManagement; } + /** + * {@inheritDoc} + */ public function getOverridenValue() { try { diff --git a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php index b70dac7130076..f5021057eef71 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php @@ -69,7 +69,6 @@ public function testGetOverridenValueIsCustomerAndCartExists() public function testGetOverridenValueIsCustomerAndCartDoesNotExist() { - $retValue = 'retValue'; $customerId = 1; $this->userContext->expects($this->once()) @@ -79,8 +78,6 @@ public function testGetOverridenValueIsCustomerAndCartDoesNotExist() ->method('getUserId') ->will($this->returnValue($customerId)); - $cart = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface') - ->getMockForAbstractClass(); $this->cartManagement->expects($this->once()) ->method('getCartForCustomer') ->with($customerId) @@ -91,7 +88,6 @@ public function testGetOverridenValueIsCustomerAndCartDoesNotExist() public function testGetOverridenValueIsCustomerAndCartIsNull() { - $retValue = 'retValue'; $customerId = 1; $this->userContext->expects($this->once()) @@ -101,8 +97,6 @@ public function testGetOverridenValueIsCustomerAndCartIsNull() ->method('getUserId') ->will($this->returnValue($customerId)); - $cart = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface') - ->getMockForAbstractClass(); $this->cartManagement->expects($this->once()) ->method('getCartForCustomer') ->with($customerId) diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php index 15bd8bee64c18..e8fee7eeea43b 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -19,11 +19,19 @@ class ParamOverriderCustomerId implements ParamOverriderInterface */ private $userContext; + /** + * Constructs an object to override the customer ID parameter on a request. + * + * @param UserContextInterface $userContext + */ public function __construct(UserContextInterface $userContext) { $this->userContext = $userContext; } + /** + * {@inheritDoc} + */ public function getOverridenValue() { if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php index c2777f4e716e0..406b755d77dd1 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartTotalRepositoryTest.php @@ -189,7 +189,6 @@ public function testGetMyTotals() /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create('Magento\Quote\Model\Quote'); $quote->load('test_order_1', 'reserved_order_id'); - $cartId = $quote->getId(); $serviceInfo = [ 'rest' => [ From 665ff1921ad7e1cecdd8d8268447372193b13c07 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 21 Apr 2015 15:55:01 -0500 Subject: [PATCH 101/115] MAGETWO-36378: Magento\Quote\Api\GuestCartManagement - Remove \Magento\Quote\Model\GuestCart\GuestCartManagement::getCartForCustomer - Remove associated unit test case --- .../Quote/Model/GuestCart/GuestCartManagement.php | 12 ------------ .../Model/GuestCart/GuestCartManagementTest.php | 14 -------------- 2 files changed, 26 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 62966b0c86f88..a1fc33a72c4d3 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -84,16 +84,4 @@ public function placeOrder($cartId) $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->quoteManagement->placeOrder($quoteIdMask->getId()); } - - /** - * {@inheritdoc} - */ - public function getCartForCustomer($customerId) - { - $cart = $this->quoteRepository->getActiveForCustomer($customerId); - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cart->getId(), 'masked_id'); - $cart->setId($quoteIdMask->getId()); - return $cart; - } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php index cc567b0262f78..b1f04f3a0c394 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php @@ -115,18 +115,4 @@ public function testPlaceOrder() $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); } - - public function testGetCartForCustomer() - { - $maskedCartId = 'masked1cart2id3'; - $cartId = 1; - $orderId = 1; - - $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf(); - $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId); - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId); - - $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); - } } From 3c759b5cca4a04e45c8ce13dbee2cbfd044568d5 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 21 Apr 2015 16:43:01 -0500 Subject: [PATCH 102/115] MAGETWO-36378: Magento\Quote\Api\GuestCartManagement - Remove $quoteRepository from the parameters of GuestCartManagement::__construct - Update unit test accordingly --- .../Magento/Quote/Model/GuestCart/GuestCartManagement.php | 8 -------- .../Test/Unit/Model/GuestCart/GuestCartManagementTest.php | 2 -- 2 files changed, 10 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index a1fc33a72c4d3..dff7f2b4a94fd 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -25,11 +25,6 @@ class GuestCartManagement implements GuestCartManagementInterface */ protected $quoteManagement; - /** - * @var QuoteRepository - */ - protected $quoteRepository; - /** * @var QuoteIdMaskFactory */ @@ -39,17 +34,14 @@ class GuestCartManagement implements GuestCartManagementInterface * Initialize dependencies. * * @param CartManagementInterface $quoteManagement - * @param QuoteRepository $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( CartManagementInterface $quoteManagement, - QuoteRepository $quoteRepository, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteManagement = $quoteManagement; - $this->quoteRepository = $quoteRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php index b1f04f3a0c394..444aa62322a04 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php @@ -47,7 +47,6 @@ protected function setUp() true, [] ); - $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); $this->quoteIdMaskFactoryMock = $this->getMock( 'Magento\Quote\Model\QuoteIdMaskFactory', ['create'], @@ -67,7 +66,6 @@ protected function setUp() 'Magento\Quote\Model\GuestCart\GuestCartManagement', [ 'quoteManagement' => $this->quoteManagementMock, - 'quoteRepository' => $this->quoteRepositoryMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); From 9dbffdb79420ee17f5ab0c2917531266e41194e1 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Tue, 21 Apr 2015 16:55:09 -0500 Subject: [PATCH 103/115] MAGETWO-36378: Magento\Quote\Api\GuestCartManagement - Remove \Magento\Quote\Model\GuestCart\GuestCartManagement::getCartForCustomer - Remove $quoteRepository from the parameters of GuestCartManagement::__construct - Update unit test accordingly --- .../Model/GuestCart/GuestCartManagement.php | 22 ------------------- .../GuestCart/GuestCartManagementTest.php | 16 -------------- 2 files changed, 38 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php index 62966b0c86f88..243c70f95e13e 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -10,8 +10,6 @@ use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Magento\Quote\Model\QuoteManagement; -use Magento\Quote\Model\QuoteRepository; /** * Cart Management class for guest carts. @@ -25,11 +23,6 @@ class GuestCartManagement implements GuestCartManagementInterface */ protected $quoteManagement; - /** - * @var QuoteRepository - */ - protected $quoteRepository; - /** * @var QuoteIdMaskFactory */ @@ -39,17 +32,14 @@ class GuestCartManagement implements GuestCartManagementInterface * Initialize dependencies. * * @param CartManagementInterface $quoteManagement - * @param QuoteRepository $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( CartManagementInterface $quoteManagement, - QuoteRepository $quoteRepository, QuoteIdMaskFactory $quoteIdMaskFactory ) { $this->quoteManagement = $quoteManagement; - $this->quoteRepository = $quoteRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; } @@ -84,16 +74,4 @@ public function placeOrder($cartId) $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->quoteManagement->placeOrder($quoteIdMask->getId()); } - - /** - * {@inheritdoc} - */ - public function getCartForCustomer($customerId) - { - $cart = $this->quoteRepository->getActiveForCustomer($customerId); - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cart->getId(), 'masked_id'); - $cart->setId($quoteIdMask->getId()); - return $cart; - } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php index cc567b0262f78..444aa62322a04 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php @@ -47,7 +47,6 @@ protected function setUp() true, [] ); - $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false); $this->quoteIdMaskFactoryMock = $this->getMock( 'Magento\Quote\Model\QuoteIdMaskFactory', ['create'], @@ -67,7 +66,6 @@ protected function setUp() 'Magento\Quote\Model\GuestCart\GuestCartManagement', [ 'quoteManagement' => $this->quoteManagementMock, - 'quoteRepository' => $this->quoteRepositoryMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock ] ); @@ -115,18 +113,4 @@ public function testPlaceOrder() $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); } - - public function testGetCartForCustomer() - { - $maskedCartId = 'masked1cart2id3'; - $cartId = 1; - $orderId = 1; - - $this->quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf(); - $this->quoteIdMaskMock->expects($this->once())->method('getId')->willReturn($maskedCartId); - $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock); - $this->quoteManagementMock->expects($this->once())->method('placeOrder')->willReturn($orderId); - - $this->assertEquals($orderId, $this->guestCartManagement->placeOrder($cartId)); - } } From 912c613d74a25210df0ed75e7d78b0e6bbffd171 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 21 Apr 2015 18:08:17 -0500 Subject: [PATCH 104/115] MAGETWO-36189: Customer-facing resources in Sales & Checkout APIs - "/mine" APIs - Fix misspelling of overriden to overridden --- .../Magento/Quote/Model/Webapi/ParamOverriderCartId.php | 2 +- .../Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php | 8 ++++---- .../Webapi/Controller/Rest/ParamOverriderCustomerId.php | 2 +- .../Magento/Webapi/Controller/Rest/ParamsOverrider.php | 2 +- .../Unit/Controller/Rest/ParamOverriderCustomerIdTest.php | 4 ++-- .../Webapi/Rest/Request/ParamOverriderInterface.php | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php index 8bb62f55c5246..3f5b280d505d2 100644 --- a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -43,7 +43,7 @@ public function __construct( /** * {@inheritDoc} */ - public function getOverridenValue() + public function getOverriddenValue() { try { if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { diff --git a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php index f5021057eef71..06945b656e687 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php @@ -64,7 +64,7 @@ public function testGetOverridenValueIsCustomerAndCartExists() ->method('getId') ->will($this->returnValue($retValue)); - $this->assertSame($retValue, $this->model->getOverridenValue()); + $this->assertSame($retValue, $this->model->getOverriddenValue()); } public function testGetOverridenValueIsCustomerAndCartDoesNotExist() @@ -83,7 +83,7 @@ public function testGetOverridenValueIsCustomerAndCartDoesNotExist() ->with($customerId) ->will($this->throwException(new NoSuchEntityException())); - $this->assertNull($this->model->getOverridenValue()); + $this->assertNull($this->model->getOverriddenValue()); } public function testGetOverridenValueIsCustomerAndCartIsNull() @@ -102,7 +102,7 @@ public function testGetOverridenValueIsCustomerAndCartIsNull() ->with($customerId) ->will($this->returnValue(null)); - $this->assertNull($this->model->getOverridenValue()); + $this->assertNull($this->model->getOverriddenValue()); } public function testGetOverridenValueIsNotCustomer() @@ -111,6 +111,6 @@ public function testGetOverridenValueIsNotCustomer() ->method('getUserType') ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); - $this->assertNull($this->model->getOverridenValue()); + $this->assertNull($this->model->getOverriddenValue()); } } diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php index e8fee7eeea43b..09a2756929399 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -32,7 +32,7 @@ public function __construct(UserContextInterface $userContext) /** * {@inheritDoc} */ - public function getOverridenValue() + public function getOverriddenValue() { if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { return $this->userContext->getUserId(); diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 5a998602fc9c5..f7b4f4605a7a6 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -44,7 +44,7 @@ public function override(array $inputData, array $parameters) if ($paramData[Converter::KEY_FORCE] || !$this->isNestedArrayValueSet($inputData, $arrayKeys)) { $paramValue = $paramData[Converter::KEY_VALUE]; if (isset($this->paramOverriders[$paramValue])) { - $value = $this->paramOverriders[$paramValue]->getOverridenValue(); + $value = $this->paramOverriders[$paramValue]->getOverriddenValue(); } else { $value = $paramData[Converter::KEY_VALUE]; } diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php index 94d9ff013295e..8e46dccd6e2af 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php @@ -45,7 +45,7 @@ public function testGetOverridenValueIsCustomer() ->method('getUserId') ->will($this->returnValue($retValue)); - $this->assertSame($retValue, $this->model->getOverridenValue()); + $this->assertSame($retValue, $this->model->getOverriddenValue()); } public function testGetOverridenValueIsNotCustomer() @@ -54,6 +54,6 @@ public function testGetOverridenValueIsNotCustomer() ->method('getUserType') ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); - $this->assertNull($this->model->getOverridenValue()); + $this->assertNull($this->model->getOverriddenValue()); } } diff --git a/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php index 0403973a58ffc..92d748e923eb1 100644 --- a/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php @@ -29,9 +29,9 @@ interface ParamOverriderInterface { /** - * Returns the overriden value to use. + * Returns the overridden value to use. * * @return string|int|null */ - public function getOverridenValue(); + public function getOverriddenValue(); } From 6b0058a1841f6d1253328515848c3de4fb0ae166 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Tue, 21 Apr 2015 18:16:20 -0500 Subject: [PATCH 105/115] MAGETWO-36427: Magento\Quote\Api\GuestShippingMethodManagement - Fix unit tests to use GuestCartTestHelper --- .../GuestCartTotalRepositoryTest.php | 20 ++++++------- .../GuestShippingMethodManagementTest.php | 30 +++++++------------ 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php index 4d39e8edeea32..4db02b5caf14e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php @@ -57,6 +57,15 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 123; + + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); + $this->model = $this->objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestCartTotalRepository', [ @@ -64,17 +73,6 @@ public function setUp() 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, ] ); - - $this->quoteIdMaskFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($this->maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($this->cartId); } public function testGetTotals() diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php index 07a83b5e281e6..c91510a165fac 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php @@ -46,12 +46,16 @@ protected function setUp() $this->shippingMethodManagementMock = $this->getMockBuilder('Magento\Quote\Api\ShippingMethodManagementInterface') ->getMockForAbstractClass(); - $this->quoteIdMaskFactoryMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMaskFactory') - ->disableOriginalConstructor() - ->getMock(); - $this->quoteIdMaskMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMask') - ->disableOriginalConstructor() - ->getMock(); + + $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + $this->cartId = 867; + + $guestCartTestHelper = new GuestCartTestHelper($this); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); + $this->model = $objectManager->getObject( 'Magento\Quote\Model\GuestCart\GuestShippingMethodManagement', [ @@ -59,20 +63,6 @@ protected function setUp() 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, ] ); - - $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $this->cartId = 867; - - $this->quoteIdMaskFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('load') - ->with($this->maskedCartId, 'masked_id') - ->willReturn($this->quoteIdMaskMock); - $this->quoteIdMaskMock->expects($this->once()) - ->method('getId') - ->willReturn($this->cartId); } public function testSet() From eaef407cfafd5b27588f438ce535fe6d5030bc18 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 22 Apr 2015 14:23:01 +0300 Subject: [PATCH 106/115] MAGETWO-36382: Magento\Quote\Api\GuestBillingAddressManagement - fixed a typo in a method name --- .../Unit/Model/GuestCart/GuestBillingAddressManagementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php index 52e611b25bde3..4f6a3e63a632d 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php @@ -88,7 +88,7 @@ public function testGet() /** * @return void */ - public function testAssing() + public function testAssign() { $addressId = 1; $this->billingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId); From 692b42ec01f7f9c3dc2516b62bc8c83834fbef60 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 22 Apr 2015 14:34:46 +0300 Subject: [PATCH 107/115] MAGETWO-36426: Magento\Quote\Api\GuestCartTotalRepository - minor changes. removed excessive code --- .../Model/GuestCart/GuestCartTotalRepositoryTest.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php index 4db02b5caf14e..a8ef8d94e9fa2 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php @@ -36,23 +36,17 @@ class GuestCartTotalRepositoryTest extends \PHPUnit_Framework_TestCase /** * @var string */ - protected $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + protected $maskedCartId; /** * @var int */ - protected $cartId = 12; + protected $cartId; public function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteIdMaskFactoryMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMaskFactory') - ->disableOriginalConstructor() - ->getMock(); - $this->quoteIdMaskMock = $this->getMockBuilder('Magento\Quote\Model\QuoteIdMask') - ->disableOriginalConstructor() - ->getMock(); $this->cartTotalRepository = $this->getMockBuilder('Magento\Quote\Api\CartTotalRepositoryInterface') ->disableOriginalConstructor() ->getMock(); From b6491d69d06e0f65f33b8ced01b74bb9f3a8ef62 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Wed, 22 Apr 2015 15:41:01 +0300 Subject: [PATCH 108/115] MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart --- .../AddProductsToCartFromCustomerWishlistOnFrontendTest.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml index 0669962376823..1cf13be71e2cd 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml @@ -33,28 +33,24 @@ - Bug: MAGETWO-36224 downloadableProduct::with_two_separately_links - - Bug: MAGETWO-36224 configurableProduct::default 3 - Bug: MAGETWO-36224 bundleProduct::bundle_dynamic_product 2 - Bug: MAGETWO-36224 bundleProduct::bundle_fixed_product 2 From ea32f1de86cfeea809162ae6451ac0d96b8fc1fb Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Wed, 22 Apr 2015 09:48:33 -0500 Subject: [PATCH 109/115] MAGETWO-36514: Fix builds - fix misspellings of overridden in tests to prevent static test failures --- .../Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php | 8 ++++---- .../Unit/Controller/Rest/ParamOverriderCustomerIdTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php index 06945b656e687..cb83bf6112341 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php @@ -42,7 +42,7 @@ public function setUp() ); } - public function testGetOverridenValueIsCustomerAndCartExists() + public function testGetOverriddenValueIsCustomerAndCartExists() { $retValue = 'retValue'; $customerId = 1; @@ -67,7 +67,7 @@ public function testGetOverridenValueIsCustomerAndCartExists() $this->assertSame($retValue, $this->model->getOverriddenValue()); } - public function testGetOverridenValueIsCustomerAndCartDoesNotExist() + public function testGetOverriddenValueIsCustomerAndCartDoesNotExist() { $customerId = 1; @@ -86,7 +86,7 @@ public function testGetOverridenValueIsCustomerAndCartDoesNotExist() $this->assertNull($this->model->getOverriddenValue()); } - public function testGetOverridenValueIsCustomerAndCartIsNull() + public function testGetOverriddenValueIsCustomerAndCartIsNull() { $customerId = 1; @@ -105,7 +105,7 @@ public function testGetOverridenValueIsCustomerAndCartIsNull() $this->assertNull($this->model->getOverriddenValue()); } - public function testGetOverridenValueIsNotCustomer() + public function testGetOverriddenValueIsNotCustomer() { $this->userContext->expects($this->once()) ->method('getUserType') diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php index 8e46dccd6e2af..bf0f152eddf5f 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php @@ -34,7 +34,7 @@ public function setUp() ); } - public function testGetOverridenValueIsCustomer() + public function testGetOverriddenValueIsCustomer() { $retValue = 'retValue'; @@ -48,7 +48,7 @@ public function testGetOverridenValueIsCustomer() $this->assertSame($retValue, $this->model->getOverriddenValue()); } - public function testGetOverridenValueIsNotCustomer() + public function testGetOverriddenValueIsNotCustomer() { $this->userContext->expects($this->once()) ->method('getUserType') From 60ccb72cd6c101dbd6d30a4fbef8fabb5044a476 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Wed, 22 Apr 2015 10:50:32 -0500 Subject: [PATCH 110/115] MAGETWO-36560: Fix builds - fixed namespace error - fixed code formatting issues --- .../Model/GuestCart/GuestCouponManagement.php | 2 +- .../GuestShippingAddressManagement.php | 1 + .../GuestCart/GuestCartItemRepositoryTest.php | 24 ++++++++++--------- .../GuestCart/GuestCartRepositoryTest.php | 2 +- .../Model/GuestCart/GuestCartTestHelper.php | 5 ++-- .../GuestCart/GuestCouponManagementTest.php | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php index 7f4d098594312..90b1047ee3c86 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -21,7 +21,7 @@ class GuestCouponManagement implements GuestCouponManagementInterface */ private $quoteIdMaskFactory; - /** + /** * @var CouponManagementInterface */ private $couponManagement; diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php index 11d4db9c51615..f2ce3fb46fcf9 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -9,6 +9,7 @@ use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Api\ShippingAddressManagementInterface; + /** * Shipping address management class for guest carts. */ diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php index f1b0763559973..37b54ee80106c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php @@ -5,7 +5,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Quote\Test\Unit\Model\Quote\Item; +namespace Magento\Quote\Test\Unit\Model\GuestCart; class GuestCartItemRepositoryTest extends \PHPUnit_Framework_TestCase { @@ -58,10 +58,11 @@ protected function setUp() * @var \Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper */ $guestCartTestHelper = new \Magento\Quote\Test\Unit\Model\GuestCart\GuestCartTestHelper($this); - list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( - $this->maskedCartId, - $this->cartId - ); + list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = + $guestCartTestHelper->mockQuoteIdMask( + $this->maskedCartId, + $this->cartId + ); $this->quoteIdMaskMock->expects($this->any()) ->method('getMaskedId') @@ -80,12 +81,13 @@ protected function setUp() $this->cartItemRepositoryMock = $this->getMock('\Magento\Quote\Model\Quote\Item\Repository', [], [], '', false); $this->guestCartItemRepository = - $objectManager->getObject('Magento\Quote\Model\GuestCart\GuestCartItemRepository', - [ - 'repository' => $this->cartItemRepositoryMock, - 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, - ] - ); + $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestCartItemRepository', + [ + 'repository' => $this->cartItemRepositoryMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + ] + ); } /** diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php index 28096160fc0b4..3a7e2fac3ae37 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -46,7 +46,7 @@ class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock( 'Magento\Quote\Api\CartRepositoryInterface', [], [], '', false); + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Api\CartRepositoryInterface', [], [], '', false); $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php index fa878c0594ee7..25649077b5fd6 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -36,14 +36,15 @@ public function __construct(\PHPUnit_Framework_TestCase $testCase) * @param $cartId * @return array */ - public function mockQuoteIdMask( $maskedCartId, $cartId) + public function mockQuoteIdMask($maskedCartId, $cartId) { $quoteIdMaskMock = $this->testCase->getMock( 'Magento\Quote\Model\QuoteIdMask', ['load', 'getId', 'getMaskedId'], [], '', - false); + false + ); $quoteIdMaskFactoryMock = $this->testCase->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false); $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock); $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf(); diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php index b1b1d1647485f..74b00ed942f4a 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php @@ -46,7 +46,7 @@ class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->couponManagementMock = $this->getMock( 'Magento\Quote\Api\CouponManagementInterface', [], [], '', false); + $this->couponManagementMock = $this->getMock('Magento\Quote\Api\CouponManagementInterface', [], [], '', false); $this->couponCode = 'test_coupon_code'; $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; From 0023d118ab195aa4c00f33f397f053632196c32e Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Wed, 22 Apr 2015 14:37:39 -0500 Subject: [PATCH 111/115] MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository - removed delete methods from interface and implementation --- .../Quote/Api/GuestCartItemRepositoryInterface.php | 9 --------- .../Quote/Model/GuestCart/GuestCartItemRepository.php | 11 ----------- 2 files changed, 20 deletions(-) diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php index 1e327884d7bed..40138b5e0cfdc 100644 --- a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -30,15 +30,6 @@ public function getList($cartId); */ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem); - /** - * Delete cart item - * - * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem - * @return void - * @throws \Magento\Framework\Exception\CouldNotSaveException - */ - public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem); - /** * Removes the specified item from the specified cart. * diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php index ce6a2d24d269e..a3750601070b8 100644 --- a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -75,15 +75,4 @@ public function deleteById($cartId, $itemId) $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->repository->deleteById($quoteIdMask->getId(), $itemId); } - - /** - * {@inheritdoc} - */ - public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) - { - /** @var $quoteIdMask QuoteIdMask */ - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id'); - $cartItem->setQuoteId($quoteIdMask->getId()); - return $this->repository->delete($cartItem); - } } From 7d0e8a06bb336c1324e85bf508e83a20fefd039d Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Wed, 22 Apr 2015 15:14:39 -0500 Subject: [PATCH 112/115] MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository - removed delete methods from non-guest versions CartItemRepositoryInterface and Repository --- .../Quote/Api/CartItemRepositoryInterface.php | 9 ---- .../Quote/Model/Quote/Item/Repository.php | 15 +------ .../GuestCart/GuestCartItemRepositoryTest.php | 11 ----- .../Unit/Model/Quote/Item/RepositoryTest.php | 44 ++----------------- 4 files changed, 4 insertions(+), 75 deletions(-) diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php index e2ef0aa810229..96787607500b7 100644 --- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php @@ -27,15 +27,6 @@ public function getList($cartId); */ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem); - /** - * Delete cart item - * - * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem - * @return void - * @throws \Magento\Framework\Exception\CouldNotSaveException - */ - public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem); - /** * Removes the specified item from the specified cart. * diff --git a/app/code/Magento/Quote/Model/Quote/Item/Repository.php b/app/code/Magento/Quote/Model/Quote/Item/Repository.php index 0a4374e2e559a..35b928ecb37a0 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Repository.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Repository.php @@ -107,10 +107,8 @@ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem) /** * {@inheritdoc} */ - public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) + public function deleteById($cartId, $itemId) { - $cartId = $cartItem->getQuoteId(); - $itemId = $cartItem->getItemId(); /** * Quote. * @@ -129,18 +127,7 @@ public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem) } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not remove item from quote')); } - } - - /** - * {@inheritdoc} - */ - public function deleteById($cartId, $itemId) - { - $item = $this->itemDataFactory->create() - ->setQuoteId($cartId) - ->setItemId($itemId); - $this->delete($item); return true; } diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php index 37b54ee80106c..9535e3c1c7455 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php @@ -130,15 +130,4 @@ public function testDeleteById() ->willReturn(true); $this->assertTrue($this->guestCartItemRepository->deleteById($this->maskedCartId, $itemId)); } - - /** - * @return void - */ - public function testDelete() - { - $this->cartItemRepositoryMock->expects($this->once()) - ->method('delete') - ->with($this->quoteItemMock); - $this->guestCartItemRepository->delete($this->quoteItemMock); - } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php index 754c1bd1e467d..9081537f2790e 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php @@ -7,7 +7,7 @@ namespace Magento\Quote\Test\Unit\Model\Quote\Item; -use \Magento\Quote\Model\Quote\Item\Repository; +use Magento\Quote\Model\Quote\Item\Repository; class RepositoryTest extends \PHPUnit_Framework_TestCase { @@ -292,15 +292,13 @@ public function testDeleteWithInvalidQuoteItem() { $cartId = 11; $itemId = 5; - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once()) ->method('getItemById')->with($itemId)->will($this->returnValue(false)); $this->quoteMock->expects($this->never())->method('removeItem'); - $this->repository->delete($this->dataMock); + $this->repository->deleteById($cartId, $itemId); } /** @@ -312,8 +310,6 @@ public function testDeleteWithCouldNotSaveException() { $cartId = 11; $itemId = 5; - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once()) @@ -328,27 +324,7 @@ public function testDeleteWithCouldNotSaveException() ->with($this->quoteMock) ->willThrowException($exception); - $this->repository->delete($this->dataMock); - } - - /** - * @return void - */ - public function testDelete() - { - $cartId = 11; - $itemId = 5; - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); - $this->quoteMock->expects($this->once())->method('removeItem'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); - - $this->repository->delete($this->dataMock); + $this->repository->deleteById($cartId, $itemId); } /** @@ -363,13 +339,6 @@ public function testDeleteByIdForCustomer() ->with($customerId) ->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId); - $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setQuoteId') - ->with($cartId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setItemId') - ->with($itemId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once()) @@ -424,13 +393,6 @@ public function testDeleteById() { $cartId = 11; $itemId = 5; - $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setQuoteId') - ->with($cartId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('setItemId') - ->with($itemId)->willReturn($this->dataMock); - $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId); - $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId); $this->quoteRepositoryMock->expects($this->once()) ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once()) From 4e58f605ab968f5bcef286987b8500a877404144 Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Thu, 23 Apr 2015 11:07:38 -0500 Subject: [PATCH 113/115] MAGETWO-36591: Merge and build stabilization for Sales & Checkout APIs - Fix \Magento\Quote\Api\CartManagementTest by adding rollback to delete created orders - Move logic for deleting create quotes to the rollback fixture --- .../testsuite/Magento/Quote/Api/CartManagementTest.php | 2 -- .../testsuite/Magento/Quote/Api/GuestCartManagementTest.php | 1 - .../Checkout/_files/quote_with_check_payment_rollback.php | 3 +++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index 3393c28e0a579..b253b589daa9d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -366,7 +366,6 @@ public function testPlaceOrder() $items = $order->getAllItems(); $this->assertCount(1, $items); $this->assertEquals('Simple Product', $items[0]->getName()); - $quote->delete(); } /** @@ -401,7 +400,6 @@ public function testPlaceOrderForMyCart() $items = $order->getAllItems(); $this->assertCount(1, $items); $this->assertEquals('Simple Product', $items[0]->getName()); - $quote->delete(); } /** diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php index df3ec6e070269..9058a930b196d 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php @@ -341,6 +341,5 @@ public function testPlaceOrder() $items = $order->getAllItems(); $this->assertCount(1, $items); $this->assertEquals('Simple Product', $items[0]->getName()); - $quote->delete(); } } diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment_rollback.php index 7d04f85c78907..e999e00ff1433 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment_rollback.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment_rollback.php @@ -5,7 +5,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +require __DIR__ . '/../../Sales/_files/default_rollback.php'; /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get('Magento\Framework\Registry')->unregister('quote'); +$quote = $objectManager->create('Magento\Quote\Model\Quote'); +$quote->load('test_order_1', 'reserved_order_id')->delete(); From 9f2baf3e57f1029320f06325578a8907b80bc89d Mon Sep 17 00:00:00 2001 From: Andriy Nasinnyk Date: Thu, 23 Apr 2015 19:59:43 +0300 Subject: [PATCH 114/115] MAGETWO-36587: Coverage job unit test failure PersonalInfoTest::testGetCurrentStatus --- .../Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php index 29adf1a01cca1..efc9e86abe834 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php @@ -171,7 +171,7 @@ public function testGetCurrentStatus($status, $lastLoginAt, $lastVisitAt, $lastL 'customer/online_customers/online_minutes_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) - ->willReturn(60); //TODO: it's value mocked because unit tests run data providers before all testsuite + ->willReturn(240); //TODO: it's value mocked because unit tests run data providers before all testsuite $this->customerLog->expects($this->any())->method('getLastLoginAt')->willReturn($lastLoginAt); $this->customerLog->expects($this->any())->method('getLastVisitAt')->willReturn($lastVisitAt); From 87eee149cf1b6bf214f0e0656fa0a2e82c4a051f Mon Sep 17 00:00:00 2001 From: Yuxing Zheng Date: Thu, 23 Apr 2015 15:13:57 -0500 Subject: [PATCH 115/115] MAGETWO-36591: Merge and build stabilization for Sales & Checkout APIs - Clean up unused variable for \Magento\Quote\Api\CartManagementTest::testPlaceOrderForMyCart --- .../testsuite/Magento/Quote/Api/CartManagementTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php index b253b589daa9d..b8ec4629f3581 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartManagementTest.php @@ -382,9 +382,6 @@ public function testPlaceOrderForMyCart() ); $token = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - /** @var $quote \Magento\Quote\Model\Quote */ - $quote = $this->objectManager->create('Magento\Quote\Model\Quote')->load('test_order_1', 'reserved_order_id'); - $serviceInfo = [ 'rest' => [ 'resourcePath' => '/V1/carts/mine/order',