diff --git a/CHANGELOG.md b/CHANGELOG.md index efe5e58b320ea3465191f46c83ecf23556444609..67c355bcc7bd8b2d1b450ebc8240d3e19e9b4cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,36 +1,94 @@ +0.74.0-beta6 +============= +* Framework improvements + * Implemented a default exception handler for blocks + * Updated the root composer.json file + * Updated the setup tool to support different editions + * Added an ability to operate with Sales & Checkout APIs as guests and registered users + * Implemented the additional Sales & Checkout APIs for registered customers and guests + * Added unit tests to cover Sales & Checkout services code +* Various + * Standardized the hierarchy of exceptions + * Added bundle product API integration to Catalog +* Fixed bugs + * Fixed an issue where it was impossible to place an order using multiple address checkout + * Fixed an issue where DB timestamp columns with current_timestamp on update were not handled correctly + * Fixed an issue with FPT in partial invoices + * Fixed a performance issue in benchmark test + * Fixed the incorrect Exception class in the Magento_CurrencySymbol module + * Fixed an issue by letting MySQL determine a database table type instead of MyISAM + * Fixed an issue where test failures occurred when the database and the application were in different time zones + * Fixed an issue where \Magento\Framework\Phrase omitted placeholder values if no renderer was set + +0.74.0-beta5 +============= +* Various + * Added the new methods/fields in the Catalog Product Data Object + * Improved the Nginx configuration sample file for better web-server responsiveness and security + * Implemented the new look & feel for Create New Order page + * Removed the redundant DB constraints for cascade operations related to order management + * Implemented the mechanism of asynchronous email notifications after creation of Orders, Invoices, Shipments and Credit Memos + * Moved the join logic on application level in order to make DB separation possible in Reports component + * Implemented the TTL and event approaches of cache invalidation, introduced the full and the partial Varnish Cache flush + * Moved all Setup commands to Magento CLI + * Exposed CMS API as Web API +* Fixed bugs: + * Unexpected response for API "/V1/customers/password" service + * Can’t include a third-party link to frontend section via layout + * Specified details for Grouped product are lost after adding to wishlist + * Impossible to configure products in customer wishlist in Admin Panel + * Adding the product from wishlist to cart if more than one store view exists + * Specified product field custom options is not displayed in wishlist in Admin Panel + * Checkout doesn't work with JS bundling enabled in production mode + * Issue with price excluding tax when selecting downloadable links + * Undefined index warning in case the frontend cache information is missing in configuration file + * "New Order" email is not sent to customer after placing order via API service + * 503 error when placing order with multiple shipping addresses if mail transport doesn't exist + * Broken words for fields with long labels all over the Admin Panel + * Issue with saving 'is_virtual' flag in quote + * "Void" button available after "Deny Payment" operation + * Uninstall logic did not clean cache properly + * Obsolete code tests did not cover Tests folders + * Random fail of Magento\Log\Test\Unit\Model\VisitorTest +* GitHub issues: + * [#1149] (https://github.com/magento/magento2/issues/1149) -- Checkout Grand Total amount miscalculation + * [#1165] (https://github.com/magento/magento2/pull/1165) -- Fix typos + * [#1182] (https://github.com/magento/magento2/pull/1182) -- Update system.xml for 'fix' sortOrder in adminhtml + * [#1186] (https://github.com/magento/magento2/pull/1186) -- SalesSequence: Fixed composer installer dependency + 0.74.0-beta4 ============= * Various - * Implemented the getDefaultResult method, to be able to catch exceptions in FrontController and redirect user to the correct page - * The getDefaultResult method is invoked to return default result of action execution within controllers. It can be used to generate the ‘execute’ method result in action controllers - * Eliminated the unused exceptions. Exceptions that weren't linked to any logic were also eliminated and replaced with LocalizedException or its child classes - * Refactored all controllers where possible: the default exception handling logic moved to FrontController. Controllers that cannot be refactored do not conflict with the new logic + * Implemented the getDefaultResult method, to be able to catch exceptions in FrontController and redirect user to the correct page + * The getDefaultResult method is invoked to return default result of action execution within controllers. It can be used to generate the ‘execute’ method result in action controllers + * Eliminated the unused exceptions. Exceptions that weren't linked to any logic were also eliminated and replaced with LocalizedException or its child classes + * Refactored all controllers where possible: the default exception handling logic moved to FrontController. Controllers that cannot be refactored do not conflict with the new logic * Framework: - * Created Magento Console to perform CLI actions - * Introduced a new SalesSequence module that is responsible for documents numeration management across the Order Management System - * Implemented the mechanism of asynchronous indexing of sales entities grids + * Created Magento Console to perform CLI actions + * Introduced a new SalesSequence module that is responsible for documents numeration management across the Order Management System + * Implemented the mechanism of asynchronous indexing of sales entities grids * Setup - * Added the ConfigOption and ConfigOptionsList classes to be used by modules to manage deployment configuration - * Moved all existing segments logic to new classes - * Added the config:set command, which enables deployment configuration management - * Removed the old 'install-configuration' tool + * Added the ConfigOption and ConfigOptionsList classes to be used by modules to manage deployment configuration + * Moved all existing segments logic to new classes + * Added the config:set command, which enables deployment configuration management + * Removed the old 'install-configuration' tool * Functional tests: - * Fixed functional test for order placement from backend - * Replaced the end-to-end test for a product with MAP with an injectable test + * Fixed functional test for order placement from backend + * Replaced the end-to-end test for a product with MAP with an injectable test * Design - * Updated the Blank and Luma themes to enable theme (not only library) variables overriding in the _theme.less file of any inherited theme. Included LESS code standards to the UI Library documentation + * Updated the Blank and Luma themes to enable theme (not only library) variables overriding in the _theme.less file of any inherited theme. Included LESS code standards to the UI Library documentation * Fixed bugs: - * Fixed an issue where composite products could not be added to the order from the Recently Viewed Products section - * Fixed an issue where not all .js files were added to a bundle - * Fixed an issue where it was possible to save an incorrect IP value in the Developer Client Restriction field - * Fixed an issue where a raw DB error was thrown when trying to enter a custom variable with duplicated variable code + * Fixed an issue where composite products could not be added to the order from the Recently Viewed Products section + * Fixed an issue where not all .js files were added to a bundle + * Fixed an issue where it was possible to save an incorrect IP value in the Developer Client Restriction field + * Fixed an issue where a raw DB error was thrown when trying to enter a custom variable with duplicated variable code 0.74.0-beta3 ============= * API - * The orders were extended with the gift messages - * The page and block data and repository interfaces - * Updated the public API list + * The orders were extended with the gift messages + * The page and block data and repository interfaces + * Updated the public API list * Framework improvements * Improved the profile generator * Introduced the new environment for Jasmine tests @@ -54,7 +112,7 @@ * Fixed the Navigation Menu items on Admin Area * Various unit and integration tests bugs * GitHub issues and requests - [#675] (https://github.com/magento/magento2/issues/675) -- Fix for Textarea element cols and rows #675 + * [#675] (https://github.com/magento/magento2/issues/675) -- Fix for Textarea element cols and rows #675 0.74.0-beta2 ============= diff --git a/app/code/Magento/AdminNotification/Setup/InstallSchema.php b/app/code/Magento/AdminNotification/Setup/InstallSchema.php index 31b8842ee72e5502ff200716c3761e519c378a45..f8118f245e8ff3cebc4cdf1e2adfc5ee3075a4ba 100644 --- a/app/code/Magento/AdminNotification/Setup/InstallSchema.php +++ b/app/code/Magento/AdminNotification/Setup/InstallSchema.php @@ -45,7 +45,7 @@ class InstallSchema implements InstallSchemaInterface 'date_added', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Create date' )->addColumn( 'title', @@ -112,7 +112,7 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Create date' )->setComment( 'Admin System Messages' diff --git a/app/code/Magento/AdminNotification/composer.json b/app/code/Magento/AdminNotification/composer.json index 7e5a4bdb5cacaf241131af12c69b3e05cc85c758..354ef5fe45ea35de94ce81c1970bbb98e1a889ab 100644 --- a/app/code/Magento/AdminNotification/composer.json +++ b/app/code/Magento/AdminNotification/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Authorization/composer.json b/app/code/Magento/Authorization/composer.json index cb7aecdfeeddfaaedc824324f3e847ea866fac55..22341f8d0b4d16e93ce92006994cd36e1fbedb58 100644 --- a/app/code/Magento/Authorization/composer.json +++ b/app/code/Magento/Authorization/composer.json @@ -3,12 +3,12 @@ "description": "Authorization module provides access to Magento ACL functionality.", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Backend/composer.json b/app/code/Magento/Backend/composer.json index 5b734aadea7a945a15231731e879d4c9a22dd4ba..d229a7feb44b54367af4b052d1c43bc2a8f7e517 100644 --- a/app/code/Magento/Backend/composer.json +++ b/app/code/Magento/Backend/composer.json @@ -3,27 +3,27 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-developer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-cron": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-reports": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-user": "0.74.0-beta4", - "magento/module-backup": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-translation": "0.74.0-beta4", - "magento/module-require-js": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-developer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-cron": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-reports": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-user": "0.74.0-beta6", + "magento/module-backup": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-translation": "0.74.0-beta6", + "magento/module-require-js": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Backup/composer.json b/app/code/Magento/Backup/composer.json index a24b41c3b8bd79936342ab1601d03716f09122bd..f7f9a0371534346f0bc39f7d7087a12200428386 100644 --- a/app/code/Magento/Backup/composer.json +++ b/app/code/Magento/Backup/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-cron": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-cron": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Bundle/Api/Data/LinkInterface.php b/app/code/Magento/Bundle/Api/Data/LinkInterface.php index e16fad7f555bee04fb7f42743598acff877c6c6b..4e2268eae8f9a533b2bed55f7a4e97990f05d62e 100644 --- a/app/code/Magento/Bundle/Api/Data/LinkInterface.php +++ b/app/code/Magento/Bundle/Api/Data/LinkInterface.php @@ -9,6 +9,24 @@ namespace Magento\Bundle\Api\Data; interface LinkInterface extends \Magento\Framework\Api\ExtensibleDataInterface { + const PRICE_TYPE_FIXED = 0; + const PRICE_TYPE_PERCENT = 1; + + /** + * Get the identifier + * + * @return string|null + */ + public function getId(); + + /** + * Set id + * + * @param string $id + * @return $this + */ + public function setId($id); + /** * Get linked product sku * @@ -69,21 +87,6 @@ interface LinkInterface extends \Magento\Framework\Api\ExtensibleDataInterface */ public function setPosition($position); - /** - * Get is defined - * - * @return bool|null - */ - public function getIsDefined(); - - /** - * Set is defined - * - * @param bool $isDefined - * @return $this - */ - public function setIsDefined($isDefined); - /** * Get is default * diff --git a/app/code/Magento/Bundle/Api/ProductLinkManagementInterface.php b/app/code/Magento/Bundle/Api/ProductLinkManagementInterface.php index 2109cde0f95d452be9456038b8cfc2fa8ca30726..0529831f4094f7b936550e37914b91208f3d282e 100644 --- a/app/code/Magento/Bundle/Api/ProductLinkManagementInterface.php +++ b/app/code/Magento/Bundle/Api/ProductLinkManagementInterface.php @@ -11,12 +11,13 @@ interface ProductLinkManagementInterface /** * Get all children for Bundle product * - * @param string $productId + * @param string $productSku + * @param int $optionId * @return \Magento\Bundle\Api\Data\LinkInterface[] * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\InputException */ - public function getChildren($productId); + public function getChildren($productSku, $optionId = null); /** * Add child product to specified Bundle option by product sku @@ -31,10 +32,23 @@ interface ProductLinkManagementInterface */ public function addChildByProductSku($sku, $optionId, \Magento\Bundle\Api\Data\LinkInterface $linkedProduct); + /** + * @param string $sku + * @param \Magento\Bundle\Api\Data\LinkInterface $linkedProduct + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\InputException + * @return bool + */ + public function saveChild( + $sku, + \Magento\Bundle\Api\Data\LinkInterface $linkedProduct + ); + /** * @param \Magento\Catalog\Api\Data\ProductInterface $product * @param int $optionId - * @param Data\LinkInterface $linkedProduct + * @param \Magento\Bundle\Api\Data\LinkInterface $linkedProduct * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\InputException diff --git a/app/code/Magento/Bundle/Model/Link.php b/app/code/Magento/Bundle/Model/Link.php index eb99eff55e334fd9c878af2054243956b76a115c..fef35d3261b030978b73d67377a75ebf4c10a491 100644 --- a/app/code/Magento/Bundle/Model/Link.php +++ b/app/code/Magento/Bundle/Model/Link.php @@ -16,17 +16,34 @@ class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements /**#@+ * Constants */ + const KEY_ID = 'id'; const KEY_SKU = 'sku'; const KEY_OPTION_ID = 'option_id'; const KEY_QTY = 'qty'; const KEY_POSITION = 'position'; - const KEY_IS_DEFINED = 'is_defined'; const KEY_IS_DEFAULT = 'is_default'; const KEY_PRICE = 'price'; const KEY_PRICE_TYPE = 'price_type'; - const KEY_CAN_CHANGE_QUANTITY = 'can_change_quantity'; + const KEY_CAN_CHANGE_QUANTITY = 'selection_can_change_quantity'; /**#@-*/ + /** + * {@inheritdoc} + */ + public function getId() + { + return $this->getData(self::KEY_ID); + } + + /** + * {@inheritdoc} + */ + public function setId($id) + { + return $this->setData(self::KEY_ID, $id); + } + + /** * {@inheritdoc} */ @@ -59,14 +76,6 @@ class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements return $this->getData(self::KEY_POSITION); } - /** - * {@inheritdoc} - */ - public function getIsDefined() - { - return $this->getData(self::KEY_IS_DEFINED); - } - /** * {@inheritdoc} */ @@ -143,17 +152,6 @@ class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements return $this->setData(self::KEY_POSITION, $position); } - /** - * Set is defined - * - * @param bool $isDefined - * @return $this - */ - public function setIsDefined($isDefined) - { - return $this->setData(self::KEY_IS_DEFINED, $isDefined); - } - /** * Set is default * diff --git a/app/code/Magento/Bundle/Model/LinkManagement.php b/app/code/Magento/Bundle/Model/LinkManagement.php index fe2c0d85d7b168d21183813afc8b72ffbb9f280e..5d240c0517e595fc5812c5c1ad4e5d1d23530b6d 100644 --- a/app/code/Magento/Bundle/Model/LinkManagement.php +++ b/app/code/Magento/Bundle/Model/LinkManagement.php @@ -75,15 +75,18 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa /** * {@inheritdoc} */ - public function getChildren($productId) + public function getChildren($productSku, $optionId = null) { - $product = $this->productRepository->get($productId); + $product = $this->productRepository->get($productSku); if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { throw new InputException(__('Only implemented for bundle product')); } $childrenList = []; foreach ($this->getOptions($product) as $option) { + if ($optionId !== null && $option->getOptionId() != $optionId) { + continue; + } /** @var \Magento\Catalog\Model\Product $selection */ foreach ($option->getSelections() as $selection) { $childrenList[] = $this->buildLink($selection, $product); @@ -107,6 +110,93 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ + public function saveChild( + $sku, + \Magento\Bundle\Api\Data\LinkInterface $linkedProduct + ) { + $product = $this->productRepository->get($sku); + if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { + throw new InputException( + __('Product with specified sku: "%1" is not a bundle product', [$product->getSku()]) + ); + } + + /** @var \Magento\Catalog\Model\Product $linkProductModel */ + $linkProductModel = $this->productRepository->get($linkedProduct->getSku()); + if ($linkProductModel->isComposite()) { + throw new InputException(__('Bundle product could not contain another composite product')); + } + + if (!$linkedProduct->getId()) { + throw new InputException(__('Id field of product link is required')); + } + + /** @var \Magento\Bundle\Model\Selection $selectionModel */ + $selectionModel = $this->bundleSelection->create(); + $selectionModel->load($linkedProduct->getId()); + if (!$selectionModel->getId()) { + throw new InputException(__('Can not find product link with id "%1"', [$linkedProduct->getId()])); + } + + $selectionModel = $this->mapProductLinkToSelectionModel( + $selectionModel, + $linkedProduct, + $linkProductModel->getId(), + $product->getId() + ); + + try { + $selectionModel->save(); + } catch (\Exception $e) { + throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e); + } + + return true; + } + + /** + * @param \Magento\Bundle\Model\Selection $selectionModel + * @param \Magento\Bundle\Api\Data\LinkInterface $productLink + * @param string $linkedProductId + * @param string $parentProductId + * @return \Magento\Bundle\Model\Selection + */ + protected function mapProductLinkToSelectionModel( + \Magento\Bundle\Model\Selection $selectionModel, + \Magento\Bundle\Api\Data\LinkInterface $productLink, + $linkedProductId, + $parentProductId + ) { + $selectionModel->setProductId($linkedProductId); + $selectionModel->setParentProductId($parentProductId); + if (($productLink->getOptionId() !== null)) { + $selectionModel->setOptionId($productLink->getOptionId()); + } + if ($productLink->getPosition() !== null) { + $selectionModel->setPosition($productLink->getPosition()); + } + if ($productLink->getQty() !== null) { + $selectionModel->setSelectionQty($productLink->getQty()); + } + if ($productLink->getPriceType() !== null) { + $selectionModel->setSelectionPriceType($productLink->getPriceType()); + } + if ($productLink->getPrice() !== null) { + $selectionModel->setSelectionPriceValue($productLink->getPrice()); + } + if ($productLink->getCanChangeQuantity() !== null) { + $selectionModel->setSelectionCanChangeQty($productLink->getCanChangeQuantity()); + } + if ($productLink->getIsDefault() !== null) { + $selectionModel->setIsDefault($productLink->getIsDefault()); + } + + return $selectionModel; + } + + /** + * {@inheritdoc} + */ public function addChild( \Magento\Catalog\Api\Data\ProductInterface $product, $optionId, @@ -119,17 +209,10 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa } $options = $this->optionCollection->create(); - $options->setProductIdFilter($product->getId())->joinValues($this->storeManager->getStore()->getId()); - $isNewOption = true; - /** @var \Magento\Bundle\Model\Option $option */ - foreach ($options as $option) { - if ($option->getOptionId() == $optionId) { - $isNewOption = false; - break; - } - } + $options->setIdFilter($optionId); + $existingOption = $options->getFirstItem(); - if ($isNewOption) { + if (!$existingOption->getId()) { throw new InputException( __( 'Product with specified sku: "%1" does not contain option: "%2"', @@ -161,16 +244,13 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa } $selectionModel = $this->bundleSelection->create(); - $selectionModel->setOptionId($optionId) - ->setPosition($linkedProduct->getPosition()) - ->setSelectionQty($linkedProduct->getQty()) - ->setSelectionPriceType($linkedProduct->getPriceType()) - ->setSelectionPriceValue($linkedProduct->getPrice()) - ->setSelectionCanChangeQty($linkedProduct->getCanChangeQuantity()) - ->setProductId($linkProductModel->getId()) - ->setParentProductId($product->getId()) - ->setIsDefault($linkedProduct->getIsDefault()) - ->setWebsiteId($this->storeManager->getStore()->getWebsiteId()); + $selectionModel = $this->mapProductLinkToSelectionModel( + $selectionModel, + $linkedProduct, + $linkProductModel->getId(), + $product->getId() + ); + $selectionModel->setOptionId($optionId); try { $selectionModel->save(); @@ -242,8 +322,9 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa '\Magento\Bundle\Api\Data\LinkInterface' ); $link->setIsDefault($selection->getIsDefault()) + ->setId($selection->getSelectionId()) ->setQty($selection->getSelectionQty()) - ->setIsDefined($selection->getSelectionCanChangeQty()) + ->setCanChangeQuantity($selection->getSelectionCanChangeQty()) ->setPrice($selectionPrice) ->setPriceType($selectionPriceType); return $link; @@ -251,7 +332,7 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa /** * @param \Magento\Catalog\Api\Data\ProductInterface $product - * @return \Magento\Bundle\Api\Data\OptionTypeInterface[] + * @return \Magento\Bundle\Api\Data\OptionInterface[] */ private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product) { diff --git a/app/code/Magento/Bundle/Model/OptionRepository.php b/app/code/Magento/Bundle/Model/OptionRepository.php index 024b6f1cd2482780901ce6a8ca475a54e8e8785e..78caa83e801b3fd014eadfcfbbaf074c554d23f5 100644 --- a/app/code/Magento/Bundle/Model/OptionRepository.php +++ b/app/code/Magento/Bundle/Model/OptionRepository.php @@ -161,7 +161,6 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt /** * {@inheritdoc} - * @SuppressWarnings(PHPMD.NPathComplexity) */ public function save( \Magento\Catalog\Api\Data\ProductInterface $product, @@ -170,35 +169,25 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt $option->setStoreId($this->storeManager->getStore()->getId()); $option->setParentId($product->getId()); - if (!$option->getOptionId()) { + $optionId = $option->getOptionId(); + $linksToAdd = []; + if (!$optionId) { $option->setDefaultTitle($option->getTitle()); - $linksToAdd = is_array($option->getProductLinks()) ? $option->getProductLinks() : []; + if (is_array($option->getProductLinks())) { + $linksToAdd = $option->getProductLinks(); + } } else { $optionCollection = $this->type->getOptionsCollection($product); - $optionCollection->setIdFilter($option->getOptionId()); /** @var \Magento\Bundle\Model\Option $existingOption */ - $existingOption = $optionCollection->getFirstItem(); + $existingOption = $optionCollection->getItemById($option->getOptionId()); - if (!$existingOption->getOptionId()) { + if (!isset($existingOption) || !$existingOption->getOptionId()) { throw new NoSuchEntityException(__('Requested option doesn\'t exist')); } $option->setData(array_merge($existingOption->getData(), $option->getData())); - - /** @var \Magento\Bundle\Api\Data\LinkInterface[] $existingLinks */ - $existingLinks = is_array($existingOption->getProductLinks()) ? $existingOption->getProductLinks() : []; - - /** @var \Magento\Bundle\Api\Data\LinkInterface[] $newProductLinks */ - $newProductLinks = is_array($option->getProductLinks()) ? $option->getProductLinks() : []; - - /** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToDelete */ - $linksToDelete = array_udiff($existingLinks, $newProductLinks, [$this, 'compareLinks']); - foreach ($linksToDelete as $link) { - $this->linkManagement->removeChild($product->getSku(), $option->getOptionId(), $link->getSku()); - } - /** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToAdd */ - $linksToAdd = array_udiff($newProductLinks, $existingLinks, [$this, 'compareLinks']); + $this->updateOptionSelection($product, $option); } try { @@ -215,6 +204,50 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt return $option->getOptionId(); } + /** + * Update option selections + * + * @param \Magento\Catalog\Api\Data\ProductInterface $product + * @param \Magento\Bundle\Api\Data\OptionInterface $option + * @return $this + */ + protected function updateOptionSelection( + \Magento\Catalog\Api\Data\ProductInterface $product, + \Magento\Bundle\Api\Data\OptionInterface $option + ) { + $optionId = $option->getOptionId(); + $existingLinks = $this->linkManagement->getChildren($product->getSku(), $optionId); + $linksToAdd = []; + $linksToUpdate = []; + $linksToDelete = []; + if (is_array($option->getProductLinks())) { + $productLinks = $option->getProductLinks(); + foreach ($productLinks as $productLink) { + if (!$productLink->getId()) { + $linksToAdd[] = $productLink; + } else { + $linksToUpdate[] = $productLink; + } + } + /** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToDelete */ + $linksToDelete = array_udiff($existingLinks, $linksToUpdate, [$this, 'compareLinks']); + } + foreach ($linksToUpdate as $linkedProduct) { + $this->linkManagement->saveChild($product->getSku(), $linkedProduct); + } + foreach ($linksToDelete as $linkedProduct) { + $this->linkManagement->removeChild( + $product->getSku(), + $option->getOptionId(), + $linkedProduct->getSku() + ); + } + foreach ($linksToAdd as $linkedProduct) { + $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct); + } + return $this; + } + /** * @param string $sku * @return \Magento\Catalog\Api\Data\ProductInterface @@ -241,7 +274,7 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt \Magento\Bundle\Api\Data\LinkInterface $firstLink, \Magento\Bundle\Api\Data\LinkInterface $secondLink ) { - if ($firstLink->getSku() == $secondLink->getSku()) { + if ($firstLink->getId() == $secondLink->getId()) { return 0; } else { return 1; diff --git a/app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php b/app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php index 76b5dd84b3620c4ee3fa4da5eae8fc6490b602ce..16bce777104a27d1a45a9ad0c26bc7282f76a000 100644 --- a/app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php +++ b/app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php @@ -52,7 +52,10 @@ class BundleLoadOptions return $product; } - $productExtension = $this->productExtensionFactory->create(); + $productExtension = $product->getExtensionAttributes(); + if ($productExtension === null) { + $productExtension = $this->productExtensionFactory->create(); + } $productExtension->setBundleProductOptions($this->productOptionList->getItems($product)); $product->setExtensionAttributes($productExtension); diff --git a/app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php b/app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php index b0e9ee6de4700da4651aee4c31aaed0b03db657b..ccfd78d1054804c09bafbe0e38c2b1675f3efd51 100644 --- a/app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php +++ b/app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php @@ -17,8 +17,9 @@ class BundleSaveOptions /** * @param \Magento\Bundle\Api\ProductOptionRepositoryInterface $optionRepository */ - public function __construct(\Magento\Bundle\Api\ProductOptionRepositoryInterface $optionRepository) - { + public function __construct( + \Magento\Bundle\Api\ProductOptionRepositoryInterface $optionRepository + ) { $this->optionRepository = $optionRepository; } @@ -45,13 +46,37 @@ class BundleSaveOptions } /* @var \Magento\Bundle\Api\Data\OptionInterface[] $options */ - $bundleProductOptions = $product->getExtensionAttributes()->getBundleProductOptions(); + $extendedAttributes = $product->getExtensionAttributes(); + if ($extendedAttributes === null) { + return $result; + } + $bundleProductOptions = $extendedAttributes->getBundleProductOptions(); + if ($bundleProductOptions == null) { + return $result; + } - if (is_array($bundleProductOptions)) { - foreach ($bundleProductOptions as $option) { - $this->optionRepository->save($result, $option); + /** @var \Magento\Bundle\Api\Data\OptionInterface[] $bundleProductOptions */ + $existingOptions = $this->optionRepository->getList($product->getSku()); + $existingOptionsMap = []; + foreach ($existingOptions as $existingOption) { + $existingOptionsMap[$existingOption->getOptionId()] = $existingOption; + } + $updatedOptionIds = []; + foreach ($bundleProductOptions as $bundleOption) { + $optionId = $bundleOption->getOptionId(); + if ($optionId) { + $updatedOptionIds[] = $optionId; } } - return $result; + $optionIdsToDelete = array_diff(array_keys($existingOptionsMap), $updatedOptionIds); + //Handle new and existing options + foreach ($bundleProductOptions as $option) { + $this->optionRepository->save($result, $option); + } + //Delete options that are not in the list + foreach ($optionIdsToDelete as $optionId) { + $this->optionRepository->delete($existingOptionsMap[$optionId]); + } + return $subject->get($result->getSku(), false, $result->getStoreId(), true); } } diff --git a/app/code/Magento/Bundle/Model/Product/LinksList.php b/app/code/Magento/Bundle/Model/Product/LinksList.php index d0b6a78635b6a905d8ba9c9e9aa0c163ee56d53e..2d0076f67847b6df0b65e0b9af418bcf4f9934f1 100644 --- a/app/code/Magento/Bundle/Model/Product/LinksList.php +++ b/app/code/Magento/Bundle/Model/Product/LinksList.php @@ -61,8 +61,9 @@ class LinksList '\Magento\Bundle\Api\Data\LinkInterface' ); $productLink->setIsDefault($selection->getIsDefault()) + ->setId($selection->getSelectionId()) ->setQty($selection->getSelectionQty()) - ->setIsDefined($selection->getSelectionCanChangeQty()) + ->setCanChangeQuantity($selection->getSelectionCanChangeQty()) ->setPrice($selectionPrice) ->setPriceType($selectionPriceType); $productLinks[] = $productLink; diff --git a/app/code/Magento/Bundle/Model/Selection.php b/app/code/Magento/Bundle/Model/Selection.php index 919c54051566f0bc631c233bb0cfd7618955a907..1f68f9795dd2b66e4b9e8866aa1fb8c7de697f8c 100644 --- a/app/code/Magento/Bundle/Model/Selection.php +++ b/app/code/Magento/Bundle/Model/Selection.php @@ -8,6 +8,8 @@ namespace Magento\Bundle\Model; /** * Bundle Selection Model * + * @method int getSelectionId() + * @method \Magento\Bundle\Model\Selection setSelectionId(int $value) * @method int getOptionId() * @method \Magento\Bundle\Model\Selection setOptionId(int $value) * @method int getParentProductId() diff --git a/app/code/Magento/Bundle/Model/Source/Option/Selection/Price/Type.php b/app/code/Magento/Bundle/Model/Source/Option/Selection/Price/Type.php index 706de8be46be2f927b9783076ae2c2350564e273..a541ac48c12486820616203fb337e3b0ae610cc0 100644 --- a/app/code/Magento/Bundle/Model/Source/Option/Selection/Price/Type.php +++ b/app/code/Magento/Bundle/Model/Source/Option/Selection/Price/Type.php @@ -5,6 +5,8 @@ */ namespace Magento\Bundle\Model\Source\Option\Selection\Price; +use Magento\Bundle\Api\Data\LinkInterface; + /** * Extended Attributes Source Model * @@ -17,6 +19,9 @@ class Type implements \Magento\Framework\Option\ArrayInterface */ public function toOptionArray() { - return [['value' => '0', 'label' => __('Fixed')], ['value' => '1', 'label' => __('Percent')]]; + return [ + ['value' => LinkInterface::PRICE_TYPE_FIXED, 'label' => __('Fixed')], + ['value' => LinkInterface::PRICE_TYPE_PERCENT, 'label' => __('Percent')] + ]; } } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php index a1d9391b3e112a3785dfa4f7f5cdbff682db01f4..e4f49d48adcf35004827caf8d85fb4028f3b19ca 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php @@ -111,7 +111,7 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); $this->option = $this->getMockBuilder('Magento\Bundle\Model\Option') - ->setMethods(['getSelections', '__wakeup']) + ->setMethods(['getSelections', 'getOptionId', '__wakeup']) ->disableOriginalConstructor() ->getMock(); $this->optionCollection = $this->getMockBuilder('Magento\Bundle\Model\Resource\Option\Collection') @@ -193,14 +193,48 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase ->willReturnSelf(); $this->link->expects($this->once())->method('setIsDefault')->willReturnSelf(); $this->link->expects($this->once())->method('setQty')->willReturnSelf(); - $this->link->expects($this->once())->method('setIsDefined')->willReturnSelf(); + $this->link->expects($this->once())->method('setCanChangeQuantity')->willReturnSelf(); $this->link->expects($this->once())->method('setPrice')->willReturnSelf(); $this->link->expects($this->once())->method('setPriceType')->willReturnSelf(); + $this->link->expects($this->once())->method('setId')->willReturnSelf(); $this->linkFactory->expects($this->once())->method('create')->willReturn($this->link); $this->assertEquals([$this->link], $this->model->getChildren($productSku)); } + public function testGetChildrenWithOptionId() + { + $productSku = 'productSku'; + + $this->getOptions(); + + $this->productRepository->expects($this->any())->method('get')->with($this->equalTo($productSku)) + ->will($this->returnValue($this->product)); + + $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle')); + + $this->productType->expects($this->once())->method('setStoreFilter')->with( + $this->equalTo($this->storeId), + $this->product + ); + $this->productType->expects($this->once())->method('getSelectionsCollection') + ->with($this->equalTo($this->optionIds), $this->equalTo($this->product)) + ->will($this->returnValue($this->selectionCollection)); + $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product)) + ->will($this->returnValue($this->optionIds)); + + $this->optionCollection->expects($this->once())->method('appendSelections') + ->with($this->equalTo($this->selectionCollection)) + ->will($this->returnValue([$this->option])); + + $this->option->expects($this->any())->method('getOptionId')->will($this->returnValue(10)); + $this->option->expects($this->never())->method('getSelections'); + + $this->dataObjectHelperMock->expects($this->never())->method('populateWithArray'); + + $this->assertEquals([], $this->model->getChildren($productSku, 1)); + } + /** * @expectedException \Magento\Framework\Exception\InputException */ @@ -243,31 +277,29 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE )); - $productMock->expects($this->once())->method('getId')->will($this->returnValue('product_id')); $store = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); $store->expects($this->any())->method('getId')->will($this->returnValue(0)); - $option = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() - ->setMethods(['getOptionId', '__wakeup']) + $emptyOption = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() + ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getOptionId')->will($this->returnValue(2)); + $emptyOption->expects($this->once()) + ->method('getId') + ->will($this->returnValue(null)); $optionsCollectionMock = $this->getMock( '\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false ); $optionsCollectionMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($this->equalTo('product_id')) + ->method('setIdFilter') + ->with($this->equalTo(1)) ->will($this->returnSelf()); $optionsCollectionMock->expects($this->once()) - ->method('joinValues') - ->with($this->equalTo(0)) - ->will($this->returnSelf()); - $optionsCollectionMock->expects($this->any())->method('getIterator')->will( - $this->returnValue(new \ArrayIterator([$option])) - ); + ->method('getFirstItem') + ->will($this->returnValue($emptyOption)); + $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( $this->returnValue($optionsCollectionMock) ); @@ -304,22 +336,18 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $store->expects($this->any())->method('getId')->will($this->returnValue(0)); $option = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() - ->setMethods(['getOptionId', '__wakeup']) + ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getOptionId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsCollectionMock = $this->getMock('\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false); $optionsCollectionMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($this->equalTo('product_id')) + ->method('setIdFilter') + ->with($this->equalTo('1')) ->will($this->returnSelf()); $optionsCollectionMock->expects($this->once()) - ->method('joinValues') - ->with($this->equalTo(0)) - ->will($this->returnSelf()); - $optionsCollectionMock->expects($this->any())->method('getIterator')->will( - $this->returnValue(new \ArrayIterator([$option])) - ); + ->method('getFirstItem') + ->will($this->returnValue($option)); $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( $this->returnValue($optionsCollectionMock) ); @@ -359,22 +387,18 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $store->expects($this->any())->method('getId')->will($this->returnValue(0)); $option = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() - ->setMethods(['getOptionId', '__wakeup']) + ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getOptionId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsCollectionMock = $this->getMock('\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false); $optionsCollectionMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($this->equalTo('product_id')) + ->method('setIdFilter') + ->with($this->equalTo(1)) ->will($this->returnSelf()); $optionsCollectionMock->expects($this->once()) - ->method('joinValues') - ->with($this->equalTo(0)) - ->will($this->returnSelf()); - $optionsCollectionMock->expects($this->any())->method('getIterator')->will( - $this->returnValue(new \ArrayIterator([$option])) - ); + ->method('getFirstItem') + ->will($this->returnValue($option)); $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( $this->returnValue($optionsCollectionMock) ); @@ -420,24 +444,20 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $store->expects($this->any())->method('getId')->will($this->returnValue(0)); $option = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() - ->setMethods(['getOptionId', '__wakeup']) + ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getOptionId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsCollectionMock = $this->getMock( '\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false ); $optionsCollectionMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($this->equalTo('product_id')) + ->method('setIdFilter') + ->with($this->equalTo(1)) ->will($this->returnSelf()); $optionsCollectionMock->expects($this->once()) - ->method('joinValues') - ->with($this->equalTo(0)) - ->will($this->returnSelf()); - $optionsCollectionMock->expects($this->any())->method('getIterator')->will( - $this->returnValue(new \ArrayIterator([$option])) - ); + ->method('getFirstItem') + ->will($this->returnValue($option)); $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( $this->returnValue($optionsCollectionMock) ); @@ -452,7 +472,7 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($selections)); $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); - $selection = $this->getMock('\Magento\Framework\Object', ['save'], [], '', false); + $selection = $this->getMock('\Magento\Bundle\Model\Selection', ['save'], [], '', false); $selection->expects($this->once())->method('save') ->will( $this->returnCallback( @@ -491,24 +511,20 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $store->expects($this->any())->method('getId')->will($this->returnValue(0)); $option = $this->getMockBuilder('\Magento\Bundle\Model\Option')->disableOriginalConstructor() - ->setMethods(['getOptionId', '__wakeup']) + ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getOptionId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->will($this->returnValue(1)); $optionsCollectionMock = $this->getMock( '\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false ); $optionsCollectionMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($this->equalTo('product_id')) + ->method('setIdFilter') + ->with($this->equalTo(1)) ->will($this->returnSelf()); $optionsCollectionMock->expects($this->once()) - ->method('joinValues') - ->with($this->equalTo(0)) - ->will($this->returnSelf()); - $optionsCollectionMock->expects($this->any())->method('getIterator')->will( - $this->returnValue(new \ArrayIterator([$option])) - ); + ->method('getFirstItem') + ->will($this->returnValue($option)); $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( $this->returnValue($optionsCollectionMock) ); @@ -523,7 +539,7 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($selections)); $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); - $selection = $this->getMock('\Magento\Framework\Object', ['save', 'getId'], [], '', false); + $selection = $this->getMock('\Magento\Bundle\Model\Selection', ['save', 'getId'], [], '', false); $selection->expects($this->once())->method('save'); $selection->expects($this->once())->method('getId')->will($this->returnValue(42)); $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); @@ -531,6 +547,298 @@ class LinkManagementTest extends \PHPUnit_Framework_TestCase $this->assertEquals(42, $result); } + public function testSaveChild() + { + $id = 12; + $optionId = 1; + $position = 3; + $qty = 2; + $priceType = 1; + $price = 10.5; + $canChangeQuantity = true; + $isDefault = true; + $linkProductId = 45; + $parentProductId = 32; + $bundleProductSku = 'bundleProductSku'; + + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); + $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); + $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId)); + $productLink->expects($this->any())->method('getPosition')->will($this->returnValue($position)); + $productLink->expects($this->any())->method('getQty')->will($this->returnValue($qty)); + $productLink->expects($this->any())->method('getPriceType')->will($this->returnValue($priceType)); + $productLink->expects($this->any())->method('getPrice')->will($this->returnValue($price)); + $productLink->expects($this->any())->method('getCanChangeQuantity')->will($this->returnValue($canChangeQuantity)); + $productLink->expects($this->any())->method('getIsDefault')->will($this->returnValue($isDefault)); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + )); + $productMock->expects($this->any())->method('getId')->will($this->returnValue($parentProductId)); + + $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue($linkProductId)); + $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $this->productRepository + ->expects($this->at(0)) + ->method('get') + ->with($bundleProductSku) + ->will($this->returnValue($productMock)); + $this->productRepository + ->expects($this->at(1)) + ->method('get') + ->with('linked_product_sku') + ->will($this->returnValue($linkedProductMock)); + + $store = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); + $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); + $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + + $selection = $this->getMock( + '\Magento\Bundle\Model\Selection', + [ + 'save', + 'getId', + 'load', + 'setProductId', + 'setParentProductId', + 'setOptionId', + 'setPosition', + 'setSelectionQty', + 'setSelectionPriceType', + 'setSelectionPriceValue', + 'setSelectionCanChangeQty', + 'setIsDefault' + ], + [], + '', + false + ); + $selection->expects($this->once())->method('save'); + $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $selection->expects($this->any())->method('getId')->will($this->returnValue($id)); + $selection->expects($this->once())->method('setProductId')->with($linkProductId); + $selection->expects($this->once())->method('setParentProductId')->with($parentProductId); + $selection->expects($this->once())->method('setOptionId')->with($optionId); + $selection->expects($this->once())->method('setPosition')->with($position); + $selection->expects($this->once())->method('setSelectionQty')->with($qty); + $selection->expects($this->once())->method('setSelectionPriceType')->with($priceType); + $selection->expects($this->once())->method('setSelectionPriceValue')->with($price); + $selection->expects($this->once())->method('setSelectionCanChangeQty')->with($canChangeQuantity); + $selection->expects($this->once())->method('setIsDefault')->with($isDefault); + + $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $this->assertTrue($this->model->saveChild($bundleProductSku, $productLink)); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testSaveChildFailedToSave() + { + $id = 12; + $linkProductId = 45; + $parentProductId = 32; + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); + $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); + $bundleProductSku = 'bundleProductSku'; + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + )); + $productMock->expects($this->any())->method('getId')->will($this->returnValue($parentProductId)); + + $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue($linkProductId)); + $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $this->productRepository + ->expects($this->at(0)) + ->method('get') + ->with($bundleProductSku) + ->will($this->returnValue($productMock)); + $this->productRepository + ->expects($this->at(1)) + ->method('get') + ->with('linked_product_sku') + ->will($this->returnValue($linkedProductMock)); + + $store = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); + $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); + $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + + $selection = $this->getMock( + '\Magento\Bundle\Model\Selection', + [ + 'save', + 'getId', + 'load', + 'setProductId', + 'setParentProductId', + 'setSelectionId', + 'setOptionId', + 'setPosition', + 'setSelectionQty', + 'setSelectionPriceType', + 'setSelectionPriceValue', + 'setSelectionCanChangeQty', + 'setIsDefault' + ], + [], + '', + false + ); + $mockException = $this->getMock('\Exception'); + $selection->expects($this->once())->method('save')->will($this->throwException($mockException)); + $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $selection->expects($this->any())->method('getId')->will($this->returnValue($id)); + $selection->expects($this->once())->method('setProductId')->with($linkProductId); + + $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $this->model->saveChild($bundleProductSku, $productLink); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testSaveChildWithoutId() + { + $bundleProductSku = "bundleSku"; + $linkedProductSku = 'simple'; + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getId')->will($this->returnValue(null)); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + )); + + $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $this->productRepository + ->expects($this->at(0)) + ->method('get') + ->with($bundleProductSku) + ->will($this->returnValue($productMock)); + $this->productRepository + ->expects($this->at(1)) + ->method('get') + ->with($linkedProductSku) + ->will($this->returnValue($linkedProductMock)); + + $this->model->saveChild($bundleProductSku, $productLink); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Can not find product link with id "12345" + */ + public function testSaveChildWithInvalidId() + { + $id = 12345; + $linkedProductSku = 'simple'; + $bundleProductSku = "bundleProductSku"; + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + )); + + $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $this->productRepository + ->expects($this->at(0)) + ->method('get') + ->with($bundleProductSku) + ->will($this->returnValue($productMock)); + $this->productRepository + ->expects($this->at(1)) + ->method('get') + ->with($linkedProductSku) + ->will($this->returnValue($linkedProductMock)); + + $selection = $this->getMock( + '\Magento\Bundle\Model\Selection', + [ + 'getId', + 'load', + ], + [], + '', + false + ); + $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $selection->expects($this->any())->method('getId')->will($this->returnValue(null)); + + $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + + $this->model->saveChild($bundleProductSku, $productLink); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testSaveChildWithCompositeProductLink() + { + $bundleProductSku = "bundleProductSku"; + $id = 12; + $linkedProductSku = 'simple'; + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + )); + + $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(true)); + $this->productRepository + ->expects($this->at(0)) + ->method('get') + ->with($bundleProductSku) + ->will($this->returnValue($productMock)); + $this->productRepository + ->expects($this->at(1)) + ->method('get') + ->with($linkedProductSku) + ->will($this->returnValue($linkedProductMock)); + + $this->model->saveChild($bundleProductSku, $productLink); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testSaveChildWithSimpleProduct() + { + $id = 12; + $linkedProductSku = 'simple'; + $bundleProductSku = "bundleProductSku"; + + $productLink = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); + $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( + \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE + )); + + $this->productRepository->expects($this->once())->method('get')->with($bundleProductSku) + ->willReturn($productMock); + + $this->model->saveChild($bundleProductSku, $productLink); + } + public function testRemoveChild() { $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); diff --git a/app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php b/app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php index 7b91140a3bfe6fd0aa0196384d298e656afbb5bd..6c4fc418f0390d2e5262d425da13355a16724a34 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php @@ -335,8 +335,9 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase ->willReturn($optCollectionMock); $existingOptionMock = $this->getMock('\Magento\Bundle\Model\Option', ['getOptionId'], [], '', false); - $optCollectionMock->expects($this->once())->method('setIdFilter')->with($optionId)->willReturnSelf(); - $optCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($existingOptionMock); + $optCollectionMock->expects($this->once())->method('getItemById') + ->with($optionId) + ->willReturn($existingOptionMock); $existingOptionMock->expects($this->once())->method('getOptionId')->willReturn(null); $this->assertEquals($optionId, $this->model->save($productMock, $optionMock)); @@ -345,13 +346,16 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase /** * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ - public function testUpdate() + public function testSaveExistingOption() { $productId = 1; + $productSku = 'bundle_sku'; $storeId = 2; $optionId = 5; $existingOptionId = 5; - $existingOptionTitle = 'option_title'; + $existingLinkToUpdateId = '23'; + $existingLinkToDeleteId = '24'; + $productSkuToDelete = 'simple2'; $storeMock = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); $storeMock->expects($this->once())->method('getId')->willReturn($storeId); @@ -359,6 +363,7 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $productMock->expects($this->once())->method('getId')->willReturn($productId); + $productMock->expects($this->any())->method('getSku')->willReturn($productSku); $optionMock = $this->getMock( '\Magento\Bundle\Model\Option', [ @@ -378,6 +383,17 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase $optionMock->expects($this->once())->method('setParentId')->with($productId)->willReturnSelf(); $optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId); + $existingLinkToUpdate = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $existingLinkToUpdate->expects($this->any())->method('getId')->willReturn($existingLinkToUpdateId); + $existingLinkToDelete = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $existingLinkToDelete->expects($this->any())->method('getId')->willReturn($existingLinkToDeleteId); + $existingLinkToDelete->expects($this->once())->method('getSku')->willReturn($productSkuToDelete); + $existingLinks = [$existingLinkToUpdate, $existingLinkToDelete]; + $this->linkManagementMock->expects($this->once()) + ->method('getChildren') + ->with($productSku, $optionId) + ->willReturn($existingLinks); + $optCollectionMock = $this->getMock('\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false); $this->typeMock->expects($this->once()) ->method('getOptionsCollection') @@ -390,22 +406,183 @@ class OptionRepositoryTest extends \PHPUnit_Framework_TestCase '', false ); - $optCollectionMock->expects($this->once())->method('setIdFilter')->with($optionId)->willReturnSelf(); - $optCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($existingOptionMock); + $optCollectionMock->expects($this->once())->method('getItemById') + ->with($optionId) + ->willReturn($existingOptionMock); $existingOptionMock->expects($this->any())->method('getOptionId')->willReturn($existingOptionId); - $existingOptionMock->expects($this->once())->method('getProductLinks')->willReturn(null); - $linkedProductMock = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); - $optionMock->expects($this->exactly(2))->method('getProductLinks')->willReturn([$linkedProductMock]); + $productLinkUpdate = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLinkUpdate->expects($this->any())->method('getId')->willReturn($existingLinkToUpdateId); + $productLinkNew = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLinkNew->expects($this->any())->method('getId')->willReturn(null); + $optionMock->expects($this->exactly(2)) + ->method('getProductLinks') + ->willReturn([$productLinkUpdate, $productLinkNew]); $this->optionResourceMock->expects($this->once())->method('save')->with($optionMock)->willReturnSelf(); $this->linkManagementMock->expects($this->once()) ->method('addChild') - ->with($productMock, $optionId, $linkedProductMock) - ->willReturn(1); + ->with($productMock, $optionId, $productLinkNew); + $this->linkManagementMock->expects($this->once()) + ->method('saveChild') + ->with($productSku, $productLinkUpdate); + $this->linkManagementMock->expects($this->once()) + ->method('removeChild') + ->with($productSku, $optionId, $productSkuToDelete); + $this->assertEquals($optionId, $this->model->save($productMock, $optionMock)); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Requested option doesn't exist + */ + public function testSaveExistingOptionNoSuchOption() + { + $productId = 1; + $productSku = 'bundle_sku'; + $storeId = 2; + $optionId = 5; + + $storeMock = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $storeMock->expects($this->once())->method('getId')->willReturn($storeId); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getId')->willReturn($productId); + $productMock->expects($this->any())->method('getSku')->willReturn($productSku); + $optionMock = $this->getMock( + '\Magento\Bundle\Model\Option', + [ + 'setStoreId', + 'setParentId', + 'getOptionId', + ], + [], + '', + false + ); + $optionMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf(); + $optionMock->expects($this->once())->method('setParentId')->with($productId)->willReturnSelf(); + $optionMock->expects($this->any())->method('getOptionId')->willReturn($optionId); + + $optCollectionMock = $this->getMock('\Magento\Bundle\Model\Resource\Option\Collection', [], [], '', false); + $this->typeMock->expects($this->once()) + ->method('getOptionsCollection') + ->with($productMock) + ->willReturn($optCollectionMock); + $existingOptionMock = $this->getMock( + '\Magento\Bundle\Model\Option', + ['getOptionId', 'getTitle', 'getProductLinks'], + [], + '', + false + ); + $optCollectionMock->expects($this->once())->method('getItemById') + ->with($optionId) + ->willReturn($existingOptionMock); + $existingOptionMock->expects($this->any())->method('getOptionId')->willReturn(null); + + $this->model->save($productMock, $optionMock); + } + + public function testSaveNewOption() + { + $productId = 1; + $productSku = 'bundle_sku'; + $storeId = 2; + $optionId = 5; + + $storeMock = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $storeMock->expects($this->once())->method('getId')->willReturn($storeId); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getId')->willReturn($productId); + $productMock->expects($this->any())->method('getSku')->willReturn($productSku); + $optionMock = $this->getMock( + '\Magento\Bundle\Model\Option', + [ + 'setStoreId', + 'setParentId', + 'getProductLinks', + 'getOptionId', + 'setOptionId', + 'setDefaultTitle', + 'getTitle' + ], + [], + '', + false + ); + $optionMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf(); + $optionMock->expects($this->once())->method('setParentId')->with($productId)->willReturnSelf(); + $optionMock->method('getOptionId') + ->will($this->onConsecutiveCalls(null, $optionId, $optionId, $optionId, $optionId)); + + $productLink1 = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink2 = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $optionMock->expects($this->exactly(2)) + ->method('getProductLinks') + ->willReturn([$productLink1, $productLink2]); + + $this->optionResourceMock->expects($this->once())->method('save')->with($optionMock)->willReturnSelf(); + $this->linkManagementMock->expects($this->at(0)) + ->method('addChild') + ->with($productMock, $optionId, $productLink1); + $this->linkManagementMock->expects($this->at(1)) + ->method('addChild') + ->with($productMock, $optionId, $productLink2); $this->assertEquals($optionId, $this->model->save($productMock, $optionMock)); } + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @expectedExceptionMessage Could not save option + */ + public function testSaveCanNotSave() + { + $productId = 1; + $productSku = 'bundle_sku'; + $storeId = 2; + $optionId = 5; + + $storeMock = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $storeMock->expects($this->once())->method('getId')->willReturn($storeId); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $productMock->expects($this->once())->method('getId')->willReturn($productId); + $productMock->expects($this->any())->method('getSku')->willReturn($productSku); + $optionMock = $this->getMock( + '\Magento\Bundle\Model\Option', + [ + 'setStoreId', + 'setParentId', + 'getProductLinks', + 'getOptionId', + 'setOptionId', + 'setDefaultTitle', + 'getTitle' + ], + [], + '', + false + ); + $optionMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf(); + $optionMock->expects($this->once())->method('setParentId')->with($productId)->willReturnSelf(); + $optionMock->method('getOptionId')->will($this->onConsecutiveCalls(null, $optionId, $optionId, $optionId)); + + $productLink1 = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $productLink2 = $this->getMock('\Magento\Bundle\Api\Data\LinkInterface'); + $optionMock->expects($this->exactly(2)) + ->method('getProductLinks') + ->willReturn([$productLink1, $productLink2]); + + $this->optionResourceMock->expects($this->once())->method('save')->with($optionMock) + ->willThrowException($this->getMock('\Exception')); + $this->model->save($productMock, $optionMock); + } + public function testGetList() { $productSku = 'simple'; diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php index e4050d99040ca61dacc97b54731fd79e67719af1..77d92ff634334b7d1fbc04e3022a33d6eea06334 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php @@ -60,7 +60,6 @@ class BundleLoadOptionsTest extends \PHPUnit_Framework_TestCase public function testAroundLoad() { - $this->markTestSkipped('MAGETWO-34577'); $productMock = $this->getMock( '\Magento\Catalog\Model\Product', ['getTypeId', 'setExtensionAttributes'], @@ -82,6 +81,7 @@ class BundleLoadOptionsTest extends \PHPUnit_Framework_TestCase ->willReturn([$optionMock]); $productExtensionMock = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtension') ->disableOriginalConstructor() + ->setMethods(['setBundleProductOptions', 'getBundleProductOptions']) ->getMock(); $this->productExtensionFactory->expects($this->once()) ->method('create') diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleSaveOptionsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleSaveOptionsTest.php index 1615760e6dbee5b4ad44d0d30cd81b53b19e691e..62095af664f2b1c04fbd1332ba5c959149e04a4f 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleSaveOptionsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleSaveOptionsTest.php @@ -43,6 +43,11 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase */ protected $productBundleOptionsMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $productInterfaceFactoryMock; + /** * @var \Closure */ @@ -54,7 +59,7 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase $this->productOptionRepositoryMock = $this->getMock('Magento\Bundle\Api\ProductOptionRepositoryInterface'); $this->productMock = $this->getMock( 'Magento\Catalog\Model\Product', - ['getExtensionAttributes', 'getTypeId'], + ['getExtensionAttributes', 'getTypeId', 'getSku', 'getStoreId'], [], '', false @@ -62,10 +67,12 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase $this->closureMock = function () { return $this->productMock; }; - $this->plugin = new BundleSaveOptions($this->productOptionRepositoryMock); + $this->plugin = new BundleSaveOptions( + $this->productOptionRepositoryMock + ); $this->productExtensionMock = $this->getMock( 'Magento\Catalog\Api\Data\ProductExtension', - ['getBundleProductOptions'], + ['getBundleProductOptions', 'setBundleProductOptions'], [], '', false @@ -98,7 +105,7 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase ->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once()) ->method('getBundleProductOptions') - ->willReturn([]); + ->willReturn(null); $this->productOptionRepositoryMock->expects($this->never())->method('save'); @@ -110,20 +117,105 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase public function testAroundSaveWhenProductIsBundleWithOptions() { + $productSku = "bundle_sku"; + $option = $this->getMock('\Magento\Bundle\Api\Data\OptionInterface'); + $this->productMock->expects($this->once())->method('getTypeId')->willReturn('bundle'); + $this->productMock->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->productExtensionMock); + $this->productExtensionMock->expects($this->once()) + ->method('getBundleProductOptions') + ->willReturn([$option]); + + $this->productOptionRepositoryMock->expects($this->once())->method('save')->with($this->productMock, $option); + + $this->productMock->expects($this->exactly(2))->method('getSku') + ->will($this->returnValue($productSku)); + + $this->productOptionRepositoryMock->expects($this->once()) + ->method('getList') + ->with($productSku) + ->will($this->returnValue([])); + + $newProductMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterface') + ->disableOriginalConstructor()->getMock(); + $this->productRepositoryMock->expects($this->once()) + ->method('get') + ->with($productSku, false, null, true) + ->willReturn($newProductMock); + + $this->assertEquals( + $newProductMock, + $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock) + ); + } + + /** + * Test the case where the product has existing options + */ + public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions() + { + $existOption1Id = 10; + $existOption2Id = 11; + $productSku = 'bundle_sku'; + $existingOption1 = $this->getMock('\Magento\Bundle\Api\Data\OptionInterface'); + $existingOption1->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue($existOption1Id)); + $existingOption2 = $this->getMock('\Magento\Bundle\Api\Data\OptionInterface'); + $existingOption2->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue($existOption2Id)); + + $bundleOptionExisting = $this->getMock('\Magento\Bundle\Api\Data\OptionInterface'); + $bundleOptionExisting->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue($existOption1Id)); + + $bundleOptionNew = $this->getMock('\Magento\Bundle\Api\Data\OptionInterface'); + $bundleOptionNew->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue(null)); + $this->productMock->expects($this->once())->method('getTypeId')->willReturn('bundle'); $this->productMock->expects($this->once()) ->method('getExtensionAttributes') ->willReturn($this->productExtensionMock); $this->productExtensionMock->expects($this->once()) ->method('getBundleProductOptions') - ->willReturn([$this->productBundleOptionsMock]); + ->willReturn([$bundleOptionExisting, $bundleOptionNew]); + $this->productMock->expects($this->exactly(2))->method('getSku') + ->will($this->returnValue($productSku)); $this->productOptionRepositoryMock->expects($this->once()) + ->method('getList') + ->with($productSku) + ->will($this->returnValue([$existingOption1, $existingOption2])); + + $this->productOptionRepositoryMock + ->expects($this->at(1)) + ->method('save') + ->with($this->productMock, $bundleOptionExisting); + + $this->productOptionRepositoryMock + ->expects($this->at(1)) ->method('save') - ->with($this->productMock, $this->productBundleOptionsMock); + ->with($this->productMock, $bundleOptionNew); + + $this->productOptionRepositoryMock + ->expects($this->once()) + ->method('delete') + ->with($existingOption2); + + $newProductMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterface') + ->disableOriginalConstructor()->getMock(); + $this->productRepositoryMock->expects($this->once()) + ->method('get') + ->with($productSku, false, null, true) + ->willReturn($newProductMock); $this->assertEquals( - $this->productMock, + $newProductMock, $this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock) ); } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/LinksListTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/LinksListTest.php index 86c409a3de09e7bde03a28658c897ab6371f5bc0..0909834ce5914307bd82d13fa7bbfcecd3a07dc6 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/LinksListTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/LinksListTest.php @@ -64,6 +64,7 @@ class LinksListTest extends \PHPUnit_Framework_TestCase 'getIsDefault', 'getSelectionQty', 'getSelectionCanChangeQty', + 'getSelectionId', '__wakeup' ], [], @@ -89,6 +90,7 @@ class LinksListTest extends \PHPUnit_Framework_TestCase public function testLinksList() { $optionId = 665; + $selectionId = 1345; $this->productTypeMock->expects($this->once()) ->method('getSelectionsCollection') ->with([$optionId], $this->productMock) @@ -99,6 +101,7 @@ class LinksListTest extends \PHPUnit_Framework_TestCase ->willReturn('selection_price_type'); $this->selectionMock->expects($this->once())->method('getSelectionPriceValue')->willReturn(12); $this->selectionMock->expects($this->once())->method('getData')->willReturn(['some data']); + $this->selectionMock->expects($this->once())->method('getSelectionId')->willReturn($selectionId); $this->selectionMock->expects($this->once())->method('getIsDefault')->willReturn(true); $this->selectionMock->expects($this->once())->method('getSelectionQty')->willReturn(66); $this->selectionMock->expects($this->once())->method('getSelectionCanChangeQty')->willReturn(22); @@ -108,8 +111,9 @@ class LinksListTest extends \PHPUnit_Framework_TestCase ->with($linkMock, ['some data'], '\Magento\Bundle\Api\Data\LinkInterface')->willReturnSelf(); $linkMock->expects($this->once())->method('setIsDefault')->with(true)->willReturnSelf(); $linkMock->expects($this->once())->method('setQty')->with(66)->willReturnSelf(); - $linkMock->expects($this->once())->method('setIsDefined')->with(22)->willReturnSelf(); + $linkMock->expects($this->once())->method('setCanChangeQuantity')->with(22)->willReturnSelf(); $linkMock->expects($this->once())->method('setPrice')->with(12)->willReturnSelf(); + $linkMock->expects($this->once())->method('setId')->with($selectionId)->willReturnSelf(); $linkMock->expects($this->once()) ->method('setPriceType')->with('selection_price_type')->willReturnSelf(); $this->linkFactoryMock->expects($this->once())->method('create')->willReturn($linkMock); diff --git a/app/code/Magento/Bundle/composer.json b/app/code/Magento/Bundle/composer.json index 6838ab7155d141c5a9e853f45cc8687406b30a78..a16b4ad6d56cfb1002fae21f984ace5e9a5ea588 100644 --- a/app/code/Magento/Bundle/composer.json +++ b/app/code/Magento/Bundle/composer.json @@ -3,28 +3,28 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-catalog-rule": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-gift-message": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-catalog-rule": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-gift-message": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-webapi": "0.74.0-beta4" + "magento/module-webapi": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Bundle/etc/data_object.xml b/app/code/Magento/Bundle/etc/data_object.xml index 88e317dafc78c8ce9d0c9a3fe6f703b777361e4a..2b3da013978f971bb20baca3a5e0ca95f2b501fc 100644 --- a/app/code/Magento/Bundle/etc/data_object.xml +++ b/app/code/Magento/Bundle/etc/data_object.xml @@ -8,7 +8,5 @@ <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd"> <custom_attributes for="Magento\Catalog\Api\Data\ProductInterface"> <attribute code="bundle_product_options" type="Magento\Bundle\Api\Data\OptionInterface[]" /> - <attribute code="price_type" type="integer" /> - <attribute code="price_view" type="string" /> </custom_attributes> </config> diff --git a/app/code/Magento/Bundle/etc/webapi.xml b/app/code/Magento/Bundle/etc/webapi.xml index ec0dffcf1049e2d29da72bb80d02e8fba97ee316..550987ba13e669b5e2a5634384b3793d8932f97e 100644 --- a/app/code/Magento/Bundle/etc/webapi.xml +++ b/app/code/Magento/Bundle/etc/webapi.xml @@ -13,7 +13,13 @@ <resource ref="Magento_Catalog::products"/> </resources> </route> - <route url="/V1/bundle-products/:productId/children" method="GET"> + <route url="/V1/bundle-products/:sku/links/:id" method="PUT"> + <service class="Magento\Bundle\Api\ProductLinkManagementInterface" method="saveChild"/> + <resources> + <resource ref="Magento_Catalog::products"/> + </resources> + </route> + <route url="/V1/bundle-products/:productSku/children" method="GET"> <service class="Magento\Bundle\Api\ProductLinkManagementInterface" method="getChildren"/> <resources> <resource ref="Magento_Catalog::products"/> diff --git a/app/code/Magento/CacheInvalidate/composer.json b/app/code/Magento/CacheInvalidate/composer.json index 3fe142a52e825fe6bae3ab6d56e798302d3ba3c3..4e1062c5a74902db562b9e2c7ed010ff9ab5bdfa 100644 --- a/app/code/Magento/CacheInvalidate/composer.json +++ b/app/code/Magento/CacheInvalidate/composer.json @@ -3,12 +3,12 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-page-cache": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-page-cache": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Captcha/composer.json b/app/code/Magento/Captcha/composer.json index 6e9a81a004a19d00e0b7c93aa1a6b75d1594e0f7..dee103fd89226bade4029e318d5b99fd03bf2b30 100644 --- a/app/code/Magento/Captcha/composer.json +++ b/app/code/Magento/Captcha/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Catalog/Api/ProductRepositoryInterface.php b/app/code/Magento/Catalog/Api/ProductRepositoryInterface.php index 8205f68fca6095f9d516c01f5ad04be1a8515725..7fb25a7c046f5124a52ba8e50171112ca670c6c3 100644 --- a/app/code/Magento/Catalog/Api/ProductRepositoryInterface.php +++ b/app/code/Magento/Catalog/Api/ProductRepositoryInterface.php @@ -27,10 +27,11 @@ interface ProductRepositoryInterface * @param string $sku * @param bool $editMode * @param null|int $storeId + * @param bool $forceReload * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function get($sku, $editMode = false, $storeId = null); + public function get($sku, $editMode = false, $storeId = null, $forceReload = false); /** * Get info about product by product id @@ -38,10 +39,11 @@ interface ProductRepositoryInterface * @param int $productId * @param bool $editMode * @param null|int $storeId + * @param bool $forceReload * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getById($productId, $editMode = false, $storeId = null); + public function getById($productId, $editMode = false, $storeId = null, $forceReload = false); /** * Delete product diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 9dbbddcee68f828b225304bea6dad7050d74c275..318fad719e5c0c857db31f5cef1dc06570328116 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -64,6 +64,8 @@ class Helper public function initialize(\Magento\Catalog\Model\Product $product) { $productData = $this->request->getPost('product'); + unset($productData['custom_attributes']); + unset($productData['extension_attributes']); if ($productData) { $stockData = isset($productData['stock_data']) ? $productData['stock_data'] : []; diff --git a/app/code/Magento/Catalog/Model/Entity/Attribute.php b/app/code/Magento/Catalog/Model/Entity/Attribute.php old mode 100644 new mode 100755 index da907bde71f75ca5ef9f2147cfc89c3070ef8c41..ca1e3038e03909c756d7b793669393f78457656e --- a/app/code/Magento/Catalog/Model/Entity/Attribute.php +++ b/app/code/Magento/Catalog/Model/Entity/Attribute.php @@ -139,14 +139,14 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute * Processing object before save data * * @return \Magento\Framework\Model\AbstractModel - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { try { $this->attrLockValidator->validate($this); } catch (\Magento\Framework\Exception\LocalizedException $exception) { - throw new \Magento\Eav\Exception(__($exception->getMessage())); + throw new \Magento\Framework\Exception\LocalizedException(__($exception->getMessage())); } $this->setData('modulePrefix', self::MODULE_NAME); diff --git a/app/code/Magento/Catalog/Model/Plugin/ProductRepository/TransactionWrapper.php b/app/code/Magento/Catalog/Model/Plugin/ProductRepository/TransactionWrapper.php new file mode 100644 index 0000000000000000000000000000000000000000..1d940a5d7aee5e62da18e7a623ee2295b36afcea --- /dev/null +++ b/app/code/Magento/Catalog/Model/Plugin/ProductRepository/TransactionWrapper.php @@ -0,0 +1,102 @@ +<?php +/** + * Plugin for \Magento\Catalog\Api\ProductRepositoryInterface + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Catalog\Model\Plugin\ProductRepository; + +class TransactionWrapper +{ + /** + * @var \Magento\Catalog\Model\Resource\Product + */ + protected $resourceModel; + + /** + * @param \Magento\Catalog\Model\Resource\Product $resourceModel + */ + public function __construct( + \Magento\Catalog\Model\Resource\Product $resourceModel + ) { + $this->resourceModel = $resourceModel; + } + + /** + * @param \Magento\Catalog\Api\ProductRepositoryInterface $subject + * @param callable $proceed + * @param \Magento\Catalog\Api\Data\ProductInterface $product + * @param bool $saveOptions + * @return \Magento\Catalog\Api\Data\ProductInterface + * @throws \Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundSave( + \Magento\Catalog\Api\ProductRepositoryInterface $subject, + \Closure $proceed, + \Magento\Catalog\Api\Data\ProductInterface $product, + $saveOptions = false + ) { + $this->resourceModel->beginTransaction(); + try { + /** @var \Magento\Catalog\Api\Data\ProductInterface $result */ + $result = $proceed($product, $saveOptions); + $this->resourceModel->commit(); + return $result; + } catch (\Exception $e) { + $this->resourceModel->rollBack(); + throw $e; + } + } + + /** + * @param \Magento\Catalog\Api\ProductRepositoryInterface $subject + * @param callable $proceed + * @param \Magento\Catalog\Api\Data\ProductInterface $product + * @return bool + * @throws \Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundDelete( + \Magento\Catalog\Api\ProductRepositoryInterface $subject, + \Closure $proceed, + \Magento\Catalog\Api\Data\ProductInterface $product + ) { + $this->resourceModel->beginTransaction(); + try { + /** @var bool $result */ + $result = $proceed($product); + $this->resourceModel->commit(); + return $result; + } catch (\Exception $e) { + $this->resourceModel->rollBack(); + throw $e; + } + } + + /** + * @param \Magento\Catalog\Api\ProductRepositoryInterface $subject + * @param callable $proceed + * @param string $productSku + * @return bool + * @throws \Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundDeleteById( + \Magento\Catalog\Api\ProductRepositoryInterface $subject, + \Closure $proceed, + $productSku + ) { + $this->resourceModel->beginTransaction(); + try { + /** @var bool $result */ + $result = $proceed($productSku); + $this->resourceModel->commit(); + return $result; + } catch (\Exception $e) { + $this->resourceModel->rollBack(); + throw $e; + } + } +} diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php old mode 100644 new mode 100755 index 2272520c1a4fdfdadc63791d8fb4d8451f104481..5d21012f3964f7798aea8822c425192146d9481d --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php @@ -44,7 +44,7 @@ class Sku extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend * * @param Product $object * @return bool - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\LocalizedException */ public function validate($object) @@ -52,7 +52,7 @@ class Sku extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $attrCode = $this->getAttribute()->getAttributeCode(); $value = $object->getData($attrCode); if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) { - throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode)); + throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode)); } if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index f1f80f7701c0cf8e260892361e90110616656a31..21a1ecedb1f403f2bbe222e6b2e5542348ab1368 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -181,6 +181,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) * @return $this * @throws LocalizedException + * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validateUserValue($values) @@ -222,9 +223,6 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType $value = $this->validatorFile->setProduct($this->getProduct()) ->validate($this->_getProcessingParams(), $option); $this->setUserValue($value); - } catch (\Magento\Framework\Exception\File\LargeSizeException $largeSizeException) { - $this->setIsValid(false); - throw new LocalizedException(__($largeSizeException->getMessage())); } catch (ProductException $e) { switch ($this->getProcessMode()) { case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL: @@ -236,7 +234,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType } } catch (\Magento\Framework\Validator\Exception $e) { $this->setUserValue(null); - } catch (\Magento\Framework\Exception\File\ValidatorException $e) { + } catch (LocalizedException $e) { $this->setIsValid(false); throw new LocalizedException(__($e->getMessage())); } catch (\Exception $e) { diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php index beb1b3d2f8da1b5421b751aab1ee24d36de49c63..9f8c3c955c96e7e08e580c5de60f5fcb3c3c77f1 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php @@ -9,6 +9,7 @@ namespace Magento\Catalog\Model\Product\Option\Type\File; use Magento\Catalog\Model\Product; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Catalog\Model\Product\Exception as ProductException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -89,10 +90,12 @@ class ValidatorFile extends Validator * @param \Magento\Framework\Object $processingParams * @param \Magento\Catalog\Model\Product\Option $option * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Zend_File_Transfer_Exception + * @throws LocalizedException + * @throws ProductException + * @throws \Exception + * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Validator\Exception - * @throws \Magento\Catalog\Model\Product\Exception + * @throws \Zend_File_Transfer_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -116,7 +119,7 @@ class ValidatorFile extends Validator // when file exceeds the upload_max_filesize, $_FILES is empty if ($this->validateContentLength()) { $value = $this->fileSize->getMaxFileSizeInMb(); - throw new \Magento\Framework\Exception\File\LargeSizeException( + throw new LocalizedException( __('The file you uploaded is larger than %1 Megabytes allowed by server', $value) ); } else { @@ -188,12 +191,10 @@ class ValidatorFile extends Validator $errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option); if (count($errors) > 0) { - throw new \Magento\Framework\Exception\File\ValidatorException(__(implode("\n", $errors))); + throw new LocalizedException(__(implode("\n", $errors))); } } else { - throw new \Magento\Framework\Exception\File\ValidatorException( - __('Please specify the product\'s required option(s).') - ); + throw new LocalizedException(__('Please specify the product\'s required option(s).')); } return $userValue; } diff --git a/app/code/Magento/Catalog/Model/ProductRepository.php b/app/code/Magento/Catalog/Model/ProductRepository.php index 43fa06093960b8abab062c90bb649cde53164d96..40ecc5d2cb3419101374a9d563b52ada19cd9967 100644 --- a/app/code/Magento/Catalog/Model/ProductRepository.php +++ b/app/code/Magento/Catalog/Model/ProductRepository.php @@ -181,10 +181,10 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa /** * {@inheritdoc} */ - public function get($sku, $editMode = false, $storeId = null) + public function get($sku, $editMode = false, $storeId = null, $forceReload = false) { $cacheKey = $this->getCacheKey(func_get_args()); - if (!isset($this->instances[$sku][$cacheKey])) { + if (!isset($this->instances[$sku][$cacheKey]) || $forceReload) { $product = $this->productFactory->create(); $productId = $this->resourceModel->getIdBySku($sku); @@ -204,10 +204,10 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa /** * {@inheritdoc} */ - public function getById($productId, $editMode = false, $storeId = null) + public function getById($productId, $editMode = false, $storeId = null, $forceReload = false) { $cacheKey = $this->getCacheKey(func_get_args()); - if (!isset($this->instancesById[$productId][$cacheKey])) { + if (!isset($this->instancesById[$productId][$cacheKey]) || $forceReload) { $product = $this->productFactory->create(); if ($editMode) { @@ -235,6 +235,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa protected function getCacheKey($data) { unset($data[0]); + unset($data['forceReload']); $serializeData = []; foreach ($data as $key => $value) { if (is_object($value)) { diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Plugin/ProductRepository/TransactionWrapperTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Plugin/ProductRepository/TransactionWrapperTest.php new file mode 100644 index 0000000000000000000000000000000000000000..681af582d1344c749c0623451ce0d4195e2f3d17 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/Plugin/ProductRepository/TransactionWrapperTest.php @@ -0,0 +1,141 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Catalog\Test\Unit\Model\Plugin\ProductRepository; + +class TransactionWrapperTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Catalog\Model\Plugin\ProductRepository\TransactionWrapper + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Resource\Product + */ + protected $resourceMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Api\ProductRepositoryInterface + */ + protected $subjectMock; + + /** + * @var \Closure + */ + protected $closureMock; + + /** + * @var \Closure + */ + protected $rollbackClosureMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $productMock; + + /** + * @var bool + */ + protected $saveOption = true; + + const ERROR_MSG = "error occurred"; + + protected function setUp() + { + $this->resourceMock = $this->getMock('Magento\Catalog\Model\Resource\Product', [], [], '', false); + $this->subjectMock = $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface', [], [], '', false); + $this->productMock = $this->getMock('Magento\Catalog\Api\Data\ProductInterface', [], [], '', false); + $productMock = $this->productMock; + $this->closureMock = function () use ($productMock) { + return $productMock; + }; + $this->rollbackClosureMock = function () use ($productMock) { + throw new \Exception(self::ERROR_MSG); + }; + + $this->model = new \Magento\Catalog\Model\Plugin\ProductRepository\TransactionWrapper($this->resourceMock); + } + + public function testAroundSaveCommit() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('commit'); + + $this->assertEquals( + $this->productMock, + $this->model->aroundSave($this->subjectMock, $this->closureMock, $this->productMock, $this->saveOption) + ); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage error occurred + */ + public function testAroundSaveRollBack() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('rollBack'); + + $this->model->aroundSave($this->subjectMock, $this->rollbackClosureMock, $this->productMock, $this->saveOption); + } + + public function testAroundDeleteCommit() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('commit'); + + $this->assertEquals( + $this->productMock, + $this->model->aroundDelete($this->subjectMock, $this->closureMock, $this->productMock, $this->saveOption) + ); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage error occurred + */ + public function testAroundDeleteRollBack() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('rollBack'); + + $this->model->aroundDelete( + $this->subjectMock, + $this->rollbackClosureMock, + $this->productMock, + $this->saveOption + ); + } + + public function testAroundDeleteByIdCommit() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('commit'); + + $this->assertEquals( + $this->productMock, + $this->model->aroundDelete($this->subjectMock, $this->closureMock, $this->productMock, $this->saveOption) + ); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage error occurred + */ + public function testAroundDeleteByIdRollBack() + { + $this->resourceMock->expects($this->once())->method('beginTransaction'); + $this->resourceMock->expects($this->once())->method('rollBack'); + + $this->model->aroundDelete( + $this->subjectMock, + $this->rollbackClosureMock, + $this->productMock, + $this->saveOption + ); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php index affded52e9586413fb24378919bf538fdf4b74fb..26f70422f0e6075392f7e52c473371af78ded36c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php @@ -75,8 +75,8 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->productRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap( [ - ['product', false, null, $productMock], - ['linkedProduct', false, null, $linkedProductMock], + ['product', false, null, false, $productMock], + ['linkedProduct', false, null, false, $linkedProductMock], ] )); $entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct'); @@ -102,8 +102,8 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->productRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap( [ - ['product', false, null, $productMock], - ['linkedProduct', false, null, $linkedProductMock], + ['product', false, null, false, $productMock], + ['linkedProduct', false, null, false, $linkedProductMock], ] )); $entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct'); @@ -129,8 +129,8 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->productRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap( [ - ['product', false, null, $productMock], - ['linkedProduct', false, null, $linkedProductMock], + ['product', false, null, false, $productMock], + ['linkedProduct', false, null, false, $linkedProductMock], ] )); $entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct'); @@ -157,8 +157,8 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->productRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap( [ - ['product', false, null, $productMock], - ['linkedProduct', false, null, $linkedProductMock], + ['product', false, null, false, $productMock], + ['linkedProduct', false, null, false, $linkedProductMock], ] )); $entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct'); @@ -186,8 +186,8 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $linkedProductMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->productRepositoryMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap( [ - ['product', false, null, $productMock], - ['linkedProduct', false, null, $linkedProductMock], + ['product', false, null, false, $productMock], + ['linkedProduct', false, null, false, $linkedProductMock], ] )); $entityMock->expects($this->exactly(2))->method('getLinkedProductSku')->willReturn('linkedProduct'); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php index d50868fc2306bb0376ba81b02973d51f3c7b42ef..a8ba184519d797718c4613f9e5f4c4c8690764bf 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php @@ -298,6 +298,55 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase $this->productMock->expects($this->once())->method('load')->with($identifier); $this->productMock->expects($this->once())->method('getId')->willReturn($identifier); $this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId)); + //Second invocation should just return from cache + $this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId)); + } + + /** + * Test the forceReload parameter + * + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function testGetByIdForcedReload() + { + $identifier = "23"; + $editMode = false; + $storeId = 0; + + $this->productFactoryMock->expects($this->exactly(2))->method('create') + ->will($this->returnValue($this->productMock)); + $this->productMock->expects($this->exactly(2))->method('load'); + $this->productMock->expects($this->exactly(2))->method('getId')->willReturn($identifier); + $this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId)); + //second invocation should just return from cache + $this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId)); + //force reload + $this->assertEquals($this->productMock, $this->model->getById($identifier, $editMode, $storeId, true)); + } + + /** + * Test forceReload parameter + * + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function testGetForcedReload() + { + $sku = "sku"; + $id = "23"; + $editMode = false; + $storeId = 0; + + $this->productFactoryMock->expects($this->exactly(2))->method('create') + ->will($this->returnValue($this->productMock)); + $this->productMock->expects($this->exactly(2))->method('load'); + $this->productMock->expects($this->exactly(2))->method('getId')->willReturn($sku); + $this->resourceModelMock->expects($this->exactly(2))->method('getIdBySku') + ->with($sku)->willReturn($id); + $this->assertEquals($this->productMock, $this->model->get($sku, $editMode, $storeId)); + //second invocation should just return from cache + $this->assertEquals($this->productMock, $this->model->get($sku, $editMode, $storeId)); + //force reload + $this->assertEquals($this->productMock, $this->model->get($sku, $editMode, $storeId, true)); } public function testGetByIdWithSetStoreId() diff --git a/app/code/Magento/Catalog/composer.json b/app/code/Magento/Catalog/composer.json index a17501b92fba48a0137473e875a019f8a5596152..16e53d937b9199bb77a3828853871a6e287d4060 100644 --- a/app/code/Magento/Catalog/composer.json +++ b/app/code/Magento/Catalog/composer.json @@ -3,37 +3,37 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-log": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-msrp": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-catalog-rule": "0.74.0-beta4", - "magento/module-product-alert": "0.74.0-beta4", - "magento/module-url-rewrite": "0.74.0-beta4", - "magento/module-catalog-url-rewrite": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-log": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-msrp": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-catalog-rule": "0.74.0-beta6", + "magento/module-product-alert": "0.74.0-beta6", + "magento/module-url-rewrite": "0.74.0-beta6", + "magento/module-catalog-url-rewrite": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-cookie": "0.74.0-beta4" + "magento/module-cookie": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 971bebcac3226849a1af0c88b08925230ea83246..acd741fdbbe66d5c107a3d24ce3d99a5ec716b52 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -461,4 +461,7 @@ <preference for="Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface" type="\Magento\Catalog\Model\Product\Option\Value" /> <virtualType name="Magento\Catalog\Model\Resource\Attribute\Collection" type="Magento\Eav\Model\Resource\Entity\Attribute\Collection"> </virtualType> + <type name="Magento\Catalog\Api\ProductRepositoryInterface"> + <plugin name="transactionWrapper" type="\Magento\Catalog\Model\Plugin\ProductRepository\TransactionWrapper" sortOrder="-1"/> + </type> </config> diff --git a/app/code/Magento/CatalogImportExport/composer.json b/app/code/Magento/CatalogImportExport/composer.json index 895c374992a5c7413d5bdd883e27bbc7714673f7..ee8f34355558e63ab22dc08089041e4bdc99c3a4 100644 --- a/app/code/Magento/CatalogImportExport/composer.json +++ b/app/code/Magento/CatalogImportExport/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "ext-ctype": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogInventory/composer.json b/app/code/Magento/CatalogInventory/composer.json index 6f54f4d56c5274996dbcab3542e7ca9079c56888..129c2285172ca06dabdd98cb51dcc1a6ba9fdad7 100644 --- a/app/code/Magento/CatalogInventory/composer.json +++ b/app/code/Magento/CatalogInventory/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php old mode 100644 new mode 100755 index a2cfaba45a1e0ccdf826cce274ad17864eb00ca7..af1dee02649e9bb3fdcf56a7d40404b79a7c65f7 --- a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php +++ b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php @@ -562,7 +562,7 @@ class IndexBuilder * @param int $websiteId * @param int|null $productId * @return \Zend_Db_Statement_Interface - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getRuleProductsStmt($websiteId, $productId = null) { diff --git a/app/code/Magento/CatalogRule/composer.json b/app/code/Magento/CatalogRule/composer.json index 2c39aa0001cf71ef677a0e496c4d2d5ffa13d85f..321bbcd7334b631b6f630452474b2ae25f5a265c 100644 --- a/app/code/Magento/CatalogRule/composer.json +++ b/app/code/Magento/CatalogRule/composer.json @@ -3,19 +3,19 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-rule": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-rule": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogSearch/composer.json b/app/code/Magento/CatalogSearch/composer.json index 3e0bd9ed81ccbc94febd4ed726ca4de507cb545c..d9f2822e173203097515ba797209fdbb4a4c8a64 100644 --- a/app/code/Magento/CatalogSearch/composer.json +++ b/app/code/Magento/CatalogSearch/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-search": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-search": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogUrlRewrite/composer.json b/app/code/Magento/CatalogUrlRewrite/composer.json index 32f42f29d03b7acf1281238e5632e84b56ae44db..2488990a45e7570de05a47be2802787cb2fe1395 100644 --- a/app/code/Magento/CatalogUrlRewrite/composer.json +++ b/app/code/Magento/CatalogUrlRewrite/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-import-export": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-url-rewrite": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-import-export": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-url-rewrite": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CatalogWidget/composer.json b/app/code/Magento/CatalogWidget/composer.json index 2fdbad2eecd8068f9441484a3ad2f24bc3e9915e..e92c896cb1a574e1aa912d5cc378bb8c70aead25 100644 --- a/app/code/Magento/CatalogWidget/composer.json +++ b/app/code/Magento/CatalogWidget/composer.json @@ -3,19 +3,19 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-rule": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-rule": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Centinel/composer.json b/app/code/Magento/Centinel/composer.json index 91cddc22bffdff2cef320c3ad1bd2febf97c3dfd..584771858a87c0b5d497fd4ff33d11d890b28892 100644 --- a/app/code/Magento/Centinel/composer.json +++ b/app/code/Magento/Centinel/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Checkout/composer.json b/app/code/Magento/Checkout/composer.json index 2877afcf85ed8820a084c34cd72c03874baf4996..266290632764108d9de90c7d0d6a60a447173e5e 100644 --- a/app/code/Magento/Checkout/composer.json +++ b/app/code/Magento/Checkout/composer.json @@ -3,32 +3,32 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-gift-message": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-msrp": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-gift-message": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-msrp": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-cookie": "0.74.0-beta4" + "magento/module-cookie": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CheckoutAgreements/composer.json b/app/code/Magento/CheckoutAgreements/composer.json index 0cbd42b9a33de770f239b024e69a8566c6d32500..4693f5b11aa25b57cde6a425594a965b1355de7f 100644 --- a/app/code/Magento/CheckoutAgreements/composer.json +++ b/app/code/Magento/CheckoutAgreements/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Cms/composer.json b/app/code/Magento/Cms/composer.json index 9d7f128e467d96a985ad917388d9b783663be082..9ee9de410e132ace5520da29bfb9f6edc89fb4c7 100644 --- a/app/code/Magento/Cms/composer.json +++ b/app/code/Magento/Cms/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-email": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", - "magento/module-variable": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-email": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", + "magento/module-variable": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CmsUrlRewrite/composer.json b/app/code/Magento/CmsUrlRewrite/composer.json index 6d12114d02e995e4c3cae99c335fc8ca89b9236c..06f0e19df1fb840dd3dde3e6028ab68dda347b3a 100644 --- a/app/code/Magento/CmsUrlRewrite/composer.json +++ b/app/code/Magento/CmsUrlRewrite/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-url-rewrite": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-url-rewrite": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Config/composer.json b/app/code/Magento/Config/composer.json index 6ad118d0eb543e2418defaf768a66bd07f250a35..04e2fbc1e741c134694fdd2579fc618a3bf132c4 100644 --- a/app/code/Magento/Config/composer.json +++ b/app/code/Magento/Config/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-cron": "0.74.0-beta4", - "magento/module-email": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-cron": "0.74.0-beta6", + "magento/module-email": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ConfigurableImportExport/composer.json b/app/code/Magento/ConfigurableImportExport/composer.json index c02fc5ab42fa2b350e886cc8ee62c11b3d27e180..d504ebf2a76d16c9f183cd6419774e822571e6c3 100644 --- a/app/code/Magento/ConfigurableImportExport/composer.json +++ b/app/code/Magento/ConfigurableImportExport/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-import-export": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/module-configurable-product": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-import-export": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/module-configurable-product": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ConfigurableProduct/composer.json b/app/code/Magento/ConfigurableProduct/composer.json index 2cc6c39ef2a720b371828d8e55fd1236fc879ce7..507ee995f908bde44cc3f29647133573e35de89c 100644 --- a/app/code/Magento/ConfigurableProduct/composer.json +++ b/app/code/Magento/ConfigurableProduct/composer.json @@ -3,26 +3,26 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-catalog-rule": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-catalog-rule": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-webapi": "0.74.0-beta4" + "magento/module-webapi": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Contact/composer.json b/app/code/Magento/Contact/composer.json index ca39cef892d13513e9d48d6013066c022d0b424a..d2e5971064d0752a9053de71ef835fa13f07b6db 100644 --- a/app/code/Magento/Contact/composer.json +++ b/app/code/Magento/Contact/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Cookie/composer.json b/app/code/Magento/Cookie/composer.json index 1fbe865788b3e7f8b8d640614720dff283fabf2c..d3d5ef16f597b19653d8a69ff3e597bca16d30bf 100644 --- a/app/code/Magento/Cookie/composer.json +++ b/app/code/Magento/Cookie/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-backend": "0.74.0-beta4" + "magento/module-backend": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Cron/Setup/InstallSchema.php b/app/code/Magento/Cron/Setup/InstallSchema.php index cc7b419fa4e66bbbfbb9468768fde123f37f1d03..e3368c677742fe41a016adc40ed7293e3e072dcf 100644 --- a/app/code/Magento/Cron/Setup/InstallSchema.php +++ b/app/code/Magento/Cron/Setup/InstallSchema.php @@ -57,7 +57,7 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'scheduled_at', diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index 59f4ab2d4721e99fbb81ea062d0e47434614d4a2..02fe4b2ed4e83bb3de474176d18e622266e9552d 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -3,13 +3,13 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php index a99c5d696096d3acb8c36937e2e78b4553a1ec8c..f6463d67084a9a95a2f7ff27c39385f16e9f937a 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php @@ -22,7 +22,7 @@ class FetchRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Cur $service = $this->getRequest()->getParam('rate_services'); $this->_getSession()->setCurrencyRateService($service); if (!$service) { - throw new \Exception(__('Please specify a correct Import Service.')); + throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a correct Import Service.')); } try { /** @var \Magento\Directory\Model\Currency\Import\ImportInterface $importModel */ diff --git a/app/code/Magento/CurrencySymbol/composer.json b/app/code/Magento/CurrencySymbol/composer.json index c2b0fa9cf6f0f0c782c12e830a670b53975b436f..4ef0b1acf67493b6de9ff927c58ba3ad8ae97166 100644 --- a/app/code/Magento/CurrencySymbol/composer.json +++ b/app/code/Magento/CurrencySymbol/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Customer/Model/Resource/GroupRepository.php b/app/code/Magento/Customer/Model/Resource/GroupRepository.php index 73b59ff2dd1e54166d149019ae8585076b46b37d..fe0d52ca471ef7a45f563a5529657d4a189a2b03 100644 --- a/app/code/Magento/Customer/Model/Resource/GroupRepository.php +++ b/app/code/Magento/Customer/Model/Resource/GroupRepository.php @@ -164,6 +164,7 @@ class GroupRepository implements \Magento\Customer\Api\GroupRepositoryInterface /** @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 @@ class GroupRepository implements \Magento\Customer\Api\GroupRepositoryInterface 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/app/code/Magento/Customer/Setup/InstallSchema.php b/app/code/Magento/Customer/Setup/InstallSchema.php index 6f6750f3797043f4f25cfb78b4fd5e83bd0f0b6a..e74309026a57bd6f342c9d09c4276cb64e1857e9 100644 --- a/app/code/Magento/Customer/Setup/InstallSchema.php +++ b/app/code/Magento/Customer/Setup/InstallSchema.php @@ -81,13 +81,13 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated At' )->addColumn( 'is_active', @@ -134,7 +134,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity' */ @@ -174,13 +174,13 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated At' )->addColumn( 'is_active', @@ -202,7 +202,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity_datetime' */ @@ -287,7 +287,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity Datetime' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity_decimal' */ @@ -372,7 +372,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity Decimal' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity_int' */ @@ -447,7 +447,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity Int' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity_text' */ @@ -524,7 +524,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity Text' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_address_entity_varchar' */ @@ -609,7 +609,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Address Entity Varchar' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_entity_datetime' */ @@ -684,7 +684,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity Datetime' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_entity_decimal' */ @@ -759,7 +759,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity Decimal' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_entity_int' */ @@ -834,7 +834,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity Int' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_entity_text' */ @@ -906,7 +906,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity Text' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_entity_varchar' */ @@ -981,7 +981,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Entity Varchar' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_group' */ @@ -1009,7 +1009,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Group' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_eav_attribute' */ @@ -1073,7 +1073,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Eav Attribute' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_form_attribute' */ @@ -1104,7 +1104,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Form Attribute' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_eav_attribute_website' */ @@ -1165,7 +1165,7 @@ class InstallSchema implements InstallSchemaInterface 'Customer Eav Attribute Website' ); $installer->getConnection()->createTable($table); - + /** * Create table 'customer_visitor' */ @@ -1193,8 +1193,8 @@ class InstallSchema implements InstallSchemaInterface 'Visitor Table' ); $installer->getConnection()->createTable($table); - + $installer->endSetup(); - + } } 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 29adf1a01cca112fc6833837accaef7d1c3864ad..efc9e86abe834e477cb21e77577a6f4358f88fc3 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 @@ class PersonalInfoTest extends \PHPUnit_Framework_TestCase '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); diff --git a/app/code/Magento/Customer/composer.json b/app/code/Magento/Customer/composer.json index f8dc83a634288b02d6b6a7238df504d63f8607c6..340ab29eca160e1cca6c80f8426ea2ebe66261cb 100644 --- a/app/code/Magento/Customer/composer.json +++ b/app/code/Magento/Customer/composer.json @@ -3,33 +3,33 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-newsletter": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-review": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", - "magento/module-integration": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-newsletter": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-review": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", + "magento/module-integration": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-cookie": "0.74.0-beta4" + "magento/module-cookie": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/CustomerImportExport/composer.json b/app/code/Magento/CustomerImportExport/composer.json index edcbf4a31a26e40315da50a4b77b187b69d49391..3635354b9f3c6e0593281f1465051226cfc8c355 100644 --- a/app/code/Magento/CustomerImportExport/composer.json +++ b/app/code/Magento/CustomerImportExport/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/DesignEditor/composer.json b/app/code/Magento/DesignEditor/composer.json index 96c6b08ef61fc7146066ed82353ce97ea8e682b6..7a24e23445b99be4268f881b05eff8013e9553da 100644 --- a/app/code/Magento/DesignEditor/composer.json +++ b/app/code/Magento/DesignEditor/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-translation": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-translation": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Developer/Model/View/Layout/Plugin.php b/app/code/Magento/Developer/Model/View/Layout/Plugin.php new file mode 100644 index 0000000000000000000000000000000000000000..4f4f059813d58552730aea52894ce610ce327799 --- /dev/null +++ b/app/code/Magento/Developer/Model/View/Layout/Plugin.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Developer\Model\View\Layout; + +use Magento\Framework\App\State; +use Magento\Framework\Exception\LocalizedException; +use Psr\Log\LoggerInterface as Logger; + +/** + * Layout plugin that handle exceptions + */ +class Plugin +{ + /** + * @var State + */ + protected $appState; + + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** + * @param State $appState + * @param Logger $logger + */ + public function __construct( + State $appState, + Logger $logger + ) { + $this->appState = $appState; + $this->logger = $logger; + } + + /** + * @param \Magento\Framework\View\Layout $subject + * @param callable $proceed + * @param string $name + * @return string + * @throws \Exception + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundRenderNonCachedElement(\Magento\Framework\View\Layout $subject, \Closure $proceed, $name) + { + $result = ''; + try { + $result = $proceed($name); + } catch (\Exception $e) { + if ($this->appState->getMode() === State::MODE_DEVELOPER) { + throw $e; + } + $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage(); + $this->logger->critical($message); + } + return $result; + } +} diff --git a/app/code/Magento/Developer/composer.json b/app/code/Magento/Developer/composer.json index f37c4cf749ba8e1849a49df486235c50b0095dd0..2acb479e5e7da4b25ea3e78b4269be86c45fa06c 100644 --- a/app/code/Magento/Developer/composer.json +++ b/app/code/Magento/Developer/composer.json @@ -3,12 +3,12 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index d793eb340a284a5d716f6f13d9b739d2984ca87d..94be2446cc1404c4c37cc2c1a740773ba7ba84f1 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -10,6 +10,9 @@ <type name="Magento\Framework\View\TemplateEngineFactory"> <plugin name="debug_hints" type="Magento\Developer\Model\TemplateEngine\Plugin\DebugHints" sortOrder="10"/> </type> + <type name="Magento\Framework\View\Layout"> + <plugin name="exception_handler" type="Magento\Developer\Model\View\Layout\Plugin" sortOrder="10"/> + </type> <type name="Magento\Framework\View\Result\Page"> <arguments> <argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument> diff --git a/app/code/Magento/Dhl/composer.json b/app/code/Magento/Dhl/composer.json index a0cd2d031e30120b94510e53be7d29f587795780..9523a52d2f19d36247e9a99814c24cf43e8ee2a5 100644 --- a/app/code/Magento/Dhl/composer.json +++ b/app/code/Magento/Dhl/composer.json @@ -3,22 +3,22 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Directory/composer.json b/app/code/Magento/Directory/composer.json index ec04012d5549bc8763750e86976313bd31e92290..bc25eea4a4f6717ae53a92714ecf462bfa6f0e6d 100644 --- a/app/code/Magento/Directory/composer.json +++ b/app/code/Magento/Directory/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Downloadable/Setup/InstallSchema.php b/app/code/Magento/Downloadable/Setup/InstallSchema.php index e7043312e7a49331987f862339b2d8463041f45f..f377662176a55473a8bd1461f7db95c44a440043 100644 --- a/app/code/Magento/Downloadable/Setup/InstallSchema.php +++ b/app/code/Magento/Downloadable/Setup/InstallSchema.php @@ -216,14 +216,14 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Date of creation' ) ->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Date of modification' ) ->addColumn( @@ -390,14 +390,14 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Creation Time' ) ->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Update Time' ) ->addIndex( diff --git a/app/code/Magento/Downloadable/composer.json b/app/code/Magento/Downloadable/composer.json index c73fbe1b106ee42cfb9d12f610894d56de73a842..69f7d646d0ffd16100c2deddc801ab123ab375ad 100644 --- a/app/code/Magento/Downloadable/composer.json +++ b/app/code/Magento/Downloadable/composer.json @@ -3,28 +3,28 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-gift-message": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-msrp": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-gift-message": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-msrp": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Eav/Exception.php b/app/code/Magento/Eav/Exception.php deleted file mode 100644 index ed5a6dd53d7140f8088c4cbc8e32d4a8c8a18ad7..0000000000000000000000000000000000000000 --- a/app/code/Magento/Eav/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Eav; - -class Exception extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php old mode 100644 new mode 100755 index cc3d3950d01b2d66fe48129d35506daa3a967a91..ac8c5805f4b72f8727d09a4a4cbc71a0f05c2258 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -14,7 +14,7 @@ use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend; use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; use Magento\Framework\App\Config\Element; use Magento\Framework\Model\AbstractModel; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor; use Magento\Framework\Model\Resource\Db\TransactionManagerInterface; @@ -334,12 +334,12 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract * Retrieve current entity config * * @return Type - * @throws EavException + * @throws LocalizedException */ public function getEntityType() { if (empty($this->_type)) { - throw new EavException(__('Entity is not initialized')); + throw new LocalizedException(__('Entity is not initialized')); } return $this->_type; } @@ -372,7 +372,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract * * @param array|string|null $attributes * @return $this - * @throws EavException + * @throws LocalizedException */ public function unsetAttributes($attributes = null) { @@ -387,7 +387,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract } if (!is_array($attributes)) { - throw new EavException(__('Unknown parameter')); + throw new LocalizedException(__('Unknown parameter')); } foreach ($attributes as $attrCode) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php old mode 100644 new mode 100755 index df877f97a92afdec4ea0cdb857e10d3a90f84ba9..5682724a47726b8504a4862eca31b2c8c75b2bfb --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -5,7 +5,7 @@ */ namespace Magento\Eav\Model\Entity; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Api\AttributeValueFactory; /** @@ -213,7 +213,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im * Prepare data for save * * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -221,7 +221,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im { // prevent overriding product data if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) { - throw new EavException( + throw new LocalizedException( __( 'The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code'] @@ -240,7 +240,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH] ) ) { - throw new EavException( + throw new LocalizedException( __('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH) ); } @@ -252,7 +252,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL); $defaultValue = $numberFormatter->parse($defaultValue); if ($defaultValue === false) { - throw new EavException(__('Invalid default decimal value')); + throw new LocalizedException(__('Invalid default decimal value')); } $this->setDefaultValue($defaultValue); } @@ -275,7 +275,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im $defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format); $this->setDefaultValue($defaultValue); } catch (\Exception $e) { - throw new EavException(__('Invalid default date')); + throw new LocalizedException(__('Invalid default date')); } } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php old mode 100644 new mode 100755 index e52ab0860e2022a332732b550391e45fabb5e305..9dbc048d711ecb5ddbcb936e1cdad322200c61c7 --- a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php @@ -6,7 +6,7 @@ namespace Magento\Eav\Model\Entity\Attribute; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Api\AttributeValueFactory; /** @@ -181,7 +181,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * @param string|int|\Magento\Eav\Model\Entity\Type $entityType * @param string $code * @return $this - * @throws EavException + * @throws LocalizedException */ public function loadByCode($entityType, $code) { @@ -195,7 +195,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens $entityTypeId = $entityType->getId(); } if (empty($entityTypeId)) { - throw new EavException(__('Invalid entity supplied')); + throw new LocalizedException(__('Invalid entity supplied')); } $this->_getResource()->loadByCode($this, $entityTypeId, $code); $this->_afterLoad(); @@ -461,7 +461,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * Retrieve backend instance * * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend - * @throws EavException + * @throws LocalizedException */ public function getBackend() { @@ -471,7 +471,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens } $backend = $this->_universalFactory->create($this->getBackendModel()); if (!$backend) { - throw new EavException(__('Invalid backend model specified: ' . $this->getBackendModel())); + throw new LocalizedException(__('Invalid backend model specified: ' . $this->getBackendModel())); } $this->_backend = $backend->setAttribute($this); } @@ -500,7 +500,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * Retrieve source instance * * @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource - * @throws EavException + * @throws LocalizedException */ public function getSource() { @@ -510,7 +510,7 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens } $source = $this->_universalFactory->create($this->getSourceModel()); if (!$source) { - throw new EavException( + throw new LocalizedException( __( 'Source model "%1" not found for attribute "%2"', $this->getSourceModel(), diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php old mode 100644 new mode 100755 index 9950d293cba1937e72b4aa479aa579ef5ea1df16..aa010892c64957ff153888590e20f49987aa82e4 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php @@ -5,7 +5,7 @@ */ namespace Magento\Eav\Model\Entity\Attribute\Backend; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * Entity/Attribute/Model - attribute backend abstract @@ -214,7 +214,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba * * @param \Magento\Framework\Object $object * @return bool - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validate($object) @@ -223,7 +223,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba $attrCode = $attribute->getAttributeCode(); $value = $object->getData($attrCode); if ($attribute->getIsVisible() && $attribute->getIsRequired() && $attribute->isValueEmpty($value)) { - throw new EavException(__('The value of attribute "%1" must be set', $attrCode)); + throw new LocalizedException(__('The value of attribute "%1" must be set', $attrCode)); } if ($attribute->getIsUnique() @@ -236,7 +236,7 @@ abstract class AbstractBackend implements \Magento\Eav\Model\Entity\Attribute\Ba if ($attribute->getIsUnique()) { if (!$attribute->getEntity()->checkAttributeUniqueValue($attribute, $object)) { $label = $attribute->getFrontend()->getLabel(); - throw new EavException(__('The value of attribute "%1" must be unique', $label)); + throw new LocalizedException(__('The value of attribute "%1" must be unique', $label)); } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php old mode 100644 new mode 100755 index 4145ac0a68cd95767a2ace6d48bda83048f00d73..147f1dcdd0bc845b871daaa2146b468438942d72 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -30,7 +30,7 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke * necessary for further process, else date string * * @param \Magento\Framework\Object $object - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave($object) @@ -41,7 +41,7 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke try { $value = $this->formatDate($object->getData($attributeName)); } catch (\Exception $e) { - throw new \Magento\Eav\Exception(__('Invalid date')); + throw new \Magento\Framework\Exception\LocalizedException(__('Invalid date')); } if (is_null($value)) { diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/Entity/Attribute/Set.php old mode 100644 new mode 100755 index c8eb151622d4d235b8460fc548ac202d504b0e4a..446f4fd65a88ba119a7ad37caa67d681aa327ffd --- a/app/code/Magento/Eav/Model/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Set.php @@ -19,7 +19,7 @@ */ namespace Magento\Eav\Model\Entity\Attribute; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; use Magento\Eav\Model\Entity\Type; use Magento\Framework\Api\AttributeValueFactory; @@ -255,17 +255,17 @@ class Set extends \Magento\Framework\Model\AbstractExtensibleModel implements * Validate attribute set name * * @return bool - * @throws EavException + * @throws LocalizedException */ public function validate() { $attributeSetName = $this->getAttributeSetName(); if ($attributeSetName == '') { - throw new EavException(__('Attribute set name is empty.')); + throw new LocalizedException(__('Attribute set name is empty.')); } if (!$this->_getResource()->validate($this, $attributeSetName)) { - throw new EavException(__('An attribute set with the "%1" name already exists.', $attributeSetName)); + throw new LocalizedException(__('An attribute set with the "%1" name already exists.', $attributeSetName)); } return true; diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php old mode 100644 new mode 100755 index 427000b106f5e6b743213ab967e33c1095a56ce9..6417cd0b506d865fcc95f1595f4845439a8500c4 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php @@ -30,7 +30,7 @@ class Config extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource /** * Retrieve all options for the source from configuration * - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return array */ public function getAllOptions() @@ -39,7 +39,7 @@ class Config extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource $this->_options = []; if (empty($this->_optionsData)) { - throw new \Magento\Eav\Exception(__('No options found.')); + throw new \Magento\Framework\Exception\LocalizedException(__('No options found.')); } foreach ($this->_optionsData as $option) { $this->_options[] = ['value' => $option['value'], 'label' => __($option['label'])]; diff --git a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php old mode 100644 new mode 100755 index 6cd6cf0e6d018dc745d1d4f66a73581ae593a915..72712e67c4406c2c2485649571e70ee145701992 --- a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php +++ b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php @@ -6,7 +6,7 @@ namespace Magento\Eav\Model\Entity\Collection; use Magento\Framework\DB\Select; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * Entity/Attribute/Model - collection abstract @@ -225,7 +225,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param \Magento\Eav\Model\Entity\AbstractEntity $entity * @return $this - * @throws EavException + * @throws LocalizedException */ public function setEntity($entity) { @@ -234,7 +234,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } elseif (is_string($entity) || $entity instanceof \Magento\Framework\App\Config\Element) { $this->_entity = $this->_eavEntityFactory->create()->setType($entity); } else { - throw new EavException(__('Invalid entity supplied: %1', print_r($entity, 1))); + throw new LocalizedException(__('Invalid entity supplied: %1', print_r($entity, 1))); } return $this; } @@ -243,12 +243,12 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * Get collection's entity object * * @return \Magento\Eav\Model\Entity\AbstractEntity - * @throws EavException + * @throws LocalizedException */ public function getEntity() { if (empty($this->_entity)) { - throw new EavException(__('Entity is not initialized')); + throw new LocalizedException(__('Entity is not initialized')); } return $this->_entity; } @@ -284,12 +284,12 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param \Magento\Framework\Object $object * @return $this - * @throws EavException + * @throws LocalizedException */ public function addItem(\Magento\Framework\Object $object) { if (!$object instanceof $this->_itemObjectClass) { - throw new EavException(__('Attempt to add an invalid object')); + throw new LocalizedException(__('Attempt to add an invalid object')); } return parent::addItem($object); } @@ -449,7 +449,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param array|string|integer|\Magento\Framework\App\Config\Element $attribute * @param bool|string $joinType flag for joining attribute * @return $this - * @throws EavException + * @throws LocalizedException */ public function addAttributeToSelect($attribute, $joinType = false) { @@ -474,7 +474,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attrInstance = $this->_eavConfig->getAttribute($this->getEntity()->getType(), $attribute); } if (empty($attrInstance)) { - throw new EavException(__('Invalid attribute requested: %1', (string)$attribute)); + throw new LocalizedException(__('Invalid attribute requested: %1', (string)$attribute)); } $this->_selectAttributes[$attrInstance->getAttributeCode()] = $attrInstance->getId(); } @@ -520,13 +520,13 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $expression * @param string $attribute * @return $this - * @throws EavException + * @throws LocalizedException */ public function addExpressionAttributeToSelect($alias, $expression, $attribute) { // validate alias if (isset($this->_joinFields[$alias])) { - throw new EavException(__('Joint field or attribute expression with this alias is already declared')); + throw new LocalizedException(__('Joint field or attribute expression with this alias is already declared')); } if (!is_array($attribute)) { $attribute = [$attribute]; @@ -622,7 +622,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $joinType inner|left * @param null $storeId * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -630,7 +630,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db { // validate alias if (isset($this->_joinAttributes[$alias])) { - throw new EavException(__('Invalid alias, already exists in joint attributes')); + throw new LocalizedException(__('Invalid alias, already exists in joint attributes')); } $bindAttribute = null; @@ -640,7 +640,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } if (!$bindAttribute || !$bindAttribute->isStatic() && !$bindAttribute->getId()) { - throw new EavException(__('Invalid foreign key')); + throw new LocalizedException(__('Invalid foreign key')); } // try to explode combined entity/attribute if supplied @@ -664,7 +664,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } } if (!$entity || !$entity->getTypeId()) { - throw new EavException(__('Invalid entity type')); + throw new LocalizedException(__('Invalid entity type')); } // cache entity @@ -677,7 +677,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attribute = $entity->getAttribute($attribute); } if (!$attribute) { - throw new EavException(__('Invalid attribute type')); + throw new LocalizedException(__('Invalid attribute type')); } if (empty($filter)) { @@ -712,13 +712,13 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string|array $cond "{{table}}.language_code='en'" OR array('language_code'=>'en') * @param string $joinType 'left' * @return $this - * @throws EavException + * @throws LocalizedException */ public function joinField($alias, $table, $field, $bind, $cond = null, $joinType = 'inner') { // validate alias if (isset($this->_joinFields[$alias])) { - throw new EavException(__('A joined field with this alias is already declared.')); + throw new LocalizedException(__('A joined field with this alias is already declared.')); } $table = $this->_resource->getTableName($table); @@ -774,7 +774,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param null|array $cond * @param string $joinType * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType = 'inner') @@ -793,11 +793,11 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db // validate fields and aliases if (!$fields) { - throw new EavException(__('Invalid joint fields')); + throw new LocalizedException(__('Invalid joint fields')); } foreach ($fields as $alias => $field) { if (isset($this->_joinFields[$alias])) { - throw new EavException(__('A joint field with this alias (%1) is already declared.', $alias)); + throw new LocalizedException(__('A joint field with this alias (%1) is already declared.', $alias)); } $this->_joinFields[$alias] = ['table' => $tableAlias, 'field' => $field]; } @@ -1100,7 +1100,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param bool $printQuery * @param bool $logQuery * @return $this - * @throws EavException + * @throws LocalizedException * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) @@ -1214,14 +1214,14 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param array $valueInfo * @return $this - * @throws EavException + * @throws LocalizedException */ protected function _setItemAttributeValue($valueInfo) { $entityIdField = $this->getEntity()->getEntityIdField(); $entityId = $valueInfo[$entityIdField]; if (!isset($this->_itemsById[$entityId])) { - throw new EavException(__('Data integrity: No header row found for attribute')); + throw new LocalizedException(__('Data integrity: No header row found for attribute')); } $attributeCode = array_search($valueInfo['attribute_id'], $this->_selectAttributes); if (!$attributeCode) { @@ -1255,7 +1255,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * * @param string $attributeCode * @return string - * @throws EavException + * @throws LocalizedException */ protected function _getAttributeFieldName($attributeCode) { @@ -1273,7 +1273,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db $attribute = $this->getAttribute($attributeCode); if (!$attribute) { - throw new EavException(__('Invalid attribute name: %1', $attributeCode)); + throw new LocalizedException(__('Invalid attribute name: %1', $attributeCode)); } if ($attribute->isStatic()) { @@ -1295,7 +1295,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db * @param string $attributeCode * @param string $joinType inner|left * @return $this - * @throws EavException + * @throws LocalizedException * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _addAttributeJoin($attributeCode, $joinType = 'inner') @@ -1333,7 +1333,7 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db } if (!$attribute) { - throw new EavException(__('Invalid attribute name: %1', $attributeCode)); + throw new LocalizedException(__('Invalid attribute name: %1', $attributeCode)); } if ($attribute->getBackend()->isStatic()) { diff --git a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php old mode 100644 new mode 100755 index f413b900610a9cf62cfed7c286c4ec11447514b7..06c71132bf982a5e9eb9a7b03c225f8129c6b6f3 --- a/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php +++ b/app/code/Magento/Eav/Model/Entity/Increment/Alphanum.php @@ -31,7 +31,7 @@ class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement * Get next id * * @return string - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getNextId() { @@ -52,7 +52,9 @@ class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement for ($i = $lid; $i >= 0; $i--) { $p = strpos($chars, $lastId[$i]); if (false === $p) { - throw new \Magento\Eav\Exception(__('Invalid character encountered in increment ID: %1', $lastId)); + throw new \Magento\Framework\Exception\LocalizedException( + __('Invalid character encountered in increment ID: %1', $lastId) + ); } if ($bumpNextChar) { $p++; diff --git a/app/code/Magento/Eav/Setup/EavSetup.php b/app/code/Magento/Eav/Setup/EavSetup.php old mode 100644 new mode 100755 index 4e2a177f364bcb103cb8dc312a4f944c01a34385..cccb9d3b0286efc053a86b5fa752cc2a6f189577 --- a/app/code/Magento/Eav/Setup/EavSetup.php +++ b/app/code/Magento/Eav/Setup/EavSetup.php @@ -10,7 +10,7 @@ use Magento\Eav\Model\Entity\Setup\PropertyMapperInterface; use Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory; use Magento\Framework\App\CacheInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Eav\Exception as EavException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -247,7 +247,7 @@ class EavSetup * * @param int|string $entityTypeId * @return int - * @throws EavException + * @throws LocalizedException */ public function getEntityTypeId($entityTypeId) { @@ -255,7 +255,7 @@ class EavSetup $entityTypeId = $this->getEntityType($entityTypeId, 'entity_type_id'); } if (!is_numeric($entityTypeId)) { - throw new EavException(__('Wrong entity ID')); + throw new LocalizedException(__('Wrong entity ID')); } return $entityTypeId; @@ -381,7 +381,7 @@ class EavSetup * @param int|string $entityTypeId * @param int|string $setId * @return int - * @throws EavException + * @throws LocalizedException */ public function getAttributeSetId($entityTypeId, $setId) { @@ -389,7 +389,7 @@ class EavSetup $setId = $this->getAttributeSet($entityTypeId, $setId, 'attribute_set_id'); } if (!is_numeric($setId)) { - throw new EavException(__('Wrong attribute set ID')); + throw new LocalizedException(__('Wrong attribute set ID')); } return $setId; @@ -598,7 +598,7 @@ class EavSetup * @param int|string $setId * @param int|string $groupId * @return $this - * @throws EavException + * @throws LocalizedException */ public function getAttributeGroupId($entityTypeId, $setId, $groupId) { @@ -611,7 +611,7 @@ class EavSetup } if (!is_numeric($groupId)) { - throw new EavException(__('Wrong attribute group ID')); + throw new LocalizedException(__('Wrong attribute group ID')); } return $groupId; } @@ -713,7 +713,7 @@ class EavSetup * * @param array $data * @return true - * @throws EavException + * @throws LocalizedException */ private function _validateAttributeData($data) { @@ -727,7 +727,7 @@ class EavSetup ['max' => $attributeCodeMaxLength] ) ) { - throw new EavException( + throw new LocalizedException( __('Maximum length of attribute code must be less than %1 symbols', $attributeCodeMaxLength) ); } diff --git a/app/code/Magento/Eav/Setup/InstallSchema.php b/app/code/Magento/Eav/Setup/InstallSchema.php index 244cfe2d85e9e56e0e5771ef30b4c3b8888fbc0f..24c041c7e2c05bd1365bfb0166cae0f253d3c0c5 100644 --- a/app/code/Magento/Eav/Setup/InstallSchema.php +++ b/app/code/Magento/Eav/Setup/InstallSchema.php @@ -179,13 +179,13 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated At' )->addColumn( 'is_active', diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php old mode 100644 new mode 100755 index 23d24c8edd47ffa94a603517f3303bf0e5c7581e..7a81bd55d364ff3423c2e2d4cb884827f4fa4c83 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/SetTest.php @@ -51,7 +51,7 @@ class SetTest extends \PHPUnit_Framework_TestCase { $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(false)); - $this->setExpectedException('Magento\Eav\Exception', $exceptionMessage); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', $exceptionMessage); $this->_model->setAttributeSetName($attributeSetName); $this->_model->validate(); } diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php old mode 100644 new mode 100755 index bbf9f3b2535633f1ff7fd5a6756ef54ce5cfc5fc..23bd155a23f02b029c93edfcc26580d478f51ac1 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Increment/AlphanumTest.php @@ -54,7 +54,7 @@ class AlphanumTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Eav\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid character encountered in increment ID: ---wrong-id--- */ public function testGetNextIdThrowsExceptionIfIdContainsNotAllowedCharacters() diff --git a/app/code/Magento/Eav/composer.json b/app/code/Magento/Eav/composer.json index aee86f0c0bb1dcf6e82ee4b869f02923dc71ca0f..48ba714ad64dafc7360bb73aa31e87ac3a96ac0d 100644 --- a/app/code/Magento/Eav/composer.json +++ b/app/code/Magento/Eav/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Email/composer.json b/app/code/Magento/Email/composer.json index 216d194849554f878ec6a21330f0b311159a55a5..afc6d37eb433e3b75b32196ad86b641530dbb796 100644 --- a/app/code/Magento/Email/composer.json +++ b/app/code/Magento/Email/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-variable": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-variable": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Fedex/composer.json b/app/code/Magento/Fedex/composer.json index 4e2a6767585aab94f821c5ebfcd1521f61fa688e..4e2b254631e2af230d799ecfca6b01371e26afcf 100644 --- a/app/code/Magento/Fedex/composer.json +++ b/app/code/Magento/Fedex/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GiftMessage/composer.json b/app/code/Magento/GiftMessage/composer.json index 5a6e0e322d63c8d982efb98e274b569016c99679..68ce2c1de0918b500fa744563995ea560aa00240 100644 --- a/app/code/Magento/GiftMessage/composer.json +++ b/app/code/Magento/GiftMessage/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-multishipping": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-multishipping": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GoogleAdwords/composer.json b/app/code/Magento/GoogleAdwords/composer.json index e0e680f846dd0cbe7da3879e32f97d85a4f57ad7..81dcd88401f817917d78a4ef6c7662e1cef9e6b8 100644 --- a/app/code/Magento/GoogleAdwords/composer.json +++ b/app/code/Magento/GoogleAdwords/composer.json @@ -3,13 +3,13 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GoogleAnalytics/composer.json b/app/code/Magento/GoogleAnalytics/composer.json index 8fd519df491f0ffe4d2defa86b083081d6c4c7a1..68cfa226900d210e823aae6eb94a46500ba21fd0 100644 --- a/app/code/Magento/GoogleAnalytics/composer.json +++ b/app/code/Magento/GoogleAnalytics/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-cookie": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-cookie": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GoogleOptimizer/composer.json b/app/code/Magento/GoogleOptimizer/composer.json index 799d8a2a8e95b0f0036a39c55b199b422972bbc6..a20b62e29cb95b1840d2dfc056c0e6df5b9638a2 100644 --- a/app/code/Magento/GoogleOptimizer/composer.json +++ b/app/code/Magento/GoogleOptimizer/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-google-analytics": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-google-analytics": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GoogleShopping/composer.json b/app/code/Magento/GoogleShopping/composer.json index 18b2a1f41eae95eed341e35d32f34d5fa17e044b..267a3c8cb23aeea71338a8532432c3e4a133ce26 100644 --- a/app/code/Magento/GoogleShopping/composer.json +++ b/app/code/Magento/GoogleShopping/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GroupedImportExport/composer.json b/app/code/Magento/GroupedImportExport/composer.json index 3ad59320df924c910b7374ec8b5e81f703f295fe..2d66faa4f5b3761512df683740754d918999fe0c 100644 --- a/app/code/Magento/GroupedImportExport/composer.json +++ b/app/code/Magento/GroupedImportExport/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-import-export": "0.74.0-beta4", - "magento/module-catalog-import-export": "0.74.0-beta4", - "magento/module-grouped-product": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-import-export": "0.74.0-beta6", + "magento/module-catalog-import-export": "0.74.0-beta6", + "magento/module-grouped-product": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/GroupedProduct/composer.json b/app/code/Magento/GroupedProduct/composer.json index 5ed831d182a1ee3ecd967c9e2e1487425fdd3368..cdd8818ca6b36d0d881e58e187ae078e61590d0c 100644 --- a/app/code/Magento/GroupedProduct/composer.json +++ b/app/code/Magento/GroupedProduct/composer.json @@ -3,22 +3,22 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/module-msrp": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/module-msrp": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ImportExport/composer.json b/app/code/Magento/ImportExport/composer.json index ca9683482f7aeea2280baeaab2f365f18f4ce62a..747df1717017a7ddeffb4d80ef8640f23e2f5dfd 100644 --- a/app/code/Magento/ImportExport/composer.json +++ b/app/code/Magento/ImportExport/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-indexer": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-indexer": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "ext-ctype": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Indexer/composer.json b/app/code/Magento/Indexer/composer.json index 605029fddc9e847a6a075fb558a1911558bfe9f3..13b2594e6abd971cfa42adbb147d542bb9f30c3a 100644 --- a/app/code/Magento/Indexer/composer.json +++ b/app/code/Magento/Indexer/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", "magento/framework": "0.74.0-beta4", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Integration/Setup/InstallSchema.php b/app/code/Magento/Integration/Setup/InstallSchema.php index 7c6bfda56692ba91f7ceb1170b00f28b055c88a4..28d24cab8f3a26047403ded521eba906af078d02 100644 --- a/app/code/Magento/Integration/Setup/InstallSchema.php +++ b/app/code/Magento/Integration/Setup/InstallSchema.php @@ -268,9 +268,6 @@ class InstallSchema implements InstallSchemaInterface \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE )->setComment( 'OAuth Nonce' - )->setOption( - 'type', - 'MyISAM' ); $installer->getConnection()->createTable($table); @@ -316,13 +313,13 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Creation Time' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_UPDATE], 'Update Time' )->addColumn( 'setup_type', diff --git a/app/code/Magento/Integration/composer.json b/app/code/Magento/Integration/composer.json index e5d7d1526fa6e61694f1a2ae576df1128dab9a55..9fa6582f0d0cd4bb38e11ceed92222616d1abd5a 100644 --- a/app/code/Magento/Integration/composer.json +++ b/app/code/Magento/Integration/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-user": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-user": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/LayeredNavigation/composer.json b/app/code/Magento/LayeredNavigation/composer.json index 0343cc36ead5f261199aabead8153cd95bba066a..ed19740fa51a2ec85a258179adb1147d47cbe49e 100644 --- a/app/code/Magento/LayeredNavigation/composer.json +++ b/app/code/Magento/LayeredNavigation/composer.json @@ -3,13 +3,13 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Log/Setup/InstallSchema.php b/app/code/Magento/Log/Setup/InstallSchema.php index 1cf4f0832bf5032958659da8bc0b55f24b244371..372d41188ca9e537430493c40e5342e5e89fadbf 100644 --- a/app/code/Magento/Log/Setup/InstallSchema.php +++ b/app/code/Magento/Log/Setup/InstallSchema.php @@ -95,7 +95,7 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Creation Time' )->addColumn( 'deleted_at', @@ -147,7 +147,7 @@ class InstallSchema implements InstallSchemaInterface 'add_date', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Date' )->setComment( 'Log Summary Table' diff --git a/app/code/Magento/Log/composer.json b/app/code/Magento/Log/composer.json index 9a3c57a59a0b3c7ebfc1588d27e207adc652260e..5179484e4165391b9d64e747c7cde887bacdc2c5 100644 --- a/app/code/Magento/Log/composer.json +++ b/app/code/Magento/Log/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/MediaStorage/composer.json b/app/code/Magento/MediaStorage/composer.json index ce826ad84af83b83aa339ff5dfacb27fd56abdfe..1a140593019d9982ad679be6ab959f95baf4ac63 100644 --- a/app/code/Magento/MediaStorage/composer.json +++ b/app/code/Magento/MediaStorage/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Msrp/composer.json b/app/code/Magento/Msrp/composer.json index 6465657065e5a4d804f1d433f5639b16307c049d..5e288eaebe15fdb2d3d2c35d2fa2ca7de5fd5dae 100644 --- a/app/code/Magento/Msrp/composer.json +++ b/app/code/Magento/Msrp/composer.json @@ -3,19 +3,19 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-bundle": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-downloadable": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-grouped-product": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-bundle": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-downloadable": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-grouped-product": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php index 7359e5dc00845341f90db7fb07c68846a5c917f0..d2d41a10d762463f1a2f54c7dfd963496d5ca7d4 100644 --- a/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php +++ b/app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php @@ -703,7 +703,7 @@ class Multishipping extends \Magento\Framework\Object $orders[] = $order; $this->_eventManager->dispatch( 'checkout_type_multishipping_create_orders_single', - ['order' => $order, 'address' => $address] + ['order' => $order, 'address' => $address, 'quote' => $this->getQuote()] ); } diff --git a/app/code/Magento/Multishipping/composer.json b/app/code/Magento/Multishipping/composer.json index d836336a7d88aee184ed0d729f7fa51889c9f115..ebcccdf5ade42bf663bb71b3bf0c100e6800df47 100644 --- a/app/code/Magento/Multishipping/composer.json +++ b/app/code/Magento/Multishipping/composer.json @@ -3,19 +3,19 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Newsletter/composer.json b/app/code/Magento/Newsletter/composer.json index 407ad2de1463b3696f35c78f5c7c20e9d1747959..2393d31c94a9e4d4840e0276b8d84bff76ea6237 100644 --- a/app/code/Magento/Newsletter/composer.json +++ b/app/code/Magento/Newsletter/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-email": "0.74.0-beta4", - "magento/module-cron": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-require-js": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-email": "0.74.0-beta6", + "magento/module-cron": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-require-js": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/OfflinePayments/composer.json b/app/code/Magento/OfflinePayments/composer.json index eca86595e769565daef0c8ae2f52aa2cabb2e9ab..f47d2c7fd2030470d1926ef74a8e7376cf9a4b78 100644 --- a/app/code/Magento/OfflinePayments/composer.json +++ b/app/code/Magento/OfflinePayments/composer.json @@ -3,12 +3,12 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-payment": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-payment": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index 21c1fc1cf75899ce1fdbb49c15e31c9865d57c32..b89948409ebd294999cae7f1d7224bf3a19972b7 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -5,6 +5,8 @@ */ namespace Magento\OfflineShipping\Model\Carrier; +use Magento\Framework\Exception\LocalizedException; + class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements \Magento\Shipping\Model\Carrier\CarrierInterface { @@ -197,7 +199,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen * @param string $type * @param string $code * @return array - * @throws \Magento\Shipping\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getCode($type, $code = '') { @@ -215,7 +217,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen ]; if (!isset($codes[$type])) { - throw new \Magento\Shipping\Exception(__('Please correct Table Rate code type: %1.', $type)); + throw new LocalizedException(__('Please correct Table Rate code type: %1.', $type)); } if ('' === $code) { @@ -223,7 +225,7 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen } if (!isset($codes[$type][$code])) { - throw new \Magento\Shipping\Exception(__('Please correct Table Rate code for type %1: %2.', $type, $code)); + throw new LocalizedException(__('Please correct Table Rate code for type %1: %2.', $type, $code)); } return $codes[$type][$code]; diff --git a/app/code/Magento/OfflineShipping/composer.json b/app/code/Magento/OfflineShipping/composer.json index 5addaf40454af6dfe699153110419fc96ac1cc94..b3ddea4da64c2a823e492e92649ee945bc126687 100644 --- a/app/code/Magento/OfflineShipping/composer.json +++ b/app/code/Magento/OfflineShipping/composer.json @@ -3,21 +3,21 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-sales-rule": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-sales-rule": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/PageCache/composer.json b/app/code/Magento/PageCache/composer.json index e8ea0a1f3d32804522d2453079ffebbe3e7441ba..b8ad947ba68430c71160dc994e099cc10c073d59 100644 --- a/app/code/Magento/PageCache/composer.json +++ b/app/code/Magento/PageCache/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Payment/composer.json b/app/code/Magento/Payment/composer.json index 5061f1511de4c95d735e5c6dba89369a1b84eb22..b4e88d864a2b2c0868d6bd2cb685f0b81bcb0d4d 100644 --- a/app/code/Magento/Payment/composer.json +++ b/app/code/Magento/Payment/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-centinel": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-centinel": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Persistent/composer.json b/app/code/Magento/Persistent/composer.json index 25abba1b5ac7eb13d1471d96f7fea162f09ac610..6b71977bb0d02f8105c6b0fc6ab5b57c6345fd7b 100644 --- a/app/code/Magento/Persistent/composer.json +++ b/app/code/Magento/Persistent/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-cron": "0.74.0-beta4", - "magento/module-page-cache": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-cron": "0.74.0-beta6", + "magento/module-page-cache": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/ProductAlert/Setup/InstallSchema.php b/app/code/Magento/ProductAlert/Setup/InstallSchema.php index 8ccda0176f7682591e0a283f97287450c331ae2d..9926f11ef1196ec4729cdb8c68a56c64ab5be4e5 100644 --- a/app/code/Magento/ProductAlert/Setup/InstallSchema.php +++ b/app/code/Magento/ProductAlert/Setup/InstallSchema.php @@ -63,7 +63,7 @@ class InstallSchema implements InstallSchemaInterface 'add_date', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Product alert add date' )->addColumn( 'last_send_date', @@ -148,7 +148,7 @@ class InstallSchema implements InstallSchemaInterface 'add_date', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Product alert add date' )->addColumn( 'send_date', diff --git a/app/code/Magento/ProductAlert/composer.json b/app/code/Magento/ProductAlert/composer.json index 83547bc81c04703c952ece152defd1631fddc081..f6482671da0a929b537d916d2d9960bcf2b24161 100644 --- a/app/code/Magento/ProductAlert/composer.json +++ b/app/code/Magento/ProductAlert/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php index 992a93583b33679287c2e3513f31980e937ea072..96787607500b7216d5826ec63141a12741a564bf 100644 --- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php +++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php @@ -28,22 +28,45 @@ interface CartItemRepositoryInterface public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem); /** - * Remove bundle option + * Removes the specified item from the specified cart. + * + * @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 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 \Magento\Quote\Api\Data\CartItemInterface $cartItem - * @return void - * @throws \Magento\Framework\Exception\CouldNotSaveException + * @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 delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem); + public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem); /** * Removes the specified item from the specified cart. * - * @param int $cartId The cart ID. + * @param int $customerId Customer 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 deleteById($cartId, $itemId); + public function deleteByIdForCustomer($customerId, $itemId); } diff --git a/app/code/Magento/Quote/Api/CartManagementInterface.php b/app/code/Magento/Quote/Api/CartManagementInterface.php index 4bf49813ac4313319350c774ee038d1f312453da..fdc0d18085cf0a4b0acf0adcd9dfa8366b78190e 100644 --- a/app/code/Magento/Quote/Api/CartManagementInterface.php +++ b/app/code/Magento/Quote/Api/CartManagementInterface.php @@ -8,13 +8,21 @@ namespace Magento\Quote\Api; interface CartManagementInterface { /** - * Enables an administrative 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 $storeId + * @return int Cart ID. * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. + */ + 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 createEmptyCart($storeId); + public function createEmptyCartForCustomer($customerId); /** * Returns information for the cart for a specified customer. diff --git a/app/code/Magento/Quote/Api/Data/CartItemInterface.php b/app/code/Magento/Quote/Api/Data/CartItemInterface.php index 4951fe1698006419285934bc95c4645537394e1c..7fd33b17342861f61f868535d4baecfcfec46750 100644 --- a/app/code/Magento/Quote/Api/Data/CartItemInterface.php +++ b/app/code/Magento/Quote/Api/Data/CartItemInterface.php @@ -119,14 +119,14 @@ interface CartItemInterface extends \Magento\Framework\Api\ExtensibleDataInterfa /** * 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/Api/GuestBillingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0400edba25ea1ec38f32cc2e4ed20c145485bd4d --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestBillingAddressManagementInterface.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Billing address management interface for guest carts. + */ +interface GuestBillingAddressManagementInterface +{ + /** + * Assigns a specified billing address to a specified cart. + * + * @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. + * @throws \Magento\Framework\Exception\InputException The specified cart ID or address data is not valid. + */ + public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address); + + /** + * Returns the billing address for a specified quote. + * + * @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. + */ + public function get($cartId); +} diff --git a/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..40138b5e0cfdcc741a462fd19262df68fbc9c027 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Cart Item repository interface for guest carts. + */ +interface GuestCartItemRepositoryInterface +{ + /** + * Lists items that are assigned to a specified cart. + * + * @param string $cartId The cart ID. + * @return \Magento\Quote\Api\Data\CartItemInterface[] Array of items. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + */ + public function getList($cartId); + + /** + * Adds the specified item to the specified cart. + * + * @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 save(\Magento\Quote\Api\Data\CartItemInterface $cartItem); + + /** + * Removes the specified item from the specified cart. + * + * @param string $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 deleteById($cartId, $itemId); +} diff --git a/app/code/Magento/Quote/Api/GuestCartManagementInterface.php b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..7fa298c2d719d7586a81f41ce777502d7d49b60e --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartManagementInterface.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Cart Management interface for guest carts. + */ +interface GuestCartManagementInterface +{ + /** + * Enables an customer or guest user to create an empty cart and quote for an anonymous customer. + * + * @return string Cart ID. + * @throws \Magento\Framework\Exception\CouldNotSaveException The empty cart and quote could not be created. + */ + public function createEmptyCart(); + + /** + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..eb7293e15ee908aa31e5154aa5b86cf630a5cd97 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartRepositoryInterface.php @@ -0,0 +1,21 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Cart Repository interface for guest carts. + */ +interface GuestCartRepositoryInterface +{ + /** + * Enables a guest 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/Api/GuestCartTotalRepositoryInterface.php b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..6384407793a7a5f736751d304292a82a5b212c42 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCartTotalRepositoryInterface.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +/** + * Cart totals repository interface for guest carts. + */ +interface GuestCartTotalRepositoryInterface +{ + /** + * Returns quote totals data for a specified cart. + * + * @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. + */ + public function get($cartId); +} diff --git a/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..14d0a1d5def59cb543f8fc60024ba8f43f155af5 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestCouponManagementInterface.php @@ -0,0 +1,44 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +/** + * Coupon management interface for guest carts. + */ +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 new file mode 100644 index 0000000000000000000000000000000000000000..e40142b3e2cb2052603955128fad18bfb4aee765 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestPaymentMethodManagementInterface.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Payment method management interface for guest carts. + */ +interface GuestPaymentMethodManagementInterface +{ + /** + * Adds a specified payment method to a specified shopping cart. + * + * @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. + * @throws \Magento\Framework\Exception\State\InvalidTransitionException The billing or shipping address + * is not set, or the specified payment method is not available. + */ + public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method); + + /** + * Returns the payment method for a specified shopping cart. + * + * @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. + */ + public function get($cartId); + + /** + * Lists available payment methods for a specified shopping cart. + * + * @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. + */ + public function getList($cartId); +} diff --git a/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..c208b9a0fe19d91fc60b678eb4e12ab2a95d5b64 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestShippingAddressManagementInterface.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Shipping address management interface for guest carts. + */ +interface GuestShippingAddressManagementInterface +{ + /** + * Assigns a specified shipping address to a specified cart. + * + * @param string $cartId The cart ID. + * @param \Magento\Quote\Api\Data\AddressInterface $address The shipping address data. + * @return int Address ID. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + * @throws \Magento\Framework\Exception\InputException The specified cart ID or address data is not valid. + */ + public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address); + + /** + * Returns the shipping address for a specified quote. + * + * @param string $cartId The cart ID. + * @return \Magento\Quote\Api\Data\AddressInterface Shipping address object. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist. + */ + public function get($cartId); +} diff --git a/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php b/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0e881009d98567359254ceb57397a0fbb403155b --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +/** + * Shipping method management interface for guest carts. + */ +interface GuestShippingMethodManagementInterface +{ + /** + * Sets the carrier and shipping methods codes for a specified cart. + * + * @param string $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\StateException The billing or shipping address is not set. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart contains only virtual products + * so the shipping method does not apply. + */ + public function set($cartId, $carrierCode, $methodCode); + + /** + * Returns selected shipping method for a specified quote. + * + * @param string $cartId The shopping cart ID. + * @return \Magento\Quote\Api\Data\ShippingMethodInterface Shipping method. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified shopping cart does not exist. + * @throws \Magento\Framework\Exception\StateException The shipping address is not set. + */ + public function get($cartId); + + /** + * Lists applicable shipping methods for a specified quote. + * + * @param string $cartId The shopping cart ID. + * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods. + * @throws \Magento\Framework\Exception\NoSuchEntityException The specified quote does not exist. + * @throws \Magento\Framework\Exception\StateException The shipping address is not set. + */ + public function getList($cartId); +} 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 f7ab6e07b0ecd9b135f3b800cd9f05e7c29e3791..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/Model/Cart/Access/CartManagementPlugin.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Quote\Model\Cart\Access; - -use Magento\Framework\Exception\AuthorizationException; -use Magento\Authorization\Model\UserContextInterface; - -class CartManagementPlugin -{ - /** - * @var UserContextInterface - */ - protected $userContext; - - /** - * @var int[] - */ - protected $allowedUserTypes = [ - UserContextInterface::USER_TYPE_ADMIN, - UserContextInterface::USER_TYPE_INTEGRATION, - ]; - - /** - * @param UserContextInterface $userContext - */ - public function __construct(UserContextInterface $userContext) - { - $this->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 0410af82ca10c736cda6c151f8bd34e81e30d60d..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/Model/Cart/Access/CartRepositoryPlugin.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Quote\Model\Cart\Access; - -use Magento\Framework\Api\SearchCriteria; -use Magento\Framework\Exception\AuthorizationException; -use Magento\Authorization\Model\UserContextInterface; - -class CartRepositoryPlugin -{ - /** - * @var UserContextInterface - */ - protected $userContext; - - /** - * @var int[] - */ - protected $allowedUserTypes = [ - UserContextInterface::USER_TYPE_ADMIN, - UserContextInterface::USER_TYPE_INTEGRATION, - ]; - - /** - * @param UserContextInterface $userContext - */ - public function __construct(UserContextInterface $userContext) - { - $this->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/GuestCart/GuestBillingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php new file mode 100644 index 0000000000000000000000000000000000000000..61788f4920def75997a0a12225990c5ba1be89d8 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestBillingAddressManagement.php @@ -0,0 +1,61 @@ +<?php +/** + * 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\Api\BillingAddressManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Billing address management service for guest carts. + */ +class GuestBillingAddressManagement implements GuestBillingAddressManagementInterface +{ + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + + /** + * @var BillingAddressManagementInterface + */ + private $billingAddressManagement; + + /** + * Constructs a quote billing address service object. + * + * @param BillingAddressManagementInterface $billingAddressManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + BillingAddressManagementInterface $billingAddressManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->billingAddressManagement = $billingAddressManagement; + } + + /** + * {@inheritDoc} + */ + public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->billingAddressManagement->assign($quoteIdMask->getId(), $address); + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->billingAddressManagement->get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php new file mode 100644 index 0000000000000000000000000000000000000000..a3750601070b89099292981361a99667a5ec39b7 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php @@ -0,0 +1,78 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +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; + +/** + * Cart Item repository class for guest carts. + */ +class GuestCartItemRepository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface +{ + /** + * @var Repository + */ + protected $repository; + + /** + * @var QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * Constructs a read service object. + * + * @param \Magento\Quote\Model\Quote\Item\Repository $repository + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + \Magento\Quote\Model\Quote\Item\Repository $repository, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->repository = $repository; + } + + /** + * {@inheritdoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + $cartItemList = $this->repository->getList($quoteIdMask->getId()); + /** @var $item CartItemInterface */ + foreach ($cartItemList as $item) { + $item->setQuoteId($quoteIdMask->getMaskedId()); + } + return $cartItemList; + } + + /** + * {@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 $this->repository->save($cartItem); + } + + /** + * {@inheritdoc} + */ + public function deleteById($cartId, $itemId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->repository->deleteById($quoteIdMask->getId(), $itemId); + } +} 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 0000000000000000000000000000000000000000..c62fab57f1bc5bf9328c7bc02cc58745b10377d1 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartManagement.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Model\GuestCart; + +use Magento\Quote\Api\GuestCartManagementInterface; +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Cart Management class for guest carts. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class GuestCartManagement implements GuestCartManagementInterface +{ + /** + * @var CartManagementInterface + */ + protected $quoteManagement; + + /** + * @var QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * Initialize dependencies. + * + * @param CartManagementInterface $quoteManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ + public function __construct( + CartManagementInterface $quoteManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteManagement = $quoteManagement; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritdoc} + */ + public function createEmptyCart() + { + /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create(); + $cartId = $this->quoteManagement->createEmptyCart(); + $quoteIdMask->setId($cartId)->save(); + return $quoteIdMask->getMaskedId(); + } + + /** + * {@inheritdoc} + */ + public function assignCustomer($cartId, $customerId, $storeId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->quoteManagement->assignCustomer($quoteIdMask->getId(), $customerId, $storeId); + } + + /** + * {@inheritdoc} + */ + public function placeOrder($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->quoteManagement->placeOrder($quoteIdMask->getId()); + } +} 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 0000000000000000000000000000000000000000..577f2b2a76b039477036bfd932f68963b64c217a --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartRepository.php @@ -0,0 +1,51 @@ +<?php +/** + * 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\Api\CartRepositoryInterface; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Cart Repository class for guest carts. + */ +class GuestCartRepository implements GuestCartRepositoryInterface +{ + /** + * @var QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * @var CartRepositoryInterface + */ + protected $quoteRepository; + + /** + * Initialize dependencies. + * + * @param CartRepositoryInterface $quoteRepository + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + CartRepositoryInterface $quoteRepository, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->quoteRepository = $quoteRepository; + } + + /** + * {@inheritdoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->quoteRepository->get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php new file mode 100644 index 0000000000000000000000000000000000000000..1ab5f5eeb8c43a88c14705240f17878335b71fce --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCartTotalRepository.php @@ -0,0 +1,52 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Model\GuestCart; + +use Magento\Quote\Api\CartTotalRepositoryInterface; +use Magento\Quote\Api\GuestCartTotalRepositoryInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Cart totals repository class for guest carts. + */ +class GuestCartTotalRepository implements GuestCartTotalRepositoryInterface +{ + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + + /** + * @var CartTotalRepositoryInterface + */ + private $cartTotalRepository; + + /** + * Constructs a cart totals data object. + * + * @param CartTotalRepositoryInterface $cartTotalRepository + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + CartTotalRepositoryInterface $cartTotalRepository, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->cartTotalRepository = $cartTotalRepository; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->cartTotalRepository->get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php new file mode 100644 index 0000000000000000000000000000000000000000..90b1047ee3c867a5b3a414f42da47469b0b79387 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php @@ -0,0 +1,72 @@ +<?php +/** + * + * 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\Api\CouponManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Coupon management class for guest carts. + */ +class GuestCouponManagement implements GuestCouponManagementInterface +{ + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + + /** + * @var CouponManagementInterface + */ + private $couponManagement; + + /** + * Constructs a coupon read service object. + * + * @param CouponManagementInterface $couponManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + CouponManagementInterface $couponManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->couponManagement = $couponManagement; + } + + /** + * {@inheritdoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->couponManagement->get($quoteIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function set($cartId, $couponCode) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->couponManagement->set($quoteIdMask->getId(), $couponCode); + } + + /** + * {@inheritdoc} + */ + public function remove($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->couponManagement->remove($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php new file mode 100644 index 0000000000000000000000000000000000000000..b0b99599ef14d631512360cd1e5f9ff1446a1d2b --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Model\GuestCart; + +use Magento\Quote\Api\PaymentMethodManagementInterface; +use Magento\Quote\Api\GuestPaymentMethodManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Payment method management class for guest carts. + */ +class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterface +{ + /** + * @var QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * @var PaymentMethodManagementInterface + */ + protected $paymentMethodManagement; + + /** + * Initialize dependencies. + * + * @param PaymentMethodManagementInterface $paymentMethodManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + PaymentMethodManagementInterface $paymentMethodManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->paymentMethodManagement = $paymentMethodManagement; + } + + /** + * {@inheritdoc} + */ + public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->paymentMethodManagement->set($quoteIdMask->getId(), $method); + } + + /** + * {@inheritdoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->paymentMethodManagement->get($quoteIdMask->getId()); + } + + /** + * {@inheritdoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->paymentMethodManagement->getList($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php new file mode 100644 index 0000000000000000000000000000000000000000..f2ce3fb46fcf9834d1af86ae5a9e2b311e478eed --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingAddressManagement.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Model\GuestCart; + +use Magento\Quote\Api\GuestShippingAddressManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; +use Magento\Quote\Api\ShippingAddressManagementInterface; + +/** + * Shipping address management class for guest carts. + */ +class GuestShippingAddressManagement implements GuestShippingAddressManagementInterface +{ + /** + * @var QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * @var ShippingAddressManagementInterface + */ + protected $shippingAddressManagement; + + /** + * Constructs a quote shipping address write service object. + * + * @param ShippingAddressManagementInterface $shippingAddressManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + ShippingAddressManagementInterface $shippingAddressManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->shippingAddressManagement = $shippingAddressManagement; + $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 $this->shippingAddressManagement->assign($quoteIdMask->getId(), $address); + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->shippingAddressManagement->get($quoteIdMask->getId()); + } +} diff --git a/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php new file mode 100644 index 0000000000000000000000000000000000000000..e847e1bd36051c8da0845f0857d53994ce387ec9 --- /dev/null +++ b/app/code/Magento/Quote/Model/GuestCart/GuestShippingMethodManagement.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Model\GuestCart; + +use Magento\Quote\Api\GuestShippingMethodManagementInterface; +use Magento\Quote\Api\ShippingMethodManagementInterface; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Model\QuoteIdMaskFactory; + +/** + * Shipping method management class for guest carts. + */ +class GuestShippingMethodManagement implements GuestShippingMethodManagementInterface +{ + /** + * @var ShippingMethodManagementInterface + */ + private $shippingMethodManagement; + + /** + * @var QuoteIdMaskFactory + */ + private $quoteIdMaskFactory; + + /** + * Constructs a shipping method read service object. + * + * @param ShippingMethodManagementInterface $shippingMethodManagement + * @param QuoteIdMaskFactory $quoteIdMaskFactory + */ + public function __construct( + ShippingMethodManagementInterface $shippingMethodManagement, + QuoteIdMaskFactory $quoteIdMaskFactory + ) { + $this->shippingMethodManagement = $shippingMethodManagement; + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + } + + /** + * {@inheritDoc} + */ + public function get($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->shippingMethodManagement->get($quoteIdMask->getId()); + } + + /** + * {@inheritDoc} + */ + public function getList($cartId) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->shippingMethodManagement->getList($quoteIdMask->getId()); + } + + /** + * {@inheritDoc} + */ + public function set($cartId, $carrierCode, $methodCode) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + return $this->shippingMethodManagement->set($quoteIdMask->getId(), $carrierCode, $methodCode); + } +} diff --git a/app/code/Magento/Quote/Model/Quote/Item/Repository.php b/app/code/Magento/Quote/Model/Quote/Item/Repository.php index fc4a0f7db7ef47c3b71ea4bbab5be324167a7425..35b928ecb37a05f51135bf34ece53d0ecbd3a07b 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 @@ class Repository implements \Magento\Quote\Api\CartItemRepositoryInterface /** * {@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,35 @@ class Repository implements \Magento\Quote\Api\CartItemRepositoryInterface } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not remove item from quote')); } + + return true; } /** * {@inheritdoc} */ - public function deleteById($cartId, $itemId) + public function getListForCustomer($customerId) { - $item = $this->itemDataFactory->create() - ->setQuoteId($cartId) - ->setItemId($itemId); + $cart = $this->quoteRepository->getActiveForCustomer($customerId); + return $this->getList($cart->getId()); + } - $this->delete($item); - return true; + /** + * {@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/QuoteIdMask.php b/app/code/Magento/Quote/Model/QuoteIdMask.php new file mode 100644 index 0000000000000000000000000000000000000000..953fe1d7af87e232fca36fd79b9d79d0e69d367d --- /dev/null +++ b/app/code/Magento/Quote/Model/QuoteIdMask.php @@ -0,0 +1,63 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Model; + +/** + * QuoteIdMask model + * + * @method string getMaskedId() + * @method QuoteIdMask setMaskedId() + */ +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 + * + * @return void + */ + protected function _construct() + { + $this->_init('Magento\Quote\Model\Resource\Quote\QuoteIdMask'); + } + + /** + * Initialize quote identifier before save + * + * @return $this + */ + public function beforeSave() + { + parent::beforeSave(); + $this->setMaskedId($this->randomDataGenerator->getUniqueHash()); + return $this; + } +} diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 241f7d4c5784fee1ee0c48dbb53f94f4c42169a2..c09a32964aa3f3cf9c7c797a7629d55a10e19b21 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 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface 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,16 +150,32 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface $this->customerRepository = $customerRepository; $this->customerModelFactory = $customerModelFactory; $this->dataObjectHelper = $dataObjectHelper; + $this->storeManager = $storeManager; } /** * {@inheritdoc} */ - public function createEmptyCart($storeId) + public function createEmptyCart() { - $quote = $this->userContext->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER - ? $this->createCustomerCart($storeId) - : $this->createAnonymousCart($storeId); + $storeId = $this->storeManager->getStore()->getStoreId(); + $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); @@ -213,16 +237,17 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface /** * 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/Model/Resource/Quote/QuoteIdMask.php b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php new file mode 100644 index 0000000000000000000000000000000000000000..8fa2507073a2e4e9b86d23bc2c953363ecd5703b --- /dev/null +++ b/app/code/Magento/Quote/Model/Resource/Quote/QuoteIdMask.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Model\Resource\Quote; + +use Magento\Framework\Model\Resource\Db\AbstractDb; + +/** + * QuoteIdMask Resource model + * @codeCoverageIgnore + */ +class QuoteIdMask extends AbstractDb +{ + /** + * Main table and field initialization + * + * @return void + */ + protected function _construct() + { + $this->_init('quote_id_mask', 'quote_id'); + $this->_isPkAutoIncrement = false; + } +} diff --git a/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php new file mode 100644 index 0000000000000000000000000000000000000000..3f5b280d505d2762e48b42c4715f1cdf74aa04a0 --- /dev/null +++ b/app/code/Magento/Quote/Model/Webapi/ParamOverriderCartId.php @@ -0,0 +1,63 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Model\Webapi; + +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Quote\Api\CartManagementInterface; + +/** + * Replaces a "%cart_id%" value with the current authenticated customer's cart + */ +class ParamOverriderCartId implements ParamOverriderInterface +{ + /** + * @var UserContextInterface + */ + private $userContext; + + /** + * @var CartManagementInterface + */ + 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 + ) { + $this->userContext = $userContext; + $this->cartManagement = $cartManagement; + } + + /** + * {@inheritDoc} + */ + public function getOverriddenValue() + { + 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(); + } + } + } catch (NoSuchEntityException $e) { + /* do nothing and just return null */ + } + return null; + } +} diff --git a/app/code/Magento/Quote/Setup/InstallSchema.php b/app/code/Magento/Quote/Setup/InstallSchema.php index 7e9947028060c0ec596393146748c4e5907b7789..905cfba56782664a89b0d33b722e9e43828e7319 100644 --- a/app/code/Magento/Quote/Setup/InstallSchema.php +++ b/app/code/Magento/Quote/Setup/InstallSchema.php @@ -1535,6 +1535,35 @@ class InstallSchema implements InstallSchemaInterface ); $installer->getConnection()->createTable($table); + /** + * Create table to store cartId and obscured UUID based cartId mapping + */ + $table = $installer->getConnection()->newTable( + $installer->getTable('quote_id_mask') + )->addColumn( + 'quote_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + ['identity' => true, 'unsigned' => true, 'nullable' => false], + 'Quote ID' + )->addForeignKey( + 'quote_id', + 'quote_id', + $installer->getTable('quote'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE + )->addColumn( + 'masked_id', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 32, + ['nullable' => 'false'], + 'Masked ID' + )->setComment( + 'Quote ID and masked ID mapping' + ); + + $installer->getConnection()->createTable($table); + $installer->endSetup(); } 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 4a900ce7550ec771285259f09d35f2055e6eaeeb..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartManagementPluginTest.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Quote\Test\Unit\Model\Cart\Access; - -use \Magento\Quote\Model\Cart\Access\CartManagementPlugin; - -class CartManagementPluginTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Quote\Model\Cart\Access\CartManagementPlugin - */ - protected $model; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $userContextMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $subjectMock; - - protected function setUp() - { - $this->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 d4e5a472c390440024e37095090d777f8b7cf0ba..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/Test/Unit/Model/Cart/Access/CartRepositoryPluginTest.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Quote\Test\Unit\Model\Cart\Access; - -use \Magento\Quote\Model\Cart\Access\CartRepositoryPlugin; - -class CartRepositoryPluginTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Quote\Model\Cart\Access\CartRepositoryPlugin - */ - protected $model; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $userContextMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $subjectMock; - - protected function setUp() - { - $this->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/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4f6a3e63a632df58afc6eadeb44871820866100c --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestBillingAddressManagementTest.php @@ -0,0 +1,97 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestBillingAddressManagement + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $billingAddressManagementMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $addressMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + /** + * @return void + */ + 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\Api\BillingAddressManagementInterface', + [], + [], + '', + 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\GuestBillingAddressManagement', + [ + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + 'billingAddressManagement' => $this->billingAddressManagementMock + ] + ); + } + + /** + * @return void + */ + public function testGet() + { + $this->billingAddressManagementMock->expects($this->once())->method('get')->willReturn($this->addressMock); + $this->assertEquals($this->addressMock, $this->model->get($this->maskedCartId)); + } + + /** + * @return void + */ + public function testAssign() + { + $addressId = 1; + $this->billingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId); + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->addressMock)); + } +} 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 0000000000000000000000000000000000000000..9535e3c1c7455e063d9fa7770e48e15616ede6a0 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php @@ -0,0 +1,133 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestCartItemRepositoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestCartItemRepository + */ + protected $guestCartItemRepository; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $cartItemRepositoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteItemMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var string + */ + protected $cartId; + + /** + * @return void + */ + protected function setUp() + { + $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, + ] + ); + } + + /** + * @return void + */ + public function testSave() + { + $expectedValue = 'expected value'; + $this->cartItemRepositoryMock->expects($this->once()) + ->method('save') + ->willReturn($expectedValue); + $this->assertEquals($expectedValue, $this->guestCartItemRepository->save($this->quoteItemMock)); + } + + /** + * @return void + */ + public function testGetList() + { + $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 testDeleteById() + { + $itemId = 5; + $this->cartItemRepositoryMock->expects($this->once()) + ->method('deleteById') + ->with($this->cartId, $itemId) + ->willReturn(true); + $this->assertTrue($this->guestCartItemRepository->deleteById($this->maskedCartId, $itemId)); + } +} 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 0000000000000000000000000000000000000000..444aa62322a04a9a039b274755c0e8ab863a2ddc --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartManagementTest.php @@ -0,0 +1,116 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestCartManagementTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteManagementMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteRepositoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \Magento\Quote\Model\GuestCart\GuestCartManagement + */ + protected $guestCartManagement; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->quoteManagementMock = $this->getMockForAbstractClass( + 'Magento\Quote\Api\CartManagementInterface', + [], + '', + false, + true, + true, + [] + ); + $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, + '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)); + } +} 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 0000000000000000000000000000000000000000..3a7e2fac3ae37a9fb1d30bdceb39a88616c40ac6 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartRepositoryTest.php @@ -0,0 +1,75 @@ +<?php +/** + * + * 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 +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestCartRepository + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteRepositoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->quoteRepositoryMock = $this->getMock('Magento\Quote\Api\CartRepositoryInterface', [], [], '', false); + $this->quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', 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\GuestCartRepository', + [ + 'quoteRepository' => $this->quoteRepositoryMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGet() + { + $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 new file mode 100644 index 0000000000000000000000000000000000000000..25649077b5fd6c9bbe8a478b4987947d59eda4cc --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTestHelper.php @@ -0,0 +1,54 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +/** + * Class GuestCartTestHelper + * + */ +class GuestCartTestHelper +{ + /** + * @var \PHPUnit_Framework_TestCase + */ + protected $testCase; + + /** + * Initialize helper + * + * @param \PHPUnit_Framework_TestCase $testCase + */ + public function __construct(\PHPUnit_Framework_TestCase $testCase) + { + $this->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) + { + $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(); + $quoteIdMaskMock->expects($this->testCase->once())->method('getId')->willReturn($cartId); + return [$quoteIdMaskFactoryMock, $quoteIdMaskMock]; + } +} 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 0000000000000000000000000000000000000000..a8ef8d94e9fa2f92b324d81931ed87c7cd647e0b --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartTotalRepositoryTest.php @@ -0,0 +1,82 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestCartTotalRepositoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestCartTotalRepository + */ + protected $model; + + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManager; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $cartTotalRepository; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + public function setUp() + { + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->cartTotalRepository = $this->getMockBuilder('Magento\Quote\Api\CartTotalRepositoryInterface') + ->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', + [ + 'cartTotalRepository' => $this->cartTotalRepository, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + ] + ); + } + + public function testGetTotals() + { + $retValue = 'retValue'; + + $this->cartTotalRepository->expects($this->once()) + ->method('get') + ->with($this->cartId) + ->will($this->returnValue($retValue)); + $this->assertSame($retValue, $this->model->get($this->maskedCartId)); + } +} 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 0000000000000000000000000000000000000000..74b00ed942f4a1ba2d8e05e4ab678a9ad05c7d3d --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php @@ -0,0 +1,87 @@ +<?php +/** + * + * 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 +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestCouponManagement + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $couponManagementMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + /** + * @var string + */ + protected $couponCode; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->couponManagementMock = $this->getMock('Magento\Quote\Api\CouponManagementInterface', [], [], '', false); + + $this->couponCode = 'test_coupon_code'; + $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\GuestCouponManagement', + [ + 'couponManagement' => $this->couponManagementMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGet() + { + $this->couponManagementMock->expects($this->once())->method('get')->willReturn($this->couponCode); + $this->assertEquals($this->couponCode, $this->model->get($this->maskedCartId)); + } + + public function testSet() + { + $this->couponManagementMock->expects($this->once())->method('set')->willReturn(true); + $this->assertTrue($this->model->set($this->maskedCartId, $this->couponCode)); + } + + public function testRemove() + { + $this->couponManagementMock->expects($this->once())->method('remove')->willReturn(true); + $this->assertTrue($this->model->remove($this->maskedCartId)); + } +} 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 0000000000000000000000000000000000000000..ebde097f89bd4c551b920d69fac12fc3b4543497 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestPaymentMethodManagementTest.php @@ -0,0 +1,94 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestPaymentMethodManagementTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $paymentMethodManagementMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $paymentMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->paymentMethodManagementMock = $this->getMock( + 'Magento\Quote\Api\PaymentMethodManagementInterface', + [], + [], + '', + 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 = $objectManager->getObject( + 'Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement', + [ + 'paymentMethodManagement' => $this->paymentMethodManagementMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testGet() + { + $this->paymentMethodManagementMock->expects($this->once())->method('get')->willReturn($this->paymentMock); + $this->assertEquals($this->paymentMock, $this->model->get($this->maskedCartId)); + } + + public function testGetList() + { + $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() + { + $paymentId = 20; + $this->paymentMethodManagementMock->expects($this->once())->method('set')->willReturn($paymentId); + $this->assertEquals($paymentId, $this->model->set($this->maskedCartId, $this->paymentMock)); + } +} 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 0000000000000000000000000000000000000000..67e35a93bf73c07409993caf9926d5fc77232301 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingAddressManagementTest.php @@ -0,0 +1,91 @@ +<?php +/** + * + * 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 +{ + /** + * @var \Magento\Quote\Api\GuestShippingAddressManagementInterface + */ + protected $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteAddressMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $quoteIdMaskMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $shippingAddressManagementMock; + + /** + * @var string + */ + protected $maskedCartId; + + /** + * @var int + */ + protected $cartId; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->shippingAddressManagementMock = $this->getMock( + 'Magento\Quote\Api\ShippingAddressManagementInterface', + [], + [], + '', + 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', + [ + 'shippingAddressManagement' => $this->shippingAddressManagementMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock + ] + ); + } + + public function testAssign() + { + $addressId = 1; + $this->shippingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId); + $this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->quoteAddressMock)); + } + + public function testGet() + { + $this->shippingAddressManagementMock->expects($this->once())->method('get')->willReturn( + $this->quoteAddressMock + ); + $this->assertEquals($this->quoteAddressMock, $this->model->get($this->maskedCartId)); + } +} 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 0000000000000000000000000000000000000000..c91510a165fac2c1ecbacf3400cfba4b6f6d5be1 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php @@ -0,0 +1,103 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Test\Unit\Model\GuestCart; + +class GuestShippingMethodManagementTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Quote\Api\GuestShippingMethodManagementInterface + */ + private $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $shippingMethodManagementMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $quoteIdMaskFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $quoteIdMaskMock; + + /** + * @var string + */ + private $maskedCartId; + + /** + * @var string + */ + private $cartId; + + protected function setUp() + { + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->shippingMethodManagementMock = + $this->getMockBuilder('Magento\Quote\Api\ShippingMethodManagementInterface') + ->getMockForAbstractClass(); + + $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', + [ + 'shippingMethodManagement' => $this->shippingMethodManagementMock, + 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, + ] + ); + } + + 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)); + } +} 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 b90d93933827cbe676a413b79cbc4ed2e0d615b4..9081537f2790e8389100a5e3c4549e3578cc0222 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 { @@ -160,6 +160,38 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $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 @@ -260,15 +292,13 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase { $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); } /** @@ -280,8 +310,6 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase { $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()) @@ -296,18 +324,21 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase ->with($this->quoteMock) ->willThrowException($exception); - $this->repository->delete($this->dataMock); + $this->repository->deleteById($cartId, $itemId); } /** * @return void */ - public function testDelete() + public function testDeleteByIdForCustomer() { + $customerId = 1; $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('getActiveForCustomer') + ->with($customerId) + ->will($this->returnValue($this->quoteMock)); + $this->quoteMock->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()) @@ -316,7 +347,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $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->assertTrue($this->repository->deleteByIdForCustomer($customerId, $itemId)); } /** @@ -334,6 +365,27 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase $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 */ @@ -341,13 +393,6 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase { $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()) 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 0000000000000000000000000000000000000000..9bd03b6bea45e5fc97ad1eac52d1285c458bd2b0 --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/QuoteIdMaskTest.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +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 + */ + protected $quoteIdMask; + + protected function setUp() + { + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->quoteIdMask = $helper->getObject( + 'Magento\Quote\Model\QuoteIdMask', + ['randomDataGenerator' => new Random()] + ); + } + + public function testBeforeSave() + { + $this->quoteIdMask->beforeSave(); + $this->assertNotNull($this->quoteIdMask->getMaskedId(), 'Masked identifier is not generated.'); + } +} diff --git a/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php index 522734a324ad98bc080654f4ceaee3e3a6da295e..12c4248d82c81175ac6d23d31f714611e1f08495 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 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase '', 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 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase 'customerRepository' => $this->customerRepositoryMock, 'customerModelFactory' => $this->customerFactoryMock, 'dataObjectHelper' => $dataObjectHelper, + 'storeManager' => $this->storeManagerMock ] ); } @@ -171,20 +186,19 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase $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() + public function testCreateEmptyCartForCustomer() { $storeId = 345; $quoteId = 2311; @@ -192,18 +206,6 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase $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,48 +214,39 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase $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->createEmptyCartForCustomer($userId)); } /** * @expectedException \Magento\Framework\Exception\CouldNotSaveException */ - public function testCreateEmptyCartLoggedInUserException() + public function testCreateEmptyCartForCustomerException() { $storeId = 345; $userId = 567; $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->createEmptyCartForCustomer($userId); } /** 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 0000000000000000000000000000000000000000..cb83bf6112341df2a9f9ccadcd2824b57ebed0fc --- /dev/null +++ b/app/code/Magento/Quote/Test/Unit/Model/Webapi/ParamOverriderCartIdTest.php @@ -0,0 +1,116 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Test\Unit\Model\Webapi; + +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Model\Webapi\ParamOverriderCartId; + +/** + * Test for \Magento\Quote\Model\Webapi\ParamOverriderCartId + */ +class ParamOverriderCartIdTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ParamOverriderCartId + */ + private $model; + + /** + * @var UserContextInterface + */ + private $userContext; + + public function setUp() + { + $this->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 testGetOverriddenValueIsCustomerAndCartExists() + { + $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->getOverriddenValue()); + } + + public function testGetOverriddenValueIsCustomerAndCartDoesNotExist() + { + $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)); + + $this->cartManagement->expects($this->once()) + ->method('getCartForCustomer') + ->with($customerId) + ->will($this->throwException(new NoSuchEntityException())); + + $this->assertNull($this->model->getOverriddenValue()); + } + + public function testGetOverriddenValueIsCustomerAndCartIsNull() + { + $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)); + + $this->cartManagement->expects($this->once()) + ->method('getCartForCustomer') + ->with($customerId) + ->will($this->returnValue(null)); + + $this->assertNull($this->model->getOverriddenValue()); + } + + public function testGetOverriddenValueIsNotCustomer() + { + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); + + $this->assertNull($this->model->getOverriddenValue()); + } +} diff --git a/app/code/Magento/Quote/composer.json b/app/code/Magento/Quote/composer.json index 173e239f796d8072845d23365a02360f0f45a16d..c4bf2a50e6d26dbf3884fd47edee836d756ea200 100644 --- a/app/code/Magento/Quote/composer.json +++ b/app/code/Magento/Quote/composer.json @@ -3,25 +3,25 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-catalog-rule": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-sales-sequence": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-catalog-rule": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-sales-sequence": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Quote/etc/acl.xml b/app/code/Magento/Quote/etc/acl.xml new file mode 100644 index 0000000000000000000000000000000000000000..14792adfa7170110bfc1da6dd6c6c6c347686f87 --- /dev/null +++ b/app/code/Magento/Quote/etc/acl.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd"> + <acl> + <resources> + <resource id="Magento_Backend::admin"> + <resource id="Magento_Cart::cart" title="Carts" sortOrder="40"> + <resource id="Magento_Cart::manage" title="Manage carts" sortOrder="10" /> + </resource> + </resource> + </resources> + </acl> +</config> diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 214e414e3207d0c9a2438f9f68d3ac35456f581e..4eeb1ff2b61a7e865d24c28af7411c599b7c3f05 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -25,4 +25,22 @@ <preference for="Magento\Quote\Api\Data\TotalsInterface" type="\Magento\Quote\Model\Cart\Totals" /> <preference for="Magento\Quote\Api\Data\TotalsItemInterface" type="\Magento\Quote\Model\Quote\Cart\Totals\Item" /> <preference for="Magento\Quote\Api\Data\CurrencyInterface" type="\Magento\Quote\Model\Cart\Currency" /> + + <preference for="Magento\Quote\Api\GuestCartManagementInterface" type="Magento\Quote\Model\GuestCart\GuestCartManagement" /> + <preference for="Magento\Quote\Api\GuestCartRepositoryInterface" type="Magento\Quote\Model\GuestCart\GuestCartRepository" /> + <preference for="Magento\Quote\Api\GuestCartItemRepositoryInterface" type="Magento\Quote\Model\GuestCart\GuestCartItemRepository" /> + <preference for="Magento\Quote\Api\GuestCouponManagementInterface" type="Magento\Quote\Model\GuestCart\GuestCouponManagement" /> + <preference for="Magento\Quote\Api\GuestPaymentMethodManagementInterface" type="Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement" /> + <preference for="Magento\Quote\Api\GuestCartTotalRepositoryInterface" type="Magento\Quote\Model\GuestCart\GuestCartTotalRepository" /> + <preference for="Magento\Quote\Api\GuestShippingAddressManagementInterface" type="Magento\Quote\Model\GuestCart\GuestShippingAddressManagement" /> + <preference for="Magento\Quote\Api\GuestShippingMethodManagementInterface" type="Magento\Quote\Model\GuestCart\GuestShippingMethodManagement" /> + <preference for="Magento\Quote\Api\GuestBillingAddressManagementInterface" type="Magento\Quote\Model\GuestCart\GuestBillingAddressManagement" /> + + <type name="Magento\Webapi\Controller\Rest\ParamsOverrider"> + <arguments> + <argument name="paramOverriders" xsi:type="array"> + <item name="%cart_id%" xsi:type="object">Magento\Quote\Model\Webapi\ParamOverriderCartId</item> + </argument> + </arguments> + </type> </config> diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index 412dab6361b1f7ef5e24168ebcb9b1b980a32c48..9540a2d3b88aa9d72923608322fec5834eb2d382 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -7,34 +7,101 @@ --> <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd"> + + <!-- Managing Cart --> <route url="/V1/carts/:cartId" method="GET"> <service class="Magento\Quote\Api\CartRepositoryInterface" method="get"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts" method="GET"> <service class="Magento\Quote\Api\CartRepositoryInterface" method="getList"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/" method="POST"> <service class="Magento\Quote\Api\CartManagementInterface" method="createEmptyCart"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + <route url="/V1/customers/:customerId/carts" method="POST"> + <service class="Magento\Quote\Api\CartManagementInterface" method="createEmptyCartForCustomer"/> + <resources> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId" method="PUT"> <service class="Magento\Quote\Api\CartManagementInterface" method="assignCustomer"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing my Cart --> + <route url="/V1/carts/mine" method="POST"> + <service class="Magento\Quote\Api\CartManagementInterface" method="createEmptyCartForCustomer"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine" method="GET"> + <service class="Magento\Quote\Api\CartManagementInterface" method="getCartForCustomer"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/order" method="PUT"> + <service class="Magento\Quote\Api\CartManagementInterface" method="placeOrder"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing guest carts --> + + <route url="/V1/guest-carts/:cartId" method="GET"> + <service class="Magento\Quote\Api\GuestCartRepositoryInterface" method="get"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <!-- No getList for anonymous guest cart users --> + <route url="/V1/guest-carts" method="POST"> + <service class="Magento\Quote\Api\GuestCartManagementInterface" method="createEmptyCart"/> <resources> <resource ref="anonymous" /> </resources> </route> + <route url="/V1/guest-carts/:cartId" method="PUT"> + <service class="Magento\Quote\Api\GuestCartManagementInterface" method="assignCustomer"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/order" method="PUT"> + <service class="Magento\Quote\Api\GuestCartManagementInterface" method="placeOrder"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + + <!-- Managing Cart Shipment Method --> <route url="/V1/carts/:cartId/selected-shipping-method" method="PUT"> <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="set"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/selected-shipping-method" method="GET"> @@ -45,14 +112,65 @@ </route> <route url="/V1/carts/:cartId/shipping-methods" method="GET"> <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="getList"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing My Cart Shipment Method --> + <route url="/V1/carts/mine/selected-shipping-method" method="PUT"> + <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="set"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/selected-shipping-method" method="GET"> + <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="get"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/shipping-methods" method="GET"> + <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="getList"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing Guest Cart Shipment Method --> + <route url="/V1/guest-carts/:cartId/selected-shipping-method" method="PUT"> + <service class="Magento\Quote\Api\GuestShippingMethodManagementInterface" method="set"/> <resources> <resource ref="anonymous" /> </resources> </route> + <route url="/V1/guest-carts/:cartId/selected-shipping-method" method="GET"> + <service class="Magento\Quote\Api\GuestShippingMethodManagementInterface" method="get"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/shipping-methods" method="GET"> + <service class="Magento\Quote\Api\GuestShippingMethodManagementInterface" method="getList"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + + <!-- Managing Cart Items --> <route url="/V1/carts/:cartId/items" method="GET"> <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="getList"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/items" method="POST"> @@ -64,91 +182,346 @@ <route url="/V1/carts/items/:itemId" method="PUT"> <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="save"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/items/:itemId" method="DELETE"> <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="deleteById"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Items --> + <route url="/V1/guest-carts/:cartId/items" method="GET"> + <service class="Magento\Quote\Api\GuestCartItemRepositoryInterface" method="getList"/> <resources> <resource ref="anonymous" /> </resources> </route> - <route url="/V1/carts/:cartId/selected-payment-methods" method="GET"> - <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="get"/> + <route url="/V1/guest-carts/items" method="POST"> + <service class="Magento\Quote\Api\GuestCartItemRepositoryInterface" method="save"/> <resources> <resource ref="anonymous" /> </resources> </route> - <route url="/V1/carts/:cartId/selected-payment-methods" method="PUT"> - <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="set"/> + <route url="/V1/guest-carts/items/:itemId" method="PUT"> + <service class="Magento\Quote\Api\GuestCartItemRepositoryInterface" method="save"/> <resources> <resource ref="anonymous" /> </resources> </route> + <route url="/V1/guest-carts/:cartId/items/:itemId" method="DELETE"> + <service class="Magento\Quote\Api\GuestCartItemRepositoryInterface" method="deleteById"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + + <!-- Managing my Cart Items --> + <route url="/V1/carts/mine/items" method="GET"> + <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="getList"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/items" method="POST"> + <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="save"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/items/:itemId" method="PUT"> + <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="save"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/items/:itemId" method="DELETE"> + <service class="Magento\Quote\Api\CartItemRepositoryInterface" method="deleteById"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="customerId" force="true">%customer_id%</parameter> + </data> + </route> + + <!-- Managing Cart Payment --> + <route url="/V1/carts/:cartId/selected-payment-method" method="GET"> + <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="get"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + <route url="/V1/carts/:cartId/selected-payment-method" method="PUT"> + <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="set"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> <route url="/V1/carts/:cartId/payment-methods" method="GET"> <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="getList"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Payment --> + <route url="/V1/guest-carts/:cartId/selected-payment-method" method="GET"> + <service class="Magento\Quote\Api\GuestPaymentMethodManagementInterface" method="get"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/selected-payment-method" method="PUT"> + <service class="Magento\Quote\Api\GuestPaymentMethodManagementInterface" method="set"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/payment-methods" method="GET"> + <service class="Magento\Quote\Api\GuestPaymentMethodManagementInterface" method="getList"/> <resources> <resource ref="anonymous" /> </resources> </route> + + <!-- Managing my Cart Payment --> + <route url="/V1/carts/mine/selected-payment-method" method="GET"> + <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="get"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/selected-payment-method" method="PUT"> + <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="set"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/payment-methods" method="GET"> + <service class="Magento\Quote\Api\PaymentMethodManagementInterface" method="getList"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing Cart Billing address --> <route url="/V1/carts/:cartId/billing-address" method="GET"> <service class="Magento\Quote\Api\BillingAddressManagementInterface" method="get"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/billing-address" method="POST"> <service class="Magento\Quote\Api\BillingAddressManagementInterface" method="assign"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Billing address --> + <route url="/V1/guest-carts/:cartId/billing-address" method="GET"> + <service class="Magento\Quote\Api\GuestBillingAddressManagementInterface" method="get"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/billing-address" method="POST"> + <service class="Magento\Quote\Api\GuestBillingAddressManagementInterface" method="assign"/> <resources> <resource ref="anonymous" /> </resources> </route> + + <!-- Managing My Cart Billing address --> + <route url="/V1/carts/mine/billing-address" method="GET"> + <service class="Magento\Quote\Api\BillingAddressManagementInterface" method="get"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/billing-address" method="POST"> + <service class="Magento\Quote\Api\BillingAddressManagementInterface" method="assign"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing Cart Coupons --> <route url="/V1/carts/:cartId/coupons" method="GET"> <service class="Magento\Quote\Api\CouponManagementInterface" method="get"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/coupons/:couponCode" method="PUT"> <service class="Magento\Quote\Api\CouponManagementInterface" method="set"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/coupons" method="DELETE"> <service class="Magento\Quote\Api\CouponManagementInterface" method="remove"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Coupons --> + <route url="/V1/guest-carts/:cartId/coupons" method="GET"> + <service class="Magento\Quote\Api\GuestCouponManagementInterface" method="get"/> <resources> <resource ref="anonymous" /> </resources> </route> + <route url="/V1/guest-carts/:cartId/coupons/:couponCode" method="PUT"> + <service class="Magento\Quote\Api\GuestCouponManagementInterface" method="set"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/coupons" method="DELETE"> + <service class="Magento\Quote\Api\GuestCouponManagementInterface" method="remove"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + + <!-- Managing mine Cart Coupons --> + <route url="/V1/carts/mine/coupons" method="GET"> + <service class="Magento\Quote\Api\CouponManagementInterface" method="get"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/coupons/:couponCode" method="PUT"> + <service class="Magento\Quote\Api\CouponManagementInterface" method="set"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/coupons" method="DELETE"> + <service class="Magento\Quote\Api\CouponManagementInterface" method="remove"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing Cart Shipping address --> <route url="/V1/carts/:cartId/shipping-address" method="GET"> <service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="get"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> <route url="/V1/carts/:cartId/shipping-address" method="POST"> <service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="assign"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Shipping address --> + <route url="/V1/guest-carts/:cartId/shipping-address" method="GET"> + <service class="Magento\Quote\Api\GuestShippingAddressManagementInterface" method="get"/> + <resources> + <resource ref="anonymous" /> + </resources> + </route> + <route url="/V1/guest-carts/:cartId/shipping-address" method="POST"> + <service class="Magento\Quote\Api\GuestShippingAddressManagementInterface" method="assign"/> <resources> <resource ref="anonymous" /> </resources> </route> + + <!-- Managing My Cart Shipping address --> + <route url="/V1/carts/mine/shipping-address" method="GET"> + <service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="get"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + <route url="/V1/carts/mine/shipping-address" method="POST"> + <service class="Magento\Quote\Api\ShippingAddressManagementInterface" method="assign"/> + <resources> + <resource ref="self" /> + </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> + </route> + + <!-- Managing Cart Order --> <route url="/V1/carts/:cartId/order" method="PUT"> <service class="Magento\Quote\Api\CartManagementInterface" method="placeOrder"/> <resources> - <resource ref="anonymous" /> + <resource ref="Magento_Cart::manage" /> </resources> </route> + + <!-- Managing Cart Total --> <route url="/V1/carts/:cartId/totals" method="GET"> <service class="Magento\Quote\Api\CartTotalRepositoryInterface" method="get"/> + <resources> + <resource ref="Magento_Cart::manage" /> + </resources> + </route> + + <!-- Managing Guest Cart Total --> + <route url="/V1/guest-carts/:cartId/totals" method="GET"> + <service class="Magento\Quote\Api\GuestCartTotalRepositoryInterface" method="get"/> <resources> <resource ref="anonymous" /> </resources> </route> - <route url="/V1/customer/:customerId/cart" method="GET"> - <service class="Magento\Quote\Api\CartManagementInterface" method="getCartForCustomer"/> + + <!-- Managing My Cart Total --> + <route url="/V1/carts/mine/totals" method="GET"> + <service class="Magento\Quote\Api\CartTotalRepositoryInterface" method="get"/> <resources> <resource ref="self" /> </resources> + <data> + <parameter name="cartId" force="true">%cart_id%</parameter> + </data> </route> </routes> 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 67774a740401df953616e1fedae05e822e81d32e..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/etc/webapi_rest/di.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0"?> -<!-- -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ ---> -<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> - <type name="Magento\Quote\Api\CartRepositoryInterface"> - <plugin name="admin_access" type="\Magento\Quote\Model\Cart\Access\CartRepositoryPlugin" /> - </type> - <type name="Magento\Quote\Api\CartManagementInterface"> - <plugin name="admin_access" type="\Magento\Quote\Model\Cart\Access\CartManagementPlugin" /> - </type> -</config> 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 67774a740401df953616e1fedae05e822e81d32e..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/etc/webapi_soap/di.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0"?> -<!-- -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ ---> -<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> - <type name="Magento\Quote\Api\CartRepositoryInterface"> - <plugin name="admin_access" type="\Magento\Quote\Model\Cart\Access\CartRepositoryPlugin" /> - </type> - <type name="Magento\Quote\Api\CartManagementInterface"> - <plugin name="admin_access" type="\Magento\Quote\Model\Cart\Access\CartManagementPlugin" /> - </type> -</config> diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php index cb2a9333fe01e3f67cc168067fc0fdc0a1bcc773..ea190558cac88646b628f4affaa5583f23f92d14 100644 --- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php @@ -323,7 +323,7 @@ class Collection extends \Magento\Quote\Model\Resource\Quote\Collection * * @param array $productIds * @return array - * @throws \Magento\Eav\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getProductData(array $productIds) { diff --git a/app/code/Magento/Reports/Setup/InstallSchema.php b/app/code/Magento/Reports/Setup/InstallSchema.php index 707597f5a747a2192ff1cb20072745c0a6e21ff4..7e619a704833f703ce6f0c9f97e4a37333e1912e 100644 --- a/app/code/Magento/Reports/Setup/InstallSchema.php +++ b/app/code/Magento/Reports/Setup/InstallSchema.php @@ -73,7 +73,7 @@ class InstallSchema implements InstallSchemaInterface 'added_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Added At' ) ->addIndex( @@ -181,7 +181,7 @@ class InstallSchema implements InstallSchemaInterface 'added_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Added At' ) ->addIndex( @@ -288,7 +288,7 @@ class InstallSchema implements InstallSchemaInterface 'logged_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Logged At' ) ->addColumn( @@ -411,7 +411,7 @@ class InstallSchema implements InstallSchemaInterface 'added_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Added At' ) ->addIndex( @@ -517,7 +517,7 @@ class InstallSchema implements InstallSchemaInterface 'added_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Added At' ) ->addIndex( diff --git a/app/code/Magento/Reports/composer.json b/app/code/Magento/Reports/composer.json index aabd59fe60af0937968167b270d3772ab595f3c5..575834f57dafa4f07f7bb71ab6935fde724e4731 100644 --- a/app/code/Magento/Reports/composer.json +++ b/app/code/Magento/Reports/composer.json @@ -3,28 +3,28 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-log": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-review": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-downloadable": "0.74.0-beta4", - "magento/module-sales-rule": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-log": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-review": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-downloadable": "0.74.0-beta6", + "magento/module-sales-rule": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/RequireJs/composer.json b/app/code/Magento/RequireJs/composer.json index 3bdd116df217cb19613fd885737933763b3b5a5f..968f8b00f4780f6abfd675c4d73350b3d1b10f95 100644 --- a/app/code/Magento/RequireJs/composer.json +++ b/app/code/Magento/RequireJs/composer.json @@ -3,11 +3,11 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Review/Setup/InstallSchema.php b/app/code/Magento/Review/Setup/InstallSchema.php index 276b7389bff8fd84a89d735d65747ae079a59320..147688bdf15e3b7dbab52eefab5c1104c547a77a 100644 --- a/app/code/Magento/Review/Setup/InstallSchema.php +++ b/app/code/Magento/Review/Setup/InstallSchema.php @@ -84,7 +84,7 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Review create date' ) ->addColumn( diff --git a/app/code/Magento/Review/composer.json b/app/code/Magento/Review/composer.json index d4cf70a117e957764d7c480611352dafc9306fa4..35197e270227acf8a04a3e0915411c076af46e0d 100644 --- a/app/code/Magento/Review/composer.json +++ b/app/code/Magento/Review/composer.json @@ -3,22 +3,22 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-newsletter": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-newsletter": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-cookie": "0.74.0-beta4" + "magento/module-cookie": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Rss/composer.json b/app/code/Magento/Rss/composer.json index 353dbf0cd9059722680694393d1eb1f6a13ec58a..cb02900c44ef080abe82adcc3879c5394cf4640c 100644 --- a/app/code/Magento/Rss/composer.json +++ b/app/code/Magento/Rss/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Rule/composer.json b/app/code/Magento/Rule/composer.json index a4ddaf6d5145ff4a1ec140f982a44c036aa886c0..4e9e4fd3965676ec789fcae5df2f3fc27a1601ca 100644 --- a/app/code/Magento/Rule/composer.json +++ b/app/code/Magento/Rule/composer.json @@ -3,16 +3,16 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php b/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php index 163a03903f878e254e5817243cff2ac0bd1288b0..35d522427429f1d01def7ad15a2f784ee2e7f31f 100644 --- a/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php +++ b/app/code/Magento/Sales/Model/Order/Creditmemo/Item.php @@ -219,7 +219,7 @@ class Item extends AbstractModel implements CreditmemoItemInterface $rowTotalInclTax = $orderItem->getRowTotalInclTax(); $baseRowTotalInclTax = $orderItem->getBaseRowTotalInclTax(); - if (!$this->isLast() && $orderItemQtyInvoiced > 0 && $this->getQty() > 0) { + if (!$this->isLast() && $orderItemQtyInvoiced > 0 && $this->getQty() >= 0) { $availableQty = $orderItemQtyInvoiced - $orderItem->getQtyRefunded(); $rowTotal = $creditmemo->roundPrice($rowTotal / $availableQty * $this->getQty()); $baseRowTotal = $creditmemo->roundPrice($baseRowTotal / $availableQty * $this->getQty(), 'base'); diff --git a/app/code/Magento/Sales/Setup/InstallSchema.php b/app/code/Magento/Sales/Setup/InstallSchema.php index fd517941e38a02bb475a13e56ab6100dd531a911..93192e49bb663de74eaf6f9c87948ed058a649a4 100644 --- a/app/code/Magento/Sales/Setup/InstallSchema.php +++ b/app/code/Magento/Sales/Setup/InstallSchema.php @@ -1308,13 +1308,13 @@ class InstallSchema implements InstallSchemaInterface 'created_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], 'Created At' )->addColumn( 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated At' )->addColumn( 'product_id', diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php index afcf792c718dddc69eab5e23a17923b32a8e8a9c..0673aa120a217ae4daa1d549b441a2969c510d81 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/ItemTest.php @@ -264,43 +264,53 @@ class ItemTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result); } - public function testCalcRowTotal() + /** + * @dataProvider calcRowTotalDataProvider + */ + public function testCalcRowTotal($qty) { $creditmemoMock = $this->getMockBuilder('\Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() ->getMock(); $creditmemoMock->expects($this->exactly(4)) ->method('roundPrice') - ->willReturnMap( - [ - [0.375, 'regular', false, 0.4], - [0.375, 'base', false, 0.4], - [1, 'including', false, 1.0], - [1, 'including_base', false, 1.0] - ] - ); + ->will($this->returnCallback( + function ($arg) { + return round($arg, 2); + } + )); + + $qtyInvoiced = 10; + $qtyRefunded = 2; + $qtyAvailable = $qtyInvoiced - $qtyRefunded; + + $rowInvoiced = 5; + $amountRefunded = 2; + + $expectedRowTotal = ($rowInvoiced - $amountRefunded) / $qtyAvailable * $qty; + $expectedRowTotal = round($expectedRowTotal, 2); $orderItemMock = $this->getMockBuilder('Magento\Sales\Model\Order\Item') ->disableOriginalConstructor() ->getMock(); $orderItemMock->expects($this->once()) ->method('getQtyInvoiced') - ->willReturn(10); + ->willReturn($qtyInvoiced); $orderItemMock->expects($this->once()) ->method('getQtyRefunded') - ->willReturn(2); + ->willReturn($qtyRefunded); $orderItemMock->expects($this->once()) ->method('getRowInvoiced') - ->willReturn(5); + ->willReturn($rowInvoiced); $orderItemMock->expects($this->once()) ->method('getAmountRefunded') - ->willReturn(2); + ->willReturn($amountRefunded); $orderItemMock->expects($this->once()) ->method('getBaseRowInvoiced') - ->willReturn(5); + ->willReturn($rowInvoiced); $orderItemMock->expects($this->once()) ->method('getBaseAmountRefunded') - ->willReturn(2); + ->willReturn($amountRefunded); $orderItemMock->expects($this->once()) ->method('getRowTotalInclTax') ->willReturn(1); @@ -313,11 +323,28 @@ class ItemTest extends \PHPUnit_Framework_TestCase $orderItemMock->expects($this->once()) ->method('getQtyOrdered') ->willReturn(1); + $orderItemMock->expects($this->any()) + ->method('getQtyToRefund') + ->willReturn($qtyAvailable); - $this->item->setData('qty', 1); + $this->item->setData('qty', $qty); $this->item->setCreditmemo($creditmemoMock); $this->item->setOrderItem($orderItemMock); $result = $this->item->calcRowTotal(); + $this->assertInstanceOf('Magento\Sales\Model\Order\Creditmemo\Item', $result); + $this->assertEquals($expectedRowTotal, $this->item->getData('row_total')); + $this->assertEquals($expectedRowTotal, $this->item->getData('base_row_total')); + } + + /** + * @return array + */ + public function calcRowTotalDataProvider() + { + return [ + 'qty 1' => [1], + 'qty 0' => [0], + ]; } } diff --git a/app/code/Magento/Sales/composer.json b/app/code/Magento/Sales/composer.json index f08be07d2c054df96d8548557fc6120723e4167b..482c2576832b49f12c0e42710c10efb31c419643 100644 --- a/app/code/Magento/Sales/composer.json +++ b/app/code/Magento/Sales/composer.json @@ -3,35 +3,35 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-sales-rule": "0.74.0-beta4", - "magento/module-sales-sequence": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-gift-message": "0.74.0-beta4", - "magento/module-reports": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-wishlist": "0.74.0-beta4", - "magento/module-email": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-sales-rule": "0.74.0-beta6", + "magento/module-sales-sequence": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-gift-message": "0.74.0-beta6", + "magento/module-reports": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-wishlist": "0.74.0-beta6", + "magento/module-email": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/SalesRule/composer.json b/app/code/Magento/SalesRule/composer.json index 585088a4f10e642d280aef2de25324692ba2224f..1ef5ba09232d018b9987d406fc67f2ef65af6209 100644 --- a/app/code/Magento/SalesRule/composer.json +++ b/app/code/Magento/SalesRule/composer.json @@ -3,26 +3,26 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-rule": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-reports": "0.74.0-beta4", - "magento/module-catalog-rule": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-rule": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-reports": "0.74.0-beta6", + "magento/module-catalog-rule": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/SalesSequence/composer.json b/app/code/Magento/SalesSequence/composer.json index da5dd3cbe32d26c5fd163586799d45cbe142642a..f3c49c8f01143db554c75ed5abdcb14935ab4ef2 100644 --- a/app/code/Magento/SalesSequence/composer.json +++ b/app/code/Magento/SalesSequence/composer.json @@ -3,11 +3,11 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Search/Setup/InstallSchema.php b/app/code/Magento/Search/Setup/InstallSchema.php index 3c20f81310ed0b9ecc5c0bd6cbb08c82eafcce28..d58c0da9a8946015c721e96229746d6beae6703a 100644 --- a/app/code/Magento/Search/Setup/InstallSchema.php +++ b/app/code/Magento/Search/Setup/InstallSchema.php @@ -104,7 +104,7 @@ class InstallSchema implements InstallSchemaInterface 'updated_at', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, - ['nullable' => false], + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Updated at' ) ->addIndex( diff --git a/app/code/Magento/Search/composer.json b/app/code/Magento/Search/composer.json index 603a26e865c9d09b2b630ae141fb3a2c5af27582..69bc52ccfec60bd0b606af29e9748896b6eefe32 100644 --- a/app/code/Magento/Search/composer.json +++ b/app/code/Magento/Search/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog-search": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-reports": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog-search": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-reports": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sendfriend/composer.json b/app/code/Magento/Sendfriend/composer.json index 7f3d863dc8a1a85844f17a47716660787d4f00d7..7acd6e8fa3cece61f1c20f06067106d0b5691ba5 100644 --- a/app/code/Magento/Sendfriend/composer.json +++ b/app/code/Magento/Sendfriend/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Shipping/Exception.php b/app/code/Magento/Shipping/Exception.php deleted file mode 100755 index b140b961cf6d2bdf50fbc78e600517b55b8d3211..0000000000000000000000000000000000000000 --- a/app/code/Magento/Shipping/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Shipping; - -class Exception extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/app/code/Magento/Shipping/composer.json b/app/code/Magento/Shipping/composer.json index 254e4868e2264e6b31fb21179a37a791458a6018..54c613d4a0a95d2ab7d0a5eae1435dbfbffa9fff 100644 --- a/app/code/Magento/Shipping/composer.json +++ b/app/code/Magento/Shipping/composer.json @@ -3,27 +3,27 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-contact": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-payment": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-contact": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-payment": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "ext-gd": "*", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-fedex": "0.74.0-beta4", - "magento/module-ups": "0.74.0-beta4" + "magento/module-fedex": "0.74.0-beta6", + "magento/module-ups": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Sitemap/composer.json b/app/code/Magento/Sitemap/composer.json index d02c8ce4a2f9c305e341968063e1a00aeaf7aafd..1fa5a0e4091d5cbbe06a12b2229f626960b65e15 100644 --- a/app/code/Magento/Sitemap/composer.json +++ b/app/code/Magento/Sitemap/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog-url-rewrite": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog-url-rewrite": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Store/composer.json b/app/code/Magento/Store/composer.json index 0f697919aab8c962bb2e6f59433e90329576aa40..d2c3e97181c1e980a0406709dd6c35b74a84a344 100644 --- a/app/code/Magento/Store/composer.json +++ b/app/code/Magento/Store/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-directory": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-directory": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Tax/composer.json b/app/code/Magento/Tax/composer.json index b8f6dca3c66d2c73183843ac6fb6fc072a10bea8..27b9422635e75187471b290bb89d920fa9ccb1c5 100644 --- a/app/code/Magento/Tax/composer.json +++ b/app/code/Magento/Tax/composer.json @@ -3,23 +3,23 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-config": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-reports": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-config": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-reports": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/TaxImportExport/composer.json b/app/code/Magento/TaxImportExport/composer.json index 0c34d619a52deac67c7a68e53e36b69cbd5b2604..334b8652a6d74ed73e037f5d001b62026444bac6 100644 --- a/app/code/Magento/TaxImportExport/composer.json +++ b/app/code/Magento/TaxImportExport/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-tax": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-tax": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Theme/composer.json b/app/code/Magento/Theme/composer.json index 306b732a8ba29f473f4473f8cb722d4c9e4112a4..cb64d49d6d2dae6c61f64b767b8fa2f2a895544f 100644 --- a/app/code/Magento/Theme/composer.json +++ b/app/code/Magento/Theme/composer.json @@ -3,23 +3,23 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-widget": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/module-media-storage": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-require-js": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-widget": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/module-media-storage": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-require-js": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-translation": "0.74.0-beta4" + "magento/module-translation": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Translation/composer.json b/app/code/Magento/Translation/composer.json index 95805c7c808a913fca7dc8b11ba06215c609a6f9..4b817066e92d7a9cccc5efbc1d2909409c383f0a 100644 --- a/app/code/Magento/Translation/composer.json +++ b/app/code/Magento/Translation/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-backend": "0.74.0-beta4", - "magento/module-developer": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-backend": "0.74.0-beta6", + "magento/module-developer": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Ui/composer.json b/app/code/Magento/Ui/composer.json index 554855a2d50cbf76f413a1a73e23a8bc04830510..ecf417cad0f81fd792b366b6d2f314848fbfcf7b 100644 --- a/app/code/Magento/Ui/composer.json +++ b/app/code/Magento/Ui/composer.json @@ -3,13 +3,13 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Ups/composer.json b/app/code/Magento/Ups/composer.json index 1b0ed9ddfe26a098dbd11900385a151af05bb303..3fed6bdce1e18410c2fc17a53d32f8a93d940f78 100644 --- a/app/code/Magento/Ups/composer.json +++ b/app/code/Magento/Ups/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/UrlRewrite/composer.json b/app/code/Magento/UrlRewrite/composer.json index fb5a936db37d184d69aca56fa324be5d607efadd..1156b7cb79022a4f0caf8e293c1b752ecc4d0cef 100644 --- a/app/code/Magento/UrlRewrite/composer.json +++ b/app/code/Magento/UrlRewrite/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog-url-rewrite": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-cms-url-rewrite": "0.74.0-beta4", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog-url-rewrite": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-cms-url-rewrite": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/User/composer.json b/app/code/Magento/User/composer.json index 577c27ba685e4ed81c654d62448ffa88c8a5d66a..1d387c17899055557bb811a7c3024d38b90ef587 100644 --- a/app/code/Magento/User/composer.json +++ b/app/code/Magento/User/composer.json @@ -3,15 +3,15 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-integration": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-integration": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Usps/composer.json b/app/code/Magento/Usps/composer.json index 4c6201a4c81cd8b767c8f2062913b379f60d4c9f..382961b5610b48750b1aa3e64d77e46433cae688 100644 --- a/app/code/Magento/Usps/composer.json +++ b/app/code/Magento/Usps/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-shipping": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/module-config": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-shipping": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/module-config": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "lib-libxml": "*", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Variable/composer.json b/app/code/Magento/Variable/composer.json index 2480b529649cc03624b374cffbcadf038db7a984..ececb67d0ec8b20c51576dfe0b271f50a9c98015 100644 --- a/app/code/Magento/Variable/composer.json +++ b/app/code/Magento/Variable/composer.json @@ -3,14 +3,14 @@ "description": "N/A", "require": { "php": "~5.4.11|~5.5.0|~5.6.0", - "magento/module-backend": "0.74.0-beta4", - "magento/module-email": "0.74.0-beta4", - "magento/module-store": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-backend": "0.74.0-beta6", + "magento/module-email": "0.74.0-beta6", + "magento/module-store": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Version/composer.json b/app/code/Magento/Version/composer.json index 577e9eafe37893adf97960f6bf4d3fbee4aad32d..7bb5e528673b62f88d0c668ab148cdae4dfbcd35 100644 --- a/app/code/Magento/Version/composer.json +++ b/app/code/Magento/Version/composer.json @@ -3,11 +3,11 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" 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 0000000000000000000000000000000000000000..09a27569293993b92a68d8cdde5dab7d67e450e8 --- /dev/null +++ b/app/code/Magento/Webapi/Controller/Rest/ParamOverriderCustomerId.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +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 + */ +class ParamOverriderCustomerId implements ParamOverriderInterface +{ + /** + * @var UserContextInterface + */ + 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 getOverriddenValue() + { + if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { + return $this->userContext->getUserId(); + } + return null; + } +} diff --git a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php index 140f7dcd6a3b37eb1ec921ec6c3dd0172a283738..f7b4f4605a7a62cdf3246fd6ad5fc1e8de279061 100644 --- a/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php +++ b/app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php @@ -6,7 +6,7 @@ namespace Magento\Webapi\Controller\Rest; -use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface; use Magento\Webapi\Model\Config\Converter; /** @@ -15,18 +15,19 @@ use Magento\Webapi\Model\Config\Converter; class ParamsOverrider { /** - * @var \Magento\Authorization\Model\UserContextInterface + * @var ParamOverriderInterface[] */ - protected $userContext; + private $paramOverriders; /** * Initialize dependencies * - * @param UserContextInterface $userContext + * @param ParamOverriderInterface[] $paramOverriders */ - public function __construct(UserContextInterface $userContext) - { - $this->userContext = $userContext; + public function __construct( + array $paramOverriders = [] + ) { + $this->paramOverriders = $paramOverriders; } /** @@ -41,10 +42,9 @@ class ParamsOverrider 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->paramOverriders[$paramValue])) { + $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 new file mode 100644 index 0000000000000000000000000000000000000000..bf0f152eddf5f123e36faa3207712a71f7c9b369 --- /dev/null +++ b/app/code/Magento/Webapi/Test/Unit/Controller/Rest/ParamOverriderCustomerIdTest.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Webapi\Test\Unit\Controller\Rest; + +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Webapi\Controller\Rest\ParamOverriderCustomerId; + +class ParamOverriderCustomerIdTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ParamOverriderCustomerId + */ + private $model; + + /** + * @var UserContextInterface + */ + private $userContext; + + public function setUp() + { + $this->userContext = $this->getMockBuilder('Magento\Authorization\Model\UserContextInterface') + ->getMockForAbstractClass(); + $this->model = (new ObjectManager($this))->getObject( + 'Magento\Webapi\Controller\Rest\ParamOverriderCustomerId', + [ + 'userContext' => $this->userContext + ] + ); + } + + public function testGetOverriddenValueIsCustomer() + { + $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->getOverriddenValue()); + } + + public function testGetOverriddenValueIsNotCustomer() + { + $this->userContext->expects($this->once()) + ->method('getUserType') + ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN)); + + $this->assertNull($this->model->getOverriddenValue()); + } +} 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 2cfe94f7d07ceafa3929116b46a7d79923243270..f5aa363b8b9c2bdeb549d4ee87cc53da2db59bcd 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 @@ class ParamsOverriderTest extends \PHPUnit_Framework_TestCase $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 @@ class ParamsOverriderTest extends \PHPUnit_Framework_TestCase '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, ], diff --git a/app/code/Magento/Webapi/composer.json b/app/code/Magento/Webapi/composer.json index 3b557619403984b0a544ea4f0efedb0ccae04ed9..c2e4ec4dacb4f073ed7c35ac5a1a557e8c27db70 100644 --- a/app/code/Magento/Webapi/composer.json +++ b/app/code/Magento/Webapi/composer.json @@ -3,18 +3,18 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-authorization": "0.74.0-beta4", - "magento/module-integration": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-authorization": "0.74.0-beta6", + "magento/module-integration": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-user": "0.74.0-beta4" + "magento/module-user": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Webapi/etc/di.xml b/app/code/Magento/Webapi/etc/di.xml index d9f47dfd67a79a139cd1f69f957c5f508d98c8a4..12b661f639c428c681b98b1df7c0f5a8131da632 100644 --- a/app/code/Magento/Webapi/etc/di.xml +++ b/app/code/Magento/Webapi/etc/di.xml @@ -30,4 +30,11 @@ <type name="Magento\Integration\Model\ConfigBasedIntegrationManager"> <plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" /> </type> + <type name="Magento\Webapi\Controller\Rest\ParamsOverrider"> + <arguments> + <argument name="paramOverriders" xsi:type="array"> + <item name="%customer_id%" xsi:type="object">Magento\Webapi\Controller\Rest\ParamOverriderCustomerId</item> + </argument> + </arguments> + </type> </config> diff --git a/app/code/Magento/Weee/Model/Total/Creditmemo/Weee.php b/app/code/Magento/Weee/Model/Total/Creditmemo/Weee.php index d45eab656ca2a5eaf6c41e5f17125b87dc6b2f8b..7ddf6d66a7d0ada34c68da378ebcde2ed6112387 100644 --- a/app/code/Magento/Weee/Model/Total/Creditmemo/Weee.php +++ b/app/code/Magento/Weee/Model/Total/Creditmemo/Weee.php @@ -49,36 +49,30 @@ class Weee extends \Magento\Sales\Model\Order\Creditmemo\Total\AbstractTotal $totalWeeeAmount = 0; $baseTotalWeeeAmount = 0; - $totalWeeeAmountInclTax = 0; $baseTotalWeeeAmountInclTax = 0; - - $totalTaxAmount = $totalWeeeAmountInclTax - $totalWeeeAmount; - $baseTotalTaxAmount = $baseTotalWeeeAmountInclTax - $baseTotalWeeeAmount; + $totalTaxAmount = 0; + $baseTotalTaxAmount = 0; foreach ($creditmemo->getAllItems() as $item) { $orderItem = $item->getOrderItem(); - if ($orderItem->isDummy() || $item->getQty() <= 0) { + $orderItemQty = $orderItem->getQtyOrdered(); + + if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() < 0) { continue; } - $ratio = $item->getQty() / $orderItem->getQtyOrdered(); + $ratio = $item->getQty() / $orderItemQty; $orderItemWeeeAmountExclTax = $orderItem->getWeeeTaxAppliedRowAmount(); $orderItemBaseWeeeAmountExclTax = $orderItem->getBaseWeeeTaxAppliedRowAmnt(); $weeeAmountExclTax = $creditmemo->roundPrice($orderItemWeeeAmountExclTax * $ratio); - $baseWeeeAmountExclTax = $creditmemo->roundPrice( - $orderItemBaseWeeeAmountExclTax * $ratio, - 'base' - ); + $baseWeeeAmountExclTax = $creditmemo->roundPrice($orderItemBaseWeeeAmountExclTax * $ratio, 'base'); $orderItemWeeeAmountInclTax = $this->_weeeData->getRowWeeeTaxInclTax($orderItem); $orderItemBaseWeeeAmountInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax($orderItem); $weeeAmountInclTax = $creditmemo->roundPrice($orderItemWeeeAmountInclTax * $ratio); - $baseWeeeAmountInclTax = $creditmemo->roundPrice( - $orderItemBaseWeeeAmountInclTax * $ratio, - 'base' - ); + $baseWeeeAmountInclTax = $creditmemo->roundPrice($orderItemBaseWeeeAmountInclTax * $ratio, 'base'); $itemTaxAmount = $weeeAmountInclTax - $weeeAmountExclTax; $itemBaseTaxAmount = $baseWeeeAmountInclTax - $baseWeeeAmountExclTax; diff --git a/app/code/Magento/Weee/Model/Total/Invoice/Weee.php b/app/code/Magento/Weee/Model/Total/Invoice/Weee.php index 457a08ccd86691eac2615dcbffcc5571bc8eaf6e..a5bed91ec0c366f9d72e7e6762be8f17249a3a3b 100644 --- a/app/code/Magento/Weee/Model/Total/Invoice/Weee.php +++ b/app/code/Magento/Weee/Model/Total/Invoice/Weee.php @@ -57,11 +57,12 @@ class Weee extends \Magento\Sales\Model\Order\Invoice\Total\AbstractTotal $orderItem = $item->getOrderItem(); $orderItemQty = $orderItem->getQtyOrdered(); - if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() <= 0) { + if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() < 0) { continue; } $ratio = $item->getQty() / $orderItemQty; + $orderItemWeeeAmount = $orderItem->getWeeeTaxAppliedRowAmount(); $orderItemBaseWeeeAmount = $orderItem->getBaseWeeeTaxAppliedRowAmnt(); $weeeAmount = $invoice->roundPrice($orderItemWeeeAmount * $ratio); diff --git a/app/code/Magento/Weee/Test/Unit/Model/Total/Creditmemo/WeeeTest.php b/app/code/Magento/Weee/Test/Unit/Model/Total/Creditmemo/WeeeTest.php index 47aa7692a51d940fb25b894b0951aac0af7590c3..0fdd0ad9bdab19c2c51da37e8b7751c807dc9620 100644 --- a/app/code/Magento/Weee/Test/Unit/Model/Total/Creditmemo/WeeeTest.php +++ b/app/code/Magento/Weee/Test/Unit/Model/Total/Creditmemo/WeeeTest.php @@ -169,6 +169,7 @@ class WeeeTest extends \PHPUnit_Framework_TestCase public function collectDataProvider() { $result = []; + // scenario 1: 3 item_1, $100 with $weee, 8.25 tax rate, 3 items invoiced, full creditmemo $result['complete_creditmemo'] = [ 'creditmemo_data' => [ @@ -236,7 +237,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'tax_ratio' => serialize(['weee' => 1.0]), 'weee_tax_applied_row_amount' => 30, 'base_weee_tax_applied_row_amount' => 30, - ], ], 'creditmemo_data' => [ @@ -248,7 +248,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 300, 'subtotal_incl_tax' => 357.22, 'base_subtotal_incl_tax' => 357.22, - ], ], ]; @@ -320,7 +319,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'tax_ratio' => serialize(['weee' => 1.65 / 2.47]), 'weee_tax_applied_row_amount' => 20, 'base_weee_tax_applied_row_amount' => 20, - ], ], 'creditmemo_data' => [ @@ -332,7 +330,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 200, 'subtotal_incl_tax' => 238.15, 'base_subtotal_incl_tax' => 238.15, - ], ], ]; @@ -404,7 +401,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'tax_ratio' => serialize(['weee' => 0.83 / 2.47]), 'weee_tax_applied_row_amount' => 10, 'base_weee_tax_applied_row_amount' => 10, - ], ], 'creditmemo_data' => [ @@ -416,7 +412,79 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 100, 'subtotal_incl_tax' => 119.07, 'base_subtotal_incl_tax' => 119.07, + ], + ], + ]; + // scenario 4: 3 item_1, $100 with $weee, 8.25 tax rate. Returning qty 0. + $result['zero_return'] = [ + 'creditmemo_data' => [ + 'items' => [ + 'item_1' => [ + 'order_item' => [ + 'qty_ordered' => 3, + 'weee_tax_applied_row_amount' => 30, + 'base_weee_tax_applied_row_amnt' => 30, + 'row_weee_tax_incl_tax' => 32.47, + 'base_row_weee_tax_incl_tax' => 32.47, + 'weee_amount_invoiced' => 30, + 'base_weee_amount_invoiced' => 30, + 'weee_amount_refunded' => 0, + 'base_weee_amount_refunded' => 0, + 'weee_tax_amount_invoiced' => 2.47, + 'base_weee_tax_amount_invoiced' => 2.47, + 'weee_tax_amount_refunded' => 0, + 'base_weee_tax_amount_refunded' => 0, + 'applied_weee' => [ + [ + 'title' => 'recycling_fee', + 'base_row_amount' => 30, + 'row_amount' => 30, + 'base_row_amount_incl_tax' => 32.47, + 'row_amount_incl_tax' => 32.47, + ], + ], + 'qty_invoiced' => 3, + ], + 'is_last' => true, + 'data_fields' => [ + 'qty' => 0, + 'applied_weee' => [ + [ + ], + ], + ], + ], + ], + 'include_in_subtotal' => false, + 'data_fields' => [ + 'grand_total' => 300, + 'base_grand_total' => 300, + 'subtotal' => 300, + 'base_subtotal' => 300, + 'subtotal_incl_tax' => 324.75, + 'base_subtotal_incl_tax' => 324.75, + 'tax_amount' => 0, + 'base_tax_amount' => 0, + ], + ], + 'expected_results' => [ + 'creditmemo_items' => [ + 'item_1' => [ + 'applied_weee' => [ + [ + 'title' => 'recycling_fee', + 'base_row_amount' => 0, + 'row_amount' => 0, + 'base_row_amount_incl_tax' => 0, + 'row_amount_incl_tax' => 0, + ], + ], + ], + ], + 'creditmemo_data' => [ + 'subtotal' => 300, + 'base_subtotal' => 300, ], ], ]; diff --git a/app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php b/app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php index 4d91954b70fa26e81bf385295b50e5c25cf60934..d034947c48d71129a8ca1bbce59d39b69275d341 100644 --- a/app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php +++ b/app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php @@ -172,6 +172,7 @@ class WeeeTest extends \PHPUnit_Framework_TestCase public function collectDataProvider() { $result = []; + // 3 item_1, $100 with $weee, 8.25 tax rate, full invoice $result['complete_invoice'] = [ 'order_data' => [ @@ -269,7 +270,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 300, 'subtotal_incl_tax' => 344.85, 'base_subtotal_incl_tax' => 344.85, - ], ], ]; @@ -360,7 +360,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'tax_ratio' => serialize(['weee' => 1.65 / 2.47]), 'weee_tax_applied_row_amount' => 20, 'base_weee_tax_applied_row_amount' => 20, - ], ], 'invoice_data' => [ @@ -372,7 +371,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 200, 'subtotal_incl_tax' => 238.15, 'base_subtotal_incl_tax' => 238.15, - ], ], ]; @@ -464,7 +462,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'tax_ratio' => serialize(['weee' => 0.82 / 2.47]), 'weee_tax_applied_row_amount' => 10, 'base_weee_tax_applied_row_amount' => 10, - ], ], 'invoice_data' => [ @@ -476,7 +473,6 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 100, 'subtotal_incl_tax' => 119.07, 'base_subtotal_incl_tax' => 119.07, - ], ], ]; @@ -580,7 +576,98 @@ class WeeeTest extends \PHPUnit_Framework_TestCase 'base_subtotal' => 100, 'subtotal_incl_tax' => 114.95, 'base_subtotal_incl_tax' => 114.95, + ], + ], + ]; + // 3 item_1, $100 with $weee, 8.25 tax rate. Invoicing qty 0. + $result['zero_invoice'] = [ + 'order_data' => [ + 'previous_invoices' => [ + ], + 'data_fields' => [ + 'shipping_tax_amount' => 1.24, + 'base_shipping_tax_amount' => 1.24, + 'shipping_hidden_tax_amount' => 0, + 'base_shipping_hidden_tax_amount' => 0, + 'tax_amount' => 16.09, + 'tax_invoiced' => 0, + 'base_tax_amount' => 16.09, + 'base_tax_amount_invoiced' => 0, + 'subtotal' => '300', + 'base_subtotal' => '300', + ], + ], + 'invoice_data' => [ + 'items' => [ + 'item_1' => [ + 'order_item' => [ + 'qty_ordered' => 3, + 'weee_tax_applied_row_amount' => 30, + 'base_weee_tax_applied_row_amnt' => 30, + 'row_weee_tax_incl_tax' => 32.47, + 'base_row_weee_tax_incl_tax' => 32.47, + 'weee_amount_invoiced' => 0, + 'base_weee_amount_invoiced' => 0, + 'weee_tax_amount_invoiced' => 0, + 'base_weee_tax_amount_invoiced' => 0, + 'applied_weee' => [ + [ + 'title' => 'recycling_fee', + 'base_row_amount' => 30, + 'row_amount' => 30, + 'base_row_amount_incl_tax' => 32.47, + 'row_amount_incl_tax' => 32.47, + ], + ], + 'applied_weee_updated' => [ + 'base_row_amount_invoiced' => 30, + 'row_amount_invoiced' => 30, + 'base_tax_amount_invoiced' => 2.47, + 'tax_amount_invoiced' => 2.47, + ], + 'qty_invoiced' => 0, + ], + 'is_last' => true, + 'data_fields' => [ + 'qty' => 0, + 'applied_weee' => [ + [ + ], + ], + ], + ], + ], + 'is_last' => true, + 'include_in_subtotal' => false, + 'data_fields' => [ + 'grand_total' => 181.09, + 'base_grand_total' => 181.09, + 'subtotal' => 300, + 'base_subtotal' => 300, + 'subtotal_incl_tax' => 314.85, + 'base_subtotal_incl_tax' => 314.85, + 'tax_amount' => 16.09, + 'base_tax_amount' => 16.09, + ], + ], + 'expected_results' => [ + 'invoice_items' => [ + 'item_1' => [ + 'applied_weee' => [ + [ + 'title' => 'recycling_fee', + 'base_row_amount' => 0, + 'row_amount' => 0, + 'base_row_amount_incl_tax' => 0, + 'row_amount_incl_tax' => 0, + ], + ], + ], + ], + 'invoice_data' => [ + 'subtotal' => 300, + 'base_subtotal' => 300, ], ], ]; diff --git a/app/code/Magento/Weee/composer.json b/app/code/Magento/Weee/composer.json index 141bd185bd9ae5fb6cefc8fa461ebb29da15ce60..9b11852f84fd425b09a62737597c797ddcdd31d8 100644 --- a/app/code/Magento/Weee/composer.json +++ b/app/code/Magento/Weee/composer.json @@ -3,20 +3,20 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-tax": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-directory": "0.74.0-beta4", - "magento/module-eav": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-quote": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-tax": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-directory": "0.74.0-beta6", + "magento/module-eav": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-quote": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Widget/composer.json b/app/code/Magento/Widget/composer.json index 6cdf154bd8f2a4e2541acb72414ae8ab49af8a63..e1ebbafa7d489f3a823f28fee6e691289851c00b 100644 --- a/app/code/Magento/Widget/composer.json +++ b/app/code/Magento/Widget/composer.json @@ -3,17 +3,17 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-cms": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-variable": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-cms": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-variable": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Wishlist/Controller/Index/Cart.php b/app/code/Magento/Wishlist/Controller/Index/Cart.php index ed155aa60585be883c005a3e2cb9f60ea4077016..61a80f8ca58ee312f0bbf5d1572b86c15395b383 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 */ @@ -66,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, @@ -76,7 +90,9 @@ class Cart extends Action\Action implements IndexInterface \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 +102,8 @@ class Cart extends Action\Action implements IndexInterface $this->productHelper = $productHelper; $this->escaper = $escaper; $this->helper = $helper; + $this->cartHelper = $cartHelper; + $this->jsonHelper = $jsonHelper; parent::__construct($context); } @@ -159,8 +177,8 @@ class Cart extends Action\Action implements IndexInterface $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 +196,13 @@ class Cart extends Action\Action implements IndexInterface $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/Test/Unit/Controller/Index/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php index fd7c06e7336d0ef29f2ab95c9ece2c6804a6a010..fcfec1f1071a82b28b866e753669733d031422de 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,12 +149,12 @@ class CartTest extends \PHPUnit_Framework_TestCase $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') ->disableOriginalConstructor() - ->setMethods(['setRedirect']) + ->setMethods(['setRedirect', 'representJson']) ->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface') @@ -187,6 +197,14 @@ class CartTest extends \PHPUnit_Framework_TestCase ->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 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, - $this->helperMock + $this->helperMock, + $this->cartHelperMock, + $this->jsonHelperMock ); } @@ -275,9 +295,13 @@ class CartTest extends \PHPUnit_Framework_TestCase } /** + * @param bool $isAjax + * + * @dataProvider dataProviderExecuteWithQuantityArray + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testExecuteWithQuantityArray() + public function testExecuteWithQuantityArray($isAjax) { $itemId = 2; $wishlistId = 1; @@ -397,6 +421,9 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->requestMock->expects($this->once()) ->method('getParams') ->willReturn($params); + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn($isAjax); $buyRequestMock = $this->getMockBuilder('Magento\Framework\Object') ->disableOriginalConstructor() @@ -467,7 +494,7 @@ class CartTest extends \PHPUnit_Framework_TestCase ->with('You added ' . $productName . ' to your shopping cart.', null) ->willReturnSelf(); - $this->checkoutCartMock->expects($this->once()) + $this->cartHelperMock->expects($this->once()) ->method('getShouldRedirectToCart') ->willReturn(false); @@ -479,12 +506,33 @@ class CartTest extends \PHPUnit_Framework_TestCase ->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], + ]; } /** diff --git a/app/code/Magento/Wishlist/composer.json b/app/code/Magento/Wishlist/composer.json index a8b906b18a926527f1dfa1cc749ff1820fd77bb6..59eee0b1b1feb0c7ab6eccbe0a4563a729e34340 100644 --- a/app/code/Magento/Wishlist/composer.json +++ b/app/code/Magento/Wishlist/composer.json @@ -3,28 +3,28 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.74.0-beta4", - "magento/module-customer": "0.74.0-beta4", - "magento/module-catalog": "0.74.0-beta4", - "magento/module-checkout": "0.74.0-beta4", - "magento/module-theme": "0.74.0-beta4", - "magento/module-catalog-inventory": "0.74.0-beta4", - "magento/module-rss": "0.74.0-beta4", - "magento/module-backend": "0.74.0-beta4", - "magento/module-sales": "0.74.0-beta4", - "magento/module-grouped-product": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", - "magento/module-ui": "0.74.0-beta4", + "magento/module-store": "0.74.0-beta6", + "magento/module-customer": "0.74.0-beta6", + "magento/module-catalog": "0.74.0-beta6", + "magento/module-checkout": "0.74.0-beta6", + "magento/module-theme": "0.74.0-beta6", + "magento/module-catalog-inventory": "0.74.0-beta6", + "magento/module-rss": "0.74.0-beta6", + "magento/module-backend": "0.74.0-beta6", + "magento/module-sales": "0.74.0-beta6", + "magento/module-grouped-product": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", + "magento/module-ui": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "suggest": { - "magento/module-configurable-product": "0.74.0-beta4", - "magento/module-downloadable": "0.74.0-beta4", - "magento/module-bundle": "0.74.0-beta4", - "magento/module-cookie": "0.74.0-beta4" + "magento/module-configurable-product": "0.74.0-beta6", + "magento/module-downloadable": "0.74.0-beta6", + "magento/module-bundle": "0.74.0-beta6", + "magento/module-cookie": "0.74.0-beta6" }, "type": "magento2-module", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml index 035364489f3caa8386c6d57bd34e6994b2d965ac..624a320f30a7e00e0722812837cab07b9d079a86 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 @@ <?php echo($block->getChildHtml('wishlist.rss.link'));?> <form class="form-wishlist-items" id="wishlist-view-form" data-mage-init='{"wishlist":{ - "dataAttribute":"item-id", - "nameFormat":"qty[{0}]", - "btnRemoveSelector":".action.delete", - "qtySelector":".qty", - "addToCartSelector":".action.tocart", - "addAllToCartSelector":".primary > .action.tocart", - "commentInputType":"textarea", - "infoList":false, "addToCartUrl":"<?php echo $block->getItemAddToCartUrl("%item%");?>", "confirmRemoveMessage":"<?php echo __("Are you sure you want to remove this product from your wishlist?") ?>", "addAllToCartUrl":"<?php echo $block->getAddAllToCartUrl(); ?>", diff --git a/app/code/Magento/Wishlist/view/frontend/web/wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/wishlist.js index ad01e333ef0cfd2a9b3b88a821fdaf665c3f390c..973cde4f0b4e90fddb1cf9990b8f726c70acd152 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/wishlist.js @@ -81,12 +81,11 @@ define([ var itemId = elem.data(this.options.dataAttribute), url = this.options.addToCartUrl.replace('%item%', itemId), inputName = $.validator.format(this.options.nameFormat, itemId), - inputValue = elem.parent().find('[name="' + inputName + '"]').val(), + inputValue = $('[name="' + inputName + '"]').val(), separator = (url.indexOf('?') >= 0) ? '&' : '?'; url += separator + inputName + '=' + encodeURIComponent(inputValue); this._validateAndRedirect(url); } - }, /** diff --git a/app/design/adminhtml/Magento/backend/composer.json b/app/design/adminhtml/Magento/backend/composer.json index f63967a044a77e63f610a42810f91990cb81c3e4..8ae2687dac7e5d03b2248d8dff711c8d8fd8a1c9 100644 --- a/app/design/adminhtml/Magento/backend/composer.json +++ b/app/design/adminhtml/Magento/backend/composer.json @@ -3,11 +3,11 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-theme", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/design/frontend/Magento/blank/composer.json b/app/design/frontend/Magento/blank/composer.json index 0310452342686164d2810d2e39e881e416c5b8cf..2a04bfacb343d811febc36cc9be67b7254e3eb41 100644 --- a/app/design/frontend/Magento/blank/composer.json +++ b/app/design/frontend/Magento/blank/composer.json @@ -3,11 +3,11 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-theme", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/design/frontend/Magento/luma/composer.json b/app/design/frontend/Magento/luma/composer.json index d37e25b11e2534ad335788f1a0d9de8df5f103c3..8fa8ad3aa9e7c50206b59568b7faff068e12c61b 100644 --- a/app/design/frontend/Magento/luma/composer.json +++ b/app/design/frontend/Magento/luma/composer.json @@ -3,12 +3,12 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/theme-frontend-blank": "0.74.0-beta4", - "magento/framework": "0.74.0-beta4", + "magento/theme-frontend-blank": "0.74.0-beta6", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-theme", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/i18n/magento/de_de/composer.json b/app/i18n/magento/de_de/composer.json index 5e596f680a07b1410cd1068172cfccee343c867f..3348716f124bbb1283aca8365bee6dc1653f53b6 100644 --- a/app/i18n/magento/de_de/composer.json +++ b/app/i18n/magento/de_de/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-de_de", "description": "German (Germany) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/en_us/composer.json b/app/i18n/magento/en_us/composer.json index c36b99a652ae5b9f810145476d1605d42928b4a2..54427d660fa30d9bae85106145c1486e6e04189d 100644 --- a/app/i18n/magento/en_us/composer.json +++ b/app/i18n/magento/en_us/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-en_us", "description": "English (United States) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/es_es/composer.json b/app/i18n/magento/es_es/composer.json index 8588126baa5e884fa3d68b19dd0c0e26849fbf6b..de93f29f35665cc28056a6bd9d273ac9a85cf89c 100644 --- a/app/i18n/magento/es_es/composer.json +++ b/app/i18n/magento/es_es/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-es_es", "description": "Spanish (Spain) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/fr_fr/composer.json b/app/i18n/magento/fr_fr/composer.json index f51c27cfef8b7227ad59085a9ea43322bb8a5b84..57c2be2ed896269ff4140ad4c4970cb450ba2b67 100644 --- a/app/i18n/magento/fr_fr/composer.json +++ b/app/i18n/magento/fr_fr/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-fr_fr", "description": "French (France) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/nl_nl/composer.json b/app/i18n/magento/nl_nl/composer.json index 16880a05b0c94333f401dfa341a372cd35117601..12c4f56f07432845832714823d15a4f34d8e4b10 100644 --- a/app/i18n/magento/nl_nl/composer.json +++ b/app/i18n/magento/nl_nl/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-nl_nl", "description": "Dutch (Netherlands) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/pt_br/composer.json b/app/i18n/magento/pt_br/composer.json index 744530a334afb482776c4892310dfbc8b52b0b55..cc1a364b3dde8fba1615b23368ee82f4041da639 100644 --- a/app/i18n/magento/pt_br/composer.json +++ b/app/i18n/magento/pt_br/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-pt_br", "description": "Portuguese (Brazil) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/app/i18n/magento/zh_cn/composer.json b/app/i18n/magento/zh_cn/composer.json index b108d5b0f5c201a014576b24ba48084baffcc704..1088c0e650ce72ad7a50a07957c4571f156913f2 100644 --- a/app/i18n/magento/zh_cn/composer.json +++ b/app/i18n/magento/zh_cn/composer.json @@ -1,13 +1,13 @@ { "name": "magento/language-zh_cn", "description": "Chinese (China) language", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { - "magento/framework": "0.74.0-beta4", + "magento/framework": "0.74.0-beta6", "magento/magento-composer-installer": "*" }, "type": "magento2-language", diff --git a/composer.json b/composer.json index 907d23ff711529e697064e42d0eab2a6c2465669..e99f901fde5affb0c5023710e7e9d788421aa9d0 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "magento/project-community-edition", - "description": "Magento project (Community Edition)", + "name": "magento/magento2ce", + "description": "Magento 2 (Community Edition)", "type": "project", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" @@ -30,7 +30,7 @@ "zendframework/zend-log": "2.3.1", "zendframework/zend-http": "2.3.1", "magento/zendframework1": "1.12.10", - "composer/composer": "1.0.0-alpha8", + "composer/composer": "1.0.0-alpha9", "monolog/monolog": "1.11.0", "oyejorge/less.php": "1.7.0.3", "tubalmartin/cssmin": "2.4.8-p4", @@ -209,5 +209,7 @@ "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/", "Magento\\ToolkitFramework\\": "dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/" } - } + }, + "minimum-stability": "alpha", + "prefer-stable": true } diff --git a/composer.lock b/composer.lock index 1850375542413cf443c72fd68f36fd6fe6b21d7f..a4498fe8e6dc972a67cd464639b3f4a7619783fd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,32 +4,32 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "35d05640e3dc260b7a5b09310611194a", + "hash": "ff2c069b557199903bafc88e8abe0cea", "packages": [ { "name": "composer/composer", - "version": "1.0.0-alpha8", + "version": "1.0.0-alpha9", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "1eb1df44a97fb2daca1bb8b007f3bee012f0aa46" + "reference": "eb1ce550ca51134ee619ad3e37f5a0b7e980dd24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/1eb1df44a97fb2daca1bb8b007f3bee012f0aa46", - "reference": "1eb1df44a97fb2daca1bb8b007f3bee012f0aa46", + "url": "https://api.github.com/repos/composer/composer/zipball/eb1ce550ca51134ee619ad3e37f5a0b7e980dd24", + "reference": "eb1ce550ca51134ee619ad3e37f5a0b7e980dd24", "shasum": "" }, "require": { - "justinrainbow/json-schema": "1.1.*", + "justinrainbow/json-schema": "~1.1", "php": ">=5.3.2", - "seld/jsonlint": "1.*", + "seld/jsonlint": "~1.0", "symfony/console": "~2.3", "symfony/finder": "~2.2", "symfony/process": "~2.1" }, "require-dev": { - "phpunit/phpunit": "~3.7.10" + "phpunit/phpunit": "~4.0" }, "suggest": { "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages", @@ -54,46 +54,57 @@ "MIT" ], "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be", - "role": "Developer" - }, { "name": "Nils Adermann", "email": "naderman@naderman.de", - "homepage": "http://www.naderman.de", - "role": "Developer" + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" } ], - "description": "Dependency Manager", + "description": "Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stack everywhere.", "homepage": "http://getcomposer.org/", "keywords": [ "autoload", "dependency", "package" ], - "time": "2014-01-06 18:39:59" + "time": "2014-12-07 17:15:20" }, { "name": "justinrainbow/json-schema", - "version": "1.1.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "05ff6d8d79fe3ad190b0663d80d3f9deee79416c" + "reference": "2465fe486c864e30badaa4d005ebdf89dbc503f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/05ff6d8d79fe3ad190b0663d80d3f9deee79416c", - "reference": "05ff6d8d79fe3ad190b0663d80d3f9deee79416c", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/2465fe486c864e30badaa4d005ebdf89dbc503f3", + "reference": "2465fe486c864e30badaa4d005ebdf89dbc503f3", "shasum": "" }, "require": { "php": ">=5.3.0" }, + "require-dev": { + "json-schema/json-schema-test-suite": "1.1.0", + "phpdocumentor/phpdocumentor": "~2", + "phpunit/phpunit": "~3.7" + }, + "bin": [ + "bin/validate-json" + ], "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, "autoload": { "psr-0": { "JsonSchema": "src/" @@ -101,14 +112,9 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "NewBSD" + "BSD-3-Clause" ], "authors": [ - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch", - "homepage": "http://wiedler.ch/igor/" - }, { "name": "Bruno Prieto Reis", "email": "bruno.p.reis@gmail.com" @@ -117,10 +123,13 @@ "name": "Justin Rainbow", "email": "justin.rainbow@gmail.com" }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, { "name": "Robert Schönthal", - "email": "robert.schoenthal@gmail.com", - "homepage": "http://digitalkaoz.net" + "email": "seroscho@googlemail.com" } ], "description": "A library to validate a json schema.", @@ -129,7 +138,7 @@ "json", "schema" ], - "time": "2012-01-03 00:33:17" + "time": "2015-03-27 16:41:39" }, { "name": "magento/magento-composer-installer", @@ -2007,19 +2016,20 @@ }, { "name": "fabpot/php-cs-fixer", - "version": "v1.6.2", + "version": "v1.7", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "a574ba148953fea1f78428d4b7c6843e759711f3" + "reference": "6425aeb97ab921371182712a18c280d546e7769b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/a574ba148953fea1f78428d4b7c6843e759711f3", - "reference": "a574ba148953fea1f78428d4b7c6843e759711f3", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/6425aeb97ab921371182712a18c280d546e7769b", + "reference": "6425aeb97ab921371182712a18c280d546e7769b", "shasum": "" }, "require": { + "ext-tokenizer": "*", "php": ">=5.3.6", "sebastian/diff": "~1.1", "symfony/console": "~2.3", @@ -2056,7 +2066,7 @@ } ], "description": "A script to automatically fix Symfony Coding Standard", - "time": "2015-04-13 21:33:33" + "time": "2015-04-16 07:21:30" }, { "name": "league/climate", @@ -3414,12 +3424,12 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "alpha", "stability-flags": { "composer/composer": 15, "phpmd/phpmd": 0 }, - "prefer-stable": false, + "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "~5.5.0|~5.6.0" diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php index 463f490480ce06c6e3016e5606971eb6ee1fe392..caf1b320ef82ce37e47ca055dbcb95bebd599bf9 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php @@ -33,12 +33,13 @@ class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAb $this->assertArrayHasKey(0, $result); $this->assertArrayHasKey('option_id', $result[0]); $this->assertArrayHasKey('is_default', $result[0]); - $this->assertArrayHasKey('is_defined', $result[0]); + $this->assertArrayHasKey('can_change_quantity', $result[0]); $this->assertArrayHasKey('price', $result[0]); $this->assertArrayHasKey('price_type', $result[0]); + $this->assertNotNull($result[0]['id']); - unset($result[0]['option_id'], $result[0]['is_default'], $result[0]['is_defined']); - unset($result[0]['price'], $result[0]['price_type']); + unset($result[0]['option_id'], $result[0]['is_default'], $result[0]['can_change_quantity']); + unset($result[0]['price'], $result[0]['price_type'], $result[0]['id']); ksort($result[0]); ksort($expected[0]); @@ -83,6 +84,55 @@ class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAb $this->assertGreaterThan(0, $childId); } + /** + * @magentoApiDataFixture Magento/Bundle/_files/product.php + * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php + */ + public function testSaveChild() + { + $productSku = 'bundle-product'; + $children = $this->getChildren($productSku); + + $linkedProduct = $children[0]; + + //Modify a few fields + $linkedProduct['is_default'] = true; + $linkedProduct['qty'] = 2; + + $this->assertTrue($this->saveChild($productSku, $linkedProduct)); + $children = $this->getChildren($productSku); + $this->assertEquals($linkedProduct, $children[0]); + } + + /** + * @param string $productSku + * @param array $linkedProduct + * @return string + */ + private function saveChild($productSku, $linkedProduct) + { + $resourcePath = self::RESOURCE_PATH . '/:sku/links/:id'; + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => str_replace( + [':sku', ':id'], + [$productSku, $linkedProduct['id']], + $resourcePath + ), + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'SaveChild', + ], + ]; + return $this->_webApiCall( + $serviceInfo, + ['sku' => $productSku, 'linkedProduct' => $linkedProduct] + ); + } + /** * @param string $productSku * @param int $optionId @@ -158,6 +208,6 @@ class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAb 'operation' => self::SERVICE_NAME . 'getChildren', ], ]; - return $this->_webApiCall($serviceInfo, ['productId' => $productSku]); + return $this->_webApiCall($serviceInfo, ['productSku' => $productSku]); } } diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductOptionRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductOptionRepositoryTest.php index 325e35ee8291041dd553575d39ed4523f71e5284..d402aea3d67a790681fe4f8970e5bda17e8bcf67 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductOptionRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductOptionRepositoryTest.php @@ -29,7 +29,7 @@ class ProductOptionRepositoryTest extends \Magento\TestFramework\TestCase\Webapi 'sku' => 'simple', 'qty' => 1, 'position' => 0, - 'is_defined' => true, + 'can_change_quantity' => 1, 'is_default' => false, 'price' => null, 'price_type' => null, @@ -42,9 +42,13 @@ class ProductOptionRepositoryTest extends \Magento\TestFramework\TestCase\Webapi $this->assertArrayHasKey('option_id', $result); $expected['product_links'][0]['option_id'] = $result['option_id']; unset($result['option_id']); + $this->assertNotNull($result['product_links'][0]['id']); + unset($result['product_links'][0]['id']); ksort($expected); ksort($result); + ksort($expected['product_links'][0]); + ksort($result['product_links'][0]); $this->assertEquals($expected, $result); } @@ -66,7 +70,7 @@ class ProductOptionRepositoryTest extends \Magento\TestFramework\TestCase\Webapi 'sku' => 'simple', 'qty' => 1, 'position' => 0, - 'is_defined' => true, + 'can_change_quantity' => 1, 'is_default' => false, 'price' => null, 'price_type' => null, @@ -80,9 +84,13 @@ class ProductOptionRepositoryTest extends \Magento\TestFramework\TestCase\Webapi $this->assertArrayHasKey('option_id', $result[0]); $expected[0]['product_links'][0]['option_id'] = $result[0]['option_id']; unset($result[0]['option_id']); + $this->assertNotNull($result[0]['product_links'][0]['id']); + unset($result[0]['product_links'][0]['id']); ksort($expected[0]); ksort($result[0]); + ksort($expected[0]['product_links'][0]); + ksort($result[0]['product_links'][0]); $this->assertEquals($expected, $result); } diff --git a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php index 1a817b18d3b593df2cbbef8280a42e40f0d5b84c..80fbe1999d3349f6b889931c23515cba7316e0c2 100644 --- a/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php @@ -10,6 +10,7 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\Api\ExtensibleDataInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; +use Magento\Bundle\Api\Data\LinkInterface; /** * Class ProductServiceTest for testing Bundle Product API @@ -19,6 +20,7 @@ class ProductServiceTest extends WebapiAbstract const SERVICE_NAME = 'catalogProductRepositoryV1'; const SERVICE_VERSION = 'V1'; const RESOURCE_PATH = '/V1/products'; + const BUNDLE_PRODUCT_ID = 'sku-test-product-bundle'; /** * @var \Magento\Catalog\Model\Resource\Product\Collection @@ -39,20 +41,7 @@ class ProductServiceTest extends WebapiAbstract */ public function tearDown() { - /** @var \Magento\Framework\Registry $registry */ - $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); - - $registry->unregister('isSecureArea'); - $registry->register('isSecureArea', true); - - $this->productCollection->addFieldToFilter( - 'sku', - ['in' => ['sku-test-product-bundle']] - )->delete(); - unset($this->productCollection); - - $registry->unregister('isSecureArea'); - $registry->register('isSecureArea', false); + $this->deleteProductBySku(self::BUNDLE_PRODUCT_ID); parent::tearDown(); } @@ -61,7 +50,6 @@ class ProductServiceTest extends WebapiAbstract */ public function testCreateBundle() { - $this->markTestSkipped('Processing of custom attributes has been changed in MAGETWO-34448.'); $bundleProductOptions = [ [ "title" => "test option", @@ -73,38 +61,365 @@ class ProductServiceTest extends WebapiAbstract "qty" => 1, 'is_default' => false, 'price' => 1.0, - 'price_type' => 1 + 'price_type' => LinkInterface::PRICE_TYPE_FIXED, ], ], ], ]; - $uniqueId = 'sku-test-product-bundle'; $product = [ - "sku" => $uniqueId, - "name" => $uniqueId, + "sku" => self::BUNDLE_PRODUCT_ID, + "name" => self::BUNDLE_PRODUCT_ID, "type_id" => "bundle", "price" => 50, 'attribute_set_id' => 4, + "custom_attributes" => [ + [ + "attribute_code" => "price_type", + "value" => \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED, + ], + [ + "attribute_code" => "price_view", + "value" => 1, + ], + ], "extension_attributes" => [ - "price_type" => \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC, "bundle_product_options" => $bundleProductOptions, - "price_view" => "test" ], ]; $response = $this->createProduct($product); - $this->assertEquals($uniqueId, $response[ProductInterface::SKU]); + $this->assertEquals(self::BUNDLE_PRODUCT_ID, $response[ProductInterface::SKU]); + $this->assertEquals(50, $response['price']); + $this->assertTrue( + isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]) + ); + $resultBundleProductOptions + = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]; + $this->assertTrue(isset($resultBundleProductOptions[0]["product_links"][0]["sku"])); + $this->assertEquals('simple', $resultBundleProductOptions[0]["product_links"][0]["sku"]); + + $response = $this->getProduct(self::BUNDLE_PRODUCT_ID); + $this->assertTrue( + isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]) + ); + $resultBundleProductOptions + = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]; + $this->assertTrue(isset($resultBundleProductOptions[0]["product_links"][0]["sku"])); + $this->assertEquals('simple', $resultBundleProductOptions[0]["product_links"][0]["sku"]); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/products_new.php + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + */ + public function testUpdateBundleModifyExistingSelection() + { + $bundleProduct = $this->createFixedPriceBundleProduct(); + $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); + + $existingSelectionId = $bundleProductOptions[0]['product_links'][0]['id']; + + //Change the type of existing option + $bundleProductOptions[0]['type'] = 'select'; + //Change the sku of existing link and qty + $bundleProductOptions[0]['product_links'][0]['sku'] = 'simple2'; + $bundleProductOptions[0]['product_links'][0]['qty'] = 2; + $bundleProductOptions[0]['product_links'][0]['price'] = 10; + $bundleProductOptions[0]['product_links'][0]['price_type'] = 1; + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); + + $updatedProduct = $this->saveProduct($bundleProduct); + + $bundleOptions = $this->getBundleProductOptions($updatedProduct); + $this->assertEquals('select', $bundleOptions[0]['type']); + $this->assertEquals('simple2', $bundleOptions[0]['product_links'][0]['sku']); + $this->assertEquals(2, $bundleOptions[0]['product_links'][0]['qty']); + $this->assertEquals($existingSelectionId, $bundleOptions[0]['product_links'][0]['id']); + $this->assertEquals(10, $bundleOptions[0]['product_links'][0]['price']); + $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['price_type']); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/products_new.php + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + */ + public function testUpdateBundleModifyExistingOptionOnly() + { + $bundleProduct = $this->createFixedPriceBundleProduct(); + $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); + + $existingSelectionId = $bundleProductOptions[0]['product_links'][0]['id']; + + //Change the type of existing option + $bundleProductOptions[0]['type'] = 'select'; + //unset product_links attribute + unset($bundleProductOptions[0]['product_links']); + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); + + $updatedProduct = $this->saveProduct($bundleProduct); + + $bundleOptions = $this->getBundleProductOptions($updatedProduct); + $this->assertEquals('select', $bundleOptions[0]['type']); + $this->assertEquals('simple', $bundleOptions[0]['product_links'][0]['sku']); + $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['qty']); + $this->assertEquals($existingSelectionId, $bundleOptions[0]['product_links'][0]['id']); + $this->assertEquals(20, $bundleOptions[0]['product_links'][0]['price']); + $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['price_type']); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/products_new.php + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + */ + public function testUpdateProductWithoutBundleOptions() + { + $bundleProduct = $this->createFixedPriceBundleProduct(); + $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); + + $existingSelectionId = $bundleProductOptions[0]['product_links'][0]['id']; + + //unset bundle_product_options + unset($bundleProductOptions[0]['product_links']); + $this->setBundleProductOptions($bundleProduct, null); + + $updatedProduct = $this->saveProduct($bundleProduct); + + $bundleOptions = $this->getBundleProductOptions($updatedProduct); + $this->assertEquals('checkbox', $bundleOptions[0]['type']); + $this->assertEquals('simple', $bundleOptions[0]['product_links'][0]['sku']); + $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['qty']); + $this->assertEquals($existingSelectionId, $bundleOptions[0]['product_links'][0]['id']); + $this->assertEquals(20, $bundleOptions[0]['product_links'][0]['price']); + $this->assertEquals(1, $bundleOptions[0]['product_links'][0]['price_type']); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/products_new.php + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + */ + public function testUpdateBundleAddSelection() + { + $bundleProduct = $this->createDynamicBundleProduct(); + $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); + + //Add a selection to existing option + $bundleProductOptions[0]['product_links'][] = [ + 'sku' => 'simple2', + 'qty' => 2, + "price" => 20, + "price_type" => 1, + "is_default" => false, + ]; + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); + $updatedProduct = $this->saveProduct($bundleProduct); + + $bundleOptions = $this->getBundleProductOptions($updatedProduct); + $this->assertEquals('simple', $bundleOptions[0]['product_links'][0]['sku']); + $this->assertEquals('simple2', $bundleOptions[0]['product_links'][1]['sku']); + $this->assertEquals(2, $bundleOptions[0]['product_links'][1]['qty']); + $this->assertGreaterThan( + $bundleOptions[0]['product_links'][0]['id'], + $bundleOptions[0]['product_links'][1]['id'] + ); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/products_new.php + * @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php + */ + public function testUpdateBundleAddAndDeleteOption() + { + $bundleProduct = $this->createDynamicBundleProduct(); + + $bundleProductOptions = $this->getBundleProductOptions($bundleProduct); + + $oldOptionId = $bundleProductOptions[0]['option_id']; + //replace current option with a new option + $bundleProductOptions[0] = [ + 'title' => 'new option', + 'required' => true, + 'type' => 'select', + 'product_links' => [ + [ + 'sku' => 'simple2', + 'qty' => 2, + "price" => 20, + "price_type" => 1, + "is_default" => false, + ], + ], + ]; + $this->setBundleProductOptions($bundleProduct, $bundleProductOptions); + $this->saveProduct($bundleProduct); + + $updatedProduct = $this->getProduct(self::BUNDLE_PRODUCT_ID); + $bundleOptions = $this->getBundleProductOptions($updatedProduct); + $this->assertEquals('new option', $bundleOptions[0]['title']); + $this->assertTrue($bundleOptions[0]['required']); + $this->assertEquals('select', $bundleOptions[0]['type']); + $this->assertGreaterThan($oldOptionId, $bundleOptions[0]['option_id']); + $this->assertFalse(isset($bundleOptions[1])); + $this->assertEquals('simple2', $bundleOptions[0]['product_links'][0]['sku']); + $this->assertEquals(2, $bundleOptions[0]['product_links'][0]['qty']); + } + + /** + * Get the bundle_product_options custom attribute from product, null if the attribute is not set + * + * @param array $product + * @return array|null + */ + protected function getBundleProductOptions($product) + { + if (isset($product[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"])) { + return $product[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]; + } else { + return null; + } + } + + /** + * Set the bundle_product_options custom attribute, replace existing attribute if exists + * + * @param array $product + * @param array $bundleProductOptions + */ + protected function setBundleProductOptions(&$product, $bundleProductOptions) + { + $product["extension_attributes"]["bundle_product_options"] = $bundleProductOptions; + return; + } + + /** + * Create dynamic bundle product with one option + * + * @return array + */ + protected function createDynamicBundleProduct() + { + $bundleProductOptions = [ + [ + "title" => "test option", + "type" => "checkbox", + "required" => 1, + "product_links" => [ + [ + "sku" => 'simple', + "qty" => 1, + "is_default" => true, + "price" => 10, + "price_type" => 1, + ], + ], + ], + ]; + + $uniqueId = self::BUNDLE_PRODUCT_ID; + $product = [ + "sku" => $uniqueId, + "name" => $uniqueId, + "type_id" => "bundle", + 'attribute_set_id' => 4, + "custom_attributes" => [ + "price_type" => [ + 'attribute_code' => 'price_type', + 'value' => \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC + ], + "price_view" => [ + "attribute_code" => "price_view", + "value" => "1", + ], + ], + "extension_attributes" => [ + "bundle_product_options" => $bundleProductOptions, + ], + ]; + + $response = $this->createProduct($product); + $this->assertTrue( + isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]) + ); $resultBundleProductOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]; - $this->assertEquals($bundleProductOptions, $resultBundleProductOptions); + $this->assertTrue(isset($resultBundleProductOptions[0]["product_links"][0]["sku"])); $this->assertEquals('simple', $resultBundleProductOptions[0]["product_links"][0]["sku"]); + $this->assertTrue(isset($response['custom_attributes'])); + $customAttributes = $this->convertCustomAttributes($response['custom_attributes']); + $this->assertTrue(isset($customAttributes['price_type'])); + $this->assertEquals(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC, $customAttributes['price_type']); + $this->assertTrue(isset($customAttributes['price_view'])); + $this->assertEquals(1, $customAttributes['price_view']); + return $response; + } + + /** + * Create fixed price bundle product with one option + * + * @return array + */ + protected function createFixedPriceBundleProduct() + { + $bundleProductOptions = [ + [ + "title" => "test option", + "type" => "checkbox", + "required" => 1, + "product_links" => [ + [ + "sku" => 'simple', + "qty" => 1, + "price" => 20, + "price_type" => 1, + "is_default" => true, + ], + ], + ], + ]; + + $uniqueId = self::BUNDLE_PRODUCT_ID; + $product = [ + "sku" => $uniqueId, + "name" => $uniqueId, + "type_id" => "bundle", + "price" => 50, + 'attribute_set_id' => 4, + "custom_attributes" => [ + "price_type" => [ + 'attribute_code' => 'price_type', + 'value' => \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED + ], + "price_view" => [ + "attribute_code" => "price_view", + "value" => "1", + ], + ], + "extension_attributes" => [ + "bundle_product_options" => $bundleProductOptions, + ], + ]; - $response = $this->getProduct($uniqueId); + $response = $this->createProduct($product); $resultBundleProductOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["bundle_product_options"]; $this->assertEquals('simple', $resultBundleProductOptions[0]["product_links"][0]["sku"]); + $this->assertTrue(isset($response['custom_attributes'])); + $customAttributes = $this->convertCustomAttributes($response['custom_attributes']); + $this->assertTrue(isset($customAttributes['price_type'])); + $this->assertEquals(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED, $customAttributes['price_type']); + $this->assertTrue(isset($customAttributes['price_view'])); + $this->assertEquals(1, $customAttributes['price_view']); + return $response; + } + + protected function convertCustomAttributes($customAttributes) + { + $convertedCustomAttribute = []; + foreach ($customAttributes as $customAttribute) { + $convertedCustomAttribute[$customAttribute['attribute_code']] = $customAttribute['value']; + } + return $convertedCustomAttribute; } /** @@ -154,7 +469,56 @@ class ProductServiceTest extends WebapiAbstract ]; $requestData = ['product' => $product]; $response = $this->_webApiCall($serviceInfo, $requestData); - $product[ProductInterface::SKU] = $response[ProductInterface::SKU]; - return $product; + return $response; + } + + /** + * Delete a product by sku + * + * @param $productSku + * @return bool + */ + protected function deleteProductBySku($productSku) + { + $resourcePath = self::RESOURCE_PATH . '/' . $productSku; + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => $resourcePath, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'deleteById', + ], + ]; + $requestData = ["sku" => $productSku]; + $response = $this->_webApiCall($serviceInfo, $requestData); + return $response; + } + + /** + * Save product + * + * @param array $product + * @return array the created product data + */ + protected function saveProduct($product) + { + $resourcePath = self::RESOURCE_PATH . '/' . $product['sku']; + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => $resourcePath, + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::SERVICE_NAME . 'Save', + ], + ]; + $requestData = ['product' => $product]; + $response = $this->_webApiCall($serviceInfo, $requestData); + return $response; } } 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 f78abc4a896adf0c4d64d5697b634b1031a3e17d..8d6c238db91f51b1afec55af59fc90d72899c6e9 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,118 @@ class BillingAddressManagementTest extends WebapiAbstract $this->assertEquals($value, $savedData[$key]); } } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testGetMyAddress() + { + $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'); + + $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() + ]; + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $token + ], + ]; + + $this->assertEquals($data, $this->_webApiCall($serviceInfo)); + } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php + */ + public function testSetMyAddress() + { + $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'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + '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 = [ + '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]); + } + } } 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 1f977421884bb9bb8d300244fd3995986c30a6f5..b8ec4629f35812fd01c7e8a6b1cf03577d4e9529 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 = []; @@ -26,7 +27,17 @@ class CartManagementTest extends WebapiAbstract $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' => [ @@ -46,14 +57,71 @@ class CartManagementTest extends WebapiAbstract $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']); } /** @@ -298,26 +366,67 @@ class CartManagementTest extends WebapiAbstract $items = $order->getAllItems(); $this->assertCount(1, $items); $this->assertEquals('Simple Product', $items[0]->getName()); - $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'); + + $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()); + } + + /** + * 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 + /** @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(); $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 ], ]; diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartRepositoryTest.php index add493db96a143faf32a0d26e183122067aaa9e6..9169ee6ca6ab690c9d367e7adc33dedaa3f217fe 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/CartRepositoryTest.php @@ -163,8 +163,8 @@ class CartRepositoryTest extends WebapiAbstract ->setValue($cart->getSubtotal()) ->create(); - $yesterdayDate = (new \DateTime())->sub(new \DateInterval('P1D'))->format('Y-m-d'); - $tomorrowDate = (new \DateTime())->add(new \DateInterval('P1D'))->format('Y-m-d'); + $yesterdayDate = (new \DateTime($cart->getCreatedAt()))->sub(new \DateInterval('P1D'))->format('Y-m-d'); + $tomorrowDate = (new \DateTime($cart->getCreatedAt()))->add(new \DateInterval('P1D'))->format('Y-m-d'); $minCreatedAtFilter = $this->filterBuilder->setField('created_at') ->setConditionType('gteq') ->setValue($yesterdayDate) 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 257cd01237d947ab653b0069b176da3b83036618..406b755d77dd133e839ab27c4396ef3ef2ddd8de 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,64 @@ class CartTotalRepositoryTest extends WebapiAbstract ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => $item->getBaseRowTotalInclTax(), ]; } + + /** + * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php + */ + public function testGetMyTotals() + { + $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'); + + $serviceInfo = [ + '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)], + ]; + + $data = $this->formatTotalsData($data); + + $this->assertEquals($data, $this->_webApiCall($serviceInfo)); + } } 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 f6f2a4655c0bc4c94258d4a377b142a4b5ac1fbd..e6c8a97b918c488762656b2850a251cc4fec215d 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,147 @@ class CouponManagementTest extends WebapiAbstract $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'); + $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'); + $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'); + + $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/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php new file mode 100644 index 0000000000000000000000000000000000000000..97838fe9f26393312c5a24c53f5ad85ab0f061e1 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestBillingAddressManagementTest.php @@ -0,0 +1,145 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +use Magento\Quote\Api\Data\AddressInterface; +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestBillingAddressManagementTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestBillingAddressManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + protected function setUp() + { + $this->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]); + } + } +} 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 0000000000000000000000000000000000000000..7287cd302008205adfafc6b6b96a7a65064e28c4 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -0,0 +1,226 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestCartItemRepositoryTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestCartItemRepositoryV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + protected function setUp() + { + $this->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(); + + /** @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', + '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(); + + /** @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); + $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(); + + /** @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); + $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/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9058a930b196d518058f1db9693fe4a5091a0b45 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartManagementTest.php @@ -0,0 +1,345 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestCartManagementTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestCartManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + protected $createdQuotes = []; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + protected function setUp() + { + $this->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()); + } +} 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 0000000000000000000000000000000000000000..b3c8e3f024e70c12332a800999e68298bad7473c --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartRepositoryTest.php @@ -0,0 +1,129 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +use Magento\TestFramework\ObjectManager; +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestCartRepositoryTest extends WebapiAbstract +{ + /** + * @var ObjectManager + */ + private $objectManager; + + protected function setUp() + { + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + protected function tearDown() + { + try { + $cart = $this->getCart('test01'); + $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/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php new file mode 100644 index 0000000000000000000000000000000000000000..87cbbbdaaf40ec9f52f36a41bc5945c6fb69ddbe --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartTotalRepositoryTest.php @@ -0,0 +1,182 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +use Magento\Quote\Model\Cart\Totals; +use Magento\Quote\Model\Cart\Totals\Item as ItemTotals; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\TestFramework\ObjectManager; +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestCartTotalRepositoryTest extends WebapiAbstract +{ + /** + * @var ObjectManager + */ + private $objectManager; + + /** + * @var SearchCriteriaBuilder + */ + private $searchBuilder; + + /** + * @var FilterBuilder + */ + private $filterBuilder; + + protected function setUp() + { + $this->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(), + ]; + } +} 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 0000000000000000000000000000000000000000..296d5d60767fb9f07477c7651c8a583a4d15939e --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCouponManagementTest.php @@ -0,0 +1,175 @@ +<?php +/** + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestCouponManagementTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestCouponManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + 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 */ + $quoteIdMask = $this->objectManager->create('Magento\Quote\Model\QuoteIdMaskFactory')->create(); + $quoteIdMask->load($quoteId); + 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->getQuoteMaskedId($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->getQuoteMaskedId($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->getQuoteMaskedId($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->getQuoteMaskedId($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); + } +} 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 0000000000000000000000000000000000000000..40579922f1896f761ef85e891a1e5f59daae39dd --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestPaymentMethodManagementTest.php @@ -0,0 +1,333 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +class GuestPaymentMethodManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestPaymentMethodManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + protected function setUp() + { + $this->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-method', + '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-method', + '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-method', + '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-method', + '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-method', + '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-method', + '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); + + 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. + * + * @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/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a1c22bf0ee869fda4e3fec3d588101ed748dfb36 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingAddressManagementTest.php @@ -0,0 +1,235 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Quote\Api; + +use Magento\Quote\Api\Data\AddressInterface; +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestShippingAddressManagementTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestShippingAddressManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var \Magento\TestFramework\ObjectManager + */ + protected $objectManager; + + protected function setUp() + { + $this->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()); + } + } + + 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->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 = $this->getQuoteMaskedId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/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'); + $quote->load('test_order_with_virtual_product', 'reserved_order_id'); + $cartId = $this->getQuoteMaskedId($quote->getId()); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . $cartId . '/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 = $this->getQuoteMaskedId($quote->getId()); + + $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 = $this->getQuoteMaskedId($quote->getId()); + + $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); + } +} 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 0000000000000000000000000000000000000000..54b89387651643a72a5c7aac9a789898942dd28e --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShippingMethodManagementTest.php @@ -0,0 +1,334 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +use Magento\Quote\Api\Data\ShippingMethodInterface; +use Magento\TestFramework\ObjectManager; +use Magento\TestFramework\TestCase\WebapiAbstract; + +class GuestShippingMethodManagementTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestShippingMethodManagementV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var ObjectManager + */ + private $objectManager; + + /** + * @var \Magento\Quote\Model\Quote + */ + protected $quote; + + protected function setUp() + { + $this->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; + } +} 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 8288f1f9b5d874e3ca80bd323ee1777c8de751f3..b4aa67ab9fa7d3061541f02879d878e84a1e110f 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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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,22 +266,126 @@ class PaymentMethodManagementTest extends \Magento\TestFramework\TestCase\Webapi $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']); } + + /** + * @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-method', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + 'token' => $this->getCustomerToken() + ] + ]; + + $requestResponse = $this->_webApiCall($serviceInfo); + + foreach ($this->getPaymentMethodFieldsForAssert() as $field) { + $this->assertArrayHasKey($field, $requestResponse); + $this->assertNotNull($requestResponse[$field]); + } + $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-method', + '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)); + } + + /** + * @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 + * + * @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; + } } 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 ff9c032601f880b6bac99622c94f2e5f6ba7915a..9a8db29b15a7abfe050ccf675c24b701eab51538 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,124 @@ class ShippingAddressManagementTest extends WebapiAbstract $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() + { + $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'); + + /** @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 + ], + ]; + + $requestData = []; + $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() + { + $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'); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::RESOURCE_PATH . 'mine/shipping-address', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + '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 = [ + '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); + } + } } 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 6217cc99b088f063669901fdc5e1d492794e1e2c..60865f081c99f6e7fdbdc93b6a901e95189e0509 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 @@ class ShippingMethodManagementTest extends WebapiAbstract $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 @@ class ShippingMethodManagementTest extends WebapiAbstract $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,54 @@ class ShippingMethodManagementTest extends WebapiAbstract $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); + $this->assertCount(1, $result); + + $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 diff --git a/dev/tests/functional/composer.json b/dev/tests/functional/composer.json index 5f5074addbc3975433141b19987cf6e9df6a55e1..efe7c5458aabed79e36e4a3ffaa646832910f8f9 100644 --- a/dev/tests/functional/composer.json +++ b/dev/tests/functional/composer.json @@ -1,6 +1,6 @@ { "require": { - "magento/mtf": "1.0.0-rc22", + "magento/mtf": "1.0.0-rc23", "php": "~5.5.0|~5.6.0", "phpunit/phpunit": "4.1.0", "phpunit/phpunit-selenium": ">=1.2", diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php index bd53879a52018d712e7ef1bdc5ef38e59caa8022..dbc8efa6e71ccd62e5fdeaf17c86b749c2e44f0f 100755 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php @@ -13,11 +13,8 @@ use Magento\Mtf\Fixture\FixtureInterface; use Magento\Mtf\Fixture\InjectableFixture; use Magento\Mtf\Client\BrowserInterface; use Magento\Mtf\Client\Element\SimpleElement; -use Magento\Mtf\Util\Iterator\File; -use Magento\Mtf\Util\XmlConverter; /** - * Class FormTabs * Is used to represent any form with tabs on the page * * @SuppressWarnings(PHPMD.NumberOfChildren) @@ -30,11 +27,6 @@ class FormTabs extends Form */ protected $tabs = []; - /** - * @var XmlConverter - */ - protected $xmlConverter; - /** * Fields which aren't assigned to any tab * @@ -48,7 +40,6 @@ class FormTabs extends Form * @param Mapper $mapper * @param BlockFactory $blockFactory * @param BrowserInterface $browser - * @param XmlConverter $xmlConverter * @param array $config */ public function __construct( @@ -56,46 +47,17 @@ class FormTabs extends Form Mapper $mapper, BlockFactory $blockFactory, BrowserInterface $browser, - XmlConverter $xmlConverter, array $config = [] ) { - $this->xmlConverter = $xmlConverter; parent::__construct($element, $blockFactory, $mapper, $browser, $config); } /** * Initialize block */ - protected function _init() + protected function init() { - $this->tabs = $this->getTabs(); - } - - /** - * Get all tabs on the form - * - * @return array - */ - protected function getTabs() - { - $result = []; - - $paths = glob( - MTF_TESTS_PATH . preg_replace('/Magento\/\w+/', '*/*', str_replace('\\', '/', get_class($this))) . '.xml' - ); - $files = new File($paths); - - foreach ($files as $file) { - $presetXml = simplexml_load_string($file); - if ($presetXml instanceof \SimpleXMLElement) { - $array = $this->xmlConverter->convert($presetXml); - if (is_array($array)) { - $result = array_replace_recursive($result, $array); - } - } - } - - return $result; + $this->tabs = $this->getFormMapping(); } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/AttributeForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/AttributeForm.php index 78e8c9965593fd9adc49af1d4885e8320472dab5..7147f86db8877e960013a314798fcd795f1b7f9a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/AttributeForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/AttributeForm.php @@ -15,7 +15,6 @@ use Magento\Mtf\Client\Element; use Magento\Mtf\Client\Element\SimpleElement; use Magento\Mtf\Client\Locator; use Magento\Mtf\Fixture\FixtureInterface; -use Magento\Mtf\Util\XmlConverter; /** * Edit attribute form on catalog product edit page. @@ -49,7 +48,6 @@ class AttributeForm extends FormTabs * @param Mapper $mapper * @param BlockFactory $blockFactory * @param BrowserInterface $browser - * @param XmlConverter $xmlConverter * @param array $config */ public function __construct( @@ -57,10 +55,9 @@ class AttributeForm extends FormTabs Mapper $mapper, BlockFactory $blockFactory, BrowserInterface $browser, - XmlConverter $xmlConverter, array $config = [] ) { - parent::__construct($element, $mapper, $blockFactory, $browser, $xmlConverter, $config); + parent::__construct($element, $mapper, $blockFactory, $browser, $config); $this->browser->switchToFrame(new Locator($this->iFrame)); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.xml index 2a4163d237a8b8ceb913303ba10463ca8a789db5..ff3443eee0b503bc7c5d17caed6389d4b8226690 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.xml @@ -6,19 +6,16 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> - <page name="CatalogProductView" area="Product" mca="catalog/product/view" module="Magento_Catalog"> - <block name="viewBlock" class="Magento\Catalog\Test\Block\Product\View" locator="#maincontent" strategy="css selector"/> - <block name="additionalInformationBlock" class="Magento\Catalog\Test\Block\Product\Additional" locator="#additional" strategy="css selector"/> - <block name="customOptionsBlock" class="Magento\Catalog\Test\Block\Product\View\CustomOptions" locator="#product-options-wrapper" strategy="css selector"/> - <block name="relatedProductBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Related" locator=".block.related" strategy="css selector"/> - <block name="upsellBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Upsell" locator=".block.upsell" strategy="css selector"/> - <block name="crosssellBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Crosssell" locator=".block.crosssell" strategy="css selector"/> - <block name="downloadableLinksBlock" class="Magento\Downloadable\Test\Block\Catalog\Product\View\Links" locator="[data-container-for=downloadable-links]" strategy="css selector"/> - <block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator=".page.messages .messages" strategy="css selector"/> - <block name="reviewSummary" class="Magento\Review\Test\Block\Product\View\Summary" locator=".product-reviews-summary" strategy="css selector"/> - <block name="customerReviewBlock" class="Magento\Review\Test\Block\Product\View" locator="#customer-reviews" strategy="css selector"/> - <block name="reviewFormBlock" class="Magento\Review\Test\Block\Form" locator="#review-form" strategy="css selector"/> - <block name="titleBlock" class="Magento\Theme\Test\Block\Html\Title" locator=".page-title-wrapper h1.page-title .base" strategy="css selector"/> - <block name="widgetView" class="Magento\Widget\Test\Block\WidgetView" locator=".column.main .widget" strategy="css selector"/> - </page> + <page name="CatalogProductView" area="Product" mca="catalog/product/view" module="Magento_Catalog"> + <block name="viewBlock" class="Magento\Catalog\Test\Block\Product\View" locator="#maincontent" strategy="css selector" /> + <block name="additionalInformationBlock" class="Magento\Catalog\Test\Block\Product\Additional" locator="#additional" strategy="css selector" /> + <block name="customOptionsBlock" class="Magento\Catalog\Test\Block\Product\View\CustomOptions" locator="#product-options-wrapper" strategy="css selector" /> + <block name="relatedProductBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Related" locator=".block.related" strategy="css selector" /> + <block name="upsellBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Upsell" locator=".block.upsell" strategy="css selector" /> + <block name="crosssellBlock" class="Magento\Catalog\Test\Block\Product\ProductList\Crosssell" locator=".block.crosssell" strategy="css selector" /> + <block name="downloadableLinksBlock" class="Magento\Downloadable\Test\Block\Catalog\Product\View\Links" locator="[data-container-for=downloadable-links]" strategy="css selector" /> + <block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator=".page.messages .messages" strategy="css selector" /> + <block name="titleBlock" class="Magento\Theme\Test\Block\Html\Title" locator=".page-title-wrapper h1.page-title .base" strategy="css selector" /> + <block name="widgetView" class="Magento\Widget\Test\Block\WidgetView" locator=".column.main .widget" strategy="css selector" /> + </page> </config> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml index 11c19fd14519b9b8fd6cb122f3214f981d06309a..0d8c49414fb80ba6fd05ed3c27f40f16fe79731f 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml @@ -182,7 +182,6 @@ <data name="productAttribute/data/is_searchable" xsi:type="string">Yes</data> <data name="productAttribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data> <data name="productAttribute/data/is_comparable" xsi:type="string">Yes</data> - <data name="issue" xsi:type="string">Bug: MAGETWO-33625</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductAttributeIsUnique" /> </variation> </testCase> diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php index 26135d5e646639ed286f07201c4272ae3b881fa1..6649d45ba0e6312653b5c6766ab1727f20786aed 100644 --- a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php @@ -33,7 +33,7 @@ class CreateCatalogRuleTest extends AbstractCatalogRuleEntityTest const TEST_TYPE = 'acceptance_test'; const MVP = 'yes'; const DOMAIN = 'MX'; - const TO_MAINTAIN = 'yes'; + const TO_MAINTAIN = 'yes'; // Selecting conditions in parallel mode /* end tags */ /** diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertOrderTotalOnReviewPage.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertOrderTotalOnReviewPage.php index 5d61be2bc1db1684505cf80daacf47325099a719..3bfb458f34130b1fe4b33f4d45b056c208a00aa4 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertOrderTotalOnReviewPage.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Constraint/AssertOrderTotalOnReviewPage.php @@ -10,8 +10,7 @@ use Magento\Checkout\Test\Page\CheckoutOnepage; use Magento\Mtf\Constraint\AbstractConstraint; /** - * Class AssertOrderTotalOnReviewPage - * Assert that Order Grand Total is correct on checkoutOnePage + * Assert that Order Grand Total is correct on checkoutOnePage. */ class AssertOrderTotalOnReviewPage extends AbstractConstraint { @@ -19,18 +18,17 @@ class AssertOrderTotalOnReviewPage extends AbstractConstraint * Assert that Order Grand Total is correct on checkoutOnePage * * @param CheckoutOnepage $checkoutOnepage - * @param string $grandTotal + * @param array $prices * @return void */ - public function processAssert(CheckoutOnepage $checkoutOnepage, $grandTotal) + public function processAssert(CheckoutOnepage $checkoutOnepage, array $prices) { $checkoutReviewGrandTotal = $checkoutOnepage->getReviewBlock()->getGrandTotal(); \PHPUnit_Framework_Assert::assertEquals( $checkoutReviewGrandTotal, - number_format($grandTotal, 2), - 'Grand Total price: \'' . $checkoutReviewGrandTotal - . '\' not equals with price from data set: \'' . $grandTotal . '\'' + number_format($prices['grandTotal'], 2), + "Grand Total price: $checkoutReviewGrandTotal not equals with price from data set: " . $prices['grandTotal'] ); } diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/PlaceOrderStep.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/PlaceOrderStep.php index 7adfc7fc1ac63ea36b5a5eb242356dc80690ac82..f0c4143e4e91b985627ff89669da80783441f69c 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/PlaceOrderStep.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/PlaceOrderStep.php @@ -12,41 +12,40 @@ use Magento\Checkout\Test\Page\CheckoutOnepageSuccess; use Magento\Mtf\TestStep\TestStepInterface; /** - * Class PlaceOrderStep - * Place order in one page checkout + * Place order in one page checkout. */ class PlaceOrderStep implements TestStepInterface { /** - * Onepage checkout page + * Onepage checkout page. * * @var CheckoutOnepage */ protected $checkoutOnepage; /** - * Assert that Order Grand Total is correct on checkout page review block + * Assert that Order Grand Total is correct on checkout page review block. * * @var AssertOrderTotalOnReviewPage */ protected $assertOrderTotalOnReviewPage; /** - * One page checkout success page + * One page checkout success page. * * @var CheckoutOnepageSuccess */ protected $checkoutOnepageSuccess; /** - * Grand total price + * Price array. * * @var string */ - protected $grandTotal; + protected $prices; /** - * Checkout method + * Checkout method. * * @var string */ @@ -58,31 +57,31 @@ class PlaceOrderStep implements TestStepInterface * @param AssertOrderTotalOnReviewPage $assertOrderTotalOnReviewPage * @param CheckoutOnepageSuccess $checkoutOnepageSuccess * @param string $checkoutMethod - * @param string|null $grandTotal + * @param array $prices */ public function __construct( CheckoutOnepage $checkoutOnepage, AssertOrderTotalOnReviewPage $assertOrderTotalOnReviewPage, CheckoutOnepageSuccess $checkoutOnepageSuccess, $checkoutMethod, - $grandTotal = null + array $prices = [] ) { $this->checkoutOnepage = $checkoutOnepage; $this->assertOrderTotalOnReviewPage = $assertOrderTotalOnReviewPage; - $this->grandTotal = $grandTotal; + $this->prices = $prices; $this->checkoutOnepageSuccess = $checkoutOnepageSuccess; $this->checkoutMethod = $checkoutMethod; } /** - * Place order after checking order totals on review step + * Place order after checking order totals on review step. * * @return array */ public function run() { - if ($this->grandTotal !== null) { - $this->assertOrderTotalOnReviewPage->processAssert($this->checkoutOnepage, $this->grandTotal); + if (!empty($this->prices)) { + $this->assertOrderTotalOnReviewPage->processAssert($this->checkoutOnepage, $this->prices); } $this->checkoutOnepage->getReviewBlock()->placeOrder(); diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml index eeea09970da769ab9eb00d22491aa9b4d6937999..3261040052d7dcff7d440a05031dc7e563d9eb03 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml @@ -55,17 +55,6 @@ <field name="gender" xsi:type="string">Male</field> </dataset> - <dataset name="johndoe_with_balance"> - <field name="firstname" xsi:type="string">John</field> - <field name="lastname" xsi:type="string">Doe</field> - <field name="email" xsi:type="string">JohnDoe_%isolation%@example.com</field> - <field name="password" xsi:type="string">123123q</field> - <field name="password_confirmation" xsi:type="string">123123q</field> - <field name="dob" xsi:type="string">01/01/1990</field> - <field name="gender" xsi:type="string">Male</field> - <field name="amount_delta" xsi:type="string">501</field> - </dataset> - <dataset name="defaultBackend"> <field name="website_id" xsi:type="string">Main Website</field> <field name="firstname" xsi:type="string">John</field> diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/UpdateDownloadableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/UpdateDownloadableProductEntityTest.xml index a7697b5d62a60d863bf99a8b6c298cadb63b6f55..69a8cb56138fc5d25a46a3eb72ac00e5dd66be17 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/UpdateDownloadableProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/UpdateDownloadableProductEntityTest.xml @@ -15,18 +15,9 @@ <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">10</data> <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">In Stock</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> - <data name="product/data/weight" xsi:type="string">-</data> - <data name="product/data/category" xsi:type="string">-</data> - <data name="product/data/description" xsi:type="string">-</data> - <data name="product/data/short_description" xsi:type="string">-</data> - <data name="product/data/stock_data/manage_stock" xsi:type="string">-</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> - <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">-</data> - <data name="product/data/stock_data/min_qty" xsi:type="string">-</data> <data name="product/data/downloadable_sample/preset" xsi:type="string">with_three_samples</data> <data name="product/data/downloadable_links/preset" xsi:type="string">with_three_links</data> <data name="product/data/custom_options/preset" xsi:type="string">two_options</data> - <data name="product/data/special_price" xsi:type="string">-</data> <data name="isRequired" xsi:type="string">No</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> @@ -46,18 +37,8 @@ <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">50</data> <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">Out of Stock</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> - <data name="product/data/weight" xsi:type="string">-</data> <data name="product/data/category" xsi:type="string">Default Category</data> - <data name="product/data/description" xsi:type="string">-</data> - <data name="product/data/short_description" xsi:type="string">-</data> - <data name="product/data/stock_data/manage_stock" xsi:type="string">-</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> - <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">-</data> - <data name="product/data/stock_data/min_qty" xsi:type="string">-</data> - <data name="product/data/downloadable_sample/preset" xsi:type="string">-</data> <data name="product/data/downloadable_links/preset" xsi:type="string">default</data> - <data name="product/data/custom_options/preset" xsi:type="string">-</data> - <data name="product/data/special_price" xsi:type="string">-</data> <data name="isRequired" xsi:type="string">No</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> @@ -71,20 +52,11 @@ <data name="product/data/price/value" xsi:type="string">9999</data> <data name="product/data/tax_class_id/dataSet" xsi:type="string">taxable_goods</data> <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">123</data> - <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">-</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> - <data name="product/data/weight" xsi:type="string">-</data> <data name="product/data/category" xsi:type="string">Default Category</data> - <data name="product/data/description" xsi:type="string">-</data> - <data name="product/data/short_description" xsi:type="string">-</data> <data name="product/data/stock_data/manage_stock" xsi:type="string">Yes</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">No</data> <data name="product/data/stock_data/min_qty" xsi:type="string">123</data> - <data name="product/data/downloadable_sample/preset" xsi:type="string">-</data> - <data name="product/data/downloadable_links/preset" xsi:type="string">-</data> - <data name="product/data/custom_options/preset" xsi:type="string">-</data> - <data name="product/data/special_price" xsi:type="string">-</data> <data name="isRequired" xsi:type="string">No</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> @@ -100,18 +72,9 @@ <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">5</data> <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">In Stock</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> - <data name="product/data/weight" xsi:type="string">-</data> <data name="product/data/category" xsi:type="string">Default Category</data> <data name="product/data/description" xsi:type="string">This is description for downloadable product</data> - <data name="product/data/short_description" xsi:type="string">-</data> - <data name="product/data/stock_data/manage_stock" xsi:type="string">-</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> - <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">-</data> - <data name="product/data/stock_data/min_qty" xsi:type="string">-</data> - <data name="product/data/downloadable_sample/preset" xsi:type="string">-</data> <data name="product/data/downloadable_links/preset" xsi:type="string">default</data> - <data name="product/data/custom_options/preset" xsi:type="string">-</data> - <data name="product/data/special_price" xsi:type="string">-</data> <data name="isRequired" xsi:type="string">No</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> @@ -127,18 +90,11 @@ <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">10</data> <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">In Stock</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> - <data name="product/data/weight" xsi:type="string">-</data> <data name="product/data/category" xsi:type="string">category %isolation%</data> - <data name="product/data/description" xsi:type="string">-</data> <data name="product/data/short_description" xsi:type="string">This is short description for downloadable product</data> - <data name="product/data/stock_data/manage_stock" xsi:type="string">-</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> - <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">-</data> - <data name="product/data/stock_data/min_qty" xsi:type="string">-</data> <data name="product/data/downloadable_sample/preset" xsi:type="string">default</data> <data name="product/data/downloadable_links/preset" xsi:type="string">with_three_links</data> <data name="product/data/custom_options/preset" xsi:type="string">default</data> - <data name="product/data/special_price" xsi:type="string">-</data> <data name="isRequired" xsi:type="string">Yes</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> @@ -159,16 +115,6 @@ <data name="product/data/quantity_and_stock_status/is_in_stock" xsi:type="string">In Stock</data> <data name="product/data/is_virtual" xsi:type="string">Yes</data> <data name="product/data/weight" xsi:type="string">10</data> - <data name="product/data/category" xsi:type="string">-</data> - <data name="product/data/description" xsi:type="string">-</data> - <data name="product/data/short_description" xsi:type="string">-</data> - <data name="product/data/stock_data/manage_stock" xsi:type="string">-</data> - <data name="product/data/stock_data/qty" xsi:type="string">-</data> - <data name="product/data/stock_data/use_config_min_qty" xsi:type="string">-</data> - <data name="product/data/stock_data/min_qty" xsi:type="string">-</data> - <data name="product/data/downloadable_sample/preset" xsi:type="string">-</data> - <data name="product/data/downloadable_links/preset" xsi:type="string">-</data> - <data name="product/data/custom_options/preset" xsi:type="string">-</data> <data name="product/data/special_price" xsi:type="string">40</data> <data name="isRequired" xsi:type="string">No</data> <data name="product/data/url_key" xsi:type="string">downloadableproduct-%isolation%</data> 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 00e3a4896a7fd2e3f979d9eefffd284b1839cda0..427bc6c11cd4edfd7ed82f34ccafe2b6229d88e2 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 @@ class Associated implements FixtureInterface '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/GroupedProduct/Test/Fixture/GroupedProduct/CheckoutData.php b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/CheckoutData.php index 2871ec912db01ef8020b14699f62d95c6f7299ac..5c45ad254c0b02f4444547e1b95ebba7fedf2727 100644 --- a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/CheckoutData.php +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/CheckoutData.php @@ -57,6 +57,39 @@ class CheckoutData extends \Magento\Catalog\Test\Fixture\CatalogProductSimple\Ch ], ], ], + 'three_simple_products_default_qty' => [ + 'options' => [ + [ + 'name' => 'product_key_0', + 'qty' => 17, + ], + [ + 'name' => 'product_key_1', + 'qty' => 36 + ], + [ + 'name' => 'product_key_2', + 'qty' => 20 + ], + ], + 'cartItem' => [ + 'price' => [ + 'product_key_0' => 560, + 'product_key_1' => 40, + 'product_key_2' => 100, + ], + 'qty' => [ + 'product_key_0' => 17, + 'product_key_1' => 36, + 'product_key_2' => 20, + ], + 'subtotal' => [ + 'product_key_0' => 9520.00, + 'product_key_1' => 1440.00, + 'product_key_2' => 2000.00, + ], + ], + ], ]; return isset($presets[$name]) ? $presets[$name] : null; } diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Repository/GroupedProduct.xml b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Repository/GroupedProduct.xml index cd0bc02b3df4ccab18c34b1876eef98e775af553..fbf4305699a447b37e9a8d1bd756caec8f1f569e 100644 --- a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Repository/GroupedProduct.xml +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Repository/GroupedProduct.xml @@ -117,5 +117,34 @@ <item name="preset" xsi:type="string">three_simple_products</item> </field> </dataset> + + <dataset name="three_simple_products_default_qty"> + <field name="name" xsi:type="string">Grouped product %isolation%</field> + <field name="sku" xsi:type="string">grouped_product_%isolation%</field> + <field name="category_ids" xsi:type="array"> + <item name="presets" xsi:type="string">default</item> + </field> + <field name="associated" xsi:type="array"> + <item name="preset" xsi:type="string">three_simple_products</item> + </field> + <field name="status" xsi:type="string">Product online</field> + <field name="visibility" xsi:type="string">Catalog, Search</field> + <field name="tax_class_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">taxable_goods</item> + </field> + <field name="url_key" xsi:type="string">test-grouped-product-%isolation%</field> + <field name="quantity_and_stock_status" xsi:type="array"> + <item name="is_in_stock" xsi:type="string">In Stock</item> + </field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="attribute_set_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="checkout_data" xsi:type="array"> + <item name="preset" xsi:type="string">three_simple_products_default_qty</item> + </field> + </dataset> </repository> </config> diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertAgreementTextPresent.php b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertAgreementTextPresent.php index 7c59cf1d4c263b8493ce2dcbb0889824a55e72ed..1bc49b0acc7773869bb8b2af6f669c01661f94df 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertAgreementTextPresent.php +++ b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertAgreementTextPresent.php @@ -8,6 +8,7 @@ namespace Magento\Install\Test\Constraint; use Magento\Install\Test\Page\Install; use Magento\Mtf\Constraint\AbstractConstraint; +use Magento\TestFramework\Inspection\Exception; /** * Check that agreement text present on Terms & Agreement page during install. @@ -15,9 +16,14 @@ use Magento\Mtf\Constraint\AbstractConstraint; class AssertAgreementTextPresent extends AbstractConstraint { /** - * Part of license agreement text. + * Part of Default license agreement text. */ - const LICENSE_AGREEMENT_TEXT = 'Open Software License ("OSL") v. 3.0'; + const DEFAULT_LICENSE_AGREEMENT_TEXT = 'Open Software License ("OSL") v. 3.0'; + + /** + * Part of Default license agreement text. + */ + const LICENSE_AGREEMENT_TEXT = 'END USER LICENSE AGREEMENT'; /** * Assert that part of license agreement text is present on Terms & Agreement page. @@ -27,11 +33,19 @@ class AssertAgreementTextPresent extends AbstractConstraint */ public function processAssert(Install $installPage) { - \PHPUnit_Framework_Assert::assertContains( - self::LICENSE_AGREEMENT_TEXT, - $installPage->getLicenseBlock()->getLicense(), - 'License agreement text is absent.' - ); + try { + \PHPUnit_Framework_Assert::assertContains( + self::LICENSE_AGREEMENT_TEXT, + $installPage->getLicenseBlock()->getLicense(), + 'License agreement text is absent.' + ); + } catch (\Exception $e) { + \PHPUnit_Framework_Assert::assertContains( + self::DEFAULT_LICENSE_AGREEMENT_TEXT, + $installPage->getLicenseBlock()->getLicense(), + 'License agreement text is absent.' + ); + } } /** diff --git a/dev/tests/functional/tests/app/Magento/OfflinePayments/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/OfflinePayments/Test/Repository/ConfigData.xml index 068ba800210194b403fb71f6770fe927ce707690..8cdbbc48f92df79fe9ed26fb4b4dacd751c923c9 100644 --- a/dev/tests/functional/tests/app/Magento/OfflinePayments/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/OfflinePayments/Test/Repository/ConfigData.xml @@ -103,12 +103,6 @@ </dataset> <dataset name="checkmo_specificcountry_gb_rollback"> - <field name="payment/checkmo/active" xsi:type="array"> - <item name="scope" xsi:type="string">payment</item> - <item name="scope_id" xsi:type="number">1</item> - <item name="label" xsi:type="string">No</item> - <item name="value" xsi:type="number">0</item> - </field> <field name="payment/checkmo/allowspecific" xsi:type="array"> <item name="scope" xsi:type="string">payment</item> <item name="scope_id" xsi:type="number">1</item> diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/Block/Form.php b/dev/tests/functional/tests/app/Magento/Review/Test/Block/ReviewForm.php old mode 100755 new mode 100644 similarity index 98% rename from dev/tests/functional/tests/app/Magento/Review/Test/Block/Form.php rename to dev/tests/functional/tests/app/Magento/Review/Test/Block/ReviewForm.php index 449bc91419bbdd368b4451d28887e03ed3661e56..ae9ad57029992bccbd9fdab092443967b673161e --- a/dev/tests/functional/tests/app/Magento/Review/Test/Block/Form.php +++ b/dev/tests/functional/tests/app/Magento/Review/Test/Block/ReviewForm.php @@ -16,7 +16,7 @@ use Magento\Mtf\Block\Form as AbstractForm; /** * Review form on frontend. */ -class Form extends AbstractForm +class ReviewForm extends AbstractForm { /** * Legend selector. diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/Block/Form.xml b/dev/tests/functional/tests/app/Magento/Review/Test/Block/ReviewForm.xml old mode 100755 new mode 100644 similarity index 100% rename from dev/tests/functional/tests/app/Magento/Review/Test/Block/Form.xml rename to dev/tests/functional/tests/app/Magento/Review/Test/Block/ReviewForm.xml diff --git a/dev/tests/functional/tests/app/Magento/Review/Test/Page/Product/CatalogProductView.xml b/dev/tests/functional/tests/app/Magento/Review/Test/Page/Product/CatalogProductView.xml new file mode 100644 index 0000000000000000000000000000000000000000..4e80f240eb1210acb7a23f17991390c3368ee5a9 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Review/Test/Page/Product/CatalogProductView.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="CatalogProductView" area="Product" mca="catalog/product/view" module="Magento_Catalog"> + <block name="reviewSummary" class="Magento\Review\Test\Block\Product\View\Summary" locator=".product-reviews-summary" strategy="css selector" /> + <block name="customerReviewBlock" class="Magento\Review\Test\Block\Product\View" locator="#customer-reviews" strategy="css selector" /> + <block name="reviewFormBlock" class="Magento\Review\Test\Block\ReviewForm" locator="#review-form" strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Coupons.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Coupons.php new file mode 100644 index 0000000000000000000000000000000000000000..e118bac1958fb0b3c9d0906bdafe181e157a9a7b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Coupons.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Adminhtml\Order\Create; + +use Magento\Backend\Test\Block\Widget\Form; +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\Client\Locator; + +/** + * Adminhtml sales order create coupons block. + */ +class Coupons extends Form +{ + /** + * Fill discount code input selector. + * + * @var string + */ + protected $couponCode = 'input[name="coupon_code"]'; + + /** + * Click apply button selector. + * + * @var string + */ + protected $applyButton = '//*[@id="coupons:code"]/following-sibling::button'; + + /** + * Enter discount code and click apply button. + * + * @param SalesRuleInjectable $code + * @return void + */ + public function applyCouponCode(SalesRuleInjectable $code) + { + $this->_rootElement->find($this->couponCode)->setValue($code->getCouponCode()); + $this->_rootElement->find($this->applyButton, Locator::SELECTOR_XPATH)->click(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php index f9c089f1a25d99465df54d38fdc02023c7916d3f..f11fc5fce5417a63c7aee70db7ba264f8dc38190 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php @@ -29,15 +29,15 @@ abstract class Sidebar extends Block protected $addToOrderProductName = '//tr/td[.="%s"]'; /** - * Add product to order by name. + * Add productz to order. * - * @param string|array $names + * @param array $products * @return void */ - public function addToOrderByName($names) + public function addProductsToOrder(array $products) { - $names = is_array($names) ? $names : [$names]; - foreach ($names as $name) { + foreach ($products as $product) { + $name = $product->getName(); $this->_rootElement->find(sprintf($this->addToOrderProductName, $name), Locator::SELECTOR_XPATH)->click(); $this->_rootElement->click(); $this->_rootElement->find(sprintf($this->addToOrder, $name), Locator::SELECTOR_XPATH, 'checkbox') diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Items.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Items.php index 7d2aec9dd17a3a28781cb7bdaeedffc277252f1b..03481f3e5b9eeaa0799429519d06796eb6b69ccd 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Items.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/Items.php @@ -11,31 +11,30 @@ use Magento\Mtf\Block\Block; use Magento\Mtf\Client\Locator; /** - * Class Items - * Adminhtml sales order create items block + * Adminhtml sales order create items block. */ class Items extends Block { /** - * 'Add Products' button + * 'Add Products' button. * * @var string */ protected $addProducts = "//button[span='Add Products']"; /** - * Item product + * Item product. * * @var string */ protected $itemProduct = '//tr[td//*[normalize-space(text())="%s"]]'; /** - * Product names + * Product names. * * @var string */ - protected $productNames = '//td[@class="col-product"]//span'; + protected $productNames = '//td[@class="col-product"]/span'; /** * Selector for template block. @@ -45,7 +44,7 @@ class Items extends Block protected $template = './ancestor::body'; /** - * Click 'Add Products' button + * Click 'Add Products' button. * * @return void */ @@ -63,7 +62,7 @@ class Items extends Block } /** - * Get item product block + * Get item product block. * * @param string $name * @return \Magento\Sales\Test\Block\Adminhtml\Order\Create\Items\ItemProduct diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.php new file mode 100644 index 0000000000000000000000000000000000000000..47e544da94f09bc336e7f58cb40ef84b443c192a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.php @@ -0,0 +1,36 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo; + +use Magento\Sales\Test\Block\Adminhtml\Order\AbstractForm; +use Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form\Items; + +/** + * Credit memo create form. + */ +class Form extends AbstractForm +{ + /** + * Items block css selector. + * + * @var string + */ + protected $items = '#creditmemo_item_container'; + + /** + * Get items block. + * + * @return Items + */ + public function getItemsBlock() + { + return $this->blockFactory->create( + 'Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form\Items', + ['element' => $this->_rootElement->find($this->items)] + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.xml new file mode 100644 index 0000000000000000000000000000000000000000..7e75ac518b8e7a2e66c38e5d9798c220d281e39f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<mapping strict="0"> + <wrapper>creditmemo</wrapper> + <fields> + <comment_text /> + <shipping_amount /> + <adjustment_positive /> + <adjustment_negative /> + <comment_customer_notify> + <input>checkbox</input> + </comment_customer_notify> + <send_email> + <input>checkbox</input> + </send_email> + </fields> +</mapping> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items.php new file mode 100644 index 0000000000000000000000000000000000000000..c97952243ea70985dd0690237b1e66ca5cdf0419 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form; + +use Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form\Items\Product; +use Magento\Mtf\Block\Block; +use Magento\Mtf\Client\Locator; +use Magento\Mtf\Fixture\FixtureInterface; + +/** + * Credit Memo Items block on Credit Memo new page. + */ +class Items extends Block +{ + /** + * Item product. + * + * @var string + */ + protected $productItems = '//tr[contains(.,"%s")]'; + + /** + * 'Update Qty's' button css selector. + * + * @var string + */ + protected $updateQty = '.update-button'; + + /** + * Get item product block. + * + * @param FixtureInterface $product + * @return Product + */ + public function getItemProductBlock(FixtureInterface $product) + { + $selector = sprintf($this->productItems, $product->getSku()); + return $this->blockFactory->create( + 'Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form\Items\Product', + ['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)] + ); + } + + /** + * Click update qty button. + * + * @return void + */ + public function clickUpdateQty() + { + $this->_rootElement->find($this->updateQty)->click(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.php new file mode 100644 index 0000000000000000000000000000000000000000..bf367ef4339cc3cd06fbd943698c8a478ae0c47b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.php @@ -0,0 +1,15 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Form\Items; + +/** + * Item product form on credit memo items block. + */ +class Product extends \Magento\Sales\Test\Block\Adminhtml\Order\AbstractForm\Product +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.xml new file mode 100644 index 0000000000000000000000000000000000000000..afde45a79835db8a6c029b9980af9a9685a3ad99 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items/Product.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<mapping strict="0"> + <fields> + <qty> + <selector>[name$="[qty]"]</selector> + </qty> + <back_to_stock> + <selector>[name$="[back_to_stock]"]</selector> + <input>checkbox</input> + </back_to_stock> + </fields> +</mapping> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php new file mode 100644 index 0000000000000000000000000000000000000000..a974bbb8b9aadb6739b31e79682eafb491b74e13 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo; + +use Magento\Mtf\Client\Locator; + +/** + * Invoice totals block. + */ +class Totals extends \Magento\Sales\Test\Block\Adminhtml\Order\Totals +{ + /** + * Submit invoice button selector. + * + * @var string + */ + protected $submit = '[data-ui-id="order-items-submit-button"]'; + + /** + * Capture amount select selector. + * + * @var string + */ + protected $capture = '[name="invoice[capture_case]"]'; + + /** + * Submit invoice. + * + * @return void + */ + public function submit() + { + $browser = $this->_rootElement; + $selector = $this->submit . '.disabled'; + $strategy = Locator::SELECTOR_CSS; + $browser->waitUntil( + function () use ($browser, $selector, $strategy) { + $element = $browser->find($selector, $strategy); + return $element->isVisible() == false ? true : null; + } + ); + $this->_rootElement->find($this->submit)->click(); + } + + /** + * Set Capture amount option: + * Capture Online|Capture Offline|Not Capture + * + * @param string $option + * @return void + */ + public function setCaptureOption($option) + { + $this->_rootElement->find($this->capture, Locator::SELECTOR_CSS, 'select')->setValue($option); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Grid.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Grid.php index 8b43fc9c27ba44de78336999a4abb55aa4278999..7895c39a3a07399c78144d6f96ac6491d794eac0 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Grid.php @@ -9,14 +9,14 @@ namespace Magento\Sales\Test\Block\Adminhtml\Order\Invoice; use Magento\Backend\Test\Block\Widget\Grid as GridInterface; /** - * Class Grid - * Sales order grid - * + * Sales order grid. */ class Grid extends GridInterface { /** - * {@inheritdoc} + * Filters array mapping. + * + * @var array */ protected $filters = [ 'id' => [ @@ -25,50 +25,42 @@ class Grid extends GridInterface ]; /** - * Invoice amount + * Invoice amount. * * @var string */ protected $invoiceAmount = 'td.col-qty.col-base_grand_total'; /** - * An element locator which allows to select entities in grid + * An element locator which allows to select entities in grid. * * @var string */ protected $selectItem = 'tbody tr .col-invoice-number'; /** - * Get first invoice amount + * Get first invoice amount. * - * @return array|string + * @return string */ public function getInvoiceAmount() { - $invoiceAmount = $this->getInvoiceAmountElement()->getText(); + $invoiceAmount = $this->_rootElement->find($this->invoiceAmount)->getText(); return $this->escapeCurrency($invoiceAmount); } /** - * Click the first invoice amount + * Click the first invoice amount. * * @return void */ public function clickInvoiceAmount() { - $this->getInvoiceAmountElement()->click(); - } - - /** - * @return mixed|\Magento\Mtf\Client\Element - */ - private function getInvoiceAmountElement() - { - return $this->_rootElement->find($this->invoiceAmount); + $this->_rootElement->find($this->invoiceAmount)->click(); } /** - * Method that escapes currency symbols + * Method that escapes currency symbols. * * @param string $price * @return string|null diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/StatusGrid.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/StatusGrid.php index 377cd4ba869dcf5fe606ce367a5b690f946c0442..f0fa33ca3a36d6e9e94681be8617915cee97c5f8 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/StatusGrid.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/StatusGrid.php @@ -7,13 +7,12 @@ namespace Magento\Sales\Test\Block\Adminhtml\Order; /** - * Class StatusGrid - * Backend sales order's status management grid + * Backend sales order's status management grid. */ class StatusGrid extends \Magento\Backend\Test\Block\Widget\Grid { /** - * Filters array mapping + * Filters array mapping. */ protected $filters = [ 'label' => [ @@ -28,7 +27,7 @@ class StatusGrid extends \Magento\Backend\Test\Block\Widget\Grid ]; /** - * Locator value for link in action column + * Locator value for link in action column. * * @var string */ @@ -42,7 +41,7 @@ class StatusGrid extends \Magento\Backend\Test\Block\Widget\Grid protected $unassignLink = '[data-column="unassign"] a'; /** - * Search custom status and unassign it + * Search custom status and unassign it. * * @param array $filter * @throws \Exception diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php index aac809e587dc15dec3869fd4730c4313dedb74b0..2cff2dad1f87ba3907482716c35b7f6953b78044 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php @@ -7,36 +7,12 @@ namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab; use Magento\Mtf\Block\Block; -use Magento\Mtf\Client\Locator; /** - * Class Info - * Order information tab block - * + * Order information tab block. */ class Info extends Block { - /** - * 3D Secure Verification Result - * - * @var string - */ - protected $_verificationResult = '//tr[normalize-space(th)="3D Secure Verification Result:"]/td'; - - /** - * 3D Secure Cardholder Validation - * - * @var string - */ - protected $_cardholderValidation = '//tr[normalize-space(th)="3D Secure Cardholder Validation:"]/td'; - - /** - * 3D Secure Electronic Commerce Indicator - * - * @var string - */ - protected $_eCommerceIndicator = '//tr[normalize-space(th)="3D Secure Electronic Commerce Indicator:"]/td'; - /** * Order status selector * @@ -44,36 +20,6 @@ class Info extends Block */ protected $orderStatus = '#order_status'; - /** - * Get 3D Secure Verification Result - * - * @return array|string - */ - public function getVerificationResult() - { - return $this->_rootElement->find($this->_verificationResult, Locator::SELECTOR_XPATH)->getText(); - } - - /** - * Get 3D Secure Verification Result - * - * @return array|string - */ - public function getCardholderValidation() - { - return $this->_rootElement->find($this->_cardholderValidation, Locator::SELECTOR_XPATH)->getText(); - } - - /** - * Get 3D Secure Electronic Commerce Indicator - * - * @return array|string - */ - public function getEcommerceIndicator() - { - return $this->_rootElement->find($this->_eCommerceIndicator, Locator::SELECTOR_XPATH)->getText(); - } - /** * Get order status from info block * diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/History.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/History.php index bacbfe439e5591e8d9439d13d450d8a73fb6f504..0a2f39e06c7ac7e1db5aadec37d8f9b259b8b55f 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/History.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/History.php @@ -27,7 +27,7 @@ class History extends Block * * @var string */ - protected $itemOrder = '//tr[td[contains(@class, "id") and normalize-space(.)="%d"]]'; + protected $itemOrder = '//tr[td[contains(@class, "id") and normalize-space(.)="%s"]]'; /** * Order total css selector. diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php index c8cb4a49db99ea30bfb4df35c1188ab72cef5c2f..04424257520c5c3fb7b7870add0d646c437c1ed5 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php @@ -155,6 +155,7 @@ class View extends Block public function openLinkByName($name) { $this->_rootElement->find(sprintf($this->link, $name), Locator::SELECTOR_XPATH)->click(); + sleep(3); // TODO: remove after resolving an issue with ajax on Frontend. } /** diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php index 4c5756fecffd692f2951fa4f406f36b5de2ce106..bee100f5630759b0c4471635a4e3ec82de5be052 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php @@ -23,6 +23,9 @@ class ActionsToolbar extends Block /** * Click link on this page. + * + * @param string $linkName + * @throws \Exception */ public function clickLink($linkName) { diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.php new file mode 100644 index 0000000000000000000000000000000000000000..8f12c2710722401f17d38ac9354f56511f53da80 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.php @@ -0,0 +1,105 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Block\Widget\Guest; + +use Magento\Mtf\Client\Locator; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\Fixture\InjectableFixture; +use Magento\Mtf\Client\Element\SimpleElement; +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Customer\Test\Fixture\Customer; + +/** + * Orders and Returns form search block. + */ +class Form extends \Magento\Mtf\Block\Form +{ + /** + * Search button selector. + * + * @var string + */ + protected $searchButtonSelector = '.action.submit'; + + /** + * Selector for loads form. + * + * @var string + */ + protected $loadsForm = 'div[id*=oar] input'; + + /** + * Fill the form. + * + * @param FixtureInterface $fixture + * @param SimpleElement|null $element + * @param bool $isSearchByEmail [optional] + * @return $this + */ + public function fill(FixtureInterface $fixture, SimpleElement $element = null, $isSearchByEmail = true) + { + if ($fixture instanceof InjectableFixture) { + /** @var OrderInjectable $fixture */ + /** @var Customer $customer */ + $customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); + $data = [ + 'order_id' => $fixture->getId(), + 'billing_last_name' => $customer->getLastname(), + ]; + + if ($isSearchByEmail) { + $data['find_order_by'] = 'Email'; + $data['email_address'] = $customer->getEmail(); + } else { + $data['find_order_by'] = 'ZIP Code'; + $data['billing_zip_code'] = $fixture->getDataFieldConfig('billing_address_id')['source']->getPostcode(); + } + } else { + $data = $fixture->getData(); + } + $fields = isset($data['fields']) ? $data['fields'] : $data; + $mapping = $this->dataMapping($fields); + + $this->waitLoadForm(); + $this->_fill($mapping, $element); + + return $this; + } + + /** + * Wait while form is loading. + * + * @return void + */ + protected function waitLoadForm() + { + $rootElement = $this->_rootElement; + $selector = $this->loadsForm; + $this->browser->waitUntil( + function () use ($rootElement, $selector) { + $inputs = $rootElement->getElements($selector); + $i = 0; + foreach ($inputs as $input) { + if ($input->isVisible()) { + ++$i; + } + } + return $i == 1 ? true : null; + } + ); + } + + /** + * Submit search form. + * + * @return void + */ + public function submit() + { + $this->_rootElement->find($this->searchButtonSelector, Locator::SELECTOR_CSS)->click(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.xml new file mode 100644 index 0000000000000000000000000000000000000000..dcbdad87eeb4d8c7d6c5790a9402e91d509ebae6 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Widget/Guest/Form.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<mapping strict="0"> + <fields> + <order_id> + <selector>[name='oar_order_id']</selector> + </order_id> + <billing_last_name> + <selector>[name='oar_billing_lastname']</selector> + </billing_last_name> + <find_order_by> + <selector>[name='oar_type']</selector> + <input>select</input> + </find_order_by> + <email_address> + <selector>[name='oar_email']</selector> + </email_address> + <billing_zip_code> + <selector>[name='oar_zip']</selector> + </billing_zip_code> + </fields> +</mapping> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderButtonsAvailable.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderButtonsAvailable.php index 676561e9aa8e9ac374bf226d5b3873677a665967..f2b7260f8930604b3eaebddbb5ffc0640bf8d3d0 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderButtonsAvailable.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderButtonsAvailable.php @@ -6,27 +6,26 @@ namespace Magento\Sales\Test\Constraint; -use Magento\Sales\Test\Page\SalesOrder; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; use Magento\Mtf\Constraint\AbstractConstraint; /** - * Class AssertOrderButtonsAvailable - * Assert that specified in data set buttons exist on order page in backend + * Assert that specified in data set buttons exist on order page in backend. */ class AssertOrderButtonsAvailable extends AbstractConstraint { /** - * Assert that specified in data set buttons exist on order page in backend + * Assert that specified in data set buttons exist on order page in backend. * - * @param SalesOrder $salesOrder + * @param SalesOrderView $salesOrderView * @param string $orderButtonsAvailable * @return void */ - public function processAssert(SalesOrder $salesOrder, $orderButtonsAvailable) + public function processAssert(SalesOrderView $salesOrderView, $orderButtonsAvailable) { $buttons = explode(',', $orderButtonsAvailable); $absentButtons = []; - $actionsBlock = $salesOrder->getOrderActionsBlock(); + $actionsBlock = $salesOrderView->getPageActions(); foreach ($buttons as $button) { $button = trim($button); @@ -42,7 +41,7 @@ class AssertOrderButtonsAvailable extends AbstractConstraint } /** - * Returns string representation of successful assertion + * Returns string representation of successful assertion. * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderCommentsHistory.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderCommentsHistory.php index 1630e60c334d05e41de2d4e4f2b0aa5003330ceb..2e88c267f38b0603d81edb6fa8a38dd2f81ac266 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderCommentsHistory.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderCommentsHistory.php @@ -26,14 +26,14 @@ class AssertOrderCommentsHistory extends AbstractConstraint * @param SalesOrderView $salesOrderView * @param OrderIndex $salesOrder * @param string $orderId - * @param string $grandTotal + * @param array $prices * @return void */ public function processAssert( SalesOrderView $salesOrderView, OrderIndex $salesOrder, $orderId, - $grandTotal + array $prices ) { $salesOrder->open(); $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]); @@ -41,7 +41,7 @@ class AssertOrderCommentsHistory extends AbstractConstraint $actualAuthorizedAmount = $salesOrderView->getOrderHistoryBlock()->getCommentsHistory(); \PHPUnit_Framework_Assert::assertContains( - self::AUTHORIZED_AMOUNT . $grandTotal, + self::AUTHORIZED_AMOUNT . $prices['grandTotal'], $actualAuthorizedAmount, 'Incorrect authorized amount value for the order #' . $orderId ); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderGrandTotal.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderGrandTotal.php index d5ba1959297105811209aa3dbbd30321748bfcdd..f0a84298aaa2108f02e364065b1505ad426bc86b 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderGrandTotal.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderGrandTotal.php @@ -21,20 +21,20 @@ class AssertOrderGrandTotal extends AbstractConstraint * @param SalesOrderView $salesOrderView * @param string $orderId * @param OrderIndex $salesOrder - * @param string $grandTotal + * @param array $prices * @return void */ public function processAssert( SalesOrderView $salesOrderView, OrderIndex $salesOrder, $orderId, - $grandTotal + array $prices ) { $salesOrder->open(); $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $orderId]); \PHPUnit_Framework_Assert::assertEquals( - $grandTotal, + $prices['grandTotal'], $salesOrderView->getOrderTotalsBlock()->getGrandTotal(), 'Grand Total price does not equal to price from data set.' ); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderNotVisibleOnMyAccount.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderNotVisibleOnMyAccount.php index 7967bf579874021a78f52deb2df10e49afab26e7..cd1d86ea1740c7c0588f3c4eb9c239c1f2b3e7b8 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderNotVisibleOnMyAccount.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertOrderNotVisibleOnMyAccount.php @@ -11,24 +11,17 @@ use Magento\Customer\Test\Page\CustomerAccountIndex; use Magento\Sales\Test\Fixture\OrderInjectable; use Magento\Sales\Test\Page\OrderHistory; use Magento\Mtf\Constraint\AbstractConstraint; -use Magento\Mtf\ObjectManager; /** - * Class AssertOrderNotVisibleOnMyAccount - * Assert order is not visible in customer account on frontend + * Assert order is not visible in customer account on frontend. */ class AssertOrderNotVisibleOnMyAccount extends AbstractConstraint { - /* tags */ - const SEVERITY = 'low'; - /* end tags */ - /** * Assert order is not visible in customer account on frontend * * @param OrderInjectable $order * @param Customer $customer - * @param ObjectManager $objectManager * @param CustomerAccountIndex $customerAccountIndex * @param OrderHistory $orderHistory * @param string $status @@ -37,7 +30,6 @@ class AssertOrderNotVisibleOnMyAccount extends AbstractConstraint public function processAssert( OrderInjectable $order, Customer $customer, - ObjectManager $objectManager, CustomerAccountIndex $customerAccountIndex, OrderHistory $orderHistory, $status @@ -46,14 +38,14 @@ class AssertOrderNotVisibleOnMyAccount extends AbstractConstraint 'id' => $order->getId(), 'status' => $status, ]; - $customerLogin = $objectManager->create( + $this->objectManager->create( 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', ['customer' => $customer] - ); - $customerLogin->run(); + )->run(); $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); \PHPUnit_Framework_Assert::assertFalse( - $orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), + $orderHistory->getOrderHistoryBlock()->isVisible() + && $orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), 'Order with following data \'' . implode(', ', $filter) . '\' is present in Orders block on frontend.' ); } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertSalesPrintOrderGrandTotal.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertSalesPrintOrderGrandTotal.php index 8c6e930acbf77be7370b1f6b4743fb3c0d44e457..7369b9449d31a91767112e44fa822c12b4c7c8aa 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertSalesPrintOrderGrandTotal.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertSalesPrintOrderGrandTotal.php @@ -18,13 +18,13 @@ class AssertSalesPrintOrderGrandTotal extends AbstractConstraint * Assert that Grand Total price was printed correctly on sales guest print page. * * @param SalesGuestPrint $salesGuestPrint - * @param string $grandTotal + * @param array $prices * @return void */ - public function processAssert(SalesGuestPrint $salesGuestPrint, $grandTotal) + public function processAssert(SalesGuestPrint $salesGuestPrint, array $prices) { \PHPUnit_Framework_Assert::assertEquals( - $grandTotal, + $prices['grandTotal'], $salesGuestPrint->getViewBlock()->getItemBlock()->getGrandTotal(), "Grand total was printed incorrectly." ); diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable.xml new file mode 100644 index 0000000000000000000000000000000000000000..4f26f0a213fffc903b7e364b16f3b79f286ea36f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable.xml @@ -0,0 +1,618 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd"> + <fixture name="orderInjectable" module="Magento_Sales" type="flat" entity_type="sales_order" collection="Magento\Sales\Model\Resource\Order\Collection" identifier="" repository_class="Magento\Sales\Test\Repository\OrderInjectable" handler_interface="Magento\Sales\Test\Handler\OrderInjectable\OrderInjectableInterface" class="Magento\Sales\Test\Fixture\OrderInjectable"> + <dataset name="default"> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="base_currency_code" xsi:type="boolean">false</field> + <field name="order_currency_code" xsi:type="string">USD</field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + </dataset> + <field name="entity_id" is_required="1" source="Magento\Sales\Test\Fixture\OrderInjectable\EntityId" group="null"> + <default_value xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default</item> + </default_value> + </field> + <field name="state" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="status" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="coupon_code" is_required="" source="Magento\Sales\Test\Fixture\OrderInjectable\CouponCode" group="null"> + <default_value xsi:type="null" /> + </field> + <field name="protect_code" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_description" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="is_virtual" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="store_id" is_required="" source="Magento\Sales\Test\Fixture\OrderInjectable\StoreId" group="null"> + <default_value xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </default_value> + </field> + <field name="customer_id" is_required="" source="Magento\Sales\Test\Fixture\OrderInjectable\CustomerId" group="null"> + <default_value xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </default_value> + </field> + <field name="base_discount_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_discount_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_discount_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_discount_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_grand_total" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_subtotal" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_subtotal_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_subtotal_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_subtotal_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_tax_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_to_global_rate" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_to_order_rate" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_invoiced_cost" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_offline_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_online_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_paid" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_qty_ordered" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="discount_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="discount_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="discount_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="discount_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="grand_total" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="store_to_base_rate" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="store_to_order_rate" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="subtotal" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="subtotal_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="subtotal_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="subtotal_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="tax_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_canceled" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_offline_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_online_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_paid" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_qty_ordered" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="can_ship_partially" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="can_ship_partially_item" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_is_guest" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_note_notify" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="billing_address_id" is_required="" source="Magento\Sales\Test\Fixture\OrderInjectable\BillingAddressId"> + <default_value xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </default_value> + </field> + <field name="customer_group_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="edit_increment" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="email_sent" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="forced_shipment_with_invoice" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="payment_auth_expiration" is_required=""> + <default_value xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </default_value> + </field> + <field name="quote_address_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="quote_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_address_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="adjustment_negative" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="adjustment_positive" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_adjustment_negative" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_adjustment_positive" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_discount_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_subtotal_incl_tax" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_total_due" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="payment_authorization_amount" is_required=""> + <default_value xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </default_value> + </field> + <field name="shipping_discount_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="subtotal_incl_tax" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_due" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="weight" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_dob" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="increment_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="applied_rule_ids" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_currency_code" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_email" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_firstname" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_lastname" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_middlename" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_prefix" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_suffix" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_taxvat" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="discount_description" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="ext_customer_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="ext_order_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="global_currency_code" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="hold_before_state" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="hold_before_status" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="order_currency_code" is_required=""> + <default_value xsi:type="string">USD</default_value> + </field> + <field name="original_increment_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="relation_child_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="relation_child_real_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="relation_parent_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="relation_parent_real_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="remote_ip" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_method" is_required=""> + <default_value xsi:type="string">flatrate_flatrate</default_value> + </field> + <field name="store_currency_code" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="store_name" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="x_forwarded_for" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_note" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="created_at" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="updated_at" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="total_item_count" is_required=""> + <default_value xsi:type="number">0</default_value> + </field> + <field name="customer_gender" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="hidden_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_hidden_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_hidden_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_hidden_tax_amnt" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="hidden_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_hidden_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="hidden_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_hidden_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="shipping_incl_tax" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_shipping_incl_tax" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="coupon_rule_name" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_customer_balance_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_balance_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_customer_balance_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_balance_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_customer_balance_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_balance_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="bs_customer_bal_total_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="customer_bal_total_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gift_cards" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_gift_cards_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gift_cards_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_gift_cards_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gift_cards_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="base_gift_cards_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gift_cards_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gift_message_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_id" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_allow_gift_receipt" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_add_card" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_price" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_tax_amount" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_price_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_tax_amount_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_tax_amount_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_tax_invoiced" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_price_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_base_tax_amount_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_tax_amount_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_base_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_items_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_base_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="gw_card_tax_refunded" is_required=""> + <default_value xsi:type="null" /> + </field> + <field name="id" /> + <field name="price" is_required="1" group="null" source="Magento\Sales\Test\Fixture\OrderInjectable\Price" /> + </fixture> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/BillingAddressId.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/BillingAddressId.php new file mode 100644 index 0000000000000000000000000000000000000000..8aaa2b0cc381d1df3bdd37aa7e590a2f5d75e433 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/BillingAddressId.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +use Magento\Customer\Test\Fixture\Address; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\DataSource; + +/** + * Billing address data. + */ +class BillingAddressId extends DataSource +{ + /** + * Current preset. + * + * @var string + */ + protected $currentPreset; + + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param array $data + * @param array $params [optional] + */ + public function __construct(FixtureFactory $fixtureFactory, array $data, array $params = []) + { + $this->params = $params; + if (isset($data['value'])) { + $this->data = $data['value']; + return; + } + if (isset($data['dataSet'])) { + $addresses = $fixtureFactory->createByCode('address', ['dataSet' => $data['dataSet']]); + $this->data = $addresses->getData(); + $this->data['street'] = [$this->data['street']]; + } + if (isset($data['billingAddress']) && $data['billingAddress'] instanceof Address) { + /** @var Address $address */ + $address = $data['billingAddress']; + $this->data = $address->getData(); + $this->data['street'] = [$this->data['street']]; + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CouponCode.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CouponCode.php new file mode 100644 index 0000000000000000000000000000000000000000..b3d081c56d4c759fe4728523de1732c42f1477d0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CouponCode.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\DataSource; + +/** + * Coupon code data. + */ +class CouponCode extends DataSource +{ + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param array $data + * @param array $params [optional] + */ + public function __construct(FixtureFactory $fixtureFactory, array $data, array $params = []) + { + $this->params = $params; + if (isset($data['value']) && $data['value'] instanceof SalesRuleInjectable) { + $this->data = $data['value']; + return; + } + if (isset($data['dataSet'])) { + $salesRule = $fixtureFactory->createByCode('salesRuleInjectable', ['dataSet' => $data['dataSet']]); + $salesRule->persist(); + $this->data = $salesRule; + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CustomerId.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CustomerId.php new file mode 100644 index 0000000000000000000000000000000000000000..b970afcd0d1ab5e7b87175dabe52324ba57d2d2f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/CustomerId.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +use Magento\Customer\Test\Fixture\Customer; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\DataSource; + +/** + * Prepare CustomerId for order list. + */ +class CustomerId extends DataSource +{ + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param array $params + * @param array $data + */ + public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = []) + { + $this->params = $params; + if (isset($data['customer']) && $data['customer'] instanceof Customer) { + $this->data = $data['customer']; + return; + } + if (isset($data['dataSet'])) { + $customer = $fixtureFactory->createByCode('customer', ['dataSet' => $data['dataSet']]); + if ($customer->hasData('id') === false) { + $customer->persist(); + } + $this->data = $customer; + } + } + + /** + * Get customer fixture. + * + * @return Customer + */ + public function getCustomer() + { + return $this->data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/EntityId.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/EntityId.php new file mode 100644 index 0000000000000000000000000000000000000000..7b99bad4281b90281275c27b779155d1c97cd53f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/EntityId.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\DataSource; + +/** + * EntityId data. + */ +class EntityId extends DataSource +{ + /** + * Current preset. + * + * @var string + */ + protected $currentPreset; + + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param array $data + * @param array $params [optional] + */ + public function __construct(FixtureFactory $fixtureFactory, array $data, array $params = []) + { + $this->params = $params; + + if (isset($data['value'])) { + $this->data = $data['value']; + return; + } + + if (!isset($data['products'])) { + return; + } + if (is_string($data['products'])) { + $products = explode(',', $data['products']); + foreach ($products as $product) { + list($fixture, $dataSet) = explode('::', trim($product)); + $product = $fixtureFactory->createByCode($fixture, ['dataSet' => $dataSet]); + $product->persist(); + $this->data['products'][] = $product; + } + } elseif (is_array($data['products'])) { + $this->data['products'] = $data['products']; + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/Price.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/Price.php new file mode 100644 index 0000000000000000000000000000000000000000..0de14ee47f836ac21ef905568ff4d19fe4a8857c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/Price.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +/** + * Data keys: + * - preset (Price data verification preset name) + */ +class Price extends \Magento\Catalog\Test\Fixture\CatalogProductSimple\Price +{ + /** + * @constructor + * @param array $params + * @param array $data + */ + public function __construct(array $params, array $data = []) + { + $this->params = $params; + if (isset($data['preset'])) { + $this->currentPreset = $data['preset']; + $this->data = $this->getPreset(); + } + } + + /** + * Get preset array + * + * @return array|null + */ + public function getPreset() + { + $presets = [ + 'default_with_discount' => [ + 'subtotal' => 560, + 'discount' => 280, + ], + 'full_invoice' => [ + [ + 'grand_order_total' => 565, + 'grand_invoice_total' => 565, + ], + ], + 'partial_invoice' => [ + [ + 'grand_order_total' => 210, + 'grand_invoice_total' => 110, + ], + ], + 'full_refund' => [ + [ + 'grand_creditmemo_total' => 565, + ], + ], + 'full_refund_with_zero_shipping_refund' => [ + [ + 'grand_creditmemo_total' => 555, + ], + ], + 'partial_refund' => [ + [ + 'grand_creditmemo_total' => 110, + ], + ], + ]; + if (!isset($presets[$this->currentPreset])) { + return null; + } + return $presets[$this->currentPreset]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/StoreId.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/StoreId.php new file mode 100644 index 0000000000000000000000000000000000000000..11579ab84e9e8502d143e5c285f4774f271415c9 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderInjectable/StoreId.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Fixture\OrderInjectable; + +use Magento\Store\Test\Fixture\Store; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\DataSource; + +/** + * Prepare StoreId for Store Group. + */ +class StoreId extends DataSource +{ + /** + * Store fixture. + * + * @var Store + */ + public $store; + + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param array $data + * @param array $params [optional] + */ + public function __construct(FixtureFactory $fixtureFactory, array $data, array $params = []) + { + $this->params = $params; + + $storeData = isset($data['dataSet']) ? ['dataSet' => $data['dataSet']] : []; + if (isset($data['data'])) { + $storeData = array_replace_recursive($storeData, $data); + } + + if ($storeData) { + $store = $fixtureFactory->createByCode('store', $storeData); + /** @var Store $store */ + if (!$store->getStoreId()) { + $store->persist(); + } + $this->store = $store; + $this->data = $store->getName(); + } + } + + /** + * Return Store fixture. + * + * @return Store + */ + public function getStore() + { + return $this->store; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderStatus.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderStatus.xml new file mode 100644 index 0000000000000000000000000000000000000000..b86502663dbd5b42802155a742536c492ab9d278 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Fixture/OrderStatus.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd"> + <fixture name="orderStatus" module="Magento_Sales" type="composite" collection="Magento\Sales\Model\Resource\Order\Status\Collection" repository_class="Magento\Sales\Test\Repository\OrderStatus" handler_interface="Magento\Sales\Test\Handler\OrderStatus\OrderStatusInterface" class="Magento\Sales\Test\Fixture\OrderStatus"> + <dataset name="default"> + <field name="status" xsi:type="string">order_status%isolation%</field> + <field name="label" xsi:type="string">orderLabel%isolation%</field> + </dataset> + <field name="status" is_required="1"> + <default_value xsi:type="string">order_status%isolation%</default_value> + </field> + <field name="label" is_required=""> + <default_value xsi:type="string">orderLabel%isolation%</default_value> + </field> + <field name="state" is_required="1"> + <default_value xsi:type="null" /> + </field> + <field name="is_default" is_required=""> + <default_value xsi:type="number">0</default_value> + </field> + <field name="visible_on_front" is_required=""> + <default_value xsi:type="number">0</default_value> + </field> + </fixture> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php new file mode 100644 index 0000000000000000000000000000000000000000..e98f4ba0afff567f479384c0c7eaecef6543505d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/Curl.php @@ -0,0 +1,375 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Handler\OrderInjectable; + +use Magento\Bundle\Test\Fixture\BundleProduct; +use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct; +use Magento\Customer\Test\Fixture\Customer; +use Magento\Downloadable\Test\Fixture\DownloadableProduct; +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\Handler\Curl as AbstractCurl; +use Magento\Mtf\Util\Protocol\CurlInterface; +use Magento\Mtf\Util\Protocol\CurlTransport; +use Magento\Mtf\Util\Protocol\CurlTransport\BackendDecorator; + +/** + * Create new order via curl. + */ +class Curl extends AbstractCurl implements OrderInjectableInterface +{ + /** + * Customer fixture. + * + * @var Customer + */ + protected $customer; + + /** + * Customer fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Mapping values for data. + * + * @var array + */ + protected $mappingData = [ + 'region_id' => [ + 'California' => '12', + ], + 'country_id' => [ + 'United States' => 'US', + ], + ]; + + /** + * Steps for create order on backend. + * + * @var array + */ + protected $steps = [ + 'customer_choice' => 'header,data', + 'products_choice' => 'search,items,shipping_method,totals,giftmessage,billing_method', + 'apply_coupon_code' => 'items,shipping_method,totals,billing_method', + 'shipping_data_address' => 'shipping_method,billing_method,shipping_address,totals,giftmessage', + 'shipping_data_method_get' => 'shipping_method,totals', + 'shipping_data_method_set' => 'shipping_method,totals,billing_method', + ]; + + /** + * Post request for creating order. + * + * @param FixtureInterface|null $fixture [optional] + * @return array + */ + public function persist(FixtureInterface $fixture = null) + { + $this->order = $fixture; + $this->customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); + $data = $this->replaceMappingData($this->prepareData($fixture)); + return ['id' => $this->createOrder($data)]; + } + + /** + * Prepare POST data for creating product request. + * + * @param FixtureInterface $fixture + * @return array + */ + protected function prepareData(FixtureInterface $fixture) + { + $result = []; + $data = $fixture->getData(); + $result['customer_choice'] = $this->prepareCustomerData($data); + $result['products_choice'] = $this->prepareProductsData($data['entity_id']); + if (isset($data['coupon_code'])) { + $result['apply_coupon_code'] = $this->prepareCouponCode($data['coupon_code']); + } + $result['order_data'] = $this->prepareOrderData($data); + $result['shipping_data_address'] = $this->prepareShippingData($result['order_data']); + $result['shipping_data_method_get'] = [ + 'payment' => $data['payment_auth_expiration'], + 'collect_shipping_rates' => 1, + ]; + $result['shipping_data_method_set'] = [ + 'order' => ['shipping_method' => $result['order_data']['order']['shipping_method']], + 'payment' => $data['payment_auth_expiration'], + ]; + + return $result; + } + + /** + * Prepare coupon data. + * + * @param SalesRuleInjectable $data + * @return array + */ + protected function prepareCouponCode(SalesRuleInjectable $data) + { + return ['order' => ['coupon' => ['code' => $data->getCouponCode()]]]; + } + + /** + * Prepare shipping data. + * + * @param array $data + * @return array + */ + protected function prepareShippingData(array $data) + { + $result = [ + 'order' => [ + 'billing_address' => $data['billing_address'], + ], + 'payment' => $this->order->getPaymentAuthExpiration(), + 'reset_shipping' => 1, + 'shipping_as_billing' => 1, + ]; + return $result; + } + + /** + * Prepare products data. + * + * @param array $data + * @return array + */ + protected function prepareProductsData(array $data) + { + $result['item'] = []; + foreach ($data['products'] as $value) { + if (!$value->hasData('checkout_data')) { + continue; + } + $methodName = 'prepare' . ucfirst($value->getDataConfig()['type_id']) . 'Data'; + if (!method_exists($this, $methodName)) { + $methodName = 'prepareSimpleData'; + } + $result['item'][$value->getId()] = $this->$methodName($value); + } + return $result; + } + + /** + * Prepare data for configurable product. + * + * @param ConfigurableProduct $product + * @return array + */ + protected function prepareConfigurableData(ConfigurableProduct $product) + { + $result = []; + $checkoutData = $product->getCheckoutData(); + $result['qty'] = $checkoutData['qty']; + $attributesData = $product->hasData('configurable_attributes_data') + ? $product->getDataFieldConfig('configurable_attributes_data')['source']->getAttributesData() + : null; + if ($attributesData == null) { + return $result; + } + foreach ($checkoutData['options']['configurable_options'] as $option) { + $attributeId = $attributesData[$option['title']]['attribute_id']; + $optionId = $attributesData[$option['title']]['options'][$option['value']]['id']; + $result['super_attribute'][$attributeId] = $optionId; + } + + return $result; + } + + /** + * Prepare data for bundle product. + * + * @param BundleProduct $product + * @return array + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + protected function prepareBundleData(BundleProduct $product) + { + $result = []; + $checkoutData = $product->getCheckoutData(); + $bundleOptions = isset($checkoutData['options']['bundle_options']) + ? $checkoutData['options']['bundle_options'] + : []; + $bundleSelections = $product->getBundleSelections(); + $bundleSelectionsData = []; + $result['qty'] = $checkoutData['qty']; + + foreach ($bundleSelections['bundle_options'] as $option) { + foreach ($option['assigned_products'] as $productData) { + $productName = $productData['search_data']['name']; + $bundleSelectionsData[$productName] = [ + 'selection_id' => $productData['selection_id'], + 'option_id' => $productData['option_id'], + ]; + } + } + + foreach ($bundleOptions as $option) { + $productName = $option['value']['name']; + foreach ($bundleSelectionsData as $fullProductName => $value) { + if (null !== strpos($fullProductName, $productName)) { + $productName = $fullProductName; + } + } + + if (isset($bundleSelectionsData[$productName])) { + $optionId = $bundleSelectionsData[$productName]['option_id']; + $selectionId = $bundleSelectionsData[$productName]['selection_id']; + $result['bundle_option'][$optionId] = $selectionId; + } + } + + return $result; + } + + /** + * Prepare data for downloadable product. + * + * @param DownloadableProduct $product + * @return array + */ + protected function prepareDownloadableData(DownloadableProduct $product) + { + $result = []; + $checkoutData = $product->getCheckoutData(); + foreach ($checkoutData['options']['links'] as $link) { + $result['links'][] = $link['id']; + } + + return $result; + } + + /** + * Prepare data for simple product. + * + * @param FixtureInterface $product + * @return array + */ + protected function prepareSimpleData(FixtureInterface $product) + { + return ['qty' => $product->getCheckoutData()['qty']]; + } + + /** + * Prepare order data. + * + * @param array $data + * @return array + */ + protected function prepareOrderData(array $data) + { + $customerGroupId = $this->customer->hasData('group_id') + ? $this->customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()->getCustomerGroupId() + : 1; + $result = [ + 'name' => $this->customer->getFirstname(), + 'order' => [ + 'currency' => $data['order_currency_code'], + 'account' => [ + 'group_id' => $customerGroupId, + 'email' => $this->customer->getEmail(), + ], + 'shipping_method' => isset($data['shipping_method']) ? $data['shipping_method'] : '', + ], + 'item' => $this->prepareOrderProductsData($data['entity_id']), + 'billing_address' => $this->prepareBillingAddress($data['billing_address_id']), + 'shipping_same_as_billing' => 'on', + 'payment' => $data['payment_auth_expiration'], + + ]; + + return $result; + } + + /** + * Prepare customer data. + * + * @param array $data + * @return array + */ + protected function prepareCustomerData(array $data) + { + return [ + 'currency_id' => $data['base_currency_code'], + 'customer_id' => $this->customer->getData('id'), + 'payment' => $data['payment_authorization_amount'], + 'store_id' => $this->order->getDataFieldConfig('store_id')['source']->store->getStoreId() + ]; + } + + /** + * Prepare order products data. + * + * @param array $data + * @return array + */ + protected function prepareOrderProductsData(array $data) + { + $result = []; + foreach ($data['products'] as $value) { + if (isset($value->getCheckoutData()['qty'])) { + $result[$value->getId()] = ['qty' => ['qty' => $value->getCheckoutData()['qty']]]; + } + } + + return $result; + } + + /** + * Prepare billing address data. + * + * @param array $data + * @return array + */ + protected function prepareBillingAddress(array $data) + { + $result = $data; + $result['firstname'] = $this->customer->getFirstname(); + $result['lastname'] = $this->customer->getLastname(); + + return $result; + } + + /** + * Create product via curl. + * + * @param array $data + * @return int|null + * @throws \Exception + */ + protected function createOrder(array $data) + { + $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); + foreach ($this->steps as $key => $step) { + if (!isset($data[$key])) { + continue; + } + $url = $_ENV['app_backend_url'] . 'sales/order_create/loadBlock/block/' . $step . '?isAjax=true'; + $curl->write(CurlInterface::POST, $url, '1.1', [], $data[$key]); + $curl->read(); + } + $url = $_ENV['app_backend_url'] . 'sales/order_create/save'; + $curl->addOption(CURLOPT_HEADER, 1); + $curl->write(CurlInterface::POST, $url, '1.1', [], $data['order_data']); + $response = $curl->read(); + $curl->close(); + + if (!strpos($response, 'data-ui-id="messages-message-success"')) { + throw new \Exception("Order creation by curl handler was not successful! Response: $response"); + } + preg_match("~<h1 class=\"page-title\">#(.*)</h1>~", $response, $matches); + + return isset($matches[1]) ? $matches[1] : null; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/OrderInjectableInterface.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/OrderInjectableInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..e08ecf55e8570d79b4ea4b06e403089e7130bd38 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderInjectable/OrderInjectableInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Handler\OrderInjectable; + +use Magento\Mtf\Handler\HandlerInterface; + +/** + * Interface OrderInjectableInterface + */ +interface OrderInjectableInterface extends HandlerInterface +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php new file mode 100644 index 0000000000000000000000000000000000000000..1ff9f0d8de366f274313dff361ab2b728bfac8de --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/Curl.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Handler\OrderStatus; + +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\Handler\Curl as AbstractCurl; +use Magento\Mtf\Util\Protocol\CurlInterface; +use Magento\Mtf\Util\Protocol\CurlTransport; +use Magento\Mtf\Util\Protocol\CurlTransport\BackendDecorator; + +/** + * Curl handler for creating OrderStatus. + */ +class Curl extends AbstractCurl implements OrderStatusInterface +{ + /** + * Default attribute values for fixture. + * + * @var array + */ + protected $defaultAttributeValues = [ + 'is_new' => 1, + 'store_labels[1]' => '', + ]; + + /** + * Mapping values for data. + * + * @var array + */ + protected $mappingData = [ + 'state' => [ + 'Pending' => 'new', + ], + 'is_default' => [ + 'Yes' => 1, + 'No' => 0, + ], + 'visible_on_front' => [ + 'Yes' => 1, + 'No' => 0, + ], + ]; + + /** + * Post request for creating OrderStatus. + * + * @param FixtureInterface $fixture + * @return void + * @throws \Exception + */ + public function persist(FixtureInterface $fixture = null) + { + $url = $_ENV['app_backend_url'] . 'sales/order_status/save/'; + $data = array_merge($this->defaultAttributeValues, $fixture->getData()); + $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); + $curl->write(CurlInterface::POST, $url, '1.1', [], $data); + $response = $curl->read(); + $curl->close(); + + if (!strpos($response, 'data-ui-id="messages-message-success"')) { + throw new \Exception("OrderStatus entity creating by curl handler was not successful! Response: $response"); + } + + if (isset($data['state'])) { + $url = $_ENV['app_backend_url'] . 'sales/order_status/assignPost/'; + $data = $this->replaceMappingData($data); + $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); + $curl->write(CurlInterface::POST, $url, '1.1', [], $data); + $response = $curl->read(); + $curl->close(); + + if (!strpos($response, 'data-ui-id="messages-message-success"')) { + throw new \Exception( + "Assigning OrderStatus entity by curl handler was not successful! Response: $response" + ); + } + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/OrderStatusInterface.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/OrderStatusInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..8bdff4f5546f34f6eca1d29afeafe7eb7b655fbe --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Handler/OrderStatus/OrderStatusInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Handler\OrderStatus; + +use Magento\Mtf\Handler\HandlerInterface; + +/** + * Interface OrderStatusInterface + */ +interface OrderStatusInterface extends HandlerInterface +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderInjectable.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderInjectable.xml new file mode 100644 index 0000000000000000000000000000000000000000..e0ac81201f8b3b611057687c771d69964ca835fd --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderInjectable.xml @@ -0,0 +1,235 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd"> + <repository class="Magento\Sales\Test\Repository\OrderInjectable"> + <dataset name="default"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="two_simple_product"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="virtual_product"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductVirtual::default</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="downloadable_product"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">downloadableProduct::with_two_bought_links</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="two_downloadable_product"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">downloadableProduct::with_two_bought_links, downloadableProduct::with_two_bought_links</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="with_coupon"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + <field name="coupon_code" xsi:type="array"> + <item name="dataSet" xsi:type="string">active_sales_rule_for_all_groups</item> + </field> + <field name="price" xsi:type="array"> + <item name="preset" xsi:type="string">default_with_discount</item> + </field> + </dataset> + + <dataset name="with_coupon"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::default</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + <field name="coupon_code" xsi:type="array"> + <item name="dataSet" xsi:type="string">active_sales_rule_for_all_groups</item> + </field> + <field name="price" xsi:type="array"> + <item name="preset" xsi:type="string">default_with_discount</item> + </field> + </dataset> + + <dataset name="simple_big_qty"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::simple_big_qty</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">johndoe_unique</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + + <dataset name="virtual_big_qty"> + <field name="entity_id" xsi:type="array"> + <item name="products" xsi:type="string">catalogProductSimple::virtual_big_qty</item> + </field> + <field name="customer_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">johndoe_unique</item> + </field> + <field name="billing_address_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">US_address</item> + </field> + <field name="store_id" xsi:type="array"> + <item name="dataSet" xsi:type="string">default_store_view</item> + </field> + <field name="shipping_method" xsi:type="string">flatrate_flatrate</field> + <field name="payment_auth_expiration" xsi:type="array"> + <item name="method" xsi:type="string">checkmo</item> + </field> + <field name="payment_authorization_amount" xsi:type="array"> + <item name="method" xsi:type="string">free</item> + </field> + <field name="base_currency_code" xsi:type="string">0</field> + <field name="order_currency_code" xsi:type="string">USD</field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderStatus.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderStatus.xml new file mode 100644 index 0000000000000000000000000000000000000000..9391fbb88435c4005376699cb3081ac07675e6c6 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Repository/OrderStatus.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd"> + <repository class="Magento\Sales\Test\Repository\OrderStatus"> + <dataset name="default"> + <field name="status" xsi:type="string">order_status%isolation%</field> + <field name="label" xsi:type="string">orderLabel%isolation%</field> + </dataset> + + <dataset name="assign_to_pending"> + <field name="status" xsi:type="string">order_status%isolation%</field> + <field name="label" xsi:type="string">orderLabel%isolation%</field> + <field name="state" xsi:type="string">Pending</field> + <field name="is_default" xsi:type="string">Yes</field> + <field name="visible_on_front" xsi:type="string">Yes</field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.php new file mode 100644 index 0000000000000000000000000000000000000000..148ccff6b0733ec95672421561ba0b04eab3525f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.php @@ -0,0 +1,167 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Constraint\AssertOrderStatusSuccessAssignMessage; +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Fixture\OrderStatus; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusAssign; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusIndex; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Custom Order Status is created. + * + * Steps: + * 1. Log in as admin. + * 2. Navigate to the Stores > Settings > Order Status. + * 3. Click on "Assign Status to State. + * 4. Fill in all data according to data set. + * 5. Save Status Assignment. + * 6. Call assert assertOrderStatusSuccessAssignMessage. + * 7. Create Order. + * 8. Perform all assertions from dataSet. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29382 + */ +class AssignCustomOrderStatusTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Order Status Index page. + * + * @var OrderStatusIndex + */ + protected $orderStatusIndex; + + /** + * Order Status Assign page. + * + * @var OrderStatusAssign + */ + protected $orderStatusAssign; + + /** + * Order Index page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * OrderStatus Fixture. + * + * @var OrderStatus + */ + protected $orderStatus; + + /** + * OrderInjectable Fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + + /** + * Prepare data. + * + * @param FixtureFactory $fixtureFactory + * @return void + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $this->fixtureFactory = $fixtureFactory; + } + + /** + * Inject pages. + * + * @param OrderStatusIndex $orderStatusIndex + * @param OrderStatusAssign $orderStatusAssign + * @param OrderIndex $orderIndex + * @return void + */ + public function __inject( + OrderStatusIndex $orderStatusIndex, + OrderStatusAssign $orderStatusAssign, + OrderIndex $orderIndex + ) { + $this->orderStatusIndex = $orderStatusIndex; + $this->orderStatusAssign = $orderStatusAssign; + $this->orderIndex = $orderIndex; + } + + /** + * Run Assign Custom OrderStatus. + * + * @param OrderStatus $orderStatus + * @param OrderInjectable $order + * @param array $orderStatusState + * @param AssertOrderStatusSuccessAssignMessage $assertion + * @return array + */ + public function test( + OrderStatus $orderStatus, + OrderInjectable $order, + array $orderStatusState, + AssertOrderStatusSuccessAssignMessage $assertion + ) { + // Preconditions: + $orderStatus->persist(); + /** @var OrderStatus $orderStatus */ + $orderStatus = $this->fixtureFactory->createByCode( + 'orderStatus', + ['data' => array_merge($orderStatus->getData(), $orderStatusState)] + ); + + // Steps: + $this->orderStatusIndex->open(); + $this->orderStatusIndex->getGridPageActions()->assignStatusToState(); + $this->orderStatusAssign->getAssignForm()->fill($orderStatus); + $this->orderStatusAssign->getPageActionsBlock()->save(); + $assertion->processAssert($this->orderStatusIndex); + + $order->persist(); + + // Prepare data for tear down + $this->orderStatus = $orderStatus; + $this->order = $order; + + return [ + 'orderId' => $order->getId(), + 'customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer(), + 'status' => $orderStatus->getLabel() + ]; + } + + /** + * Change created order status and unassign custom order status + * + * @return void + */ + public function tearDown() + { + $this->orderIndex->open()->getSalesOrderGrid()->massaction([['id' => $this->order->getId()]], 'Cancel'); + $filter = ['label' => $this->orderStatus->getLabel()]; + $this->orderStatusIndex->open()->getOrderStatusGrid()->searchAndUnassign($filter); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..295a0103799502586f3c49783973c38eb5cc6983 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/AssignCustomOrderStatusTest.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\AssignCustomOrderStatusTest"> + <variation name="AssignCustomOrderStatusTestVariation1"> + <data name="orderStatusState/state" xsi:type="string">Pending</data> + <data name="orderStatusState/is_default" xsi:type="string">No</data> + <data name="orderStatusState/visible_on_front" xsi:type="string">Yes</data> + <data name="statusToCheck" xsi:type="string">Pending</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="AssignCustomOrderStatusTestVariation2"> + <data name="orderStatusState/state" xsi:type="string">Pending</data> + <data name="orderStatusState/is_default" xsi:type="string">Yes</data> + <data name="orderStatusState/visible_on_front" xsi:type="string">No</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderNotVisibleOnMyAccount" /> + </variation> + <variation name="AssignCustomOrderStatusTestVariation3"> + <data name="orderStatusState/state" xsi:type="string">Pending</data> + <data name="orderStatusState/is_default" xsi:type="string">Yes</data> + <data name="orderStatusState/visible_on_front" xsi:type="string">Yes</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ae747237cf2f89bac2cd70a58fa4609e2d55da77 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.php @@ -0,0 +1,97 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Enable payment method "Check/Money Order". + * 2. Enable shipping method one of "Flat Rate". + * 3. Create order + * + * Steps: + * 1. Login to backend. + * 2. Sales > Orders. + * 3. Open the created order. + * 4. Do cancel Order. + * 5. Perform all assetions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28191 + */ +class CancelCreatedOrderTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * Enable "Check/Money Order" and "Flat Rate" in configuration. + * + * @return void + */ + public function __prepare() + { + $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => 'checkmo, flatrate', 'rollback' => true] + )->run(); + } + + /** + * Inject pages + * + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @return void + */ + public function __inject(OrderIndex $orderIndex, SalesOrderView $salesOrderView) + { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + } + + /** + * Cancel created order. + * + * @param OrderInjectable $order + * @return array + */ + public function test(OrderInjectable $order) + { + // Preconditions + $order->persist(); + + // Steps + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); + $this->salesOrderView->getPageActions()->cancel(); + + return [ + 'customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer(), + ]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..b5c195908cc8140a1b75fd84fc4c8f55549123c0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CancelCreatedOrderTest.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\CancelCreatedOrderTest"> + <variation name="CancelCreatedOrderTestVariation1"> + <data name="description" xsi:type="string">cancel order and check status on the frontend</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data> + <data name="status" xsi:type="string">Canceled</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..f54fc41993282a7ae85effedd6b33161aa14df37 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.php @@ -0,0 +1,126 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Enable payment method "Check/Money Order". + * 2. Enable shipping method one of "Flat Rate/Free Shipping". + * 3. Create order. + * 4. Create Invoice. + * + * Steps: + * 1. Go to Sales > Orders > find out placed order and open. + * 2. Click 'Credit Memo' button. + * 3. Fill data from dataSet. + * 4. On order's page click 'Refund offline' button. + * 5. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29116 + */ +class CreateCreditMemoEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const STABLE = 'no'; // Backend customer form load + /* end tags */ + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + + /** + * Skip fields for create product fixture. + * + * @var array + */ + protected $skipFields = [ + 'attribute_set_id', + 'website_ids', + 'checkout_data', + 'type_id', + 'price', + ]; + + /** + * Set up configuration. + * + * @param FixtureFactory $fixtureFactory + * @return void + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $this->fixtureFactory = $fixtureFactory; + + $setupConfigurationStep = $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => 'checkmo, flatrate'] + ); + $setupConfigurationStep->run(); + } + + /** + * Create credit memo. + * + * @param OrderInjectable $order + * @param array $data + * @return array + */ + public function test(OrderInjectable $order, array $data) + { + // Preconditions + $order->persist(); + $this->objectManager->create('Magento\Sales\Test\TestStep\CreateInvoiceStep', ['order' => $order])->run(); + + // Steps + $createCreditMemoStep = $this->objectManager->create( + 'Magento\Sales\Test\TestStep\CreateCreditMemoStep', + ['order' => $order, 'data' => $data] + ); + $result = $createCreditMemoStep->run(); + + return [ + 'ids' => ['creditMemoIds' => $result['creditMemoIds']], + 'product' => $this->getProduct($order, $data), + 'customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer() + ]; + } + + /** + * Get product's fixture. + * + * @param OrderInjectable $order + * @param array $data + * @param int $index [optional] + * @return FixtureInterface + */ + protected function getProduct(OrderInjectable $order, array $data, $index = 0) + { + if (!isset($data['items_data'][$index]['back_to_stock']) + || $data['items_data'][$index]['back_to_stock'] != 'Yes' + ) { + return $order->getEntityId()['products'][$index]; + } + $product = $order->getEntityId()['products'][$index]; + $productData = $product->getData(); + $checkoutDataQty = $productData['checkout_data']['qty']; + $productData['quantity_and_stock_status']['qty'] -= ($checkoutDataQty - $data['items_data'][$index]['qty']); + $productData = array_diff_key($productData, array_flip($this->skipFields)); + + return $this->fixtureFactory->create(get_class($product), ['data' => $productData]); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..1d730f56e5bbcc70863d71c20ca7f9ddc99b4d7c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCreditMemoEntityTest.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\CreateCreditMemoEntityTest"> + <variation name="CreateCreditMemoEntityTestVariation1"> + <data name="description" xsi:type="string">Assert items return to stock (partial refund)</data> + <data name="data/items_data/0/back_to_stock" xsi:type="string">Yes</data> + <data name="data/items_data/0/qty" xsi:type="string">1</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::product_100_dollar</data> + <data name="order/data/price/preset" xsi:type="string">partial_refund</data> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertCreditMemoButton" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundInCreditMemoTab" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundInRefundsGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundedGrandTotalOnFrontend" /> + <constraint name="Magento\Catalog\Test\Constraint\AssertProductForm" /> + <constraint name="Magento\Sales\Test\Constraint\AssertCreditMemoItems" /> + </variation> + <variation name="CreateCreditMemoEntityTestVariation2"> + <data name="description" xsi:type="string">Assert 0 shipping refund</data> + <data name="data/items_data/0/qty" xsi:type="string">1</data> + <data name="data/form_data/shipping_amount" xsi:type="string">0</data> + <data name="data/form_data/adjustment_positive" xsi:type="string">5</data> + <data name="data/form_data/adjustment_negative" xsi:type="string">10</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default</data> + <data name="order/data/price/preset" xsi:type="string">full_refund_with_zero_shipping_refund</data> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertCreditMemoButton" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundInCreditMemoTab" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundInRefundsGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertRefundedGrandTotalOnFrontend" /> + <constraint name="Magento\Sales\Test\Constraint\AssertCreditMemoItems" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a16471097cef29fc08be51ec17988b56d724c5a9 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderStatus; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusIndex; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusNew; +use Magento\Mtf\TestCase\Injectable; + +/** + * Steps: + * 1. Log in as admin. + * 2. Navigate to the Stores > Settings > Order Status. + * 3. Click on "Create New Status" button. + * 4. Fill in all data according to data set. + * 5. Save order status. + * 6. Verify created order status. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-23412 + */ +class CreateCustomOrderStatusEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Order staus page. + * + * @var OrderStatusIndex + */ + protected $orderStatusIndexPage; + + /** + * Create order status page. + * + * @var OrderStatusNew + */ + protected $orderStatusNewPage; + + /** + * Inject pages. + * + * @param OrderStatusIndex $orderStatusIndexPage + * @param OrderStatusNew $orderStatusNewPage + * @return void + */ + public function __inject( + OrderStatusIndex $orderStatusIndexPage, + OrderStatusNew $orderStatusNewPage + ) { + $this->orderStatusIndexPage = $orderStatusIndexPage; + $this->orderStatusNewPage = $orderStatusNewPage; + } + + /** + * Run Create Order Status test. + * + * @param OrderStatus $orderStatus + * @return void + */ + public function testCreateOrderStatus(OrderStatus $orderStatus) + { + // Steps + $this->orderStatusIndexPage->open(); + $this->orderStatusIndexPage->getGridPageActions()->addNew(); + $this->orderStatusNewPage->getOrderStatusForm()->fill($orderStatus); + $this->orderStatusNewPage->getFormPageActions()->save(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..2de5caa7940d118fdcb2e9d83811f32f4a675ec5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateCustomOrderStatusEntityTest.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\CreateCustomOrderStatusEntityTest"> + <variation name="CreateCustomOrderStatusEntityTestVariation1"> + <data name="orderStatus/data/status" xsi:type="string">order_status%isolation%</data> + <data name="orderStatus/data/label" xsi:type="string">orderLabel%isolation%</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + </variation> + <variation name="CreateCustomOrderStatusEntityTestVariation2"> + <data name="orderStatus/data/status" xsi:type="string">pending</data> + <data name="orderStatus/data/label" xsi:type="string">orderLabel%isolation%</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusDuplicateStatus" /> + </variation> + <variation name="CreateCustomOrderStatusEntityTestVariation3"> + <data name="orderStatus/data/status" xsi:type="string">order_status%isolation%</data> + <data name="orderStatus/data/label" xsi:type="string">Processing</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1c490060364c978df658f645025826b5f2335f0f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Enable payment method "Check/Money Order". + * 2. Enable shipping method one of "Flat Rate/Free Shipping". + * 3. Create order. + * + * Steps: + * 1. Go to Sales > Orders. + * 2. Select created order in the grid and open it. + * 3. Click 'Invoice' button. + * 4. Fill data according to dataSet. + * 5. Click 'Submit Invoice' button. + * 6. Perform assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28209 + */ +class CreateInvoiceEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Set up configuration. + * + * @return void + */ + public function __prepare() + { + $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => 'checkmo, flatrate'] + )->run(); + } + + /** + * Create invoice. + * + * @param OrderInjectable $order + * @param array $data + * @return array + */ + public function test(OrderInjectable $order, array $data) + { + // Preconditions + $order->persist(); + + // Steps + $result = $this->objectManager->create( + 'Magento\Sales\Test\TestStep\CreateInvoiceStep', + ['order' => $order, 'data' => $data] + )->run(); + + return [ + 'ids' => [ + 'invoiceIds' => $result['invoiceIds'], + 'shipmentIds' => isset($result['shipmentIds']) ? $result['shipmentIds'] : null, + ] + ]; + } + + /** + * Log out. + * + * @return void + */ + public function tearDown() + { + $this->objectManager->create('Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep')->run(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..43b018bc8b8c2d6a7f689c61dd5e96aa9761aac1 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateInvoiceEntityTest.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\CreateInvoiceEntityTest"> + <variation name="CreateInvoiceEntityTestVariation1"> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/price/preset" xsi:type="string">full_invoice</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default</data> + <data name="order/data/total_qty_ordered/0" xsi:type="string">1</data> + <data name="data/items_data/0/qty" xsi:type="string">-</data> + <data name="data/form_data/do_shipment" xsi:type="string">Yes</data> + <data name="data/form_data/comment_text" xsi:type="string">comments</data> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceWithShipmentSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertNoInvoiceButton" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceInInvoicesTab" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceInInvoicesGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoicedAmountOnFrontend" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertNoShipButton" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentInShipmentsTab" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceItems" /> + </variation> + <variation name="CreateInvoiceEntityTestVariation2"> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/price/preset" xsi:type="string">partial_invoice</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::product_100_dollar</data> + <data name="order/data/total_qty_ordered/0" xsi:type="string">-</data> + <data name="data/items_data/0/qty" xsi:type="string">1</data> + <data name="data/form_data/do_shipment" xsi:type="string">No</data> + <data name="data/form_data/comment_text" xsi:type="string">comments</data> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceInInvoicesTab" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceInInvoicesGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoiceItems" /> + <constraint name="Magento\Sales\Test\Constraint\AssertInvoicedAmountOnFrontend" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.php new file mode 100644 index 0000000000000000000000000000000000000000..67700cfedc82feb577c88a8b86f66ffd30bac571 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create product. + * + * Steps: + * 1. Open Backend. + * 2. Open Sales -> Orders. + * 3. Click Create New Order. + * 4. Select Customer created in preconditions. + * 5. Add Product. + * 6. Fill data according dataSet. + * 7. Click Update Product qty. + * 8. Fill data according dataSet. + * 9. Click Get Shipping Method and rates. + * 10. Fill data according dataSet. + * 11. Submit Order. + * 12. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28696 + */ +class CreateOrderBackendTest extends Scenario +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TEST_TYPE = 'acceptance_test'; + /* end tags */ + + /** + * Runs sales order on backend. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } + + /** + * Disable enabled config after test. + * + * @return void + */ + public function tearDown() + { + if (isset($this->currentVariation['arguments']['configData'])) { + $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => $this->currentVariation['arguments']['configData'], 'rollback' => true] + )->run(); + } + $this->objectManager->create('Magento\SalesRule\Test\TestStep\DeleteAllSalesRuleStep')->run(); + $this->objectManager->create('Magento\Tax\Test\TestStep\DeleteAllTaxRulesStep')->run(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8328baab4af1305a8f77e86a412dc67fdc3f4ba --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/CreateOrderBackendTest.xml @@ -0,0 +1,152 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\CreateOrderBackendTest"> + <variation name="CreateOrderBackendTestVariation1"> + <data name="description" xsi:type="string">Create order with simple product for registered US customer using Fixed shipping method and Cash on Delivery payment method</data> + <data name="products" xsi:type="string">catalogProductSimple::default</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="saveAddress" xsi:type="string">No</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">565.00</item> + </data> + <data name="payment/method" xsi:type="string">cashondelivery</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Reorder, Cancel, Send Notification, Hold, Invoice, Ship, Edit</data> + <data name="configData" xsi:type="string">cashondelivery</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="CreateOrderBackendTestVariation2"> + <data name="issue" xsi:type="string">Bug: MAGETWO-36210</data> + <data name="description" xsi:type="string">Create order with virtual product for registered UK customer using Check/Money Order payment method</data> + <data name="products" xsi:type="string">catalogProductVirtual::default</data> + <data name="customer/dataSet" xsi:type="string">customer_UK</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_UK</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">10.00</item> + </data> + <data name="payment/method" xsi:type="string">checkmo</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Cancel, Send Notification, Hold, Invoice, Edit</data> + <data name="configData" xsi:type="string">checkmo_specificcountry_gb</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="CreateOrderBackendTestVariation3"> + <data name="description" xsi:type="string">Create order with simple product for registered US customer using Fixed shipping method and Bank Transfer payment method</data> + <data name="products" xsi:type="string">catalogProductSimple::default</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="saveAddress" xsi:type="string">No</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">565.00</item> + </data> + <data name="payment/method" xsi:type="string">banktransfer</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Cancel, Send Notification, Hold, Reorder, Invoice, Edit</data> + <data name="configData" xsi:type="string">banktransfer</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="CreateOrderBackendTestVariation4"> + <data name="tag" xsi:type="string">to_maintain:yes</data> + <data name="description" xsi:type="string">Create order with virtual product for registered UK customer using Bank Transfer payment method</data> + <data name="products" xsi:type="string">catalogProductVirtual::default</data> + <data name="customer/dataSet" xsi:type="string">customer_UK</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_UK</data> + <data name="saveAddress" xsi:type="string">No</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">10.00</item> + </data> + <data name="payment/method" xsi:type="string">banktransfer</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Cancel, Send Notification, Hold, Invoice, Edit</data> + <data name="configData" xsi:type="string">freeshipping_specificcountry_gb, banktransfer</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="CreateOrderBackendTestVariation5"> + <data name="tag" xsi:type="string">to_maintain:yes</data> + <data name="description" xsi:type="string">Create order with simple product for registered US customer using Fixed shipping method and Purchase Order payment method</data> + <data name="products" xsi:type="string">catalogProductSimple::default</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="saveAddress" xsi:type="string">No</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">565.00</item> + </data> + <data name="payment/method" xsi:type="string">purchaseorder</data> + <data name="payment/po_number" xsi:type="string">123456</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Cancel, Send Notification, Hold, Invoice, Reorder, Edit</data> + <data name="configData" xsi:type="string">purchaseorder</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + <variation name="CreateOrderBackendTestVariation6"> + <data name="description" xsi:type="string">MAGETWO-12395 - Create Offline Order for Registered Customer in Admin</data> + <data name="products" xsi:type="string">catalogProductSimple::simple_10_dollar, configurableProduct::with_one_option</data> + <data name="taxRule" xsi:type="string">us_ca_ny_rule</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="saveAddress" xsi:type="string">No</data> + <data name="checkoutMethod" xsi:type="string">login</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">32.73</item> + </data> + <data name="payment/method" xsi:type="string">checkmo</data> + <data name="tag" xsi:type="string">test_type:acceptance_test</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + </variation> + <variation name="CreateOrderBackendTestVariation7"> + <data name="description" xsi:type="string">MAGETWO-12520 - Create Order for New Customer in Admin with Offline Payment Method</data> + <data name="products" xsi:type="string">catalogProductSimple::simple_10_dollar, configurableProduct::with_one_option</data> + <data name="taxRule" xsi:type="string">us_ca_ny_rule</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="saveAddress" xsi:type="string">Yes</data> + <data name="checkoutMethod" xsi:type="string">register</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">32.73</item> + </data> + <data name="payment/method" xsi:type="string">checkmo</data> + <data name="tag" xsi:type="string">test_type:acceptance_test, to_maintain:yes</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + <constraint name="Magento\Customer\Test\Constraint\AssertCustomerForm" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c0c57982c726f90a33f1d94b028b2a040bded26a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.php @@ -0,0 +1,97 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Enable payment method "Check/Money Order". + * 2. Enable shipping method one of "Flat Rate". + * 3. Create order. + * + * Steps: + * 1. Login to backend. + * 2. Go to Sales > Orders. + * 3. Open the created order. + * 4. Do 'Hold' for Order. + * 5. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28214 + */ +class HoldCreatedOrderTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * Enable "Check/Money Order" and "Flat Rate" in configuration. + * + * @return void + */ + public function __prepare() + { + $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => 'checkmo, flatrate', 'rollback' => true] + )->run(); + } + + /** + * Inject pages. + * + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @return void + */ + public function __inject(OrderIndex $orderIndex, SalesOrderView $salesOrderView) + { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + } + + /** + * Put created order on hold. + * + * @param OrderInjectable $order + * @return array + */ + public function test(OrderInjectable $order) + { + // Preconditions + $order->persist(); + + // Steps + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); + $this->salesOrderView->getPageActions()->hold(); + + return [ + 'customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer(), + ]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..962f0262f34f2714a8bc06325a8926069115d57e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/HoldCreatedOrderTest.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\HoldCreatedOrderTest"> + <variation name="HoldCreatedOrderTestVariation1"> + <data name="description" xsi:type="string">hold order and check status on the front in my account</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data> + <data name="orderButtonsUnavailable" xsi:type="string">Invoice,Cancel,Reorder,Ship,Edit</data> + <data name="status" xsi:type="string">On Hold</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderOnHoldSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsUnavailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertUnholdButton" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..264f392cf0123e8e85c8579d9593506bab5bb04d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.php @@ -0,0 +1,140 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestCase\Injectable; + +/** + * Precondition: + * 1. Create orders. + * + * Steps: + * 1. Navigate to backend. + * 2. Go to Sales > Orders. + * 3. Select Mass Action according to dataSet. + * 4. Submit. + * 5. Perform Asserts. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-27897 + */ +class MassOrdersUpdateTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Order index page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + + /** + * Injection data. + * + * @param OrderIndex $orderIndex + * @param FixtureFactory $fixtureFactory + * @return void + */ + public function __inject(OrderIndex $orderIndex, FixtureFactory $fixtureFactory) + { + $this->orderIndex = $orderIndex; + $this->fixtureFactory = $fixtureFactory; + } + + /** + * Mass orders update. + * + * @param string $steps + * @param int $ordersCount + * @param string $action + * @param string $resultStatuses + * @return array + */ + public function test($steps, $ordersCount, $action, $resultStatuses) + { + // Preconditions + $orders = $this->createOrders($ordersCount, $steps); + $items = $this->prepareFilter($orders); + + // Steps + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->massaction($items, $action); + + return ['orders' => $orders, 'orderStatuses' => explode(',', $resultStatuses)]; + } + + /** + * Create orders. + * + * @param int $count + * @param string $steps + * @return array + */ + protected function createOrders($count, $steps) + { + $orders = []; + $steps = explode('|', $steps); + for ($i = 0; $i < $count; $i++) { + /** @var OrderInjectable $order */ + $order = $this->fixtureFactory->createByCode('orderInjectable', ['dataSet' => 'default']); + $order->persist(); + $orders[$i] = $order; + $this->processSteps($order, $steps[$i]); + } + + return $orders; + } + + /** + * Process which step to take for order. + * + * @param OrderInjectable $order + * @param string $steps + * @return void + */ + protected function processSteps(OrderInjectable $order, $steps) + { + $steps = array_diff(explode(',', $steps), ['-']); + foreach ($steps as $step) { + $action = str_replace(' ', '', ucwords($step)); + $methodAction = (($action != 'OnHold') ? 'Create' : '') . $action . 'Step'; + $path = 'Magento\Sales\Test\TestStep'; + $processStep = $this->objectManager->create($path . '\\' . $methodAction, ['order' => $order]); + $processStep->run(); + } + } + + /** + * Prepare filter. + * + * @param OrderInjectable[] $orders + * @return array + */ + protected function prepareFilter(array $orders) + { + $items = []; + foreach ($orders as $order) { + $items[] = ['id' => $order->getId()]; + } + + return $items; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c9c529d4ae07bebf8cf83fa3fb22575c2509fd47 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MassOrdersUpdateTest.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MassOrdersUpdateTest"> + <variation name="MassOrdersUpdateTestVariation1"> + <data name="description" xsi:type="string">cancel orders in status Pending and Processing</data> + <data name="steps" xsi:type="string">-</data> + <data name="action" xsi:type="string">Cancel</data> + <data name="ordersCount" xsi:type="string">1</data> + <data name="resultStatuses" xsi:type="string">Canceled</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelMassActionSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation2"> + <data name="description" xsi:type="string">try to cancel orders in status Complete, Closed</data> + <data name="steps" xsi:type="string">invoice, shipment|invoice, credit memo</data> + <data name="action" xsi:type="string">Cancel</data> + <data name="ordersCount" xsi:type="string">2</data> + <data name="resultStatuses" xsi:type="string">Complete,Closed</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelMassActionFailMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation3"> + <data name="tag" xsi:type="string">to_maintain:yes</data> + <data name="description" xsi:type="string">try to cancel orders in status Pending, Closed</data> + <data name="steps" xsi:type="string">invoice|invoice, credit memo</data> + <data name="action" xsi:type="string">Cancel</data> + <data name="ordersCount" xsi:type="string">2</data> + <data name="resultStatuses" xsi:type="string">Processing,Closed</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderCancelMassActionFailMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation4"> + <data name="description" xsi:type="string">Put orders in statuses Pending, Processing on Hold</data> + <data name="steps" xsi:type="string">-|invoice</data> + <data name="action" xsi:type="string">Hold</data> + <data name="ordersCount" xsi:type="string">2</data> + <data name="resultStatuses" xsi:type="string">On Hold,On Hold</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderOnHoldSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation5"> + <data name="description" xsi:type="string">Try to put order in statuse Complete on Hold</data> + <data name="steps" xsi:type="string">invoice, shipment</data> + <data name="action" xsi:type="string">Hold</data> + <data name="ordersCount" xsi:type="string">1</data> + <data name="resultStatuses" xsi:type="string">Complete</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderOnHoldFailMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation6"> + <data name="description" xsi:type="string">Release order in statuse On Hold</data> + <data name="steps" xsi:type="string">on hold</data> + <data name="action" xsi:type="string">Unhold</data> + <data name="ordersCount" xsi:type="string">1</data> + <data name="resultStatuses" xsi:type="string">Pending</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderReleaseSuccessMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + <variation name="MassOrdersUpdateTestVariation7"> + <data name="description" xsi:type="string">try to Release order in status Pending</data> + <data name="steps" xsi:type="string">-</data> + <data name="action" xsi:type="string">Unhold</data> + <data name="ordersCount" xsi:type="string">1</data> + <data name="resultStatuses" xsi:type="string">Pending</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderReleaseFailMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrdersInOrdersGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4a66d441d4fc9221cf5b1d0f349f1b6af332d518 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.php @@ -0,0 +1,103 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Customer\Test\Page\Adminhtml\CustomerIndex; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit; +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create product. + * 3. Create order with this product. + * + * Steps: + * 1. Open Customers > All Customers. + * 2. Search and open customer from preconditions. + * 3. Click Create Order. + * 4. Check product in Last Ordered Items section. + * 5. Click Update Changes. + * 6. Perform all assertions. + * + * @group Customers_(CS), Order_Management_(CS) + * @ZephyrId MAGETWO-27640 + */ +class MoveLastOrderedProductsOnOrderPageTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Order create index page. + * + * @var OrderCreateIndex + */ + protected $orderCreateIndex; + + /** + * Customer index page. + * + * @var CustomerIndex + */ + protected $customerIndex; + + /** + * Customer index edit page. + * + * @var CustomerIndexEdit + */ + protected $customerIndexEdit; + + /** + * Inject pages. + * + * @param OrderCreateIndex $orderCreateIndex + * @param CustomerIndex $customerIndex + * @param CustomerIndexEdit $customerIndexEdit + * @return void + */ + public function __inject( + OrderCreateIndex $orderCreateIndex, + CustomerIndex $customerIndex, + CustomerIndexEdit $customerIndexEdit + ) { + $this->orderCreateIndex = $orderCreateIndex; + $this->customerIndex = $customerIndex; + $this->customerIndexEdit = $customerIndexEdit; + } + + /** + * Move last ordered products on order page. + * + * @param OrderInjectable $order + * @return array + */ + public function test(OrderInjectable $order) + { + // Preconditions: + $order->persist(); + $customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer(); + + // Steps: + $this->customerIndex->open(); + $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); + $this->customerIndexEdit->getPageActionsBlock()->createOrder(); + $this->orderCreateIndex->getStoreBlock()->selectStoreView(); + $products = $order->getEntityId()['products']; + $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); + $activitiesBlock->getLastOrderedItemsBlock()->addProductsToOrder($products); + $activitiesBlock->updateChanges(); + + return ['products' => $products]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..db32b31002732a1c3df2362d9af163e1c64e0321 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveLastOrderedProductsOnOrderPageTest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveLastOrderedProductsOnOrderPageTest"> + <variation name="MoveLastOrderedProductsOnOrderPageTestVariation1"> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + <variation name="MoveLastOrderedProductsOnOrderPageTestVariation2"> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">configurableProduct::default</data> + <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..65eb1855623eea37ff73dfa9fd3a4647423dec7c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.php @@ -0,0 +1,171 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Catalog\Test\Page\Product\CatalogProductCompare; +use Magento\Catalog\Test\Page\Product\CatalogProductView; +use Magento\Cms\Test\Page\CmsIndex; +use Magento\Customer\Test\Fixture\Customer; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndex; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit; +use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex; +use Magento\Mtf\Client\BrowserInterface; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create products. + * 3. Add products to compare list. + * + * Steps: + * 1. Open Customers -> All Customers. + * 2. Search and open customer from preconditions. + * 3. Click 'Create Order'. + * 4. Check product in comparison list section. + * 5. Click 'Update Changes'. + * 6. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28050 + */ +class MoveProductsInComparedOnOrderPageTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Cms index page. + * + * @var CmsIndex + */ + protected $cmsIndex; + + /** + * Browser instance. + * + * @var BrowserInterface + */ + protected $browser; + + /** + * Catalog product page. + * + * @var CatalogProductView + */ + protected $catalogProductView; + + /** + * Order create index page. + * + * @var OrderCreateIndex + */ + protected $orderCreateIndex; + + /** + * Customer index page. + * + * @var CustomerIndex + */ + protected $customerIndex; + + /** + * Customer index edit page. + * + * @var CustomerIndexEdit + */ + protected $customerIndexEdit; + + /** + * Catalog product compare page. + * + * @var CatalogProductCompare + */ + protected $catalogProductCompare; + + /** + * Create customer. + * + * @param Customer $customer + * @param BrowserInterface $browser + * @return array + */ + public function __prepare(Customer $customer, BrowserInterface $browser) + { + $customer->persist(); + $this->browser = $browser; + + return ['customer' => $customer]; + } + + /** + * Inject pages. + * + * @param CmsIndex $cmsIndex + * @param CatalogProductView $catalogProductView + * @param OrderCreateIndex $orderCreateIndex + * @param CustomerIndex $customerIndex + * @param CustomerIndexEdit $customerIndexEdit + * @param CatalogProductCompare $catalogProductCompare + * @return void + */ + public function __inject( + CmsIndex $cmsIndex, + CatalogProductView $catalogProductView, + OrderCreateIndex $orderCreateIndex, + CustomerIndex $customerIndex, + CustomerIndexEdit $customerIndexEdit, + CatalogProductCompare $catalogProductCompare + ) { + $this->cmsIndex = $cmsIndex; + $this->catalogProductView = $catalogProductView; + $this->orderCreateIndex = $orderCreateIndex; + $this->customerIndex = $customerIndex; + $this->customerIndexEdit = $customerIndexEdit; + $this->catalogProductCompare = $catalogProductCompare; + } + + /** + * Move compare products on order page. + * + * @param Customer $customer + * @param string $products + * @return array + */ + public function test(Customer $customer, $products) + { + // Preconditions + // Create products + $products = $this->objectManager->create( + '\Magento\Catalog\Test\TestStep\CreateProductsStep', + ['products' => $products] + )->run()['products']; + // Login under customer + $this->objectManager->create( + 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', + ['customer' => $customer] + )->run(); + // Add products to compare + foreach ($products as $itemProduct) { + $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html'); + $this->catalogProductView->getViewBlock()->clickAddToCompare(); + } + + // Steps + $this->customerIndex->open(); + $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); + $this->customerIndexEdit->getPageActionsBlock()->createOrder(); + $this->orderCreateIndex->getStoreBlock()->selectStoreView(); + $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); + $activitiesBlock->getProductsInComparisonBlock()->addProductsToOrder($products); + $activitiesBlock->updateChanges(); + + return ['products' => $products, 'productsIsConfigured' => false]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..28946b2dfd52d04182904397f556dfeae39e71df --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveProductsInComparedOnOrderPageTest.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveProductsInComparedOnOrderPageTest"> + <variation name="MoveProductsInComparedOnOrderPageTestVariation1"> + <data name="products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + <variation name="MoveProductsInComparedOnOrderPageTestVariation2"> + <data name="tag" xsi:type="string">to_maintain:yes</data> + <data name="products" xsi:type="string">configurableProduct::default,configurableProduct::default</data> + <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fa3bf369cad5c5e0a9a47303538f760912cdf2fe --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php @@ -0,0 +1,173 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Catalog\Test\Page\Product\CatalogProductCompare; +use Magento\Catalog\Test\Page\Product\CatalogProductView; +use Magento\Cms\Test\Page\CmsIndex; +use Magento\Customer\Test\Fixture\Customer; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndex; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit; +use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex; +use Magento\Mtf\Client\BrowserInterface; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create products. + * 3. Add products to compare list. + * 4. Clear compare list. + * + * Steps: + * 1. Open Customers > All Customers. + * 2. Search and open customer from preconditions. + * 3. Click 'Create Order'. + * 4. Check product in 'Recently compared List' section. + * 5. Click 'Update Changes'. + * 6. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28109 + */ +class MoveRecentlyComparedProductsOnOrderPageTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Cms index page. + * + * @var CmsIndex + */ + protected $cmsIndex; + + /** + * Browser instance. + * + * @var BrowserInterface + */ + protected $browser; + + /** + * Catalog product page. + * + * @var CatalogProductView + */ + protected $catalogProductView; + + /** + * Order create index page. + * + * @var OrderCreateIndex + */ + protected $orderCreateIndex; + + /** + * Customer index page. + * + * @var CustomerIndex + */ + protected $customerIndex; + + /** + * Customer index edit page. + * + * @var CustomerIndexEdit + */ + protected $customerIndexEdit; + + /** + * Catalog product compare page. + * + * @var CatalogProductCompare + */ + protected $catalogProductCompare; + + /** + * Create customer. + * + * @param Customer $customer + * @param BrowserInterface $browser + * @return array + */ + public function __prepare(Customer $customer, BrowserInterface $browser) + { + $customer->persist(); + $this->browser = $browser; + + return ['customer' => $customer]; + } + + /** + * Inject pages. + * + * @param CmsIndex $cmsIndex + * @param CatalogProductView $catalogProductView + * @param OrderCreateIndex $orderCreateIndex + * @param CustomerIndex $customerIndex + * @param CustomerIndexEdit $customerIndexEdit + * @param CatalogProductCompare $catalogProductCompare + * @return void + */ + public function __inject( + CmsIndex $cmsIndex, + CatalogProductView $catalogProductView, + OrderCreateIndex $orderCreateIndex, + CustomerIndex $customerIndex, + CustomerIndexEdit $customerIndexEdit, + CatalogProductCompare $catalogProductCompare + ) { + $this->cmsIndex = $cmsIndex; + $this->catalogProductView = $catalogProductView; + $this->orderCreateIndex = $orderCreateIndex; + $this->customerIndex = $customerIndex; + $this->customerIndexEdit = $customerIndexEdit; + $this->catalogProductCompare = $catalogProductCompare; + } + + /** + * Move recently compared products on order page. + * + * @param Customer $customer + * @param string $products + * @return array + */ + public function test(Customer $customer, $products) + { + // Preconditions + // Create product + $products = $this->objectManager->create( + '\Magento\Catalog\Test\TestStep\CreateProductsStep', + ['products' => $products] + )->run()['products']; + // Login under customer + $this->objectManager->create( + 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', + ['customer' => $customer] + )->run(); + foreach ($products as $itemProduct) { + $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html'); + $this->catalogProductView->getViewBlock()->clickAddToCompare(); + } + $this->cmsIndex->getLinksBlock()->openLink("Compare Products"); + $this->catalogProductCompare->getCompareProductsBlock()->removeAllProducts(); + + // Steps: + $this->customerIndex->open(); + $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); + $this->customerIndexEdit->getPageActionsBlock()->createOrder(); + $this->orderCreateIndex->getStoreBlock()->selectStoreView(); + $activitiesBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); + $activitiesBlock->getRecentlyComparedProductsBlock()->addProductsToOrder($products); + $activitiesBlock->updateChanges(); + + return ['products' => $products, 'productsIsConfigured' => false]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c392c0ed4648acf34955412584f8679b15bb700e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyComparedProductsOnOrderPageTest"> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariation1"> + <data name="products" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariation2" firstConstraint="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" method="test"> + <data name="products" xsi:type="string">configurableProduct::default,configurableProduct::default</data> + <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..31fd3de31d59505404cb4f90d48fd0987adbf77a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create product. + * 3. Open product on frontend. + * + * Steps: + * 1. Login in to Backend. + * 2. Open Customers > All Customers. + * 3. Search and open customer from preconditions. + * 4. Click Create Order. + * 5. Check product in Recently Viewed Products section. + * 6. Click Update Changes. + * 7. Click Configure. + * 8. Fill data from dataSet. + * 9. Click OK. + * 10. Click Update Items and Qty's button. + * 11. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29723 + */ +class MoveRecentlyViewedProductsOnOrderPageTest extends Scenario +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Runs Move Recently Viewed Products On Order Page. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..7bd0a534e1993380d2719d2a38d53d8e0bddeee2 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyViewedProductsOnOrderPageTest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyViewedProductsOnOrderPageTest"> + <variation name="MoveRecentlyViewedProductsOnOrderPageTestVariation1"> + <data name="products" xsi:type="string">configurableProduct::default</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + <variation name="MoveRecentlyViewedProductsOnOrderPageTestVariation2"> + <data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..36637b0a89863b410d7db2f3d1fbc30c7de15e62 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.php @@ -0,0 +1,169 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Catalog\Test\Page\Product\CatalogProductView; +use Magento\Customer\Test\Fixture\Customer; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndex; +use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit; +use Magento\Customer\Test\Page\CustomerAccountLogout; +use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex; +use Magento\Mtf\Client\BrowserInterface; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Create customer. + * 2. Create product. + * 3. Add product to cart. + * + * Steps: + * 1. Open Customers > All Customers. + * 2. Search and open customer from preconditions. + * 3. Click Create Order. + * 4. Check product in Shopping Cart section. + * 5. Click Update Changes. + * 6. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28540 + */ +class MoveShoppingCartProductsOnOrderPageTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Customer logout page + * + * @var CustomerAccountLogout + */ + protected $customerAccountLogout; + + /** + * Browser instance + * + * @var BrowserInterface + */ + protected $browser; + + /** + * Catalog product page + * + * @var CatalogProductView + */ + protected $catalogProductView; + + /** + * Customer index page + * + * @var CustomerIndex + */ + protected $customerIndex; + + /** + * Customer index edit page + * + * @var CustomerIndexEdit + */ + protected $customerIndexEdit; + + /** + * Order create index page + * + * @var OrderCreateIndex + */ + protected $orderCreateIndex; + + /** + * Prepare data. + * + * @param Customer $customer + * @return array + */ + public function __prepare(Customer $customer) + { + $customer->persist(); + + return ['customer' => $customer]; + } + + /** + * Inject pages. + * + * @param CustomerAccountLogout $customerAccountLogout + * @param CatalogProductView $catalogProductView + * @param CustomerIndex $customerIndex + * @param CustomerIndexEdit $customerIndexEdit + * @param BrowserInterface $browser + * @param OrderCreateIndex $orderCreateIndex + * @return void + */ + public function __inject( + CustomerAccountLogout $customerAccountLogout, + CatalogProductView $catalogProductView, + CustomerIndex $customerIndex, + CustomerIndexEdit $customerIndexEdit, + BrowserInterface $browser, + OrderCreateIndex $orderCreateIndex + ) { + $this->customerAccountLogout = $customerAccountLogout; + $this->catalogProductView = $catalogProductView; + $this->customerIndex = $customerIndex; + $this->customerIndexEdit = $customerIndexEdit; + $this->browser = $browser; + $this->orderCreateIndex = $orderCreateIndex; + } + + /** + * Create order from customer page (cartActions). + * + * @param Customer $customer + * @param string $product + * @return array + */ + public function test(Customer $customer, $product) + { + //Preconditions + // Create product + $product = $this->objectManager->create( + '\Magento\Catalog\Test\TestStep\CreateProductStep', + ['product' => $product] + )->run()['product']; + // Login under customer + $this->objectManager->create( + 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', + ['customer' => $customer] + )->run(); + $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); + $this->catalogProductView->getViewBlock()->addToCart($product); + + //Steps + $this->customerIndex->open(); + $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]); + $this->customerIndexEdit->getPageActionsBlock()->createOrder(); + $this->orderCreateIndex->getStoreBlock()->selectStoreView(); + $this->orderCreateIndex->getCustomerActivitiesBlock()->getShoppingCartItemsBlock() + ->addProductsToOrder([$product]); + $this->orderCreateIndex->getCustomerActivitiesBlock()->updateChanges(); + + return ['products' => [$product]]; + } + + /** + * Log out after test. + * + * @return void + */ + public function tearDown() + { + $this->customerAccountLogout->open(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..60887adfe898c5620a78e453d395a8d3c2ef22c5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveShoppingCartProductsOnOrderPageTest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveShoppingCartProductsOnOrderPageTest"> + <variation name="MoveShoppingCartProductsOnOrderPageTestVariation1"> + <data name="product" xsi:type="string">catalogProductSimple::default</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + <variation name="MoveShoppingCartProductsOnOrderPageTestVariation2" firstConstraint="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" method="test"> + <data name="product" xsi:type="string">configurableProduct::default</data> + <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1e7e13da8b55aa384852be9ec86a09d943bb2df8 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Mtf\Client\BrowserInterface; +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Create products. + * 2. Enable all Gift Options. + * 3. Create Gift Card Account with Balance = 1. + * 4. Create Customer Account. + * 5. Place order with options according to dataSet. + * + * Steps: + * 1. Find the Order on frontend. + * 2. Navigate to: Orders and Returns. + * 3. Fill the form with correspondent Order data. + * 4. Click on the "Continue" button. + * 5. Click on the "Print Order" button. + * 6. Perform appropriate assertions.v + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-30253 + */ +class PrintOrderFrontendGuestTest extends Scenario +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Browser. + * + * @var BrowserInterface + */ + protected $browser; + + /** + * Prepare data. + * + * @param BrowserInterface $browser + */ + public function __prepare(BrowserInterface $browser) + { + $this->browser = $browser; + } + + /** + * Runs print order on frontend. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } + + /** + * Close browser. + * + * @return void + */ + public function tearDown() + { + $this->objectManager->create('Magento\SalesRule\Test\TestStep\DeleteAllSalesRuleStep')->run(); + $this->browser->closeWindow(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c5bce1d33a76dc478e09ee229b777fff8e2345b3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/PrintOrderFrontendGuestTest.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\PrintOrderFrontendGuestTest"> + <variation name="PrintOrderFrontendGuestTestVariation1"> + <data name="customer" xsi:type="array"> + <item name="dataSet" xsi:type="string">johndoe_with_addresses"</item> + </data> + <data name="billingAddress" xsi:type="array"> + <item name="dataSet" xsi:type="string">customer_US"</item> + </data> + <data name="payment" xsi:type="array"> + <item name="method" xsi:type="string">checkmo"</item> + </data> + <data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product, configurableProduct::default, downloadableProduct::default</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">723.00</item> + </data> + <data name="paymentMethod" xsi:type="string">Check / Money order</data> + <data name="salesRule" xsi:type="string">active_sales_rule_with_fixed_price_discount_coupon</data> + <data name="salesRuleDiscount" xsi:type="string">300.00</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <constraint name="Magento\Sales\Test\Constraint\AssertSalesPrintOrderBillingAddress" /> + <constraint name="Magento\Sales\Test\Constraint\AssertSalesPrintOrderGrandTotal" /> + <constraint name="Magento\Sales\Test\Constraint\AssertSalesPrintOrderPaymentMethod" /> + <constraint name="Magento\Sales\Test\Constraint\AssertSalesPrintOrderProducts" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertSalesRuleOnPrintOrder" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShippingMethodOnPrintOrder" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2706971f12810aad500a1c8cee168296420b5384 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Create two products. + * 2. Create a customer. + * 3. Create order. + * + * Steps: + * 1. Go to backend. + * 2. Open Sales > Orders. + * 3. Open the created order. + * 4. Do 'Reorder' for placed order. + * 5. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29007 + */ +class ReorderOrderEntityTest extends Scenario +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Reorder created order. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } + + /** + * Disable enabled config after test. + * + * @return void + */ + public function tearDown() + { + if (isset($this->currentVariation['arguments']['configData'])) { + $setConfigStep = $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => $this->currentVariation['arguments']['configData'], 'rollback' => true] + ); + $setConfigStep->run(); + } + $this->objectManager->create('Magento\SalesRule\Test\TestStep\DeleteAllSalesRuleStep')->run(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..200b45de0adb16a93d2c5343434e3038d064973d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/ReorderOrderEntityTest.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\ReorderOrderEntityTest"> + <variation name="ReorderOrderEntityTestVariation1"> + <data name="description" xsi:type="string">Reorder placed order (update products, billing address).</data> + <data name="order/dataSet" xsi:type="string">two_simple_product</data> + <data name="salesRule" xsi:type="string">active_sales_rule_with_fixed_price_discount_coupon</data> + <data name="customer/dataSet" xsi:type="string">customer_US</data> + <data name="billingAddress/dataSet" xsi:type="string">customer_US</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="prices" xsi:type="array"> + <item name="grandTotal" xsi:type="string">1,030.00</item> + </data> + <data name="payment/method" xsi:type="string">checkmo</data> + <data name="previousOrderStatus" xsi:type="string">Pending</data> + <data name="status" xsi:type="string">Pending</data> + <data name="orderButtonsAvailable" xsi:type="string">Back, Reorder, Cancel, Send Notification, Hold, Invoice, Ship, Edit</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertReorderStatusIsCorrect" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusIsCorrect" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderButtonsAvailable" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.php new file mode 100644 index 0000000000000000000000000000000000000000..05813d46b2d8b1850062a97c3401775e4290d93a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderStatus; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusIndex; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Custom Order Status is created. + * 2. Order Status assigned to State. + * + * Steps: + * 1. Log in to backend. + * 2. Navigate to the Stores > Settings > Order Status. + * 3. Click "Unassign" for appropriate status. + * 4. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29450 + */ +class UnassignCustomOrderStatusTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Order Status Index page. + * + * @var OrderStatusIndex + */ + protected $orderStatusIndex; + + /** + * Injection data. + * + * @param OrderStatusIndex $orderStatusIndex + * @return void + */ + public function __inject(OrderStatusIndex $orderStatusIndex) + { + $this->orderStatusIndex = $orderStatusIndex; + } + + /** + * Run Unassign Custom OrderStatus test. + * + * @param OrderStatus $orderStatus + * @return void + */ + public function test(OrderStatus $orderStatus) + { + // Preconditions: + $orderStatus->persist(); + + // Steps: + $orderStatusLabel = $orderStatus->getLabel(); + $this->orderStatusIndex->open(); + $this->orderStatusIndex->getOrderStatusGrid()->searchAndUnassign(['label' => $orderStatusLabel]); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c429fc46730d9b6983b05843d316b1f6a9586c1e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UnassignCustomOrderStatusTest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\UnassignCustomOrderStatusTest"> + <variation name="UnassignCustomOrderStatusTestVariation1"> + <data name="description" xsi:type="string">unassign order status</data> + <data name="orderStatus/dataSet" xsi:type="string">assign_to_pending</data> + <data name="defaultState" xsi:type="string">Pending</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusSuccessUnassignMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusNotAssigned" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1ddf03146ceeee32abf630ad2166ac73b2f7f1c4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.php @@ -0,0 +1,159 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Fixture\OrderStatus; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusEdit; +use Magento\Sales\Test\Page\Adminhtml\OrderStatusIndex; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Custom Order Status is created. + * 2. New order should be created if orderExist=Yes. + * + * Steps: + * 1. Log in as admin. + * 2. Navigate to the Stores > Settings > Order Status. + * 3. Click on Custom Order Status from grid. + * 4. Fill in all data according to data set. + * 5. Save order status. + * 6. Perform all assertions. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-29868 + */ +class UpdateCustomOrderStatusTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Order Status Index page. + * + * @var OrderStatusIndex + */ + protected $orderStatusIndex; + + /** + * Order Status Edit page. + * + * @var OrderStatusEdit + */ + protected $orderStatusEdit; + + /** + * Order Index page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * OrderStatus Fixture. + * + * @var OrderStatus + */ + protected $orderStatus; + + /** + * OrderStatus Fixture. + * + * @var OrderStatus + */ + protected $orderStatusInitial; + + /** + * OrderInjectable Fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Injection data. + * + * @param OrderStatusIndex $orderStatusIndex + * @param OrderStatusEdit $orderStatusEdit + * @param OrderIndex $orderIndex + * @return void + */ + public function __inject( + OrderStatusIndex $orderStatusIndex, + OrderStatusEdit $orderStatusEdit, + OrderIndex $orderIndex + ) { + $this->orderStatusIndex = $orderStatusIndex; + $this->orderStatusEdit = $orderStatusEdit; + $this->orderIndex = $orderIndex; + } + + /** + * Run Update Custom OrderStatus Test. + * + * @param OrderStatus $orderStatusInitial + * @param OrderStatus $orderStatus + * @param OrderInjectable $order + * @param FixtureFactory $fixtureFactory + * @param string $orderExist + * @return array + */ + public function test( + OrderStatus $orderStatusInitial, + OrderStatus $orderStatus, + OrderInjectable $order, + FixtureFactory $fixtureFactory, + $orderExist + ) { + // Preconditions: + $orderStatusInitial->persist(); + if ($orderExist == 'Yes') { + $order->persist(); + } + // Steps: + $this->orderStatusIndex->open(); + $this->orderStatusIndex->getOrderStatusGrid()->searchAndOpen(['label' => $orderStatusInitial->getLabel()]); + $this->orderStatusEdit->getOrderStatusForm()->fill($orderStatus); + $this->orderStatusEdit->getFormPageActions()->save(); + + // Configuring orderStatus for asserts. + $orderStatus = $fixtureFactory->createByCode( + 'orderStatus', + ['data' => array_merge($orderStatusInitial->getData(), $orderStatus->getData())] + ); + + // Prepare data for tear down + $this->orderStatus = $orderStatus; + $this->orderStatusInitial = $orderStatusInitial; + $this->order = $order; + + return [ + 'orderStatus' => $orderStatus, + 'status' => $orderStatus->getLabel(), + 'customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer() + ]; + } + + /** + * Change created order status and unassign custom order status if order was created. + * + * @return void + */ + public function tearDown() + { + if ($this->order->hasData('id')) { + $this->orderIndex->open()->getSalesOrderGrid()->massaction([['id' => $this->order->getId()]], 'Cancel'); + $filter = ['label' => $this->orderStatus->getLabel(), 'status' => $this->orderStatusInitial->getStatus()]; + $this->orderStatusIndex->open()->getOrderStatusGrid()->searchAndUnassign($filter); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..3db975b7ed80ef2a51bca736ad384f19ec914aa5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/UpdateCustomOrderStatusTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\UpdateCustomOrderStatusTest"> + <variation name="UpdateCustomOrderStatusTestVariation1"> + <data name="description" xsi:type="string">change status label to existed</data> + <data name="orderStatusInitial/dataSet" xsi:type="string">default</data> + <data name="orderExist" xsi:type="string">No</data> + <data name="orderStatus/data/label" xsi:type="string">Processing</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + </variation> + <variation name="UpdateCustomOrderStatusTestVariation2"> + <data name="description" xsi:type="string">change status label to new and check orderStatus for order with changed orderStatus</data> + <data name="orderStatusInitial/dataSet" xsi:type="string">assign_to_pending</data> + <data name="orderExist" xsi:type="string">Yes</data> + <data name="orderStatus/data/label" xsi:type="string">orderLabel%isolation%</data> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusSuccessCreateMessage" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderStatusInGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGrid" /> + <constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/AddRecentlyViewedProductsToCartStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/AddRecentlyViewedProductsToCartStep.php index d995a2c78298b4d2932cf9836377407933f321eb..c642f0e5ccee6a3e86fdf0dc7768440222d3dac1 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/AddRecentlyViewedProductsToCartStep.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/AddRecentlyViewedProductsToCartStep.php @@ -47,21 +47,7 @@ class AddRecentlyViewedProductsToCartStep implements TestStepInterface public function run() { $recentlyBlock = $this->orderCreateIndex->getCustomerActivitiesBlock(); - $recentlyBlock->getRecentlyViewedItemsBlock()->addToOrderByName($this->extractProductNames()); + $recentlyBlock->getRecentlyViewedItemsBlock()->addProductsToOrder($this->products); $recentlyBlock->updateChanges(); } - - /** - * Extract products name. - * - * @return array - */ - protected function extractProductNames() - { - $result = []; - foreach ($this->products as $product) { - $result[] = $product->getName(); - } - return $result; - } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php new file mode 100644 index 0000000000000000000000000000000000000000..fa43917e81db2e7454503c886f21e2dc7550ecdc --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php @@ -0,0 +1,106 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderCreditMemoNew; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Create credit memo from order on backend. + */ +class CreateCreditMemoStep implements TestStepInterface +{ + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * OrderCreditMemoNew Page. + * + * @var OrderCreditMemoNew + */ + protected $orderCreditMemoNew; + + /** + * OrderInjectable fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Credit memo data. + * + * @var array|null + */ + protected $data; + + /** + * @construct + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @param OrderInjectable $order + * @param OrderCreditMemoNew $orderCreditMemoNew + * @param array|null $data [optional] + */ + public function __construct( + OrderIndex $orderIndex, + SalesOrderView $salesOrderView, + OrderInjectable $order, + OrderCreditMemoNew $orderCreditMemoNew, + $data = null + ) { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + $this->order = $order; + $this->orderCreditMemoNew = $orderCreditMemoNew; + $this->data = $data; + } + + /** + * Create credit memo from order on backend. + * + * @return array + */ + public function run() + { + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); + $this->salesOrderView->getPageActions()->orderCreditMemo(); + if (!empty($this->data)) { + $this->orderCreditMemoNew->getFormBlock()->fillData($this->data, $this->order->getEntityId()['products']); + $this->orderCreditMemoNew->getFormBlock()->updateQty(); + } + $this->orderCreditMemoNew->getFormBlock()->submit(); + + return ['creditMemoIds' => $this->getCreditMemoIds()]; + } + + /** + * Get credit memo ids. + * + * @return array + */ + protected function getCreditMemoIds() + { + $this->salesOrderView->getOrderForm()->openTab('creditmemos'); + return $this->salesOrderView->getOrderForm()->getTabElement('creditmemos')->getGridBlock()->getIds(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateInvoiceStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateInvoiceStep.php new file mode 100644 index 0000000000000000000000000000000000000000..304f58063a029496d5b50dfb06dab0cdb02a4d9b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateInvoiceStep.php @@ -0,0 +1,146 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\OrderInvoiceNew; +use Magento\Sales\Test\Page\Adminhtml\OrderInvoiceView; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Shipping\Test\Page\Adminhtml\OrderShipmentView; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Create invoice from order on backend. + */ +class CreateInvoiceStep implements TestStepInterface +{ + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * Order New Invoice Page. + * + * @var OrderInvoiceNew + */ + protected $orderInvoiceNew; + + /** + * Order invoice view page. + * + * @var OrderInvoiceView + */ + protected $orderInvoiceView; + + /** + * Order shipment view page. + * + * @var OrderShipmentView + */ + protected $orderShipmentView; + + /** + * OrderInjectable fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Invoice data. + * + * @var array|null + */ + protected $data; + + /** + * @construct + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @param OrderInvoiceNew $orderInvoiceNew + * @param OrderInvoiceView $orderInvoiceView + * @param OrderInjectable $order + * @param OrderShipmentView $orderShipmentView + * @param array|null $data[optional] + */ + public function __construct( + OrderIndex $orderIndex, + SalesOrderView $salesOrderView, + OrderInvoiceNew $orderInvoiceNew, + OrderInvoiceView $orderInvoiceView, + OrderInjectable $order, + OrderShipmentView $orderShipmentView, + $data = null + ) { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + $this->orderInvoiceNew = $orderInvoiceNew; + $this->orderInvoiceView = $orderInvoiceView; + $this->order = $order; + $this->orderShipmentView = $orderShipmentView; + $this->data = $data; + } + + /** + * Create invoice (with shipment optionally) for order on backend. + * + * @return array + */ + public function run() + { + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); + $this->salesOrderView->getPageActions()->invoice(); + if (!empty($this->data)) { + $this->orderInvoiceNew->getFormBlock()->fillData($this->data, $this->order->getEntityId()['products']); + $this->orderInvoiceNew->getFormBlock()->updateQty(); + } + $this->orderInvoiceNew->getFormBlock()->submit(); + $invoiceIds = $this->getInvoiceIds(); + if (!empty($this->data)) { + $shipmentIds = $this->getShipmentIds(); + } + + return [ + 'invoiceIds' => $invoiceIds, + 'shipmentIds' => isset($shipmentIds) ? $shipmentIds : null, + ]; + } + + /** + * Get invoice ids. + * + * @return array + */ + protected function getInvoiceIds() + { + $this->salesOrderView->getOrderForm()->openTab('invoices'); + return $this->salesOrderView->getOrderForm()->getTabElement('invoices')->getGridBlock()->getIds(); + } + + /** + * Get shipment ids. + * + * @return array + */ + protected function getShipmentIds() + { + $this->salesOrderView->getOrderForm()->openTab('shipments'); + return $this->salesOrderView->getOrderForm()->getTabElement('shipments')->getGridBlock()->getIds(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateOrderStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateOrderStep.php new file mode 100644 index 0000000000000000000000000000000000000000..5373d0da6c99781491bf2ad6d7d2f0ed23e1f808 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateOrderStep.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Step for create order. + */ +class CreateOrderStep implements TestStepInterface +{ + /** + * Order. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Preparing step properties. + * + * @constructor + * @param OrderInjectable $order + */ + public function __construct(OrderInjectable $order) + { + $this->order = $order; + } + + /** + * Create order. + * + * @return array + */ + public function run() + { + $this->order->persist(); + + return ['products' => $this->order->getEntityId()['products'], 'order' => $this->order]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateShipmentStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateShipmentStep.php new file mode 100644 index 0000000000000000000000000000000000000000..1ea259d0e05cd8bab3aa9ffdbb4130114a86562d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateShipmentStep.php @@ -0,0 +1,116 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Shipping\Test\Page\Adminhtml\OrderShipmentNew; +use Magento\Shipping\Test\Page\Adminhtml\OrderShipmentView; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Create shipping from order on backend. + */ +class CreateShipmentStep implements TestStepInterface +{ + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * New Order Shipment Page. + * + * @var OrderShipmentNew + */ + protected $orderShipmentNew; + + /** + * Order shipment view page. + * + * @var OrderShipmentView + */ + protected $orderShipmentView; + + /** + * OrderInjectable fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * Invoice data. + * + * @var array|null + */ + protected $data; + + /** + * @construct + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @param OrderShipmentNew $orderShipmentNew + * @param OrderShipmentView $orderShipmentView + * @param OrderInjectable $order + * @param array|null $data [optional] + */ + public function __construct( + OrderIndex $orderIndex, + SalesOrderView $salesOrderView, + OrderShipmentNew $orderShipmentNew, + OrderShipmentView $orderShipmentView, + OrderInjectable $order, + $data = null + ) { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + $this->orderShipmentNew = $orderShipmentNew; + $this->orderShipmentView = $orderShipmentView; + $this->order = $order; + $this->data = $data; + } + + /** + * Create shipping for order on backend. + * + * @return array + */ + public function run() + { + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); + $this->salesOrderView->getPageActions()->ship(); + if (!empty($this->data)) { + $this->orderShipmentNew->getFormBlock()->fillData($this->data, $this->order->getEntityId()['products']); + } + $this->orderShipmentNew->getFormBlock()->submit(); + + return ['shipmentIds' => $this->getShipmentIds()]; + } + + /** + * Get shipment id. + * + * @return array + */ + public function getShipmentIds() + { + $this->salesOrderView->getOrderForm()->openTab('shipments'); + return $this->salesOrderView->getOrderForm()->getTabElement('shipments')->getGridBlock()->getIds(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OnHoldStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OnHoldStep.php new file mode 100644 index 0000000000000000000000000000000000000000..ede5372c7f4bdb1cd91b42a5ee7eb2a68bf74b2d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OnHoldStep.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Sales\Test\Page\Adminhtml\SalesOrderView; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * On hold order on backend. + */ +class OnHoldStep implements TestStepInterface +{ + /** + * Orders Page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order View Page. + * + * @var SalesOrderView + */ + protected $salesOrderView; + + /** + * OrderInjectable fixture. + * + * @var OrderInjectable + */ + protected $order; + + /** + * @construct + * @param OrderIndex $orderIndex + * @param SalesOrderView $salesOrderView + * @param OrderInjectable $order + */ + public function __construct(OrderIndex $orderIndex, SalesOrderView $salesOrderView, OrderInjectable $order) + { + $this->orderIndex = $orderIndex; + $this->salesOrderView = $salesOrderView; + $this->order = $order; + } + + /** + * On hold order on backend. + * + * @return void + */ + public function run() + { + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); + $this->salesOrderView->getPageActions()->hold(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenOrderStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenOrderStep.php new file mode 100644 index 0000000000000000000000000000000000000000..d82b38e263d797a526c9f8bad5c39b213c8457c4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenOrderStep.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\Adminhtml\OrderIndex; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Open order step. + */ +class OpenOrderStep implements TestStepInterface +{ + /** + * Sales order index page. + * + * @var OrderIndex + */ + protected $orderIndex; + + /** + * Order instance. + * + * @var OrderInjectable + */ + protected $order; + + /** + * @constructor + * @param OrderInjectable $order + * @param OrderIndex $orderIndex + */ + public function __construct(OrderInjectable $order, OrderIndex $orderIndex) + { + $this->orderIndex = $orderIndex; + $this->order = $order; + } + + /** + * Open order. + * + * @return void + */ + public function run() + { + $this->orderIndex->open(); + $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenSalesOrderOnFrontendForGuestStep.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenSalesOrderOnFrontendForGuestStep.php new file mode 100644 index 0000000000000000000000000000000000000000..783f7e0f37c7c60f4325508d6410b046b4a98ead --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/OpenSalesOrderOnFrontendForGuestStep.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\TestStep; + +use Magento\Cms\Test\Page\CmsIndex; +use Magento\Customer\Test\Page\CustomerAccountLogout; +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Sales\Test\Page\SalesGuestForm; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Open sales order page on frontend for guest. + */ +class OpenSalesOrderOnFrontendForGuestStep implements TestStepInterface +{ + /** + * Customer log out page. + * + * @var CustomerAccountLogout + */ + protected $customerAccountLogout; + + /** + * Cms index page. + * + * @var CmsIndex + */ + protected $cmsIndex; + + /** + * Sales guest page. + * + * @var SalesGuestForm + */ + protected $salesGuestForm; + + /** + * Fixture order. + * + * @var OrderInjectable + */ + protected $order; + + /** + * @constructor + * @param CustomerAccountLogout $customerAccountLogout + * @param CmsIndex $cmsIndex + * @param SalesGuestForm $salesGuestForm + * @param OrderInjectable $order + */ + public function __construct( + CustomerAccountLogout $customerAccountLogout, + CmsIndex $cmsIndex, + SalesGuestForm $salesGuestForm, + OrderInjectable $order + ) { + $this->customerAccountLogout = $customerAccountLogout; + $this->cmsIndex = $cmsIndex; + $this->salesGuestForm = $salesGuestForm; + $this->order = $order; + } + + /** + * Run step. + * + * @return void + */ + public function run() + { + $this->customerAccountLogout->open(); + $this->cmsIndex->getFooterBlock()->clickLink('Orders and Returns'); + $this->salesGuestForm->getSearchForm()->fill($this->order); + $this->salesGuestForm->getSearchForm()->submit(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/etc/testcase.xml index 4e5838f04aecf4c22d2ccb9ab95d93a37ffd415e..4e7817f293e701d2d0254be667ed8be7eadba345 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/etc/testcase.xml @@ -35,11 +35,7 @@ </scenario> <scenario name="MoveRecentlyViewedProductsOnOrderPageTest" firstStep="createProducts"> <step name="createProducts" module="Magento_Catalog" next="createCustomer" /> - <step name="createCustomer" module="Magento_Customer" next="loginCustomerOnFrontend"> - <item name="customer"> - <item name="dataSet" value="default" /> - </item> - </step> + <step name="createCustomer" module="Magento_Customer" next="loginCustomerOnFrontend" /> <step name="loginCustomerOnFrontend" module="Magento_Customer" next="openProductsOnFrontend" /> <step name="openProductsOnFrontend" module="Magento_Catalog" next="openCustomerOnBackend" /> <step name="openCustomerOnBackend" module="Magento_Customer" next="createOrderFromCustomerAccount" /> @@ -50,26 +46,14 @@ </scenario> <scenario name="PrintOrderFrontendGuestTest" firstStep="createProducts"> <step name="createProducts" module="Magento_Catalog" next="createCustomer" /> - <step name="createCustomer" module="Magento_Customer" next="openSalesOrders"> - <item name="customer"> - <item name="dataSet" value="johndoe_with_addresses" /> - </item> - </step> + <step name="createCustomer" module="Magento_Customer" next="openSalesOrders" /> <step name="openSalesOrders" module="Magento_Sales" next="createNewOrder" /> <step name="createNewOrder" module="Magento_Sales" next="selectCustomerOrder" /> <step name="selectCustomerOrder" module="Magento_Sales" next="selectStore" /> <step name="selectStore" module="Magento_Sales" next="addProducts" /> <step name="addProducts" module="Magento_Sales" next="fillBillingAddress" /> - <step name="fillBillingAddress" module="Magento_Sales" next="selectPaymentMethodForOrder"> - <item name="billingAddress"> - <item name="dataSet" value="customer_US" /> - </item> - </step> - <step name="selectPaymentMethodForOrder" module="Magento_Sales" next="selectShippingMethodForOrder"> - <item name="payment"> - <item name="method" value="checkmo" /> - </item> - </step> + <step name="fillBillingAddress" module="Magento_Sales" next="selectPaymentMethodForOrder" /> + <step name="selectPaymentMethodForOrder" module="Magento_Sales" next="selectShippingMethodForOrder" /> <step name="selectShippingMethodForOrder" module="Magento_Sales" next="submitOrder" /> <step name="submitOrder" module="Magento_Sales" next="openSalesOrderOnFrontendForGuest" /> <step name="openSalesOrderOnFrontendForGuest" module="Magento_Sales" next="printOrderOnFrontend" /> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Grid.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Grid.php new file mode 100644 index 0000000000000000000000000000000000000000..02d2e2652fad958f5dbde7807cc33c1b6ae18e10 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Grid.php @@ -0,0 +1,83 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Block\Adminhtml\Promo; + +use Magento\Mtf\Client\Locator; + +/** + * Backend sales rule grid. + */ +class Grid extends \Magento\Backend\Test\Block\Widget\Grid +{ + /** + * Id of a row selector. + * + * @var string + */ + protected $rowIdSelector = 'td.col-rule_id'; + + /** + * Locator for promo quote form. + * + * @var string + */ + protected $promoQuoteFormSelector = 'div#promo_catalog_edit_tabs'; + + /** + * First row selector + * + * @var string + */ + protected $firstRowSelector = '//tr[1]/td[@data-column="name"]'; + + /** + * Filters array mapping. + * + * @var array + */ + protected $filters = [ + 'rule_id' => [ + 'selector' => '#promo_quote_grid_filter_rule_id', + ], + 'name' => [ + 'selector' => 'input[name="name"]', + ], + ]; + + /** + * Locator value for link in sales rule name column. + * + * @var string + */ + protected $editLink = 'td[class*=col-name]'; + + /** + * An element locator which allows to select entities in grid. + * + * @var string + */ + protected $selectItem = 'tbody tr .col-name'; + + /** + * Return the id of the row that matched the search filter. + * + * @param $filter + * @param bool $isSearchable + * @return array|int|string + */ + public function getIdOfRow($filter, $isSearchable = true) + { + $rid = -1; + $this->search($filter, $isSearchable); + $rowItem = $this->_rootElement->find($this->rowItem, Locator::SELECTOR_CSS); + if ($rowItem->isVisible()) { + $idElement = $rowItem->find($this->rowIdSelector); + $rid = $idElement->getText(); + } + return $rid; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php new file mode 100644 index 0000000000000000000000000000000000000000..9a2b007711a0dde54bb0dbb61aa80122318f7e79 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit; + +use Magento\Backend\Test\Block\Widget\FormTabs; + +/** + * Sales rule edit form. + */ +class PromoQuoteForm extends FormTabs +{ + /** + * Selector of element to wait for. If set by child will wait for element after action + * + * @var string + */ + protected $waitForSelector = 'div#promo_catalog_edit_tabs'; + + /** + * Wait for should be for visibility or not? + * + * @var boolean + */ + protected $waitForSelectorVisible = false; +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml new file mode 100644 index 0000000000000000000000000000000000000000..756e14f274fa065bdd3ce9914a5d41d6e778841d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<tabs> + <rule_information> + <class>\Magento\Backend\Test\Block\Widget\Tab</class> + <selector>#promo_catalog_edit_tabs_main_section</selector> + <strategy>css selector</strategy> + <fields> + <name /> + <description /> + <is_active> + <input>select</input> + </is_active> + <website_ids> + <selector>[name="website_ids[]"]</selector> + <input>multiselect</input> + </website_ids> + <customer_group_ids> + <selector>[name="customer_group_ids[]"]</selector> + <input>multiselect</input> + </customer_group_ids> + <coupon_type> + <input>select</input> + </coupon_type> + <coupon_code /> + <uses_per_coupon /> + <uses_per_customer /> + <from_date /> + <to_date /> + <sort_order /> + <is_rss> + <input>select</input> + </is_rss> + </fields> + </rule_information> + <conditions> + <class>\Magento\Backend\Test\Block\Widget\Tab</class> + <selector>#promo_catalog_edit_tabs_conditions_section</selector> + <strategy>css selector</strategy> + <fields> + <conditions_serialized> + <selector>#rule_conditions_fieldset</selector> + <input>conditions</input> + </conditions_serialized> + </fields> + </conditions> + <actions> + <class>\Magento\Backend\Test\Block\Widget\Tab</class> + <selector>#promo_catalog_edit_tabs_actions_section</selector> + <strategy>css selector</strategy> + <fields> + <simple_action> + <input>select</input> + </simple_action> + <discount_amount /> + <discount_qty /> + <discount_step /> + <apply_to_shipping> + <input>select</input> + </apply_to_shipping> + <stop_rules_processing> + <input>select</input> + </stop_rules_processing> + <simple_free_shipping> + <input>select</input> + </simple_free_shipping> + <actions_serialized> + <selector>#rule_actions_fieldset</selector> + <input>conditions</input> + </actions_serialized> + </fields> + </actions> + <labels> + <class>\Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Tab\Labels</class> + <selector>#promo_catalog_edit_tabs_labels_section</selector> + <strategy>css selector</strategy> + </labels> +</tabs> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php new file mode 100644 index 0000000000000000000000000000000000000000..35ad53e038c1c94d20ee093d83b640ce7d590390 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Tab; + +use Magento\Mtf\Client\Element\SimpleElement; +use Magento\Backend\Test\Block\Widget\Tab; + +/** + * Sales rule condition tab. + */ +class Conditions extends Tab +{ + /** + * Field Prefix Constant + */ + const FIELD_PREFIX = '#conditions__1__'; + + /** + * Set the mapping and fill the form. + * + * @param array $fields + * @param SimpleElement|null $element + * @return $this + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + public function fillFormTab(array $fields, SimpleElement $element = null) + { + foreach ($fields as $key => $value) { + $this->mapping[$key] = self::FIELD_PREFIX . $key; + } + return parent::fillFormTab($fields, $element); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php new file mode 100644 index 0000000000000000000000000000000000000000..7805f1ec94f6ac91cdf3075d5f8f546626cdc407 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Tab/Labels.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Tab; + +use Magento\Backend\Test\Block\Widget\Tab; +use Magento\Mtf\Client\Element\SimpleElement; + +/** + * Backend sales rule label tab. + */ +class Labels extends Tab +{ + /** + * Store label field name. + */ + const STORE_LABEL_NAME = '[name="store_labels[%s]"]'; + + /** + * Fill data to labels fields on labels tab. + * + * @param array $fields + * @param SimpleElement|null $element + * @return $this + */ + public function fillFormTab(array $fields, SimpleElement $element = null) + { + if (isset($fields['store_labels'])) { + $count = 0; + foreach ($fields['store_labels']['value'] as $storeLabel) { + $element->find(sprintf(self::STORE_LABEL_NAME, $count))->setValue($storeLabel); + ++$count; + } + } + + return $this; + } + + /** + * Get data of labels tab. + * + * @param array|null $fields + * @param SimpleElement|null $element + * @return array + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getDataFormTab($fields = null, SimpleElement $element = null) + { + $context = $element === null ? $this->_rootElement : $element; + $storeLabels = []; + $count = 0; + $field = $context->find(sprintf(self::STORE_LABEL_NAME, $count)); + while ($field->isVisible()) { + $fieldValue = $field->getValue(); + if ($fieldValue != '') { + $storeLabels[$count] = $fieldValue; + } + ++$count; + $field = $context->find(sprintf(self::STORE_LABEL_NAME, $count)); + } + + return ['store_labels' => $storeLabels]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/Items.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/Items.php new file mode 100644 index 0000000000000000000000000000000000000000..5914551482f6ab10db655f07b811b185723865bc --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/Items.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Block\Order; + +/** + * Items block on order's view page. + */ +class Items extends \Magento\Sales\Test\Block\Order\Items +{ + /** + * Sales Rule selector. + * + * @var string + */ + protected $salesRuleSelector = '.discount > .amount > span.price'; + + /** + * Get sales rule discount. + * + * @return string + */ + public function getSalesRuleDiscount() + { + return $this->escapeCurrency($this->_rootElement->find($this->salesRuleSelector)->getText()); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/View.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/View.php new file mode 100644 index 0000000000000000000000000000000000000000..58c533220c5140b2dee350de44ae27ffb3292390 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Order/View.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Block\Order; + +use Magento\Mtf\Client\Locator; + +/** + * View block on order's view page. + */ +class View extends \Magento\Sales\Test\Block\Order\View +{ + /** + * Get item block. + * + * @param int $id [optional] + * @return Items + */ + public function getItemBlock($id = null) + { + $selector = ($id === null) ? $this->content : sprintf($this->itemBlock, $id) . $this->content; + return $this->blockFactory->create( + 'Magento\SalesRule\Test\Block\Order\Items', + ['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)] + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleApplying.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleApplying.php new file mode 100644 index 0000000000000000000000000000000000000000..1b573901d93ca029d529bf6c812e436b43d0ee05 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleApplying.php @@ -0,0 +1,209 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\Catalog\Test\Fixture\CatalogProductSimple; +use Magento\Catalog\Test\Page\Category\CatalogCategoryView; +use Magento\Catalog\Test\Page\Product\CatalogProductView; +use Magento\Checkout\Test\Page\CheckoutCart; +use Magento\Cms\Test\Page\CmsIndex; +use Magento\Customer\Test\Fixture\Address; +use Magento\Customer\Test\Fixture\Customer; +use Magento\Customer\Test\Page\CustomerAccountLogin; +use Magento\Customer\Test\Page\CustomerAccountLogout; +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Abstract class for implementing assert applying. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +abstract class AssertCartPriceRuleApplying extends AbstractConstraint +{ + /** + * Page CheckoutCart. + * + * @var CheckoutCart + */ + protected $checkoutCart; + + /** + * Page CmsIndex. + * + * @var CmsIndex + */ + protected $cmsIndex; + + /** + * Page CustomerAccountLogin. + * + * @var CustomerAccountLogin + */ + protected $customerAccountLogin; + + /** + * Page CustomerAccountLogout. + * + * @var CustomerAccountLogout + */ + protected $customerAccountLogout; + + /** + * Page CatalogCategoryView. + * + * @var CatalogCategoryView + */ + protected $catalogCategoryView; + + /** + * Page CatalogProductView. + * + * @var CatalogProductView + */ + protected $catalogProductView; + + /** + * Customer from precondition. + * + * @var Customer + */ + protected $customer; + + /** + * First product from precondition. + * + * @var CatalogProductSimple + */ + protected $productForSalesRule1; + + /** + * Second product from precondition. + * + * @var CatalogProductSimple + */ + protected $productForSalesRule2; + + /** + * Implementation assert. + * + * @return void + */ + abstract protected function assert(); + + /** + * 1. Navigate to frontend + * 2. If "Log Out" link is visible and "isLoggedIn" empty + * - makes logout + * 3. If "isLoggedIn" not empty + * - login as customer + * 4. Clear shopping cart + * 5. Add test product(s) to shopping cart with specify quantity + * 6. If "salesRule/data/coupon_code" not empty: + * - fill "Enter your code" input in Dіscount Codes + * - click "Apply Coupon" button + * 7. If "address/data/country_id" not empty: + * On Estimate Shipping and Tax: + * - fill Country, State/Province, Zip/Postal Code + * - click 'Get a Quote' button + * - select 'Flat Rate' shipping + * - click 'Update Total' button + * 8. Implementation assert + * + * @param CheckoutCart $checkoutCart + * @param CmsIndex $cmsIndex + * @param CustomerAccountLogin $customerAccountLogin + * @param CustomerAccountLogout $customerAccountLogout + * @param CatalogCategoryView $catalogCategoryView + * @param CatalogProductView $catalogProductView + * @param Customer $customer + * @param SalesRuleInjectable $salesRule + * @param SalesRuleInjectable $salesRuleOrigin + * @param array $productQuantity + * @param CatalogProductSimple $productForSalesRule1 + * @param CatalogProductSimple $productForSalesRule2 + * @param Address $address + * @param int|null $isLoggedIn + * @param array $shipping + * @return void + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + */ + public function processAssert( + CheckoutCart $checkoutCart, + CmsIndex $cmsIndex, + CustomerAccountLogin $customerAccountLogin, + CustomerAccountLogout $customerAccountLogout, + CatalogCategoryView $catalogCategoryView, + CatalogProductView $catalogProductView, + Customer $customer, + SalesRuleInjectable $salesRule, + SalesRuleInjectable $salesRuleOrigin, + array $productQuantity, + CatalogProductSimple $productForSalesRule1, + CatalogProductSimple $productForSalesRule2 = null, + Address $address = null, + $isLoggedIn = null, + array $shipping = [] + ) { + $this->checkoutCart = $checkoutCart; + $this->cmsIndex = $cmsIndex; + $this->customerAccountLogin = $customerAccountLogin; + $this->customerAccountLogout = $customerAccountLogout; + $this->catalogCategoryView = $catalogCategoryView; + $this->catalogProductView = $catalogProductView; + $this->customer = $customer; + $this->productForSalesRule1 = $productForSalesRule1; + $this->productForSalesRule2 = $productForSalesRule2; + $isLoggedIn ? $this->login() : $this->customerAccountLogout->open(); + $this->checkoutCart->open()->getCartBlock()->clearShoppingCart(); + $this->addProductsToCart($productQuantity); + $this->checkoutCart->open(); + if ($address !== null) { + $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address); + $this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping); + } + if ($salesRule->getCouponCode() || $salesRuleOrigin->getCouponCode()) { + $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode( + $salesRule->getCouponCode() ? $salesRule->getCouponCode() : $salesRuleOrigin->getCouponCode() + ); + } + $this->assert(); + } + + /** + * LogIn customer. + * + * @return void + */ + protected function login() + { + $this->objectManager->create( + 'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep', + ['customer' => $this->customer] + )->run(); + } + + /** + * Add products to cart. + * + * @param array $productQuantity + * @return void + */ + protected function addProductsToCart(array $productQuantity) + { + foreach ($productQuantity as $product => $quantity) { + if ($quantity > 0) { + $categoryName = $this->$product->getCategoryIds()[0]; + $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName); + $this->catalogCategoryView->getListProductBlock()->getProductItem($this->$product)->open(); + $this->catalogProductView->getViewBlock()->setQtyAndClickAddToCart($quantity); + $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); + } + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsApplied.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsApplied.php new file mode 100644 index 0000000000000000000000000000000000000000..55a3450a6e108f56d86c72c681135232309b0c5f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsApplied.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +/** + * Check that shopping cart subtotal not equals with grand total(excluding shipping price if exist). + */ +class AssertCartPriceRuleConditionIsApplied extends AssertCartPriceRuleApplying +{ + /** + * Assert that shopping cart subtotal not equals with grand total. + * + * @return void + */ + protected function assert() + { + $subTotal = $this->checkoutCart->getTotalsBlock()->getSubtotal(); + $grandTotal = $this->checkoutCart->getTotalsBlock()->getGrandTotal(); + + if ($this->checkoutCart->getTotalsBlock()->isVisibleShippingPriceBlock()) { + $shippingPrice = $this->checkoutCart->getTotalsBlock()->getShippingPrice(); + $grandTotal = number_format(($grandTotal - $shippingPrice), 2); + } + \PHPUnit_Framework_Assert::assertNotEquals( + $subTotal, + $grandTotal, + 'Shopping cart subtotal: \'' . $subTotal . '\' equals with grand total: \'' . $grandTotal . '\'' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return "Shopping cart subtotal doesn't equal to grand total - price rule has been applied."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsNotApplied.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsNotApplied.php new file mode 100644 index 0000000000000000000000000000000000000000..b1c0efdbff284fe2b9e48a8ceab0f85a9afa77f8 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleConditionIsNotApplied.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +/** + * Check that shopping cart subtotal equals with grand total (excluding shipping price if exist). + */ +class AssertCartPriceRuleConditionIsNotApplied extends AssertCartPriceRuleApplying +{ + /** + * Assert that shopping cart subtotal equals with grand total. + * + * @return void + */ + protected function assert() + { + $subTotal = $this->checkoutCart->getTotalsBlock()->getSubtotal(); + $grandTotal = $this->checkoutCart->getTotalsBlock()->getGrandTotal(); + + if ($this->checkoutCart->getTotalsBlock()->isVisibleShippingPriceBlock()) { + $shippingPrice = $this->checkoutCart->getTotalsBlock()->getShippingPrice(); + $grandTotal = number_format(($grandTotal - $shippingPrice), 2); + } + \PHPUnit_Framework_Assert::assertEquals( + $subTotal, + $grandTotal, + 'Shopping cart subtotal: \'' . $subTotal . '\' not equals with grand total: \'' . $grandTotal . '\'' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return "Shopping cart subtotal equals to grand total - price rule has not been applied."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleForm.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleForm.php new file mode 100644 index 0000000000000000000000000000000000000000..ccd77f877ced270b43d7bcc9f2081422676f0b58 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleForm.php @@ -0,0 +1,106 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Assert sales rule form. + */ +class AssertCartPriceRuleForm extends AbstractConstraint +{ + /** + * Skipped fields for verify data. + * + * @var array + */ + protected $skippedFields = [ + 'conditions_serialized', + 'actions_serialized', + 'from_date', + 'to_date', + 'id' + ]; + + /** + * Assert that displayed sales rule data on edit page(backend) equals passed from fixture. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @param PromoQuoteEdit $promoQuoteEdit + * @param SalesRuleInjectable $salesRule + * @param SalesRuleInjectable $salesRuleOrigin + * @return void + */ + public function processAssert( + PromoQuoteIndex $promoQuoteIndex, + PromoQuoteEdit $promoQuoteEdit, + SalesRuleInjectable $salesRule, + SalesRuleInjectable $salesRuleOrigin = null + ) { + $filter = [ + 'name' => $salesRule->hasData('name') ? $salesRule->getName() : $salesRuleOrigin->getName(), + ]; + + $promoQuoteIndex->open(); + $promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen($filter); + $formData = $promoQuoteEdit->getSalesRuleForm()->getData(); + $fixtureData = $salesRuleOrigin != null + ? array_merge($salesRuleOrigin->getData(), $salesRule->getData()) + : $salesRule->getData(); + $dataDiff = $this->verify($fixtureData, $formData); + \PHPUnit_Framework_Assert::assertTrue( + empty($dataDiff), + 'Sales rule data on edit page(backend) not equals to passed from fixture.' + . "\nFailed values:\n " . implode(";\n ", $dataDiff) + ); + } + + /** + * Verify data in form equals to passed from fixture. + * + * @param array $fixtureData + * @param array $formData + * @return array + */ + protected function verify(array $fixtureData, array $formData) + { + $errorMessage = []; + + foreach ($fixtureData as $key => $value) { + if (is_array($value)) { + $diff = array_diff($value, $formData[$key]); + $diff = array_merge($diff, array_diff($formData[$key], $value)); + if (!empty($diff)) { + $errorMessage[] = "Data in " . $key . " field is not equal." + . "\nExpected: " . implode(", ", $value) + . "\nActual: " . implode(", ", $formData[$key]); + } + } else { + if (!in_array($key, $this->skippedFields) && $value !== $formData[$key]) { + $errorMessage[] = "Data in " . $key . " field not equal." + . "\nExpected: " . $value + . "\nActual: " . $formData[$key]; + } + } + } + + return $errorMessage; + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Displayed sales rule data on edit page(backend) equals to passed from fixture.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleFreeShippingIsApplied.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleFreeShippingIsApplied.php new file mode 100644 index 0000000000000000000000000000000000000000..92814e0453ba21253a61e4d22b288a8ac8b418d5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleFreeShippingIsApplied.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +/** + * Check that shopping cart free shipping is applied. + */ +class AssertCartPriceRuleFreeShippingIsApplied extends AssertCartPriceRuleApplying +{ + const FREE_SHIPPING_PRICE = '0.00'; + + /** + * Assert that free shipping is applied in shopping cart. + * + * @return void + */ + protected function assert() + { + $shippingPrice = $this->checkoutCart->getTotalsBlock()->getShippingPrice(); + + \PHPUnit_Framework_Assert::assertEquals( + $shippingPrice, + self::FREE_SHIPPING_PRICE, + 'Current shipping price: \'' . $shippingPrice + . '\' not equals with free shipping price: \'' . self::FREE_SHIPPING_PRICE . '\'' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Free shipping is applied.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleIsNotPresentedInGrid.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleIsNotPresentedInGrid.php new file mode 100644 index 0000000000000000000000000000000000000000..4c2fd8856a08fdd1af69c5594124fef9443166f4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleIsNotPresentedInGrid.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Assert if sales rule is absent in grid. + */ +class AssertCartPriceRuleIsNotPresentedInGrid extends AbstractConstraint +{ + /** + * Assert that sales rule is not present in cart price rules grid. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @param SalesRuleInjectable $salesRule + * @return void + */ + public function processAssert(PromoQuoteIndex $promoQuoteIndex, SalesRuleInjectable $salesRule) + { + \PHPUnit_Framework_Assert::assertFalse( + $promoQuoteIndex->getPromoQuoteGrid()->isRowVisible(['name' => $salesRule->getName()]), + 'Sales rule \'' . $salesRule->getName() . '\' is present in cart price rules grid.' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Sales rule is not present in cart price rules grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessDeleteMessage.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessDeleteMessage.php new file mode 100644 index 0000000000000000000000000000000000000000..4c507b9605f409dbf1132308e66021b54ee994e3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessDeleteMessage.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Assert sales rule delte message. + */ +class AssertCartPriceRuleSuccessDeleteMessage extends AbstractConstraint +{ + /* tags */ + const SEVERITY = 'low'; + /* end tags */ + + const SUCCESS_DELETE_MESSAGE = 'The rule has been deleted.'; + + /** + * Assert that success message is displayed after sales rule delete. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @return void + */ + public function processAssert(PromoQuoteIndex $promoQuoteIndex) + { + $actualMessage = $promoQuoteIndex->getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_DELETE_MESSAGE, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::SUCCESS_DELETE_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Sales rule success delete message is present.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessSaveMessage.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessSaveMessage.php new file mode 100644 index 0000000000000000000000000000000000000000..409498a592682a5890945a2a9d979c631502f762 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleSuccessSaveMessage.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Assert sales rule save message. + */ +class AssertCartPriceRuleSuccessSaveMessage extends AbstractConstraint +{ + const SUCCESS_MESSAGE = 'The rule has been saved.'; + + /** + * Assert that success message is displayed after sales rule save. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @return void + */ + public function processAssert(PromoQuoteIndex $promoQuoteIndex) + { + $actualMessage = $promoQuoteIndex->getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_MESSAGE, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::SUCCESS_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Sales rule success save message is present.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertSalesRuleOnPrintOrder.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertSalesRuleOnPrintOrder.php new file mode 100644 index 0000000000000000000000000000000000000000..6c2afcd79bdc35b145038c8cd5311a3625c06e70 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertSalesRuleOnPrintOrder.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Constraint; + +use Magento\Sales\Test\Page\SalesGuestPrint; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Assert that sales rule amount printed correctly on sales guest print page. + */ +class AssertSalesRuleOnPrintOrder extends AbstractConstraint +{ + /** + * Assert that sales rule amount printed correctly on sales guest print page. + * + * @param SalesGuestPrint $salesGuestPrint + * @param string $salesRuleDiscount + * @return void + */ + public function processAssert(SalesGuestPrint $salesGuestPrint, $salesRuleDiscount) + { + \PHPUnit_Framework_Assert::assertEquals( + $salesRuleDiscount, + $salesGuestPrint->getViewSalesRule()->getItemBlock()->getSalesRuleDiscount(), + "Sales rule amount not equals." + ); + } + + /** + * Returns a string representation of successful assertion. + * + * @return string + */ + public function toString() + { + return "Sales rule amount was printed correctly."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable.xml new file mode 100644 index 0000000000000000000000000000000000000000..25f432794e8432456a08e315988cfe84f60525fb --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd"> + <fixture name="salesRuleInjectable" module="Magento_SalesRule" type="flat" entity_type="salesrule" collection="Magento\SalesRule\Model\Resource\Rule\Collection" repository_class="Magento\SalesRule\Test\Repository\SalesRuleInjectable" handler_interface="Magento\SalesRule\Test\Handler\SalesRuleInjectable\SalesRuleInjectableInterface" class="Magento\SalesRule\Test\Fixture\SalesRuleInjectable"> + <dataset name="default"> + <field name="name" xsi:type="string">Default price rule %isolation%</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + <item name="2" xsi:type="string">Wholesale</item> + <item name="3" xsi:type="string">Retailer</item> + </field> + <field name="coupon_type" xsi:type="string">No Coupon</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + </dataset> + <field name="rule_id" is_required="1" /> + <field name="name" group="rule_information"> + <default_value xsi:type="string">Default price rule %isolation%</default_value> + </field> + <field name="description" group="rule_information" /> + <field name="from_date" group="rule_information" source="Magento\Backend\Test\Fixture\Source\Date" /> + <field name="to_date" group="rule_information" source="Magento\Backend\Test\Fixture\Source\Date" /> + <field name="uses_per_customer" group="rule_information"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="is_active" group="rule_information"> + <default_value xsi:type="string">Active</default_value> + </field> + <field name="conditions_serialized" group="conditions" source="Magento\SalesRule\Test\Fixture\SalesRuleInjectable\ConditionsSerialized" /> + <field name="actions_serialized" group="actions" /> + <field name="stop_rules_processing" group="actions"> + <default_value xsi:type="string">1</default_value> + </field> + <field name="is_advanced"> + <default_value xsi:type="string">1</default_value> + </field> + <field name="product_ids" /> + <field name="sort_order" group="rule_information"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="simple_action" group="actions"> + <default_value xsi:type="string">Percent of product price discount</default_value> + </field> + <field name="discount_amount" group="actions"> + <default_value xsi:type="number">50</default_value> + </field> + <field name="discount_qty" group="actions" /> + <field name="discount_step" group="actions" /> + <field name="apply_to_shipping" group="actions"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="times_used"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="is_rss" group="rule_information"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="coupon_type" group="rule_information"> + <default_value xsi:type="string">No Coupon</default_value> + </field> + <field name="use_auto_generation" group="rule_information"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="uses_per_coupon" group="rule_information"> + <default_value xsi:type="number">0</default_value> + </field> + <field name="simple_free_shipping" group="actions" /> + <field name="id" /> + <field name="website_ids" group="rule_information"> + <default_value xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </default_value> + </field> + <field name="customer_group_ids" group="rule_information"> + <default_value xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + <item name="2" xsi:type="string">Wholesale</item> + <item name="3" xsi:type="string">Retailer</item> + </default_value> + </field> + <field name="store_labels" group="labels" /> + <field name="coupon_code" group="rule_information" /> + <field name="rule" /> + </fixture> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable/ConditionsSerialized.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable/ConditionsSerialized.php new file mode 100644 index 0000000000000000000000000000000000000000..4d9c65cff5333e179f7dc06f72f857f5da9baf54 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRuleInjectable/ConditionsSerialized.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Fixture\SalesRuleInjectable; + +use Magento\Mtf\Fixture\DataSource; + +/** + * Source for conditions serialized. + */ +class ConditionsSerialized extends DataSource +{ + /** + * Path to chooser grid class + * + * @var array + */ + protected $chooserGrid = []; + + /** + * Path to additional chooser grid class + * + * @var array + */ + protected $additionalChooserGrid = []; + + /** + * @constructor + * @param array $params + * @param string $data + */ + public function __construct(array $params, $data) + { + $this->chooserGrid = array_merge($this->chooserGrid, $this->additionalChooserGrid); + $this->params = $params; + foreach ($this->chooserGrid as $conditionsType => $chooserGrid) { + $data = preg_replace( + '#(' . preg_quote($conditionsType) . '\|.*?\|)([^\d].*?)#', + '${1}%' . $chooserGrid['class'] . '#' . $chooserGrid['field'] . '%${2}', + $data + ); + } + $this->data = $data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/Curl.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/Curl.php new file mode 100644 index 0000000000000000000000000000000000000000..2543ccdf8197195b9cdbdc2bdb6444ef5903a784 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/Curl.php @@ -0,0 +1,195 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Handler\SalesRuleInjectable; + +use Magento\Backend\Test\Handler\Conditions; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\Util\Protocol\CurlInterface; +use Magento\Mtf\Util\Protocol\CurlTransport; +use Magento\Mtf\Util\Protocol\CurlTransport\BackendDecorator; + +/** + * Curl handler for creating sales rule. + */ +class Curl extends Conditions implements SalesRuleInjectableInterface +{ + /** + * Map of type parameter. + * + * @var array + */ + protected $mapTypeParams = [ + 'Subtotal' => [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'base_subtotal', + ], + 'Conditions combination' => [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Combine', + 'aggregator' => 'all', + 'value' => '1', + ], + 'Shipping Country' => [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'country_id', + ], + 'Shipping Postcode' => [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'postcode', + ], + 'Category' => [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Product', + 'attribute' => 'category_ids', + ] + ]; + + /** + * Map of type additional parameter. + * + * @var array + */ + protected $additionalMapTypeParams = []; + + /** + * Mapping values for data. + * + * @var array + */ + protected $mappingData = [ + 'is_active' => [ + 'Active' => 1, + 'Inactive' => 0, + ], + 'coupon_type' => [ + 'No Coupon' => 1, + 'Specific Coupon' => 2, + 'Auto' => 3, + ], + 'is_rss' => [ + 'Yes' => 1, + 'No' => 2, + ], + 'simple_action' => [ + 'Percent of product price discount' => 'by_percent', + 'Fixed amount discount' => 'by_fixed', + 'Fixed amount discount for whole cart' => 'cart_fixed', + 'Buy X get Y free (discount amount is Y)' => 'buy_x_get_y', + ], + 'apply_to_shipping' => [ + 'Yes' => 1, + 'No' => 2, + ], + 'stop_rules_processing' => [ + 'Yes' => 1, + 'No' => 2, + ], + 'simple_free_shipping' => [ + 'No' => 0, + 'For matching items only' => 1, + 'For shipment with matching items' => 2, + ], + ]; + + /** + * Mapping values for Websites. + * + * @var array + */ + protected $websiteIds = [ + 'Main Website' => 1, + ]; + + /** + * Mapping values for customer group. + * + * @var array + */ + protected $customerIds = [ + 'NOT LOGGED IN' => 0, + 'General' => 1, + 'Wholesale' => 2, + 'Retailer' => 3, + ]; + + /** + * Post request for creating sales rule. + * + * @param FixtureInterface $fixture + * @return array + * @throws \Exception + */ + public function persist(FixtureInterface $fixture = null) + { + $this->mapTypeParams = array_merge($this->mapTypeParams, $this->additionalMapTypeParams); + $url = $_ENV['app_backend_url'] . 'sales_rule/promo_quote/save/'; + $data = $this->replaceMappingData($fixture->getData()); + $data['rule'] = []; + if (isset($data['conditions_serialized'])) { + $data['rule']['conditions'] = $this->prepareCondition($data['conditions_serialized']); + unset($data['conditions_serialized']); + } + + $data['website_ids'] = $this->prepareWebsites($data); + $data['customer_group_ids'] = $this->prepareCustomerGroup($data); + + if (isset($data['actions_serialized'])) { + $this->mapTypeParams['Conditions combination']['type'] = + 'Magento\SalesRule\Model\Rule\Condition\Product\Combine'; + $data['rule']['actions'] = $this->prepareCondition($data['actions_serialized']); + unset($data['actions_serialized']); + } + $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); + $curl->write(CurlInterface::POST, $url, '1.0', [], $data); + $response = $curl->read(); + $curl->close(); + if (!strpos($response, 'data-ui-id="messages-message-success"')) { + throw new \Exception("Sales rule entity creating by curl handler was not successful! Response: $response"); + } + + preg_match('`<tr.*title=".*sales_rule\/promo_quote\/edit\/id\/([\d]+)`ims', $response, $matches); + if (empty($matches)) { + throw new \Exception('Cannot find Sales Rule id'); + } + + return ['id' => $matches[1]]; + } + + /** + * Prepare website data for curl. + * + * @param array $data + * @return array + */ + protected function prepareWebsites(array $data) + { + $websiteIds = []; + if (!empty($data['website_ids'])) { + foreach ($data['website_ids'] as $name) { + $websiteIds[] = isset($this->websiteIds[$name]) ? $this->websiteIds[$name] : $name; + } + } + + return $websiteIds; + } + + /** + * Prepare customer group data for curl. + * + * @param array $data + * @return array + */ + protected function prepareCustomerGroup(array $data) + { + $groupIds = []; + if (!empty($data['customer_group_ids'])) { + foreach ($data['customer_group_ids'] as $name) { + $groupIds[] = isset($this->customerIds[$name]) ? $this->customerIds[$name] : $name; + } + } + + return $groupIds; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/SalesRuleInjectableInterface.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/SalesRuleInjectableInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..0a9c2598e8c49b16841c1efd0fda60e4d1d1d248 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Handler/SalesRuleInjectable/SalesRuleInjectableInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\Handler\SalesRuleInjectable; + +use Magento\Mtf\Handler\HandlerInterface; + +/** + * Interface SalesRuleInterface. + */ +interface SalesRuleInjectableInterface extends HandlerInterface +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteEdit.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteEdit.xml new file mode 100644 index 0000000000000000000000000000000000000000..23b3fe8d67b3aa5d93acb24f2f156893daff2730 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteEdit.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="PromoQuoteEdit" area="Adminhtml" mca="sales_rule/promo_quote/edit" module="Magento_SalesRule"> + <block name="formPageActions" class="Magento\Backend\Test\Block\FormPageActions" locator=".page-main-actions" strategy="css selector" /> + <block name="salesRuleForm" class="Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\PromoQuoteForm" locator="[id='page:main-container']" strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteIndex.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteIndex.xml new file mode 100644 index 0000000000000000000000000000000000000000..3c65c8a4ced63aff55114c7e1a47188d2539f65d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteIndex.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="PromoQuoteIndex" area="Adminhtml" mca="sales_rule/promo_quote/index" module="Magento_SalesRule"> + <block name="promoQuoteGrid" class="Magento\SalesRule\Test\Block\Adminhtml\Promo\Grid" locator="#promo_quote_grid" strategy="css selector" /> + <block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator="#messages" strategy="css selector" /> + <block name="gridPageActions" class="Magento\Backend\Test\Block\GridPageActions" locator=".page-main-actions" strategy="css selector" /> + <block name="systemMessageDialog" class="Magento\AdminNotification\Test\Block\System\Messages" locator='[role="dialog"].ui-popup-message' strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteNew.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteNew.xml new file mode 100644 index 0000000000000000000000000000000000000000..2b2fa68cfa4f2d53f2babbba07dc8a99fe829bc0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/Adminhtml/PromoQuoteNew.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="PromoQuoteNew" area="Adminhtml" mca="sales_rule/promo_quote/new" module="Magento_SalesRule"> + <block name="salesRuleForm" class="Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\PromoQuoteForm" locator="[id='page:main-container']" strategy="css selector" /> + <block name="formPageActions" class="Magento\Backend\Test\Block\FormPageActions" locator=".page-main-actions" strategy="css selector" /> + <block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator="#messages" strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/SalesGuestPrint.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/SalesGuestPrint.xml new file mode 100644 index 0000000000000000000000000000000000000000..db17a5c1271975c0e2da482d7173f9d90e527724 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Page/SalesGuestPrint.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="SalesGuestPrint" mca="sales/guest/print"> + <block name="viewSalesRule" class="Magento\SalesRule\Test\Block\Order\View" locator=".order-details-items" strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRuleInjectable.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRuleInjectable.xml new file mode 100644 index 0000000000000000000000000000000000000000..02d81f565a253de17ec04662a14bf162c330b256 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRuleInjectable.xml @@ -0,0 +1,176 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd"> + <repository class="Magento\SalesRule\Test\Repository\SalesRuleInjectable"> + <dataset name="active_sales_rule_with_percent_price_discount_coupon"> + <field name="name" xsi:type="string">Shopping Cart Price Rule with Specific Coupon %isolation%</field> + <field name="description" xsi:type="string">Description for Cart Price Rule</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + </field> + <field name="coupon_type" xsi:type="string">Specific Coupon</field> + <field name="coupon_code" xsi:type="string">123-abc-ABC-987-%isolation%</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + <field name="store_labels" xsi:type="array"> + <item name="0" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + <item name="1" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + </field> + </dataset> + + <dataset name="active_sales_rule_with_coupon_10"> + <field name="name" xsi:type="string">10% Off Coupon</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + </field> + <field name="coupon_type" xsi:type="string">Specific Coupon</field> + <field name="coupon_code" xsi:type="string">1234</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">10</field> + </dataset> + + <dataset name="active_sales_rule_with_fixed_price_discount_coupon"> + <field name="name" xsi:type="string">Shopping Cart Price Rule with Specific Coupon %isolation%</field> + <field name="description" xsi:type="string">Description for Cart Price Rule</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + </field> + <field name="coupon_type" xsi:type="string">Specific Coupon</field> + <field name="coupon_code" xsi:type="string">123-abc-ABC-987-%isolation%</field> + <field name="simple_action" xsi:type="string">Fixed amount discount</field> + <field name="discount_amount" xsi:type="string">50</field> + <field name="store_labels" xsi:type="array"> + <item name="0" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + <item name="1" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + </field> + </dataset> + + <dataset name="active_sales_rule_for_retailer"> + <field name="name" xsi:type="string">Shopping Cart Price Rule %isolation%</field> + <field name="description" xsi:type="string">Description for Cart Price Rule</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">Retailer</item> + </field> + <field name="coupon_type" xsi:type="string">No Coupon</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + <field name="stop_rules_processing" xsi:type="string">Yes</field> + </dataset> + + <dataset name="active_sales_rule_with_complex_conditions"> + <field name="name" xsi:type="string">Shopping Cart Price Rule with with complex conditions %isolation%</field> + <field name="description" xsi:type="string">Shopping Cart Price Rule with with complex conditions</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + <item name="2" xsi:type="string">Wholesale</item> + <item name="3" xsi:type="string">Retailer</item> + </field> + <field name="coupon_type" xsi:type="string">Specific Coupon</field> + <field name="coupon_code" xsi:type="string">123-abc-ABC-987-%isolation%</field> + <field name="uses_per_coupon" xsi:type="string">13</field> + <field name="uses_per_customer" xsi:type="string">63</field> + <field name="from_date" xsi:type="array"> + <item name="pattern" xsi:type="string">3/25/2014</item> + </field> + <field name="to_date" xsi:type="array"> + <item name="pattern" xsi:type="string">6/29/2024</item> + </field> + <field name="sort_order" xsi:type="string">1</field> + <field name="is_rss" xsi:type="string">Yes</field> + <field name="conditions_serialized" xsi:type="string">[Subtotal|is|300]{Conditions combination:[[Shipping Country|is|United States][Shipping Postcode|is|123456789a]]}</field> + <field name="actions_serialized" xsi:type="string">[Category|is|2]</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + <field name="discount_step" xsi:type="string">0</field> + <field name="apply_to_shipping" xsi:type="string">Yes</field> + <field name="stop_rules_processing" xsi:type="string">Yes</field> + <field name="simple_free_shipping" xsi:type="string">For matching items only</field> + <field name="store_labels" xsi:type="array"> + <item name="0" xsi:type="string">Shopping Cart Price Rule with with complex conditions</item> + <item name="1" xsi:type="string">Shopping Cart Price Rule with with complex conditions</item> + </field> + </dataset> + + <dataset name="inactive_sales_rule"> + <field name="name" xsi:type="string">Inactive Cart Price Rule %isolation%</field> + <field name="is_active" xsi:type="string">Inactive</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + </field> + <field name="coupon_type" xsi:type="string">No Coupon</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + </dataset> + + <dataset name="active_sales_rule_for_all_groups"> + <field name="name" xsi:type="string">Shopping Cart Price Rule with Specific Coupon %isolation%</field> + <field name="description" xsi:type="string">Description for Cart Price Rule</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + <item name="2" xsi:type="string">Wholesale</item> + <item name="3" xsi:type="string">Retailer</item> + </field> + <field name="coupon_type" xsi:type="string">Specific Coupon</field> + <field name="coupon_code" xsi:type="string">123-abc-ABC-987-%isolation%</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + <field name="store_labels" xsi:type="array"> + <item name="0" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + <item name="1" xsi:type="string">Shopping Cart price Rule with Specific Coupon</item> + </field> + </dataset> + + <dataset name="active_sales_rule_for_all_groups_no_coupon"> + <field name="name" xsi:type="string">Shopping Cart Price Rule with Specific Coupon %isolation%</field> + <field name="description" xsi:type="string">Description for Cart Price Rule</field> + <field name="is_active" xsi:type="string">Active</field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="string">Main Website</item> + </field> + <field name="customer_group_ids" xsi:type="array"> + <item name="0" xsi:type="string">NOT LOGGED IN</item> + <item name="1" xsi:type="string">General</item> + <item name="2" xsi:type="string">Wholesale</item> + <item name="3" xsi:type="string">Retailer</item> + </field> + <field name="coupon_type" xsi:type="string">No Coupon</field> + <field name="simple_action" xsi:type="string">Percent of product price discount</field> + <field name="discount_amount" xsi:type="string">50</field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..24bafea36fbe42b87673f83accf39b5a70ddc666 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php @@ -0,0 +1,147 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestCase; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteNew; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestCase\Injectable; + +/** + * Precondition: + * 1. 2 sub categories in Default Category are created. + * 2. 2 simple products are created and assigned to different subcategories by one for each. + * 3. Default customer are created. + * + * Steps: + * 1. Login to backend as admin. + * 2. Navigate to MARKETING > Cart Price Rule. + * 3. Create Cart Price rule according to dataset and click "Save" button. + * 4. Perform asserts. + * + * @group Shopping_Cart_Price_Rules_(CS) + * @ZephyrId MAGETWO-24855 + */ +class CreateSalesRuleEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Page PromoQuoteNew. + * + * @var PromoQuoteNew + */ + protected $promoQuoteNew; + + /** + * Page PromoQuoteEdit. + * + * @var PromoQuoteEdit + */ + protected $promoQuoteEdit; + + /** + * Page PromoQuoteIndex. + * + * @var PromoQuoteIndex + */ + protected $promoQuoteIndex; + + /** + * Sales rule name. + * + * @var string + */ + protected $salesRuleName; + + /** + * Inject pages. + * + * @param PromoQuoteNew $promoQuoteNew + * @param PromoQuoteIndex $promoQuoteIndex + * @param PromoQuoteEdit $promoQuoteEdit + * @return void + */ + public function __inject( + PromoQuoteNew $promoQuoteNew, + PromoQuoteIndex $promoQuoteIndex, + PromoQuoteEdit $promoQuoteEdit + ) { + $this->promoQuoteNew = $promoQuoteNew; + $this->promoQuoteIndex = $promoQuoteIndex; + $this->promoQuoteEdit = $promoQuoteEdit; + } + + /** + * Create customer and 2 simple products with categories before run test. + * + * @param FixtureFactory $fixtureFactory + * @return array + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $customer = $fixtureFactory->createByCode('customer', ['dataSet' => 'default']); + $customer->persist(); + + $productForSalesRule1 = $fixtureFactory->createByCode( + 'catalogProductSimple', + ['dataSet' => 'simple_for_salesrule_1'] + ); + $productForSalesRule1->persist(); + + $productForSalesRule2 = $fixtureFactory->createByCode( + 'catalogProductSimple', + ['dataSet' => 'simple_for_salesrule_2'] + ); + $productForSalesRule2->persist(); + + return [ + 'customer' => $customer, + 'productForSalesRule1' => $productForSalesRule1, + 'productForSalesRule2' => $productForSalesRule2 + ]; + } + + /** + * Create Sales Rule Entity. + * + * @param SalesRuleInjectable $salesRule + * @return void + */ + public function testCreateSalesRule(SalesRuleInjectable $salesRule) + { + // Preconditions + $this->salesRuleName = $salesRule->getName(); + + // Steps + $this->promoQuoteNew->open(); + $this->promoQuoteNew->getSalesRuleForm()->fill($salesRule); + $this->promoQuoteNew->getFormPageActions()->save(); + } + + /** + * Delete current sales rule. + * + * @return void + */ + public function tearDown() + { + $filter = [ + 'name' => $this->salesRuleName, + ]; + + $this->promoQuoteIndex->open(); + $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen($filter); + $this->promoQuoteEdit->getFormPageActions()->delete(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..0ff2064ad79fba1554e4e82552471a3c81422704 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -0,0 +1,264 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\SalesRule\Test\TestCase\CreateSalesRuleEntityTest"> + <variation name="CreateSalesRuleEntityTestVariation1"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule1 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Sales Cart Rule labels</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation2"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule2 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> + <data name="salesRule/data/coupon_code" xsi:type="string">1A2B3C-456-zxc-%isolation%</data> + <data name="salesRule/data/simple_action" xsi:type="string">Fixed amount discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">35</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Coupon code+fixed amount discount</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">2</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation3"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule3 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> + <data name="salesRule/data/coupon_code" xsi:type="string">Lorem ipsum dolor sit amet, consectetur adipiscing elit - %isolation%</data> + <data name="salesRule/data/simple_action" xsi:type="string">Fixed amount discount for whole cart</data> + <data name="salesRule/data/discount_amount" xsi:type="string">60</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Coupon code+Fixed amount discount for whole cart</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">3</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation4"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule4 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">Specific Coupon</data> + <data name="salesRule/data/coupon_code" xsi:type="string">1A2B3C-456-zxc-%isolation%</data> + <data name="salesRule/data/simple_action" xsi:type="string">Buy X get Y free (discount amount is Y)</data> + <data name="salesRule/data/discount_amount" xsi:type="string">1</data> + <data name="salesRule/data/discount_step" xsi:type="string">3</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Buy X get Y free</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">4</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation5"> + <data name="isLoggedIn" xsi:type="string">1</data> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule5 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">General</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/discount_qty" xsi:type="string">2</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">3</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation6"> + <data name="address/data/country_id" xsi:type="string">United States</data> + <data name="address/data/region_id" xsi:type="string">California</data> + <data name="address/data/postcode" xsi:type="string">95814</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule6 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">Yes</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Apply discount to Shipping Amount</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation7"> + <data name="address/data/country_id" xsi:type="string">United States</data> + <data name="address/data/region_id" xsi:type="string">California</data> + <data name="address/data/postcode" xsi:type="string">95814</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule7 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">For matching items only</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Free Shipping in conditions</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleFreeShippingIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation8"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule8 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">[Subtotal|is|150]</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Sales Cart Rule labels</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation9"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule9 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">[Subtotal|is|150]</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Subtotal Action-Condition test</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">2</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsNotApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation10"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule10 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">[Total Items Quantity|is|2]</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Total Items Quantity is 2</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">2</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation11"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule11 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">[Total Weight|is|150]</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Total Weight is 150</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation12"> + <data name="address/data/country_id" xsi:type="string">United States</data> + <data name="address/data/region_id" xsi:type="string">California</data> + <data name="address/data/postcode" xsi:type="string">95814</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule12 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">{Conditions combination:[[Shipping Method|is|\[flatrate\] Fixed][Shipping Postcode|is|95814][Shipping State/Province|is|California][Shipping Country|is|United States]]}</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Rule applied conditions combination</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + <variation name="CreateSalesRuleEntityTestVariation13"> + <data name="salesRule/data/name" xsi:type="string">Shopping Cart Price Rule13 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Shopping Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/website_0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/group_0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">{Product attribute combination:[Attribute Set|is|Default]}</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/store_labels_0" xsi:type="string">Product attribute discount</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..49f3e7655790d8cf6ec4842d2861cc55692e5a72 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestCase; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\TestCase\Injectable; + +/** + * Precondition: + * 1. Several Shopping Cart Price Rules are created. + * + * Steps: + * 1. Login to backend. + * 2. Navigate to MARKETING > Cart Price Rules. + * 3. Open from grid test Rule. + * 4. Click 'Delete' button. + * 5. Perform asserts. + * + * @group Shopping_Cart_Price_Rules_(CS) + * @ZephyrId MAGETWO-24985 + */ +class DeleteSalesRuleEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Page PromoQuoteEdit. + * + * @var PromoQuoteEdit + */ + protected $promoQuoteEdit; + + /** + * Page PromoQuoteIndex. + * + * @var PromoQuoteIndex + */ + protected $promoQuoteIndex; + + /** + * Inject pages. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @param PromoQuoteEdit $promoQuoteEdit + */ + public function __inject( + PromoQuoteIndex $promoQuoteIndex, + PromoQuoteEdit $promoQuoteEdit + ) { + $this->promoQuoteIndex = $promoQuoteIndex; + $this->promoQuoteEdit = $promoQuoteEdit; + } + + /** + * Delete Sales Rule Entity. + * + * @param SalesRuleInjectable $salesRule + * @return void + */ + public function testDeleteSalesRule(SalesRuleInjectable $salesRule) + { + // Preconditions + $salesRule->persist(); + + // Steps + $this->promoQuoteIndex->open(); + $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen(['name' => $salesRule->getName()]); + $this->promoQuoteEdit->getFormPageActions()->delete(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..2d76e09d87b8cdfb29e6b3b8b1ca4236a4a9a3dd --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/DeleteSalesRuleEntityTest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\SalesRule\Test\TestCase\DeleteSalesRuleEntityTest"> + <variation name="DeleteSalesRuleEntityTestVariation1"> + <data name="salesRule/dataSet" xsi:type="string">active_sales_rule_with_percent_price_discount_coupon</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessDeleteMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleIsNotPresentedInGrid" /> + </variation> + <variation name="DeleteSalesRuleEntityTestVariation2"> + <data name="salesRule/dataSet" xsi:type="string">active_sales_rule_with_complex_conditions</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessDeleteMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleIsNotPresentedInGrid" /> + </variation> + <variation name="DeleteSalesRuleEntityTestVariation3"> + <data name="salesRule/dataSet" xsi:type="string">inactive_sales_rule</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessDeleteMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleIsNotPresentedInGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ed72d923f05b1911611a38244d9f5e2b79c5d669 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.php @@ -0,0 +1,132 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestCase; + +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestCase\Injectable; + +/** + * Precondition: + * 1. Cart Price Rule is created. + * + * Steps: + * 1. Login to backend. + * 2. Navigate to MARKETING > Cart Price Rules. + * 3. Click Cart Price Rule from grid. + * 4. Edit test value(s) according to dataset. + * 5. Click 'Save' button. + * 6. Perform asserts. + * + * @group Shopping_Cart_Price_Rules_(CS) + * @ZephyrId MAGETWO-24860 + */ +class UpdateSalesRuleEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + const TO_MAINTAIN = 'yes'; + /* end tags */ + + /** + * Page PromoQuoteEdit. + * + * @var PromoQuoteEdit + */ + protected $promoQuoteEdit; + + /** + * Page PromoQuoteIndex. + * + * @var PromoQuoteIndex + */ + protected $promoQuoteIndex; + + /** + * Sales rule name. + * + * @var string + */ + protected $salesRuleName; + + /** + * Create simple product with category. + * + * @param FixtureFactory $fixtureFactory + * @return array + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $productForSalesRule1 = $fixtureFactory->createByCode( + 'catalogProductSimple', + ['dataSet' => 'simple_for_salesrule_1'] + ); + $productForSalesRule1->persist(); + return [ + 'productForSalesRule1' => $productForSalesRule1, + ]; + } + + /** + * Inject pages. + * + * @param PromoQuoteIndex $promoQuoteIndex + * @param PromoQuoteEdit $promoQuoteEdit + * @return void + */ + public function __inject( + PromoQuoteIndex $promoQuoteIndex, + PromoQuoteEdit $promoQuoteEdit + ) { + $this->promoQuoteIndex = $promoQuoteIndex; + $this->promoQuoteEdit = $promoQuoteEdit; + } + + /** + * Update Sales Rule Entity. + * + * @param SalesRuleInjectable $salesRule + * @param SalesRuleInjectable $salesRuleOrigin + * @return void + */ + public function testUpdateSalesRule( + SalesRuleInjectable $salesRule, + SalesRuleInjectable $salesRuleOrigin + ) { + // Preconditions + $salesRuleOrigin->persist(); + $filter = [ + 'name' => $salesRuleOrigin->getName(), + ]; + $this->salesRuleName = $salesRule->hasData('name') ? $salesRule->getName() : $salesRuleOrigin->getName(); + + // Steps + $this->promoQuoteIndex->open(); + $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen($filter); + $this->promoQuoteEdit->getSalesRuleForm()->fill($salesRule); + $this->promoQuoteEdit->getFormPageActions()->save(); + } + + /** + * Delete current sales rule. + * + * @return void + */ + public function tearDown() + { + $filter = [ + 'name' => $this->salesRuleName, + ]; + + $this->promoQuoteIndex->open(); + $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen($filter); + $this->promoQuoteEdit->getFormPageActions()->delete(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..f4f2c01eeccecd1c2ca4136cf63606d93f27d4ca --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/UpdateSalesRuleEntityTest.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\SalesRule\Test\TestCase\UpdateSalesRuleEntityTest"> + <variation name="UpdateSalesRuleEntityTestVariation1"> + <data name="salesRuleOrigin/dataSet" xsi:type="string">active_sales_rule_with_complex_conditions</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">{Conditions combination:[[Shipping Method|is|\[flatrate\] Fixed][Shipping Postcode|is|95814][Shipping State/Province|is|California][Shipping Country|is|United States]]}</data> + <data name="salesRule/data/simple_action" xsi:type="string">Buy X get Y free (discount amount is Y)</data> + <data name="salesRule/data/discount_amount" xsi:type="string">1</data> + <data name="salesRule/data/discount_step" xsi:type="string">3</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">4</data> + <data name="address/data/country_id" xsi:type="string">United States</data> + <data name="address/data/region_id" xsi:type="string">California</data> + <data name="address/data/postcode" xsi:type="string">95814</data> + <data name="shipping/shipping_service" xsi:type="string">Flat Rate</data> + <data name="shipping/shipping_method" xsi:type="string">Fixed</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage"/> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm"/> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied"/> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnBackendStep.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnBackendStep.php new file mode 100644 index 0000000000000000000000000000000000000000..7e193a4d0ab1cc570bbbebad6dedda8c57946c6d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnBackendStep.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestStep; + +use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex; +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Apply Sales Rule on backend. + */ +class ApplySalesRuleOnBackendStep implements TestStepInterface +{ + /** + * Order Create Index. + * + * @var OrderCreateIndex + */ + protected $orderCreateIndex; + + /** + * SalesRule fixture. + * + * @var SalesRuleInjectable + */ + protected $salesRule; + + /** + * @constructor + * @param OrderCreateIndex $orderCreateIndex + * @param SalesRuleInjectable $salesRule + */ + public function __construct(OrderCreateIndex $orderCreateIndex, SalesRuleInjectable $salesRule = null) + { + $this->orderCreateIndex = $orderCreateIndex; + $this->salesRule = $salesRule; + } + + /** + * Apply gift card before one page checkout. + * + * @return void + */ + public function run() + { + if ($this->salesRule !== null) { + $this->orderCreateIndex->getCouponsBlock()->applyCouponCode($this->salesRule); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnFrontendStep.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnFrontendStep.php new file mode 100644 index 0000000000000000000000000000000000000000..6bff54ec11dee9b17a78f52478fff86e8652457d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnFrontendStep.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestStep; + +use Magento\Checkout\Test\Page\CheckoutCart; +use Magento\SalesRule\Test\Fixture\SalesRuleInjectable; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Apply Sales Rule before one page checkout. + */ +class ApplySalesRuleOnFrontendStep implements TestStepInterface +{ + /** + * Checkout cart page. + * + * @var CheckoutCart + */ + protected $checkoutCart; + + /** + * SalesRule fixture. + * + * @var SalesRuleInjectable + */ + protected $salesRule; + + /** + * @constructor + * @param CheckoutCart $checkoutCart + * @param SalesRuleInjectable $salesRule + */ + public function __construct(CheckoutCart $checkoutCart, SalesRuleInjectable $salesRule = null) + { + $this->checkoutCart = $checkoutCart; + $this->salesRule = $salesRule; + } + + /** + * Apply coupon before one page checkout. + * + * @return void + */ + public function run() + { + if ($this->salesRule !== null) { + $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($this->salesRule->getCouponCode()); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/CreateSalesRuleStep.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/CreateSalesRuleStep.php new file mode 100644 index 0000000000000000000000000000000000000000..c458bed8659ad8e8b3d2d381a1601ecfade3e163 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/CreateSalesRuleStep.php @@ -0,0 +1,63 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestStep; + +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Creating sales rule. + */ +class CreateSalesRuleStep implements TestStepInterface +{ + /** + * Sales Rule coupon. + * + * @var string + */ + protected $salesRule; + + /** + * Factory for Fixture. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + + /** + * Preparing step properties. + * + * @constructor + * @param FixtureFactory $fixtureFactory + * @param string $salesRule + */ + public function __construct(FixtureFactory $fixtureFactory, $salesRule = null) + { + $this->fixtureFactory = $fixtureFactory; + $this->salesRule = $salesRule; + } + + /** + * Create sales rule. + * + * @return array + */ + public function run() + { + $result['salesRule'] = null; + if ($this->salesRule !== null) { + $salesRule = $this->fixtureFactory->createByCode( + 'salesRuleInjectable', + ['dataSet' => $this->salesRule] + ); + $salesRule->persist(); + $result['salesRule'] = $salesRule; + } + + return $result; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/DeleteAllSalesRuleStep.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/DeleteAllSalesRuleStep.php new file mode 100644 index 0000000000000000000000000000000000000000..0141a0506fd6e926987234027c894c7462c01245 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/DeleteAllSalesRuleStep.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\SalesRule\Test\TestStep; + +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; +use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; +use Magento\Mtf\TestStep\TestStepInterface; + +/** + * Delete all Sales Rule on backend. + */ +class DeleteAllSalesRuleStep implements TestStepInterface +{ + /** + * Promo Quote index page. + * + * @var PromoQuoteIndex + */ + protected $promoQuoteIndex; + + /** + * Promo Quote edit page. + * + * @var PromoQuoteEdit + */ + protected $promoQuoteEdit; + + /** + * @construct + * @param PromoQuoteIndex $promoQuoteIndex + * @param PromoQuoteEdit $promoQuoteEdit + */ + public function __construct( + PromoQuoteIndex $promoQuoteIndex, + PromoQuoteEdit $promoQuoteEdit + ) { + $this->promoQuoteIndex = $promoQuoteIndex; + $this->promoQuoteEdit = $promoQuoteEdit; + } + + /** + * Delete Sales Rule on backend. + * + * @return array + */ + public function run() + { + $this->promoQuoteIndex->open(); + while ($this->promoQuoteIndex->getPromoQuoteGrid()->isFirstRowVisible()) { + $this->promoQuoteIndex->getPromoQuoteGrid()->openFirstRow(); + $this->promoQuoteEdit->getFormPageActions()->delete(); + $this->promoQuoteIndex->getSystemMessageDialog()->closePopup(); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/curl/di.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/curl/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..2591249e9e02850c5123b9c66a0652a7bd5cfa00 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/curl/di.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> + <preference for="Magento\SalesRule\Test\Handler\SalesRuleInjectable\SalesRuleInjectableInterface" type="\Magento\SalesRule\Test\Handler\SalesRuleInjectable\Curl" /> +</config> diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/testcase.xml new file mode 100644 index 0000000000000000000000000000000000000000..ee5c69ad94715ea590bd880b56e73c54d815872e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/etc/testcase.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/TestCase/etc/testcase.xsd"> + <scenario name="OnePageCheckoutTest"> + <step name="createSalesRule" module="Magento_SalesRule" prev="estimateShippingAndTax" next="applySalesRuleOnFrontend"/> + <step name="applySalesRuleOnFrontend" module="Magento_SalesRule" prev="createSalesRule" next="proceedToCheckout"/> + </scenario> + <scenario name="ReorderOrderEntityTest"> + <step name="createSalesRule" module="Magento_SalesRule" next="applySalesRuleOnBackend"/> + <step name="applySalesRuleOnBackend" module="Magento_SalesRule" next="fillBillingAddress"/> + </scenario> + <scenario name="CreateOrderBackendTest"> + <step name="createSalesRule" module="Magento_SalesRule" next="applySalesRuleOnBackend"/> + <step name="applySalesRuleOnBackend" module="Magento_SalesRule" next="fillBillingAddress"/> + </scenario> + <scenario name="CreateOrderFromCustomerPageTest"> + <step name="createSalesRule" module="Magento_SalesRule" next="openCustomerOnBackend"/> + <step name="applySalesRuleOnBackend" module="Magento_SalesRule" next="fillBillingAddress"/> + </scenario> + <scenario name="PrintOrderFrontendGuestTest"> + <step name="createSalesRule" module="Magento_SalesRule" next="applySalesRuleOnBackend"/> + <step name="applySalesRuleOnBackend" module="Magento_SalesRule" next="fillBillingAddress"/> + </scenario> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.php b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.php new file mode 100644 index 0000000000000000000000000000000000000000..01c8abab19d6a8456a07e91145ce901957609c86 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Shipping\Test\Block\Adminhtml; + +use Magento\Sales\Test\Block\Adminhtml\Order\AbstractForm; +use Magento\Shipping\Test\Block\Adminhtml\Form\Items; +use Magento\Shipping\Test\Block\Adminhtml\Order\Tracking; + +/** + * Shipment create form. + */ +class Form extends AbstractForm +{ + /** + * Items block css selector. + * + * @var string + */ + protected $items = '#ship_items_container'; + + /** + * Tracking block css selector. + * + * @var string + */ + protected $tracking = '#tracking_numbers_table'; + + /** + * Get items block. + * + * @return Items + */ + protected function getItemsBlock() + { + return $this->blockFactory->create( + 'Magento\Shipping\Test\Block\Adminhtml\Form\Items', + ['element' => $this->_rootElement->find($this->items)] + ); + } + + /** + * Get tracking block. + * + * @return Tracking + */ + protected function getTrackingBlock() + { + return $this->blockFactory->create( + 'Magento\Shipping\Test\Block\Adminhtml\Order\Tracking', + ['element' => $this->_rootElement->find($this->tracking)] + ); + } + + /** + * Fill form data. + * + * @param array $data + * @param array|null $products [optional] + * @return void + */ + public function fillData(array $data, $products = null) + { + $data = $this->prepareData($data); + if (isset($data['form_data'])) { + if (isset($data['form_data']['tracking'])) { + $this->getTrackingBlock()->fill($data['form_data']['tracking']); + unset($data['form_data']['tracking']); + } + $this->_fill($this->dataMapping($data['form_data'])); + } + if (isset($data['items_data']) && $products !== null) { + foreach ($products as $key => $product) { + $this->getItemsBlock()->getItemProductBlock($product)->fillProduct($data['items_data'][$key]); + } + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.xml b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.xml new file mode 100644 index 0000000000000000000000000000000000000000..7e75ac518b8e7a2e66c38e5d9798c220d281e39f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<mapping strict="0"> + <wrapper>creditmemo</wrapper> + <fields> + <comment_text /> + <shipping_amount /> + <adjustment_positive /> + <adjustment_negative /> + <comment_customer_notify> + <input>checkbox</input> + </comment_customer_notify> + <send_email> + <input>checkbox</input> + </send_email> + </fields> +</mapping> diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items.php b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items.php new file mode 100644 index 0000000000000000000000000000000000000000..64b61d1a5ef7bcf90f1bc0712c5101e16287d41c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Shipping\Test\Block\Adminhtml\Form; + +use Magento\Sales\Test\Block\Adminhtml\Order\AbstractItemsNewBlock; +use Magento\Shipping\Test\Block\Adminhtml\Form\Items\Product; +use Magento\Mtf\Client\Locator; +use Magento\Mtf\Fixture\FixtureInterface; + +/** + * Adminhtml items to ship block. + */ +class Items extends AbstractItemsNewBlock +{ + /** + * Get item product block. + * + * @param FixtureInterface $product + * @return Product + */ + public function getItemProductBlock(FixtureInterface $product) + { + $selector = sprintf($this->productItem, $product->getSku()); + return $this->blockFactory->create( + 'Magento\Shipping\Test\Block\Adminhtml\Form\Items\Product', + ['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)] + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.php b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.php new file mode 100644 index 0000000000000000000000000000000000000000..ea14abdae485087e28c4eb728e8273161fb426b7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.php @@ -0,0 +1,15 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Shipping\Test\Block\Adminhtml\Form\Items; + +/** + * Item product form on shipment items block. + */ +class Product extends \Magento\Sales\Test\Block\Adminhtml\Order\AbstractForm\Product +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.xml b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7fff42f107e3901ca16dc791b77a27194229976 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/Block/Adminhtml/Form/Items/Product.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<mapping strict="0"> + <fields> + <qty> + <selector>input.qty-item</selector> + </qty> + </fields> +</mapping> diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.php b/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4391265ca5bb52050392431e47f82ae69c2fbd1c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Shipping\Test\TestCase; + +use Magento\Sales\Test\Fixture\OrderInjectable; +use Magento\Mtf\TestCase\Injectable; + +/** + * Preconditions: + * 1. Enable payment method "Check/Money Order". + * 2. Enable shipping method one of "Flat Rate/Free Shipping". + * 3. Create order. + * + * Steps: + * 1. Go to Sales > Orders. + * 2. Select created order in the grid and open it. + * 3. Click 'Ship' button. + * 4. Fill data according to dataSet. + * 5. Click 'Submit Shipment' button. + * 6. Perform all asserts. + * + * @group Order_Management_(CS) + * @ZephyrId MAGETWO-28708 + */ +class CreateShipmentEntityTest extends Injectable +{ + /* tags */ + const MVP = 'yes'; + const DOMAIN = 'CS'; + /* end tags */ + + /** + * Set up configuration. + * + * @return void + */ + public function __prepare() + { + $this->objectManager->create( + 'Magento\Config\Test\TestStep\SetupConfigurationStep', + ['configData' => "checkmo,flatrate"] + )->run(); + } + + /** + * Create shipment. + * + * @param OrderInjectable $order + * @param array $data + * @return array + */ + public function test(OrderInjectable $order, array $data) + { + // Preconditions + $order->persist(); + + // Steps + $createShipping = $this->objectManager->create( + 'Magento\Sales\Test\TestStep\CreateShipmentStep', + ['order' => $order, 'data' => $data] + ); + + return ['ids' => $createShipping->run()]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.xml b/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..aeb61fe1fc158c20a7d238ef8487dd56417c255d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Shipping/Test/TestCase/CreateShipmentEntityTest.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> + <testCase name="Magento\Shipping\Test\TestCase\CreateShipmentEntityTest"> + <variation name="CreateShipmentEntityTestVariation1"> + <data name="description" xsi:type="string">shipment with tracking number</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::default</data> + <data name="order/data/total_qty_ordered/0" xsi:type="string">1</data> + <data name="data/items_data/0/qty" xsi:type="string">-</data> + <data name="data/form_data/comment_text" xsi:type="string">comments for shipment</data> + <data name="data/form_data/tracking/0/carrier_code" xsi:type="string">Custom Value</data> + <data name="data/form_data/tracking/0/title" xsi:type="string">title</data> + <data name="data/form_data/tracking/0/number" xsi:type="string">199</data> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentSuccessCreateMessage" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentInShipmentsTab" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentInShipmentsGrid" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentItems" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertNoShipButton" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipTotalQuantity" /> + </variation> + <variation name="CreateShipmentEntityTestVariation2"> + <data name="description" xsi:type="string">partial shipment</data> + <data name="order/dataSet" xsi:type="string">default</data> + <data name="order/data/entity_id/products" xsi:type="string">catalogProductSimple::product_100_dollar</data> + <data name="order/data/total_qty_ordered/0" xsi:type="string">1</data> + <data name="data/items_data/0/qty" xsi:type="string">1</data> + <data name="data/form_data/comment_text" xsi:type="string">comments for shipment</data> + <data name="data/form_data/tracking/0/carrier_code" xsi:type="string">-</data> + <data name="data/form_data/tracking/0/title" xsi:type="string">-</data> + <data name="data/form_data/tracking/0/number" xsi:type="string">-</data> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentSuccessCreateMessage" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentInShipmentsTab" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentInShipmentsGrid" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipmentItems" /> + <constraint name="Magento\Shipping\Test\Constraint\AssertShipTotalQuantity" /> + </variation> + </testCase> +</config> 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 64ec7938f66cdaa860638795869c3e55997f3b49..227831ea819eae4d3844f1354e69a6dd8f79786e 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 @@ -10,8 +10,6 @@ use Magento\Checkout\Test\Fixture\Cart; use Magento\Customer\Test\Fixture\Customer; /** - * Test Flow: - * * Preconditions: * 1. Create customer and login to frontend * 2. Create products @@ -43,7 +41,6 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli */ public function test(Customer $customer, $products, $qty) { - $this->markTestIncomplete('Bug: MAGETWO-34757'); // Preconditions $customer->persist(); $this->loginCustomer($customer); @@ -71,11 +68,13 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli $productBlock = $this->wishlistIndex->getWishlistBlock()->getProductItemsBlock(); foreach ($products as $product) { $this->cmsIndex->getLinksBlock()->openLink("My Wish List"); + $this->cmsIndex->getCmsPageBlock()->waitPageInit(); if ($qty != '-') { $productBlock->getItemProduct($product)->fillProduct(['qty' => $qty]); $this->wishlistIndex->getWishlistBlock()->clickUpdateWishlist(); } $productBlock->getItemProduct($product)->clickAddToCart(); + $this->cmsIndex->getCmsPageBlock()->waitPageInit(); if (!$this->wishlistIndex->getWishlistBlock()->isVisible()) { $this->catalogProductView->getViewBlock()->addToCart($product); $this->catalogProductView->getMessagesBlock()->waitSuccessMessage(); 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 fe86f41997e58a8a52dbabf86db8742cbcf7c600..1cf13be71e2cd00324fbc5303d2a6bd31230fa33 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 @@ -6,54 +6,55 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> - <testCase name="Magento\Wishlist\Test\TestCase\AddProductsToCartFromCustomerWishlistOnFrontendTest"> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation1" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">catalogProductSimple::product_100_dollar</data> - <data name="qty" xsi:type="string">2</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation2" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">catalogProductVirtual::product_50_dollar</data> - <data name="qty" xsi:type="string">1</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation3" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">catalogProductSimple::default,catalogProductVirtual::product_50_dollar,catalogProductSimple::default,catalogProductVirtual::product_50_dollar</data> - <data name="qty" xsi:type="string">-</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertWishlistIsEmpty"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertWishlistIsEmpty" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation4" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">groupedProduct::three_simple_products</data> - <data name="qty" xsi:type="string">-</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation5" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">downloadableProduct::with_two_separately_links</data> - <data name="qty" xsi:type="string">-</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation6" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">configurableProduct::default</data> - <data name="qty" xsi:type="string">3</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation7" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product</data> - <data name="qty" xsi:type="string">2</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation8" firstConstraint="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" method="test"> - <data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data> - <data name="qty" xsi:type="string">2</data> - <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" next="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist"/> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" prev="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart"/> - </variation> - </testCase> + <testCase name="Magento\Wishlist\Test\TestCase\AddProductsToCartFromCustomerWishlistOnFrontendTest"> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation1"> + <data name="products" xsi:type="string">catalogProductSimple::product_100_dollar</data> + <data name="qty" xsi:type="string">2</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation2"> + <data name="products" xsi:type="string">catalogProductVirtual::product_50_dollar</data> + <data name="qty" xsi:type="string">1</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation3"> + <data name="issue" xsi:type="string">Bug: MAGETWO-36215</data> + <data name="products" xsi:type="string">catalogProductSimple::default,catalogProductVirtual::product_50_dollar,catalogProductSimple::default,catalogProductVirtual::product_50_dollar</data> + <data name="qty" xsi:type="string">-</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertWishlistIsEmpty" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation4"> + <data name="products" xsi:type="string">groupedProduct::three_simple_products_default_qty</data> + <data name="qty" xsi:type="string">-</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation5"> + <data name="products" xsi:type="string">downloadableProduct::with_two_separately_links</data> + <data name="qty" xsi:type="string">-</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation6"> + <data name="products" xsi:type="string">configurableProduct::default</data> + <data name="qty" xsi:type="string">3</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation7"> + <data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product</data> + <data name="qty" xsi:type="string">2</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation8"> + <data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data> + <data name="qty" xsi:type="string">2</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> + </variation> + </testCase> </config> diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/ConfigureProductInCustomerWishlistOnBackendTest.xml b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/ConfigureProductInCustomerWishlistOnBackendTest.xml index 3894fece0c5d382961acbf9d1c8cd52c88e46177..0c7a970f47d1b3d68bfc5295ef76dd55c8fcbc54 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/ConfigureProductInCustomerWishlistOnBackendTest.xml +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/ConfigureProductInCustomerWishlistOnBackendTest.xml @@ -6,26 +6,26 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> - <testCase name="Magento\Wishlist\Test\TestCase\ConfigureProductInCustomerWishlistOnBackendTest"> - <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation1" firstConstraint="Magento\Wishlist\Test\Constraint\AssertProductInCustomerWishlistOnBackendGrid" method="test"> - <data name="product" xsi:type="string">catalogProductSimple::with_two_custom_option</data> - <constraint name="Magento\Wishlist\Test\Constraint\AssertProductInCustomerWishlistOnBackendGrid"/> - </variation> - <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation2" firstConstraint="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInCustomerWishlistOnBackendGrid" method="test"> - <data name="product" xsi:type="string">configurableProduct::default</data> - <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInCustomerWishlistOnBackendGrid"/> - </variation> - <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation3" firstConstraint="Magento\Bundle\Test\Constraint\AssertBundleProductInCustomerWishlistOnBackendGrid" method="test"> - <data name="product" xsi:type="string">bundleProduct::bundle_dynamic_product</data> - <constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductInCustomerWishlistOnBackendGrid"/> - </variation> - <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation4" firstConstraint="Magento\Downloadable\Test\Constraint\AssertDownloadableProductInCustomerWishlistOnBackendGrid" method="test"> - <data name="product" xsi:type="string">downloadableProduct::with_two_separately_links</data> - <constraint name="Magento\Downloadable\Test\Constraint\AssertDownloadableProductInCustomerWishlistOnBackendGrid"/> - </variation> - <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation5" firstConstraint="Magento\GroupedProduct\Test\Constraint\AssertGroupedProductInCustomerWishlistOnBackendGrid" method="test"> - <data name="product" xsi:type="string">groupedProduct::three_simple_products</data> - <constraint name="Magento\GroupedProduct\Test\Constraint\AssertGroupedProductInCustomerWishlistOnBackendGrid"/> - </variation> - </testCase> + <testCase name="Magento\Wishlist\Test\TestCase\ConfigureProductInCustomerWishlistOnBackendTest"> + <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation1"> + <data name="product" xsi:type="string">catalogProductSimple::with_two_custom_option</data> + <constraint name="Magento\Wishlist\Test\Constraint\AssertProductInCustomerWishlistOnBackendGrid" /> + </variation> + <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation2"> + <data name="product" xsi:type="string">configurableProduct::default</data> + <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductInCustomerWishlistOnBackendGrid" /> + </variation> + <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation3"> + <data name="product" xsi:type="string">bundleProduct::bundle_dynamic_product</data> + <constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductInCustomerWishlistOnBackendGrid" /> + </variation> + <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation4"> + <data name="product" xsi:type="string">downloadableProduct::with_two_separately_links</data> + <constraint name="Magento\Downloadable\Test\Constraint\AssertDownloadableProductInCustomerWishlistOnBackendGrid" /> + </variation> + <variation name="ConfigureProductInCustomerWishlistOnBackendTestVariation5"> + <data name="product" xsi:type="string">groupedProduct::three_simple_products</data> + <constraint name="Magento\GroupedProduct\Test\Constraint\AssertGroupedProductInCustomerWishlistOnBackendGrid" /> + </variation> + </testCase> </config> diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/Plugin/BundleSaveOptionsTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/Plugin/BundleSaveOptionsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b46a6544e18aa8f3c0a466afb394c30183e3223e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/Plugin/BundleSaveOptionsTest.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Bundle\Model\Plugin; + +class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Catalog\Model\Product + */ + protected $_model; + + /** + * @var \Magento\Catalog\Api\ProductRepositoryInterface + */ + protected $productRepository; + + protected function setUp() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface'); + } + + /** + * @magentoDataFixture Magento/Bundle/_files/product.php + * @magentoDbIsolation enabled + */ + public function testSaveSuccess() + { + $title = "new title"; + $bundleProductSku = 'bundle-product'; + $product = $this->productRepository->get($bundleProductSku); + $bundleExtensionAttributes = $product->getExtensionAttributes()->getBundleProductOptions(); + $bundleOption = $bundleExtensionAttributes[0]; + $this->assertEquals(true, $bundleOption->getRequired()); + $bundleOption->setTitle($title); + + $oldDescription = $product->getDescription(); + $description = $oldDescription . "hello"; + $product->setDescription($description); + $product->getExtensionAttributes()->setBundleProductOptions([$bundleOption]); + $product = $this->productRepository->save($product); + + $this->assertEquals($description, $product->getDescription()); + $this->assertEquals($title, $product->getExtensionAttributes()->getBundleProductOptions()[0]->getTitle()); + } + + /** + * @magentoDataFixture Magento/Bundle/_files/product.php + * @magentoDbIsolation enabled + */ + public function testSaveFailure() + { + $this->markTestSkipped("When MAGETWO-36510 is fixed, need to change Dbisolation to disabled"); + $bundleProductSku = 'bundle-product'; + $product = $this->productRepository->get($bundleProductSku); + $bundleExtensionAttributes = $product->getExtensionAttributes()->getBundleProductOptions(); + $bundleOption = $bundleExtensionAttributes[0]; + $this->assertEquals(true, $bundleOption->getRequired()); + $bundleOption->setRequired(false); + //set an incorrect option id to trigger exception + $bundleOption->setOptionId(-1); + + $description = "hello"; + + $product->setDescription($description); + $product->getExtensionAttributes()->setBundleProductOptions([$bundleOption]); + $caughtException = false; + try { + $this->productRepository->save($product); + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + $caughtException = true; + } + + $this->assertTrue($caughtException); + /** @var \Magento\Catalog\Model\Product $product */ + $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Catalog\Model\Product')->load($product->getId()); + $this->assertEquals(null, $product->getDescription()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Bundle/_files/product.php b/dev/tests/integration/testsuite/Magento/Bundle/_files/product.php index 1bb799689c7ec3748bb251a5ae75f80dbd996271..663c2d0225742e375ea459b0b70ae903d90e00b7 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/_files/product.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/_files/product.php @@ -31,6 +31,12 @@ $product->setTypeId( \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED )->setStockData( ['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1] +)->setPriceView( + 1 +)->setPriceType( + 1 +)->setPrice( + 10.0 )->setBundleOptionsData( [ [ diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php index eb8ec06003ac4f24253b991563579c4818fe3335..96833ea6131be828d3511fcd39db17b0409c0d02 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php @@ -66,10 +66,10 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase /** * @return void */ - public function testLargeSizeException() + public function testLargeSizeFile() { $this->setExpectedException( - '\Magento\Framework\Exception\File\LargeSizeException', + '\Magento\Framework\Exception\LocalizedException', sprintf('The file you uploaded is larger than %s Megabytes allowed by server', $this->maxFileSizeInMb) ); $this->prepareEnv(); @@ -108,7 +108,7 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception\File\ValidatorException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please specify the product's required option(s). * @return void */ @@ -131,7 +131,7 @@ class ValidatorFileTest extends \PHPUnit_Framework_TestCase public function testInvalidateFile() { $this->setExpectedException( - '\Magento\Framework\Exception\File\ValidatorException', + '\Magento\Framework\Exception\LocalizedException', "The file 'test.jpg' for 'MediaOption' has an invalid extension.\n" . "The file 'test.jpg' for 'MediaOption' has an invalid extension.\n" . "Maximum allowed image size for 'MediaOption' is 2000x2000 px.\n" 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 0000000000000000000000000000000000000000..c66670aa8719af2cc1a5575596f7b8c65661bf58 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers.php @@ -0,0 +1,28 @@ +<?php +/** + * SalesRule 10% discount coupon + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $salesRule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->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 0000000000000000000000000000000000000000..a6f462f767443532421f66b9e8d144335469233e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_generalusers_rollback.php @@ -0,0 +1,12 @@ +<?php +/** + * SalesRule 10% discount coupon + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $salesRule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->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 0000000000000000000000000000000000000000..53c90ee1778f1eb0c67b16c1af81e4a87f9cb47f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/discount_10percent_rollback.php @@ -0,0 +1,12 @@ +<?php +/** + * SalesRule 10% discount coupon + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $salesRule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->load('Test Coupon', 'name'); +$salesRule->delete(); 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 65cdb896f134ccdc968d833ae6816ebf8a15ab70..c06216ed07d89f96f5e144815c68a97964e6300b 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(); 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 9bc73ec6d964fc69c7bdc78fa6a8fa15b83a0583..098b8e746cd5b099605ed37fb437cd2ba8e82781 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_check_payment.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment.php index 355706e20824a14eea670c5cc3678c2cdf2ee9d0..1f0a0a45197c70eec8b032eea8555dba723c18e9 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,11 @@ $quote->getPayment()->setMethod('checkmo'); $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/Checkout/_files/quote_with_check_payment_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_check_payment_rollback.php index 7d04f85c78907dae2949522fef4d0001086cdac0..e999e00ff14336961e2581ba9983960cd1e0e9fe 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(); 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 d017de00edb5e8a0a476d4804a84903e70160489..dcf8ab45afc9802ac729f00210a68f59bfee159d 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 @@ $quoteProduct = $product->load($product->getIdBySku('simple_one')); $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 d39da02e43d07343fa5d566c23e1016fa6f2bde2..e15c08b356f56ffc6677a1018b6613a1f4223a74 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 @@ $quote->getPayment() ->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(); 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 c828e4acf0c793a28d33237f0c31a815ca3b8095..92d03e750c176358c6927bd9724022b80e40a565 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 3d410ba47f558b83bcc8d91d93bed5221a22f37c..e917e5c33e8ddfcb09eafeb08420a2df028ef886 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->setStoreId( ); $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 60b8a06b2dcfe58c829b67db2fcde71798e88e1f..5639fc74d602ef9f26a9ebcaa5e50a23e03052e4 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 f892d8e7abade648085ddb2cb5b6f1cc44d79a48..56ae6b1a7643bd074ebd807ea00a77d60da41769 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->setStoreId( ); $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 abd211dba8b7844b3644c2ae0e406b867da88c0b..c87f4d43a8ac58aab785cb180a22c241c9f6aba7 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 d68124215662e455600af9d538dc7f2db59f7c51..1d19150c3a3a52f274c6301d4559e17245293717 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->setStoreId(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_virtual_product_saved_rollback.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_virtual_product_saved_rollback.php index 4447d3cf57862f35cded4b095ccc5d0285bd06e0..914ec199cfd3308429bb94bd660ca8f5c04da531 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()); 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 f147db9a5a5cc26f376e77d0080e766967e7344e..905a5a9affc1d62dd9ba398a247cf40dbfc12780 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 @@ class GroupRepositoryTest extends \PHPUnit_Framework_TestCase 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'] + ], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php new file mode 100644 index 0000000000000000000000000000000000000000..0732a8e7916e7b6e9ca46a6a221a5dc56ea016b6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenAction.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use Magento\Framework\View\LayoutInterface; + +class BrokenAction extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @param LayoutInterface $layout + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setLayout(LayoutInterface $layout) + { + return $this; + } + + /** + * @param string $action + * @throws LocalizedException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function initAction($action) + { + throw new LocalizedException(new Phrase('Init action problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with action problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php new file mode 100644 index 0000000000000000000000000000000000000000..b421b1f76d693fceff48282d953b097d552c233e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenConstructor.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; + +class BrokenConstructor extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @throws LocalizedException + */ + public function __construct() + { + throw new LocalizedException(new Phrase('Construction problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with construction problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php new file mode 100644 index 0000000000000000000000000000000000000000..4673250a1cb08e29e0935e4f9dbf02c173a2e7c1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Fixture/Block/BrokenLayout.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Fixture\Block; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; +use Magento\Framework\View\LayoutInterface; + +class BrokenLayout extends \Magento\Framework\View\Element\AbstractBlock +{ + /** + * @param LayoutInterface $layout + * @throws LocalizedException + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setLayout(LayoutInterface $layout) + { + throw new LocalizedException(new Phrase('Prepare layout problem.')); + } + + /** + * Produce and return block's html output + * + * @return string + */ + public function toHtml() + { + return '<p>Rendered with layout problem.</p>'; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php new file mode 100644 index 0000000000000000000000000000000000000000..64d383ed99a249cd738ff1be87433ea241458f3e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTestWithExceptions.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View; + +use \Magento\Framework\App\State; + +class LayoutTestWithExceptions extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\View\Layout + */ + protected $layout; + + public function setUp() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $layoutFactory = $objectManager->get('Magento\Framework\View\LayoutFactory'); + $this->layout = $layoutFactory->create(); + $layoutElement = new \Magento\Framework\View\Layout\Element( + __DIR__ . '/_files/layout_with_exceptions/layout.xml', + 0, + true + ); + + $this->layout->setXml($layoutElement); + $objectManager->get('Magento\Framework\App\Cache\Type\Layout')->clean(); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Construction problem. + */ + public function testProcessWithExceptionsDeveloperMode() + { + $this->layout->generateElements(); + } + + /** + * @magentoAppIsolation enabled + */ + public function testProcessWithExceptions() + { + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\App\State') + ->setMode(State::MODE_DEFAULT); + + $this->layout->generateElements(); + + $this->layout->addOutputElement('block.with.broken.constructor'); + $this->layout->addOutputElement('block.with.broken.layout'); + $this->layout->addOutputElement('block.with.broken.action'); + + $this->assertEmpty($this->layout->getOutput()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php b/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php index 2f43263c6989c9428586006bdd7c2a6dfa43f2ce..df662db1bd7af9e9b39ccca6ca0b0a963012bc26 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Utility/Layout.php @@ -104,6 +104,8 @@ class Layout 'cache' => $objectManager->get('Magento\Framework\App\Cache\Type\Layout'), 'readerContextFactory' => $objectManager->get('Magento\Framework\View\Layout\Reader\ContextFactory'), 'generatorContextFactory' => $objectManager->get('Magento\Framework\View\Layout\Generator\ContextFactory'), + 'appState' => $objectManager->get('Magento\Framework\App\State'), + 'logger' => $objectManager->get('Psr\Log\LoggerInterface'), ]; } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml new file mode 100644 index 0000000000000000000000000000000000000000..a52c0a6645cf38171cec6ded52f867f5ce5e5d37 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/View/_files/layout_with_exceptions/layout.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> + <body> + <referenceContainer name="root"> + <block class="Magento\Framework\View\Fixture\Block\BrokenConstructor" name="block.with.broken.constructor"/> + <block class="Magento\Framework\View\Fixture\Block\BrokenLayout" name="block.with.broken.layout"/> + <block class="Magento\Framework\View\Fixture\Block\BrokenAction" name="block.with.broken.action"> + <action method="initAction"> + <argument name="action" xsi:type="string">action</argument> + </action> + </block> + </referenceContainer> + </body> +</page> diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php index 8bdafe16f41aa3263b3a75e208e2a8545efbaa5d..2fb7467a1c15bc58a2a6391dfb9eb8854c3c456e 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->getPayment()->setMethod('checkmo'); $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(); 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 8d5992519026fd63f5669052fc465a5f932accff..40e14157ff895104bac231809bc61c6b81f98bfc 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 @@ $customerRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager( ->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(); diff --git a/dev/tests/performance/benchmark.jmx b/dev/tests/performance/benchmark.jmx index cd9ed6d2ce32c5897479e3b872accca6454d0e05..34b8617830f417808bcc2e5086b8ecf6efe94c72 100644 --- a/dev/tests/performance/benchmark.jmx +++ b/dev/tests/performance/benchmark.jmx @@ -864,7 +864,7 @@ <collectionProp name="Arguments.arguments"> <elementProp name="billing[address_id]" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">true</boolProp> - <stringProp name="Argument.value">37</stringProp> + <stringProp name="Argument.value"></stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">billing[address_id]</stringProp> @@ -962,7 +962,7 @@ </elementProp> <elementProp name="billing[save_in_address_book]" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">true</boolProp> - <stringProp name="Argument.value">1</stringProp> + <stringProp name="Argument.value">0</stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">billing[save_in_address_book]</stringProp> diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b7fb0b8ae7a94fac791f68ba00a147f6bf138776 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ExceptionHierarchyTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Test\Integrity; + +use Magento\Framework\App\Utility\Files as UtilityFiles; + +/** + * Checks that all Exceptions inherit LocalizedException + */ +class ExceptionHierarchyTest extends \PHPUnit_Framework_TestCase +{ + /** + * @param \ReflectionClass $reflectionException + * @dataProvider isInheritedLocalizedExceptionDataProvider + */ + public function testIsInheritedLocalizedException(\ReflectionClass $reflectionException) + { + $this->assertTrue( + $reflectionException->isSubclassOf('Magento\Framework\Exception\LocalizedException'), + "{$reflectionException->name} is not inherited LocalizedException" + ); + } + + /** + * @return array + */ + public function isInheritedLocalizedExceptionDataProvider() + { + $files = UtilityFiles::init()->getClassFiles(true, false, false, true, false); + $blacklistExceptions = $this->getBlacklistExceptions(); + + $data = []; + foreach ($files as $file) { + $className = $this->convertPathToClassName($file); + try { + $reflectionClass = new \ReflectionClass($className); + if ($reflectionClass->isSubclassOf('Exception') && !in_array($className, $blacklistExceptions)) { + $data[$className] = [$reflectionClass]; + } + } catch (\Exception $e) { + $this->fail("File name and class name '{$className}' is not appropriate"); + } + } + return $data; + } + + /** + * @param string $filePath + * @return string + */ + protected function convertPathToClassName($filePath) + { + $className = str_replace('.php', "", substr($filePath, strpos($filePath, '/Magento'))); + $className = implode("\\", explode("/", $className)); + return $className; + } + + /** + * @return array + */ + protected function getBlacklistExceptions() + { + $blacklistFiles = str_replace('\\', '/', realpath(__DIR__)) . '/_files/blacklist/exception_hierarchy*.txt'; + $exceptions = []; + foreach (glob($blacklistFiles) as $fileName) { + $exceptions = array_merge($exceptions, file($fileName, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)); + } + return $exceptions; + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt new file mode 100644 index 0000000000000000000000000000000000000000..068e1ea553cbddd2adc20851f582c3188be8fda6 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/exception_hierarchy.txt @@ -0,0 +1,4 @@ +\Magento\Framework\Exception\LocalizedException +\Magento\Framework\View\Asset\File\NotFoundException +\Magento\Framework\Config\Dom\ValidationException +\Magento\Framework\Gdata\Gshopping\HttpException diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php old mode 100644 new mode 100755 index 90b625089853d0b67d07b46418ddbd2b9735b9ae..b843bebb849ca047a25b4a7f69c4512795e6519d --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3118,6 +3118,19 @@ return [ ['Magento\LocaleFactory'], ['Magento\Framework\LocaleFactory'], ['Magento\Core\Helper\Data', 'Magento\Framework\Json\Helper\Data'], + ['Magento\Framework\App\DeploymentConfig\BackendConfig'], + ['Magento\Framework\App\DeploymentConfig\DbConfig'], + ['Magento\Framework\App\DeploymentConfig\InstallConfig'], + ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], + ['Magento\Framework\App\DeploymentConfig\SessionConfig'], + ['Magento\Framework\App\DeploymentConfig\CacheConfig'], + ['Magento\Setup\Model\DeploymentConfigMapper'], + ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], + ['Magento\Framework\Filesystem\Io\IoException'], + ['Magento\Framework\DB\DBException'], + ['Magento\Framework\DB\Tree\TreeException'], + ['Magento\Framework\DB\Tree\Node\NodeException'], + ['Magento\Framework\DB\Tree\NodeSet\NodeSetException'], ['Magento\Backup\Exception'], ['Magento\Catalog\Exception'], ['Magento\Reports\Exception'], @@ -3138,20 +3151,16 @@ return [ ['Magento\CatalogRule\CatalogRuleException'], ['Magento\Payment\Exception'], ['Magento\UrlRewrite\Model\Storage\DuplicateEntryException'], - ['Magento\Framework\App\DeploymentConfig\BackendConfig'], - ['Magento\Framework\App\DeploymentConfig\DbConfig'], - ['Magento\Framework\App\DeploymentConfig\InstallConfig'], - ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], - ['Magento\Framework\App\DeploymentConfig\SessionConfig'], - ['Magento\Framework\App\DeploymentConfig\CacheConfig'], - ['Magento\Setup\Model\DeploymentConfigMapper'], - ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], ['Magento\Setup\Mvc\Console\RouteListener'], ['Magento\Setup\Mvc\Console\RouteMatcher'], ['Magento\Setup\Mvc\Console\VerboseValidator'], ['Magento\Setup\Controller\ConsoleController'], ['Magento\Setup\Model\UserConfigurationDataMapper', 'Magento\Setup\Model\StoreConfigurationDataMapper'], ['Magento\Framework\App\State\Cleanup', 'Magento\Framework\App\State\CleanupFiles'], + ['Magento\Eav\Exception'], + ['Magento\Framework\Exception\File\ValidatorException'], + ['Magento\Framework\Filesystem\FilesystemException', 'Magento\Framework\Exception\FileSystemException'], + ['Magento\Shipping\Exception'], ['Magento\Log\Model\Shell'], ['Magento\Log\App\Shell'], ['Magento\Framework\App\Cache\ManagerApp'], diff --git a/lib/internal/Magento/Framework/AppInterface.php b/lib/internal/Magento/Framework/AppInterface.php index 8b705a12fe4825cc7b9b108f1ffd18a07e87a7eb..7bf9c70ada1b61682217450ee8aa846de7e01943 100644 --- a/lib/internal/Magento/Framework/AppInterface.php +++ b/lib/internal/Magento/Framework/AppInterface.php @@ -17,7 +17,7 @@ interface AppInterface /** * Magento version */ - const VERSION = '0.74.0-beta4'; + const VERSION = '0.74.0-beta6'; /** * Launch application diff --git a/lib/internal/Magento/Framework/Archive/Helper/File.php b/lib/internal/Magento/Framework/Archive/Helper/File.php old mode 100644 new mode 100755 index 549c3b8849fe73ba906f1fe643e8f45d2fae37bd..eab51af7b2c87cbb6f8decc1e814af08645af7f6 --- a/lib/internal/Magento/Framework/Archive/Helper/File.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File.php @@ -11,7 +11,7 @@ */ namespace Magento\Framework\Archive\Helper; -use Magento\Framework\Exception\LocalizedException as MagentoException; +use Magento\Framework\Exception\LocalizedException; class File { @@ -87,7 +87,7 @@ class File * @param string $mode * @param int $chmod * @return void - * @throws MagentoException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function open($mode = 'w+', $chmod = 0666) @@ -96,13 +96,13 @@ class File if ($this->_isInWriteMode) { if (!is_writable($this->_fileLocation)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Permission denied to write to %1', [$this->_fileLocation]) ); } if (is_file($this->_filePath) && !is_writable($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase( "Can't open file %1 for writing. Permission denied.", [$this->_fileName] @@ -113,13 +113,13 @@ class File if ($this->_isReadableMode($mode) && (!is_file($this->_filePath) || !is_readable($this->_filePath))) { if (!is_file($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('File %1 does not exist', [$this->_filePath]) ); } if (!is_readable($this->_filePath)) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Permission denied to read file %1', [$this->_filePath]) ); } @@ -191,14 +191,14 @@ class File * * @param string $mode * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _open($mode) { $this->_fileHandler = @fopen($this->_filePath, $mode); if (false === $this->_fileHandler) { - throw new MagentoException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath])); + throw new LocalizedException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath])); } } @@ -207,14 +207,14 @@ class File * * @param string $data * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _write($data) { $result = @fwrite($this->_fileHandler, $data); if (false === $result) { - throw new MagentoException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath])); + throw new LocalizedException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath])); } } @@ -223,14 +223,14 @@ class File * * @param int $length * @return string - * @throws MagentoException + * @throws LocalizedException */ protected function _read($length) { $result = fread($this->_fileHandler, $length); if (false === $result) { - throw new MagentoException( + throw new LocalizedException( new \Magento\Framework\Phrase('Failed to read data from %1', [$this->_filePath]) ); } @@ -284,12 +284,12 @@ class File * Check whether file is opened * * @return void - * @throws MagentoException + * @throws LocalizedException */ protected function _checkFileOpened() { if (!$this->_fileHandler) { - throw new MagentoException(new \Magento\Framework\Phrase('File not opened')); + throw new LocalizedException(new \Magento\Framework\Phrase('File not opened')); } } } diff --git a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php index ac5f33263ec03c3ac9452229a31c8d0d71690272..938cfe6a31ec26f0193059607e1a20ea68bba299 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php +++ b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php @@ -985,7 +985,7 @@ interface AdapterInterface * @param \Magento\Framework\DB\Select $select * @param int $stepCount * @return \Magento\Framework\DB\Select[] - * @throws \Magento\Framework\DB\DBException + * @throws \Magento\Framework\Exception\LocalizedException */ public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100); diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index f3bf8e12d893c11bd321989e4786d1d65893976d..b4b07cd12e81494298dd43dea4a4156c8a684670 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -18,6 +18,7 @@ use Magento\Framework\DB\LoggerInterface; use Magento\Framework\DB\Profiler; use Magento\Framework\DB\Select; use Magento\Framework\DB\Statement\Parameter; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Stdlib\DateTime; use Magento\Framework\Stdlib\String; @@ -3322,13 +3323,13 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface * @param \Magento\Framework\DB\Select $select * @param int $stepCount * @return \Magento\Framework\DB\Select[] - * @throws \Magento\Framework\DB\DBException + * @throws LocalizedException */ public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100) { $fromSelect = $select->getPart(\Magento\Framework\DB\Select::FROM); if (empty($fromSelect)) { - throw new \Magento\Framework\DB\DBException( + throw new LocalizedException( new \Magento\Framework\Phrase('Select object must have correct "FROM" part') ); } @@ -3380,7 +3381,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface * @param Select $select * @param string|array $table * @return string - * @throws \Magento\Framework\DB\DBException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -3438,7 +3439,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface } if (!$columns) { - throw new \Magento\Framework\DB\DBException( + throw new LocalizedException( new \Magento\Framework\Phrase('The columns for UPDATE statement are not defined') ); } diff --git a/lib/internal/Magento/Framework/DB/DBException.php b/lib/internal/Magento/Framework/DB/DBException.php deleted file mode 100644 index 6af4e98427bbf852c39c0b4494e4a5bba23339b1..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/DBException.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB; - -/** - * TODO - * - * @author Magento Core Team <core@magentocommerce.com> - */ -class DBException extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Ddl/Table.php b/lib/internal/Magento/Framework/DB/Ddl/Table.php index eee5ed9bc320a574eec14163bcf05fa4b21fd353..a623ba4c0fb3398a107d72140fe711adfa19b946 100644 --- a/lib/internal/Magento/Framework/DB/Ddl/Table.php +++ b/lib/internal/Magento/Framework/DB/Ddl/Table.php @@ -59,7 +59,7 @@ class Table const MAX_VARBINARY_SIZE = 2147483648; /** - * Default values for timestampses - fill with current timestamp on inserting record, on changing and both cases + * Default values for timestamps - fill with current timestamp on inserting record, on changing and both cases */ const TIMESTAMP_INIT_UPDATE = 'TIMESTAMP_INIT_UPDATE'; diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php index 92e206b069b491c3717db2b9484b9e25c4cff263..b89a7d646d07823c7da54caaca77bfc7d4f300b3 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/Tree/NodeTest.php @@ -93,7 +93,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => null, 'keys' => null, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty array of node information', ], [ @@ -101,7 +101,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => null, 'keys' => true, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty array of node information' ], [ @@ -109,7 +109,7 @@ class NodeTest extends \PHPUnit_Framework_TestCase 'node_data' => true, 'keys' => null, ], - '\Magento\Framework\DB\Tree\Node\NodeException', + '\Magento\Framework\Exception\LocalizedException', 'Empty keys array' ] ]; diff --git a/lib/internal/Magento/Framework/DB/Tree.php b/lib/internal/Magento/Framework/DB/Tree.php index e2449c2bc8498fcd4758cc194862d3f78ee9742f..f06e9d291a89490355f627251548d701b66e36d9 100644 --- a/lib/internal/Magento/Framework/DB/Tree.php +++ b/lib/internal/Magento/Framework/DB/Tree.php @@ -10,13 +10,11 @@ namespace Magento\Framework\DB; \Zend_Loader::loadClass('\Magento\Framework\DB\Tree\NodeSet'); use Magento\Framework\DB\Tree\Node; use Magento\Framework\DB\Tree\NodeSet; -use Magento\Framework\DB\Tree\TreeException; +use Magento\Framework\Exception\LocalizedException; /** * Magento Library - */ -require_once 'Tree/TreeException.php'; -/** + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Tree @@ -79,7 +77,7 @@ class Tree /** * @param array $config - * @throws TreeException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -97,7 +95,7 @@ class Tree // make sure it's a \Zend_Db_Adapter if (!$connection instanceof \Zend_Db_Adapter_Abstract) { - throw new TreeException( + throw new LocalizedException( new \Magento\Framework\Phrase('db object does not implement \Zend_Db_Adapter_Abstract') ); } @@ -109,7 +107,7 @@ class Tree $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); } } else { - throw new TreeException(new \Magento\Framework\Phrase('db object is not set in config')); + throw new LocalizedException(new \Magento\Framework\Phrase('db object is not set in config')); } if (!empty($config['table'])) { diff --git a/lib/internal/Magento/Framework/DB/Tree/Node.php b/lib/internal/Magento/Framework/DB/Tree/Node.php index e9ea215876818ab635f24972875564cc4dd82ef7..f3e353ba81a4dba8180416e1cd4f711d78edbc99 100644 --- a/lib/internal/Magento/Framework/DB/Tree/Node.php +++ b/lib/internal/Magento/Framework/DB/Tree/Node.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\DB\Tree; -use Magento\Framework\DB\Tree\Node\NodeException; +use Magento\Framework\Exception\LocalizedException; /** * @SuppressWarnings(PHPMD.UnusedPrivateField) @@ -60,15 +60,15 @@ class Node /** * @param array $nodeData * @param array $keys - * @throws NodeException + * @throws LocalizedException */ public function __construct($nodeData, $keys) { if (empty($nodeData)) { - throw new NodeException(new \Magento\Framework\Phrase('Empty array of node information')); + throw new LocalizedException(new \Magento\Framework\Phrase('Empty array of node information')); } if (empty($keys)) { - throw new NodeException(new \Magento\Framework\Phrase('Empty keys array')); + throw new LocalizedException(new \Magento\Framework\Phrase('Empty keys array')); } $this->id = $nodeData[$keys['id']]; diff --git a/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php b/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php deleted file mode 100644 index 6f3fa5edae5e2a478cf2c750c6a9950a169866fb..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/Node/NodeException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree\Node; - -class NodeException extends \Magento\Framework\DB\Tree\TreeException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php b/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php deleted file mode 100644 index 62c7b9554b2665afc84dffc67bbcd1552e1acd56..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/NodeSet/NodeSetException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree\NodeSet; - -class NodeSetException extends \Magento\Framework\DB\Tree\TreeException -{ -} diff --git a/lib/internal/Magento/Framework/DB/Tree/TreeException.php b/lib/internal/Magento/Framework/DB/Tree/TreeException.php deleted file mode 100644 index e462b47654bc44077946460d55dc8c9b350a9e72..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/DB/Tree/TreeException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\DB\Tree; - -class TreeException extends \Magento\Framework\DB\DBException -{ -} diff --git a/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php b/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php deleted file mode 100644 index 73a22a65116e664f73531b2f34ed1612e5e803e3..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Exception/File/LargeSizeException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Exception\File; - -use Magento\Framework\Exception\LocalizedException; - -class LargeSizeException extends LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/Exception/File/ValidatorException.php b/lib/internal/Magento/Framework/Exception/File/ValidatorException.php deleted file mode 100644 index a8f78f8aeb2668009a79ccdd4a0ced4ed55c5286..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Exception/File/ValidatorException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Exception\File; - -use Magento\Framework\Exception\LocalizedException; - -class ValidatorException extends LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php index ed850baec96a9bb36bea2aaaa294ec3073394519..1f897eee69f0194cdc69fe580f9ee81a402e94d4 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Filesystem\Io; +use Magento\Framework\Phrase; +use Magento\Framework\Exception\LocalizedException; + /** * FTP client */ @@ -66,7 +69,7 @@ class Ftp extends AbstractIo * * @param array $args * @return true - * @throws IoException + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -74,7 +77,7 @@ class Ftp extends AbstractIo { if (empty($args['host'])) { $this->_error = self::ERROR_EMPTY_HOST; - throw new IoException(new \Magento\Framework\Phrase('Empty host specified')); + throw new LocalizedException(new Phrase('Empty host specified')); } if (empty($args['port'])) { @@ -107,22 +110,20 @@ class Ftp extends AbstractIo } if (!$this->_conn) { $this->_error = self::ERROR_INVALID_CONNECTION; - throw new IoException( - new \Magento\Framework\Phrase('Could not establish FTP connection, invalid host or port') - ); + throw new LocalizedException(new Phrase('Could not establish FTP connection, invalid host or port')); } if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password'])) { $this->_error = self::ERROR_INVALID_LOGIN; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid user name or password')); + throw new LocalizedException(new Phrase('Invalid user name or password')); } if (!empty($this->_config['path'])) { if (!@ftp_chdir($this->_conn, $this->_config['path'])) { $this->_error = self::ERROR_INVALID_PATH; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid path')); + throw new LocalizedException(new Phrase('Invalid path')); } } @@ -130,7 +131,7 @@ class Ftp extends AbstractIo if (!@ftp_pasv($this->_conn, true)) { $this->_error = self::ERROR_INVALID_MODE; $this->close(); - throw new IoException(new \Magento\Framework\Phrase('Invalid file transfer mode')); + throw new LocalizedException(new Phrase('Invalid file transfer mode')); } } diff --git a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php b/lib/internal/Magento/Framework/Filesystem/Io/IoException.php deleted file mode 100644 index 3d94334dcae56b811afb12cc45fbe2deec95296f..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Filesystem\Io; - -/** - * Io exception - */ -class IoException extends \Magento\Framework\Exception\LocalizedException -{ -} diff --git a/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php b/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php index b90ff7acb3929174c921ac4a7e0ea5c3e464fab7..7b70fa5d35e61e3174d0b008a275f2afd8880d3c 100644 --- a/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php @@ -205,6 +205,21 @@ abstract class AbstractExtensibleModel extends AbstractModel implements return parent::unsetData($key); } + /** + * Convert custom values if necessary + * + * @param array $customAttributes + * @return void + */ + protected function convertCustomAttributeValues(array &$customAttributes) + { + foreach ($customAttributes as $attributeCode => $attributeValue) { + if ($attributeValue instanceof \Magento\Framework\Api\AttributeValue) { + $customAttributes[$attributeCode] = $attributeValue->getValue(); + } + } + } + /** * Object data getter * @@ -231,6 +246,7 @@ abstract class AbstractExtensibleModel extends AbstractModel implements $customAttributes = isset($this->_data[self::CUSTOM_ATTRIBUTES]) ? $this->_data[self::CUSTOM_ATTRIBUTES] : []; + $this->convertCustomAttributeValues($customAttributes); $data = array_merge($this->_data, $customAttributes); unset($data[self::CUSTOM_ATTRIBUTES]); } else { @@ -238,6 +254,9 @@ abstract class AbstractExtensibleModel extends AbstractModel implements if ($data === null) { /** Try to find necessary data in custom attributes */ $data = parent::getData(self::CUSTOM_ATTRIBUTES . "/{$key}", $index); + if ($data instanceof \Magento\Framework\Api\AttributeValue) { + $data = $data->getValue(); + } } } return $data; diff --git a/lib/internal/Magento/Framework/Model/AbstractModel.php b/lib/internal/Magento/Framework/Model/AbstractModel.php index 43223069055fdaab1fe7decf6754233bf990ab5a..fcd03252a4160d16805909a3bc45492f896f2e85 100644 --- a/lib/internal/Magento/Framework/Model/AbstractModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractModel.php @@ -127,6 +127,13 @@ abstract class AbstractModel extends \Magento\Framework\Object */ protected $_actionValidator; + /** + * Array to store object's original data + * + * @var array + */ + protected $storedData = []; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -301,6 +308,7 @@ abstract class AbstractModel extends \Magento\Framework\Object $this->_afterLoad(); $this->setOrigData(); $this->_hasDataChanges = false; + $this->updateStoredData(); return $this; } @@ -354,6 +362,7 @@ abstract class AbstractModel extends \Magento\Framework\Object { $this->getResource()->afterLoad($this); $this->_afterLoad(); + $this->updateStoredData(); return $this; } @@ -566,6 +575,7 @@ abstract class AbstractModel extends \Magento\Framework\Object $this->_eventManager->dispatch('model_save_after', ['object' => $this]); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]); $this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData()); + $this->updateStoredData(); return $this; } @@ -611,6 +621,7 @@ abstract class AbstractModel extends \Magento\Framework\Object $this->_eventManager->dispatch('model_delete_after', ['object' => $this]); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]); $this->_eventManager->dispatch($this->_eventPrefix . '_delete_after', $this->_getEventData()); + $this->storedData = []; return $this; } @@ -689,4 +700,29 @@ abstract class AbstractModel extends \Magento\Framework\Object { return $this; } + + /** + * Synchronize object's stored data with the actual data + * + * @return $this + */ + private function updateStoredData() + { + if (isset($this->_data)) { + $this->storedData = $this->_data; + } else { + $this->storedData = []; + } + return $this; + } + + /** + * Model StoredData getter + * + * @return array + */ + public function getStoredData() + { + return $this->storedData; + } } diff --git a/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php b/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php index 393c90be8e000891cad8ca84d83e6e8cbcf3ccc7..351365b08d9eb57d45b6b65a50c53edbb93d482c 100644 --- a/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php +++ b/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php @@ -417,9 +417,10 @@ abstract class AbstractDb extends \Magento\Framework\Model\Resource\AbstractReso * Not auto increment primary key support */ if ($this->_isPkAutoIncrement) { - $data = $this->_prepareDataForSave($object); - unset($data[$this->getIdFieldName()]); - $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); + $data = $this->prepareDataForUpdate($object); + if (!empty($data)) { + $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); + } } else { $select = $this->_getWriteAdapter()->select()->from( $this->getMainTable(), @@ -428,8 +429,7 @@ abstract class AbstractDb extends \Magento\Framework\Model\Resource\AbstractReso $condition ); if ($this->_getWriteAdapter()->fetchOne($select) !== false) { - $data = $this->_prepareDataForSave($object); - unset($data[$this->getIdFieldName()]); + $data = $this->prepareDataForUpdate($object); if (!empty($data)) { $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); } @@ -770,4 +770,27 @@ abstract class AbstractDb extends \Magento\Framework\Model\Resource\AbstractReso } return $checksum; } + + /** + * Get the array of data fields that was changed or added + * + * @param \Magento\Framework\Model\AbstractModel $object + * @return array + */ + protected function prepareDataForUpdate($object) + { + $data = $object->getData(); + foreach ($object->getStoredData() as $key => $value) { + if (array_key_exists($key, $data) && $data[$key] === $value) { + unset($data[$key]); + } + } + $dataObject = clone $object; + $dataObject->setData($data); + $data = $this->_prepareDataForTable($dataObject, $this->getMainTable()); + unset($data[$this->getIdFieldName()]); + unset($dataObject); + + return $data; + } } diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/AbstractModelTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/AbstractModelTest.php index 49b76a75b8ac30215540f4ebee497986fa232d84..71df4ee8ed9475b92e10972758dc62b3b5926bb3 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/AbstractModelTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/AbstractModelTest.php @@ -108,4 +108,22 @@ class AbstractModelTest extends \PHPUnit_Framework_TestCase $this->resourceMock->expects($this->once())->method('delete')->with($this->model); $this->model->delete(); } + + public function testUpdateStoredData() + { + $this->model->setData( + [ + 'id' => 1000, + 'name' => 'Test Name' + ] + ); + $this->assertEmpty($this->model->getStoredData()); + $this->model->afterLoad(); + $this->assertEquals($this->model->getData(), $this->model->getStoredData()); + $this->model->setData('value', 'Test Value'); + $this->model->afterSave(); + $this->assertEquals($this->model->getData(), $this->model->getStoredData()); + $this->model->afterDelete(); + $this->assertEmpty($this->model->getStoredData()); + } } diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/Resource/Db/AbstractDbTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/Resource/Db/AbstractDbTest.php index 66e49e079e7f0f340db69bf355c973c1b894e9a9..6745f6d62c7412089519d0bd6569d0ef29624cbd 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/Resource/Db/AbstractDbTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/Resource/Db/AbstractDbTest.php @@ -61,7 +61,12 @@ class AbstractDbTest extends \PHPUnit_Framework_TestCase $this->_model = $this->getMockForAbstractClass( 'Magento\Framework\Model\Resource\Db\AbstractDb', - [$contextMock] + [$contextMock], + '', + true, + true, + true, + ['_prepareDataForTable'] ); } @@ -422,4 +427,85 @@ class AbstractDbTest extends \PHPUnit_Framework_TestCase [null, false] ]; } + + public function testPrepareDataForUpdate() + { + $adapterInterfaceMock = $this->getMock('\Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false); + $context = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( + 'Magento\Framework\Model\Context' + ); + $registryMock = $this->getMock('\Magento\Framework\Registry', [], [], '', false); + $resourceMock = $this->getMock( + 'Magento\Framework\Model\Resource\Db\AbstractDb', + [ + '_construct', + '_getReadAdapter', + '_getWriteAdapter', + '__wakeup', + 'getIdFieldName' + ], + [], + '', + false + ); + $adapterMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false); + $resourceMock->expects($this->any()) + ->method('_getWriteAdapter') + ->will($this->returnValue($adapterMock)); + $resourceCollectionMock = $this->getMock('Magento\Framework\Data\Collection\Db', [], [], '', false); + $abstractModelMock = $this->getMockForAbstractClass( + 'Magento\Framework\Model\AbstractModel', + [$context, $registryMock, $resourceMock, $resourceCollectionMock] + ); + $data = 'tableName'; + $this->_resourcesMock->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue($adapterInterfaceMock) + ); + $this->_resourcesMock->expects($this->any())->method('getTableName')->with($data)->will( + $this->returnValue('tableName') + ); + $this->_resourcesMock->expects($this->any()) + ->method('_getWriteAdapter') + ->will($this->returnValue($adapterInterfaceMock)); + $mainTableReflection = new \ReflectionProperty( + 'Magento\Framework\Model\Resource\Db\AbstractDb', + '_mainTable' + ); + $mainTableReflection->setAccessible(true); + $mainTableReflection->setValue($this->_model, 'tableName'); + $idFieldNameReflection = new \ReflectionProperty( + 'Magento\Framework\Model\Resource\Db\AbstractDb', + '_idFieldName' + ); + $idFieldNameReflection->setAccessible(true); + $idFieldNameReflection->setValue($this->_model, 'idFieldName'); + $adapterInterfaceMock->expects($this->any())->method('save')->with('tableName', 'idFieldName'); + $adapterInterfaceMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName')); + + $abstractModelMock->setIdFieldName('id'); + $abstractModelMock->setData( + [ + 'id' => 12345, + 'name' => 'Test Name', + 'value' => 'Test Value' + ] + ); + $abstractModelMock->afterLoad(); + $this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData()); + $newData = ['value' => 'Test Value New']; + $this->_model->expects($this->once())->method('_prepareDataForTable')->will($this->returnValue($newData)); + $abstractModelMock->addData($newData); + $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData()); + $abstractModelMock->isObjectNew(false); + $adapterInterfaceMock->expects($this->once()) + ->method('update') + ->with( + 'tableName', + $newData, + 'idFieldName' + ); + + $this->_model->save($abstractModelMock); + } } diff --git a/lib/internal/Magento/Framework/Phrase.php b/lib/internal/Magento/Framework/Phrase.php index 02c4e0c063c63a36ae430ad59ac233d43b9417ac..992834a4816e1c14f8a56c488a739ed97c3d70f4 100644 --- a/lib/internal/Magento/Framework/Phrase.php +++ b/lib/internal/Magento/Framework/Phrase.php @@ -9,6 +9,7 @@ namespace Magento\Framework; use Zend\Stdlib\JsonSerializable; use Magento\Framework\Phrase\RendererInterface; +use Magento\Framework\Phrase\Renderer\Placeholder; class Phrase implements JsonSerializable { @@ -51,7 +52,11 @@ class Phrase implements JsonSerializable */ public static function getRenderer() { - return self::$renderer; + if (self::$renderer) { + return self::$renderer; + } else { + self::$renderer = new \Magento\Framework\Phrase\Renderer\Placeholder(); + } } /** @@ -93,7 +98,7 @@ class Phrase implements JsonSerializable */ public function render() { - return self::$renderer ? self::$renderer->render([$this->text], $this->arguments) : $this->text; + return self::getRenderer() ? self::getRenderer()->render([$this->text], $this->arguments) : $this->text; } /** diff --git a/lib/internal/Magento/Framework/Phrase/README.md b/lib/internal/Magento/Framework/Phrase/README.md index 9024d6c5bb29d3806a979904d50363e4b52d1433..779979edbb489f8369cc192f1e19ecb19b578699 100644 --- a/lib/internal/Magento/Framework/Phrase/README.md +++ b/lib/internal/Magento/Framework/Phrase/README.md @@ -1,8 +1,8 @@ -# Phase +# Phrase -Class *\Magento\Framework\Phrase* calls renderer to make the translation of the text. **Phase** provides *RedererInterface* and a few renderers to support different kinds of needs of translation of the text. Here are list of renderers in this library: +Class *\Magento\Framework\Phrase* calls renderer to make the translation of the text. **Phrase** provides *RendererInterface* and a few renderers to support different kinds of needs of translation of the text. Here are list of renderers in this library: + * Placeholder render - it replaces placeholders with parameters for substitution. It is the default render if none is set for the Phrase. * Translate render - it is a base renderer that implements text translations. * Inline render - it adds inline translate part to text translation and returns the strings by a template. - * Placeholder render - it replaces placeholders with parameters for substitution. * Composite render - it can have several renderers, calls each renderer for processing the text. Array of renderer class names pass into composite render constructor as a parameter. \ No newline at end of file diff --git a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php index f458d7bd8ece62465704e1d8ef22fd8980ec18a5..580be037ad2062b87fa247b6e5e23f89e75b9241 100644 --- a/lib/internal/Magento/Framework/Reflection/TypeProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/TypeProcessor.php @@ -6,12 +6,14 @@ 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 + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class TypeProcessor { @@ -108,6 +110,9 @@ class TypeProcessor public function register($type) { $typeName = $this->normalizeType($type); + if (null === $typeName) { + return null; + } if (!$this->isTypeSimple($typeName) && !$this->isTypeAny($typeName)) { $typeSimple = $this->getArrayItemType($type); if (!(class_exists($typeSimple) || interface_exists($typeSimple))) { @@ -288,6 +293,9 @@ class TypeProcessor */ public function normalizeType($type) { + if ($type == 'null') { + return null; + } $normalizationMap = [ self::STRING_TYPE => self::NORMALIZED_STRING_TYPE, self::INT_TYPE => self::NORMALIZED_INT_TYPE, diff --git a/lib/internal/Magento/Framework/Test/Unit/PhraseTest.php b/lib/internal/Magento/Framework/Test/Unit/PhraseTest.php index 79a257b4ff77ceb505138f1cc486499c9ee06ca3..f3e8c8d9e0195e9fd64d659d6a020d71c8f93f88 100755 --- a/lib/internal/Magento/Framework/Test/Unit/PhraseTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/PhraseTest.php @@ -19,6 +19,11 @@ class PhraseTest extends \PHPUnit_Framework_TestCase */ protected $rendererMock; + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManager; + /** * SetUp method * @@ -29,6 +34,7 @@ class PhraseTest extends \PHPUnit_Framework_TestCase $this->defaultRenderer = Phrase::getRenderer(); $this->rendererMock = $this->getMockBuilder('Magento\Framework\Phrase\RendererInterface') ->getMock(); + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); } /** @@ -51,7 +57,10 @@ class PhraseTest extends \PHPUnit_Framework_TestCase $text = 'some text'; $arguments = ['arg1', 'arg2']; $result = 'rendered text'; - $phrase = new Phrase($text, $arguments); + $phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + 'arguments' => $arguments, + ]); Phrase::setRenderer($this->rendererMock); $this->rendererMock->expects($this->once()) @@ -72,7 +81,9 @@ class PhraseTest extends \PHPUnit_Framework_TestCase $this->rendererMock->expects($this->never()) ->method('render'); - new Phrase('some text'); + $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => 'some text', + ]); } /** @@ -85,7 +96,10 @@ class PhraseTest extends \PHPUnit_Framework_TestCase $text = 'some text'; $arguments = ['arg1', 'arg2']; $result = 'rendered text'; - $phrase = new Phrase($text, $arguments); + $phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + 'arguments' => $arguments, + ]); Phrase::setRenderer($this->rendererMock); $this->rendererMock->expects($this->once()) @@ -105,6 +119,9 @@ class PhraseTest extends \PHPUnit_Framework_TestCase { $text = 'some text'; $phrase = new Phrase($text); + $phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + ]); $this->assertEquals($text, $phrase->getText()); } @@ -118,10 +135,36 @@ class PhraseTest extends \PHPUnit_Framework_TestCase { $text = 'some text'; $arguments = ['arg1', 'arg2']; - $phrase1 = new Phrase($text); - $phrase2 = new Phrase($text, $arguments); + $phrase1 = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + ]); + $phrase2 = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + 'arguments' => $arguments, + ]); $this->assertEquals([], $phrase1->getArguments()); $this->assertEquals($arguments, $phrase2->getArguments()); } + + /** + * Test default rendering + * + * @return void + */ + public function testDefaultRendering() + { + $text = 'parameter1 is replaced by %1 parameter2 is replaced by %2'; + $arguments = ['arg1', 'arg2']; + $result = 'parameter1 is replaced by arg1 parameter2 is replaced by arg2'; + $phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [ + 'text' => $text, + 'arguments' => $arguments, + ]); + + $this->assertEquals($text, $phrase->getText()); + $this->assertEquals($arguments, $phrase->getArguments()); + $this->assertTrue($phrase->getRenderer() instanceof \Magento\Framework\Phrase\Renderer\Placeholder); + $this->assertEquals($result, $phrase->render()); + } } diff --git a/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php new file mode 100644 index 0000000000000000000000000000000000000000..f848775a34b79ca17c1cc93d69071ab80a664a07 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlock.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Element; + +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; + +/** + * Class of a Exception Handler Block + * + * Block for default and maintenance mode. During layout loading process corrupted block (that throws exception) + * will be replaced with a "dummy" block. As result, page will be loaded without broken block. + * + * When calls from parent to child block occurred and the error appeared in the child block, + * all blocks chain would be removed. + */ +class ExceptionHandlerBlock implements BlockInterface +{ + /** + * @var string + */ + protected $blockName; + + /** + * @param string $blockName + */ + public function __construct($blockName = '') + { + $this->blockName = $blockName; + } + + /** + * Throws an exception when parent block calls corrupted child block method + * + * @param string $method + * @param array $args + * @return void + * @throws LocalizedException + */ + public function __call($method, $args) + { + throw new LocalizedException( + new Phrase('Block %1 throws exception and cannot be rendered.', [$this->blockName]) + ); + } + + /** + * Declared in BlockInterface and also throws an exception + * + * @throws LocalizedException + * @return void + */ + public function toHtml() + { + throw new LocalizedException( + new Phrase('Block %1 throws exception and cannot be rendered.', [$this->blockName]) + ); + } +} diff --git a/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..522324c0ea22df2f5ffacfb7496d07127819d4cb --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/ExceptionHandlerBlockFactory.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Element; + +/** + * Class ExceptionHandlerBlockFactory + * @package Magento\Framework\View\Element + */ +class ExceptionHandlerBlockFactory +{ + const DEFAULT_INSTANCE_NAME = 'Magento\Framework\View\Element\ExceptionHandlerBlock'; + + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $objectManager; + + /** + * @var string + */ + protected $instanceName; + + /** + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param string $instanceName + */ + public function __construct( + \Magento\Framework\ObjectManagerInterface $objectManager, + $instanceName = self::DEFAULT_INSTANCE_NAME + ) { + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + /** + * Create exception handling block + * + * @param array $data + * @return \Magento\Framework\View\Element\BlockInterface + */ + public function create(array $data = []) + { + return $this->objectManager->create($this->instanceName, $data); + } +} diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index c2184cfff688e3f04e0863954a831e68b82b9ce2..6c857548d18ed329d6767bbc6f35684f8205e059 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -148,9 +148,9 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra /** * @param Layout\ProcessorFactory $processorFactory - * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param ManagerInterface $eventManager * @param Layout\Data\Structure $structure - * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param MessageManagerInterface $messageManager * @param Design\Theme\ResolverInterface $themeResolver * @param Layout\ReaderPool $readerPool * @param Layout\GeneratorPool $generatorPool @@ -458,14 +458,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra { $this->build(); if (!isset($this->_renderElementCache[$name]) || !$useCache) { - if ($this->isUiComponent($name)) { - $result = $this->_renderUiComponent($name); - } elseif ($this->isBlock($name)) { - $result = $this->_renderBlock($name); - } else { - $result = $this->_renderContainer($name); - } - $this->_renderElementCache[$name] = $result; + $this->_renderElementCache[$name] = $this->renderNonCachedElement($name); } $this->_renderingOutput->setData('output', $this->_renderElementCache[$name]); $this->_eventManager->dispatch( @@ -475,6 +468,24 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra return $this->_renderingOutput->getData('output'); } + /** + * Render non cached element + * + * @param string $name + * @return string + */ + public function renderNonCachedElement($name) + { + if ($this->isUiComponent($name)) { + $result = $this->_renderUiComponent($name); + } elseif ($this->isBlock($name)) { + $result = $this->_renderBlock($name); + } else { + $result = $this->_renderContainer($name); + } + return $result; + } + /** * Gets HTML of block element * diff --git a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php index 1bd30ebe9ca8c29dfedb2a98423306a3174266d4..d6b0a5b5a11f35c268155d40e59312ece89c7fae 100644 --- a/lib/internal/Magento/Framework/View/Layout/Generator/Block.php +++ b/lib/internal/Magento/Framework/View/Layout/Generator/Block.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\View\Layout\Generator; +use Magento\Framework\App\State; use Magento\Framework\ObjectManager\Config\Reader\Dom; use Magento\Framework\View\Layout; @@ -49,6 +50,16 @@ class Block implements Layout\GeneratorInterface */ protected $scopeResolver; + /** + * @var State + */ + protected $appState; + + /** + * @var \Magento\Framework\View\Element\ExceptionHandlerBlock + */ + protected $exceptionHandlerBlockFactory; + /** * @param \Magento\Framework\View\Element\BlockFactory $blockFactory * @param \Magento\Framework\Data\Argument\InterpreterInterface $argumentInterpreter @@ -56,6 +67,8 @@ class Block implements Layout\GeneratorInterface * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver + * @param \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory + * @param State $appState */ public function __construct( \Magento\Framework\View\Element\BlockFactory $blockFactory, @@ -63,7 +76,9 @@ class Block implements Layout\GeneratorInterface \Magento\Framework\Event\ManagerInterface $eventManager, \Psr\Log\LoggerInterface $logger, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\ScopeResolverInterface $scopeResolver + \Magento\Framework\App\ScopeResolverInterface $scopeResolver, + \Magento\Framework\View\Element\ExceptionHandlerBlockFactory $exceptionHandlerBlockFactory, + State $appState ) { $this->blockFactory = $blockFactory; $this->argumentInterpreter = $argumentInterpreter; @@ -71,6 +86,8 @@ class Block implements Layout\GeneratorInterface $this->logger = $logger; $this->scopeConfig = $scopeConfig; $this->scopeResolver = $scopeResolver; + $this->exceptionHandlerBlockFactory = $exceptionHandlerBlockFactory; + $this->appState = $appState; } /** @@ -89,6 +106,7 @@ class Block implements Layout\GeneratorInterface * @param Layout\Reader\Context $readerContext * @param Context $generatorContext * @return $this + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function process(Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext) { @@ -102,34 +120,72 @@ class Block implements Layout\GeneratorInterface foreach ($scheduledStructure->getElements() as $elementName => $element) { list($type, $data) = $element; if ($type === self::TYPE) { - $block = $this->generateBlock($scheduledStructure, $structure, $elementName); - $blocks[$elementName] = $block; - $layout->setBlock($elementName, $block); - if (!empty($data['actions'])) { - $blockActions[$elementName] = $data['actions']; + try { + $block = $this->generateBlock($scheduledStructure, $structure, $elementName); + $blocks[$elementName] = $block; + $layout->setBlock($elementName, $block); + if (!empty($data['actions'])) { + $blockActions[$elementName] = $data['actions']; + } + } catch (\Exception $e) { + $this->handleRenderException($e); + unset($blocks[$elementName]); } } } // Set layout instance to all generated block (trigger _prepareLayout method) foreach ($blocks as $elementName => $block) { - $block->setLayout($layout); - $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]); + try { + $block->setLayout($layout); + $this->eventManager->dispatch('core_layout_block_create_after', ['block' => $block]); + } catch (\Exception $e) { + $this->handleRenderException($e); + $layout->setBlock( + $elementName, + $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]) + ); + unset($blockActions[$elementName]); + } $scheduledStructure->unsetElement($elementName); } // Run all actions after layout initialization foreach ($blockActions as $elementName => $actions) { - foreach ($actions as $action) { - list($methodName, $actionArguments, $configPath, $scopeType) = $action; - if (empty($configPath) - || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope()) - ) { - $this->generateAction($blocks[$elementName], $methodName, $actionArguments); + try { + foreach ($actions as $action) { + list($methodName, $actionArguments, $configPath, $scopeType) = $action; + if (empty($configPath) + || $this->scopeConfig->isSetFlag($configPath, $scopeType, $this->scopeResolver->getScope()) + ) { + $this->generateAction($blocks[$elementName], $methodName, $actionArguments); + } } + } catch (\Exception $e) { + $this->handleRenderException($e); + $layout->setBlock( + $elementName, + $this->exceptionHandlerBlockFactory->create(['blockName' => $elementName]) + ); } } return $this; } + /** + * Handle exceptions during rendering process + * + * @param \Exception $cause + * @throws \Exception + * @return void + */ + protected function handleRenderException(\Exception $cause) + { + if ($this->appState->getMode() === State::MODE_DEVELOPER) { + throw $cause; + } + $message = ($cause instanceof LocalizedException) ? $cause->getLogMessage() : $cause->getMessage(); + $this->logger->critical($message); + } + /** * Create block and set related data * diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php index 7679ac3d2846e2f1a06c3dada1b988e275ea5de4..45effcf449e43c4e7a05dcc77d37003195069eea 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -26,11 +26,6 @@ class LayoutTest extends \PHPUnit_Framework_TestCase */ protected $processorFactoryMock; - /** - * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject - */ - protected $appStateMock; - /** * @var \Magento\Framework\View\Design\Theme\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ diff --git a/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..92d748e923eb148cadd2b8a2af7a8628116f2630 --- /dev/null +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/ParamOverriderInterface.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\Webapi\Rest\Request; + +/** + * Override parameter values + * + * Parameters in the webapi.xml can be forced. This ensures that on specific routes, a specific value is always used. + * For instance, if there is a ".../me/..." route, the route should use only user information specific to the + * currently logged in user. More specifically, if there was a "/customers/me/addresses" route, the service method + * invoked could have a signature of "getAddresses($customerId)", but in the webapi.xml, the $customerId parameter + * would be forced to be the customer id of the current authenticated user. + * + * The forced override parameter configuration is in the webapi.xml. + * + * <data> + * <parameter name="customer.id" force="true">%customer_id%</parameter> + * </data> + * + * 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 overridden value to use. + * + * @return string|int|null + */ + public function getOverriddenValue(); +} diff --git a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php index 14caad463c95a3878d7351a339c20173665b6dc1..e232546d6ac1eea71af4a52b97f22aace0e83717 100644 --- a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php @@ -137,8 +137,7 @@ class ServiceInputProcessor if (is_subclass_of($className, self::EXTENSION_ATTRIBUTES_TYPE)) { $className = substr($className, 0, -strlen('Interface')); } - $factory = $this->objectManager->get($className . 'Factory'); - $object = $factory->create(); + $object = $this->objectManager->create($className); foreach ($data as $propertyName => $value) { // Converts snake_case to uppercase CamelCase to help form getter/setter method names diff --git a/lib/internal/Magento/Framework/Webapi/Test/Unit/ServiceInputProcessorTest.php b/lib/internal/Magento/Framework/Webapi/Test/Unit/ServiceInputProcessorTest.php index 41cdf8184ba372143f8ed2fdde2ff790f8633fa0..ac75d2c131fb1cd2319c1ebd36ab58014917ec87 100644 --- a/lib/internal/Magento/Framework/Webapi/Test/Unit/ServiceInputProcessorTest.php +++ b/lib/internal/Magento/Framework/Webapi/Test/Unit/ServiceInputProcessorTest.php @@ -42,6 +42,14 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase $this->objectManagerMock = $this->getMockBuilder('\Magento\Framework\ObjectManagerInterface') ->disableOriginalConstructor() ->getMock(); + $this->objectManagerMock->expects($this->any()) + ->method('create') + ->willReturnCallback( + function ($className) use ($objectManager) { + return $objectManager->getObject($className); + } + ); + /** @var \Magento\Framework\Reflection\TypeProcessor $typeProcessor */ $typeProcessor = $objectManager->getObject('Magento\Framework\Reflection\TypeProcessor'); $cache = $this->getMockBuilder('Magento\Framework\App\Cache\Type\Webapi') @@ -119,12 +127,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testNestedDataProperties() { - $this->setupFactory( - [ - 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Nested', - '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple', - ] - ); $data = ['nested' => ['details' => ['entityId' => 15, 'name' => 'Test']]]; $result = $this->serviceInputProcessor->process( 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService', @@ -167,7 +169,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testAssociativeArrayProperties() { - $this->setupFactory(['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple']); $data = ['associativeArray' => ['key' => 'value', 'key_two' => 'value_two']]; $result = $this->serviceInputProcessor->process( 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService', @@ -186,7 +187,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testAssociativeArrayPropertiesWithItem() { - $this->setupFactory(['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray']); $data = ['associativeArray' => ['item' => 'value']]; $result = $this->serviceInputProcessor->process( 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService', @@ -204,7 +204,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testAssociativeArrayPropertiesWithItemArray() { - $this->setupFactory(['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray']); $data = ['associativeArray' => ['item' => ['value1','value2']]]; $result = $this->serviceInputProcessor->process( 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService', @@ -223,11 +222,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testArrayOfDataObjectProperties() { - $this->setupFactory( - [ - '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple' - ] - ); $data = [ 'dataObjects' => [ ['entityId' => 14, 'name' => 'First'], @@ -259,7 +253,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testNestedSimpleArrayProperties() { - $this->setupFactory(['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray']); $data = ['arrayData' => ['ids' => [1, 2, 3, 4]]]; $result = $this->serviceInputProcessor->process( 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\TestService', @@ -281,7 +274,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testNestedAssociativeArrayProperties() { - $this->setupFactory(['Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray']); $data = [ 'associativeArrayData' => ['associativeArray' => ['key' => 'value', 'key2' => 'value2']], ]; @@ -305,12 +297,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase public function testNestedArrayOfDataObjectProperties() { - $this->setupFactory( - [ - 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\DataArray', - '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple', - ] - ); $data = [ 'dataObjects' => [ 'items' => [['entityId' => 1, 'name' => 'First'], ['entityId' => 2, 'name' => 'Second']], @@ -352,14 +338,6 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase */ public function testCustomAttributesProperties($customAttributeType, $inputData, $expectedObject) { - $this->setupFactory( - [ - 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\ObjectWithCustomAttributes', - '\Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple', - 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple', - 'Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray', - ] - ); $this->customAttributeTypeLocator->expects($this->any())->method('getType')->willReturn($customAttributeType); $result = $this->serviceInputProcessor->process( @@ -521,27 +499,4 @@ class ServiceInputProcessorTest extends \PHPUnit_Framework_TestCase ]] ); } - protected function setupFactory(array $classNames) - { - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - $returnValueMap = []; - foreach ($classNames as $className) { - $factoryMock = $this->getMockBuilder($className . 'Factory') - ->setMethods(['create']) - ->disableOriginalConstructor() - ->getMock(); - $factoryMock->expects($this->any()) - ->method('create') - ->willReturnCallback( - function () use ($objectManager, $className) { - return $objectManager->getObject($className); - } - ); - $returnValueMap[] = [$className . 'Factory', $factoryMock]; - } - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->will($this->returnValueMap($returnValueMap)); - } } diff --git a/lib/internal/Magento/Framework/composer.json b/lib/internal/Magento/Framework/composer.json index 3b4455968232441ab79e3998be622b4d838f74fa..769a3a5d91d3f53dba9d6c08ee4fb4a25dbe4732 100644 --- a/lib/internal/Magento/Framework/composer.json +++ b/lib/internal/Magento/Framework/composer.json @@ -2,7 +2,7 @@ "name": "magento/framework", "description": "N/A", "type": "magento2-library", - "version": "0.74.0-beta4", + "version": "0.74.0-beta6", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/setup/src/Magento/Setup/Model/License.php b/setup/src/Magento/Setup/Model/License.php index beb3d857aedea1ca21ca059697d79434a114a263..1c7458bd3404c1c816d134f61a97c4f41a43b5ee 100644 --- a/setup/src/Magento/Setup/Model/License.php +++ b/setup/src/Magento/Setup/Model/License.php @@ -16,12 +16,19 @@ use Magento\Framework\Filesystem; */ class License { + /** + * Default License File location + * + * @var string + */ + const DEFAULT_LICENSE_FILENAME = 'LICENSE.txt'; + /** * License File location * * @var string */ - const LICENSE_FILENAME = 'LICENSE.txt'; + const LICENSE_FILENAME = 'LICENSE_EE.txt'; /** * Directory that contains license file @@ -43,13 +50,16 @@ class License /** * Returns contents of License file. * - * @return string + * @return string|boolean */ public function getContents() { - if (!$this->dir->isFile(self::LICENSE_FILENAME)) { + if ($this->dir->isFile(self::LICENSE_FILENAME)) { + return $this->dir->readFile(self::LICENSE_FILENAME); + } elseif ($this->dir->isFile(self::DEFAULT_LICENSE_FILENAME)) { + return $this->dir->readFile(self::DEFAULT_LICENSE_FILENAME); + } else { return false; } - return $this->dir->readFile(self::LICENSE_FILENAME); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/LicenseTest.php b/setup/src/Magento/Setup/Test/Unit/Model/LicenseTest.php index 1d8f9f3accce01dd668f9f8b4ed4e998a2fafe47..3bb5a5324c33e7b58bb3d11a28cacdd10f0a8735 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/LicenseTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/LicenseTest.php @@ -33,14 +33,12 @@ class LicenseTest extends \PHPUnit_Framework_TestCase public function testGetContents() { $this->directoryReadMock - ->expects($this->once()) + ->expects($this->atLeastOnce()) ->method('readFile') - ->with(License::LICENSE_FILENAME) ->will($this->returnValue('License text')); $this->directoryReadMock - ->expects($this->once()) + ->expects($this->atLeastOnce()) ->method('isFile') - ->with(License::LICENSE_FILENAME) ->will($this->returnValue(true)); $license = new License($this->filesystemMock); @@ -50,9 +48,8 @@ class LicenseTest extends \PHPUnit_Framework_TestCase public function testGetContentsNoFile() { $this->directoryReadMock - ->expects($this->once()) + ->expects($this->atLeastOnce()) ->method('isFile') - ->with(License::LICENSE_FILENAME) ->will($this->returnValue(false)); $license = new License($this->filesystemMock);