diff --git a/app/code/Magento/Catalog/Block/Product/AbstractProduct.php b/app/code/Magento/Catalog/Block/Product/AbstractProduct.php index d9702c5073fb653c132c89d761e9ddf14faa34c1..f1bb89d4424f7f4436abea0c137a0457a0ad13c8 100644 --- a/app/code/Magento/Catalog/Block/Product/AbstractProduct.php +++ b/app/code/Magento/Catalog/Block/Product/AbstractProduct.php @@ -124,7 +124,7 @@ class AbstractProduct extends \Magento\Framework\View\Element\Template */ public function getAddToCartUrl($product, $additional = []) { - if ($product->getTypeInstance()->hasRequiredOptions($product)) { + if (!$product->getTypeInstance()->isPossibleBuyFromList($product)) { if (!isset($additional['_escape'])) { $additional['_escape'] = true; } diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index 6de6ea6c6c6bca8029aee2be5749d555690d48c8..11b8d03fc7ee5cc23dd627e65ad9651a5b243b7d 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -1092,4 +1092,15 @@ abstract class AbstractType { return []; } + + /** + * Check if product can be potentially buyed from the category page or some other list + * + * @param \Magento\Catalog\Model\Product $product + * @return bool + */ + public function isPossibleBuyFromList($product) + { + return !$this->hasRequiredOptions($product); + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php index f420f140b35820e3cbcebf986ed305217523aab2..39e3263722a7c3f84fce9f6ce3e5b8ee2f2899d6 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php @@ -154,9 +154,9 @@ class ListProductTest extends \PHPUnit_Framework_TestCase ]; $this->typeInstanceMock->expects($this->once()) - ->method('hasRequiredOptions') + ->method('isPossibleBuyFromList') ->with($this->equalTo($this->productMock)) - ->will($this->returnValue(false)); + ->will($this->returnValue(true)); $this->cartHelperMock->expects($this->any()) ->method('getAddUrl') ->with($this->equalTo($this->productMock), $this->equalTo([])) diff --git a/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js b/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js index 45c9f73e051c788c55f24d2f95f1e286c7d6bd02..7db4f5d745626c0da12d9a4032bc5466c57f282b 100644 --- a/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js +++ b/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js @@ -84,6 +84,17 @@ define([ } if (res.backUrl) { + var eventData = { + 'form': form, + 'redirectParameters': [] + } + // trigger global event, so other modules will be able add parameters to redirect url + $('body').trigger('catalogCategoryAddToCartRedirect', eventData); + if (eventData.redirectParameters.length > 0) { + var parameters = res.backUrl.split('#'); + parameters.push(eventData.redirectParameters.join('&')); + res.backUrl = parameters.join('#'); + } window.location = res.backUrl; return; } diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 0b8a4aee9feced6e4f104208b7563bda16b6305c..0bd2f23418221770d4562eb67d6af9d3e8bd4646 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -1287,4 +1287,19 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType } return $this->catalogConfig; } + + /** + * @inheritdoc + */ + public function isPossibleBuyFromList($product) + { + $isAllCustomOptionsDisplayed = true; + foreach ($this->getConfigurableAttributes($product) as $attribute) { + $eavAttribute = $attribute->getProductAttribute(); + + $isAllCustomOptionsDisplayed = ($isAllCustomOptionsDisplayed && $eavAttribute->getUsedInProductListing()); + } + + return $isAllCustomOptionsDisplayed; + } } diff --git a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml index 86046fdce4b6ee3d264d86f94f3a7dcfbf4b13b3..9c3274627b984cc093ecf5f39c54190ead2412fa 100644 --- a/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml +++ b/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml @@ -7,15 +7,17 @@ <?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?> <div class="swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>"></div> <script> - require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) { - $('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({ - selectorProduct: '.product-item-details', - onlySwatches: true, - enableControlLabel: false, - numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>, - jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>, - jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>, - mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>' - }); + require( + ["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer", "Magento_Swatches/js/catalog-add-to-cart"], + function ($) { + $('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({ + selectorProduct: '.product-item-details', + onlySwatches: true, + enableControlLabel: false, + numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>, + jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>, + jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>, + mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>' + }); }); </script> diff --git a/app/code/Magento/Swatches/view/frontend/web/js/catalog-add-to-cart.js b/app/code/Magento/Swatches/view/frontend/web/js/catalog-add-to-cart.js new file mode 100644 index 0000000000000000000000000000000000000000..7900ff67b09be952f13bcfd1bd88842327dd0db4 --- /dev/null +++ b/app/code/Magento/Swatches/view/frontend/web/js/catalog-add-to-cart.js @@ -0,0 +1,17 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +require([ + 'jquery' +], function ($) { + 'use strict'; + + $('body').on('catalogCategoryAddToCartRedirect', function (event, data) { + $(data.form).find('[name*="super"]').each(function (index, item) { + var $item = $(item); + + data.redirectParameters.push($item.attr('data-attr-name') + '=' + $item.val()); + }); + }); +}); diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index 54e207c335ffb5b6a007a7774df4e2c4a0760628..452c9b6f94d3c60e83bd35a5a932c6b5f8a9092f 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -264,6 +264,8 @@ define([ */ _init: function () { if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') { + // store unsorted attributes + this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes); this._sortAttributes(); this._RenderControls(); $(this.element).trigger('swatch.initialized'); @@ -617,6 +619,7 @@ define([ $parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected'); $label.text($this.attr('option-label')); $input.val($this.attr('option-id')); + $input.attr('data-attr-name', this._getAttributeCodeById(attributeId)); $this.addClass('selected'); $widget._toggleCheckedAttributes($this, $wrapper); } @@ -633,6 +636,19 @@ define([ $input.trigger('change'); }, + /** + * Get human readable attribute code (eg. size, color) by it ID from configuration + * + * @param {Number} attributeId + * @returns {*} + * @private + */ + _getAttributeCodeById: function (attributeId) { + var attribute = this.options.jsonConfig.mappedAttributes[attributeId]; + + return attribute ? attribute.code : attributeId; + }, + /** * Toggle accessibility attributes * @@ -1104,7 +1120,7 @@ define([ params = $.parseQuery(window.location.href.substr(hashIndex + 1)); selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) { - var attribute = this.options.jsonConfig.attributes[attributeId]; + var attribute = this.options.jsonConfig.mappedAttributes[attributeId]; return attribute ? attribute.code : attributeId; }.bind(this))); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php index a4a773ae7c7ecd02e11b6e824d6ec3d50925523b..db43cc535ca01c4bbac96e425a435bd71ef3fcef 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php @@ -47,6 +47,14 @@ class Curl extends AbstractCurl implements CatalogProductAttributeInterface 'No' => 0, 'Yes' => 1, ], + 'is_global' => [ + 'Store View' => '0', + 'Global' => '1', + ], + 'used_in_product_listing' => [ + 'No' => '0', + 'Yes' => '1', + ], ]; /** @@ -76,6 +84,7 @@ class Curl extends AbstractCurl implements CatalogProductAttributeInterface unset($data['options']); } + $data = $this->changeStructureOfTheData($data); $url = $_ENV['app_backend_url'] . 'catalog/product_attribute/save/back/edit'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write($url, $data); @@ -104,4 +113,13 @@ class Curl extends AbstractCurl implements CatalogProductAttributeInterface return $resultData; } + + /** + * @param array $data + * @return array + */ + protected function changeStructureOfTheData(array $data) + { + return $data; + } } diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php index bf5d5944aa3da0a7093d5bbe33ea00897f3b5397..626be7dee3652ee88407d47f1bac313a96dde225 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php @@ -172,7 +172,7 @@ class Curl extends ProductCurl implements ConfigurableProductInterface $keyIds[] = $attribute['options'][$optionKey]['id']; $configurableAttribute[] = sprintf( '"%s":"%s"', - $attribute['attribute_code'], + isset($attribute['attribute_code']) ? $attribute['attribute_code'] : $attribute['frontend_label'], $attribute['options'][$optionKey]['id'] ); } diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ListProduct.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ListProduct.php new file mode 100644 index 0000000000000000000000000000000000000000..39c630a0aa2060f23e6ef87c2682e73169ffa777 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ListProduct.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Block\Product; + +use Magento\Mtf\Client\Locator; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Catalog\Test\Block\Product\ListProduct as CatalogListProduct; + +/** + * Product list block. + */ +class ListProduct extends CatalogListProduct +{ + /** + * @inheritdoc + */ + public function getProductItem(FixtureInterface $product) + { + $locator = sprintf($this->productItem, $product->getName()); + + return $this->blockFactory->create( + \Magento\Swatches\Test\Block\Product\ProductList\ProductItem::class, + ['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)] + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php new file mode 100755 index 0000000000000000000000000000000000000000..414d03bc687871490b551fcfb807f2958fd4e25e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Block\Product\ProductList; + +use Magento\Mtf\Client\Locator; +use Magento\Catalog\Test\Block\Product\ProductList\ProductItem as CatalogProductItem; + +/** + * Product item block on frontend category view. + */ +class ProductItem extends CatalogProductItem +{ + /** + * Selector for the swatches of the product. + * + * @var string + */ + protected $swatchSelector = 'div[option-id="%s"]'; + + /** + * Fill product options on category page. + * + * @param \Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct $product + * @return void + */ + public function fillData(\Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct $product) + { + $checkoutData = $product->getCheckoutData(); + $options = $checkoutData['options']['configurable_options']; + $confAttrData = $product->getDataFieldConfig('configurable_attributes_data'); + $confAttrSource = $confAttrData['source']; + $attributes = $confAttrSource->getAttributes(); + + foreach ($options as $option) { + if (!isset($attributes[$option['title']])) { + continue; + } + $availableOptions = $attributes[$option['title']]->getOptions(); + $optionKey = str_replace('option_key_', '', $option['value']); + if (!isset($availableOptions[$optionKey])) { + continue; + } + $optionForSelect = $availableOptions[$optionKey]; + $this->clickOnSwatch($optionForSelect['id']); + } + } + + /** + * Click on swatch. + * + * @param $optionId + */ + private function clickOnSwatch($optionId) + { + $selector = sprintf($this->swatchSelector, $optionId); + $this->_rootElement->find($selector, Locator::SELECTOR_CSS)->click(); + } + + /** + * @inheritdoc + */ + public function clickAddToCart() + { + $this->_rootElement->hover(); + parent::clickAddToCart(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ViewWithSwatches.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ViewWithSwatches.php new file mode 100644 index 0000000000000000000000000000000000000000..c1405b4a807718edbb511569ac23d03fc2b52d43 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ViewWithSwatches.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Block\Product; + +use Magento\Catalog\Test\Block\Product\View; +use Magento\Mtf\Fixture\InjectableFixture; + +/** + * Configurable product view block with swatch attributes on frontend product page + */ +class ViewWithSwatches extends View +{ + /** + * Selector for swatch attribute value + * + * @var string + */ + private $swatchAttributeSelector = '.swatch-attribute.%s .swatch-attribute-selected-option'; + + /** + * Get chosen options from the product view page. + * + * @param InjectableFixture $product + * @return array + */ + public function getSelectedSwatchOptions(InjectableFixture $product) + { + $checkoutData = $product->getCheckoutData(); + $availableAttributes = $product->getConfigurableAttributesData(); + $attributesData = $availableAttributes['attributes_data']; + $formData = []; + foreach ($checkoutData['options']['configurable_options'] as $item) { + $selector = sprintf($this->swatchAttributeSelector, $attributesData[$item['title']]['attribute_code']); + $this->waitForElementVisible($selector); + $selected = $this->_rootElement->find($selector)->getText(); + $formData[$item['title']] = $selected; + } + + return $formData; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Constraint/AssertSwatchConfigurableProductPage.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Constraint/AssertSwatchConfigurableProductPage.php new file mode 100644 index 0000000000000000000000000000000000000000..460a13ce49d704f30f513af5c8f3189c45f3ffc4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Constraint/AssertSwatchConfigurableProductPage.php @@ -0,0 +1,97 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Constraint; + +use Magento\Catalog\Test\Constraint\AssertProductPage; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Catalog\Test\Page\Product\CatalogProductView; +use Magento\Mtf\Client\BrowserInterface; + +/** + * Assert that product with swatches and regular dropdown redirect can't be add to cart from catalog catergory page. + */ +class AssertSwatchConfigurableProductPage extends AssertProductPage +{ + /** + * {@inheritdoc} + */ + public function processAssert( + BrowserInterface $browser, + CatalogProductView $catalogProductView, + FixtureInterface $product + ) { + $this->product = $product; + $this->productView = $catalogProductView->getProductViewWithSwatchesBlock(); + $this->objectManager->create( + \Magento\Swatches\Test\TestStep\AddProductToCartFromCatalogCategoryPageStep::class, + [ + 'product' => $product + ] + )->run(); + // we need this line for waiti until page will be fully loaded + $this->productView->getSelectedSwatchOptions($this->product); + $errors = $this->verify(); + \PHPUnit_Framework_Assert::assertEmpty( + $errors, + "\nFound the following errors:\n" . implode(" \n", $errors) + ); + } + + /** + * Verify product on product view page. + * + * @return array + */ + protected function verify() + { + $errors = parent::verify(); + $errors[] = $this->verifySwatches(); + + return array_filter($errors); + } + + /** + * Verify selected swatches on product view page. + * + * @return array + */ + protected function verifySwatches() + { + $actualData = $this->productView->getSelectedSwatchOptions($this->product); + $expectedData = $this->convertCheckoutData($this->product); + $this->verifyData($expectedData, $actualData); + } + + /** + * Get swatch attributes formatter to attributes comparison. + * + * @param FixtureInterface $product + * @return array + */ + public function convertCheckoutData(FixtureInterface $product) + { + $out = []; + $checkoutData = $product->getCheckoutData(); + $availableAttributes = $product->getConfigurableAttributesData(); + $attributesData = $availableAttributes['attributes_data']; + foreach ($checkoutData['options']['configurable_options'] as $item) { + $out[$item['title']] = $attributesData[$item['title']]['options'][$item['value']]['label']; + } + + return $out; + } + + /** + * Return string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Swatch attributes displayed as expected on product page'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/Cart/Item.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/Cart/Item.php new file mode 100644 index 0000000000000000000000000000000000000000..46c9b383ae8420c5210a3d4f71ac49b3513b1724 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/Cart/Item.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Fixture\Cart; + +use Magento\ConfigurableProduct\Test\Fixture\Cart\Item as ConfigurableCart; + +/** + * @inheritdoc + */ +class Item extends ConfigurableCart +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/ConfigurableProduct.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/ConfigurableProduct.xml new file mode 100644 index 0000000000000000000000000000000000000000..dbc57a321a68238adff45355fd87a4e97028cde2 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/ConfigurableProduct.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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="configurableProductSwatch" + module="Magento_Swatches" + class="Magento\Swatches\Test\Fixture\ConfigurableProduct" + extends="\Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct" + > + </fixture> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/SwatchProductAttribute.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/SwatchProductAttribute.xml new file mode 100644 index 0000000000000000000000000000000000000000..d96331b8159d50a60f6aa215d523d492aa5de7a4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Fixture/SwatchProductAttribute.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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="swatchesProductAttribute" + module="Magento_Swatches" + handler_interface="Magento\Swatches\Test\Handler\SwatchProductAttribute\SwatchProductAttributeInterface" + repository_class="Magento\Swatches\Test\Repository\SwatchProductAttribute" + class="Magento\Swatches\Test\Fixture\SwatchesProductAttribute" + extends="\Magento\Catalog\Test\Fixture\CatalogProductAttribute"> + </fixture> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/Curl.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/Curl.php new file mode 100644 index 0000000000000000000000000000000000000000..86de2d651da1ecf3d48fdb165de0b223a665f126 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/Curl.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Handler\SwatchProductAttribute; + +use Magento\Catalog\Test\Handler\CatalogProductAttribute\Curl as CatalogProductAttributeCurl; +use Magento\Mtf\Config\DataInterface; +use Magento\Mtf\System\Event\EventManagerInterface; + +/** + * Curl handler for creating Swatch Attribute. + */ +class Curl extends CatalogProductAttributeCurl implements SwatchProductAttributeInterface +{ + /** + * Add mapping data related to swatches. + * + * @param DataInterface $configuration + * @param EventManagerInterface $eventManager + */ + public function __construct(DataInterface $configuration, EventManagerInterface $eventManager) + { + parent::__construct($configuration, $eventManager); + $this->mappingData['frontend_input'] = [ + 'Text Swatch' => 'swatch_text', + ]; + } + + /** + * Re-map options from default options structure to swatches structure, + * as swatches was initially created with name convention differ from other attributes. + * + * @param array $data + * @return array + */ + protected function changeStructureOfTheData(array $data) + { + $data = parent::changeStructureOfTheData($data); + $data['optiontext'] = $data['option']; + $data['swatchtext'] = [ + 'value' => $data['option']['value'] + ]; + unset($data['option']); + return $data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/SwatchProductAttributeInterface.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/SwatchProductAttributeInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..41fdebdd5ce8b084eca0a40c58aeba580a7b3518 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/SwatchProductAttributeInterface.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\Handler\SwatchProductAttribute; + +use Magento\Mtf\Handler\HandlerInterface; + +/** + * Interface for swatch specific Curl calls + */ +interface SwatchProductAttributeInterface extends HandlerInterface +{ + // +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Category/CatalogCategoryView.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Category/CatalogCategoryView.xml new file mode 100644 index 0000000000000000000000000000000000000000..9cb5e4fbdf69756a5289555e15d568f577bbf21d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Category/CatalogCategoryView.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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="CatalogCategoryView" area="Category" mca="catalog/category/view" module="Magento_Catalog"> + <block name="listSwatchesProductBlock" class="Magento\Swatches\Test\Block\Product\ListProduct" locator=".products.wrapper.grid" strategy="css selector"/> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Product/CatalogProductView.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Product/CatalogProductView.xml new file mode 100644 index 0000000000000000000000000000000000000000..315c6a02ee968e6bc93ec52bd5555d65be3f87d7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Page/Product/CatalogProductView.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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"> + <block name="productViewWithSwatchesBlock" class="Magento\Swatches\Test\Block\Product\ViewWithSwatches" locator="#maincontent" strategy="css selector" /> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct.xml new file mode 100644 index 0000000000000000000000000000000000000000..22e73572ead0d9081b3bdf15c78f75df12409a3c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2016 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\ConfigurableProduct\Test\Repository\ConfigurableProduct"> + <dataset name="product_with_text_swatch"> + <field name="name" xsi:type="string">Test configurable product with color and size %isolation%</field> + <field name="sku" xsi:type="string">sku_test_configurable_product_%isolation%</field> + <field name="product_has_weight" xsi:type="string">This item has weight</field> + <field name="weight" xsi:type="string">30</field> + <field name="status" xsi:type="string">Yes</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">configurable-product-%isolation%</field> + <field name="configurable_attributes_data" xsi:type="array"> + <item name="dataset" xsi:type="string">text_swatch</item> + </field> + <field name="quantity_and_stock_status" xsi:type="array"> + <item name="is_in_stock" xsi:type="string">In Stock</item> + </field> + <field name="category_ids" xsi:type="array"> + <item name="dataset" xsi:type="string">default_subcategory</item> + </field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="array"> + <item name="dataset" xsi:type="string">default</item> + </item> + </field> + <field name="attribute_set_id" xsi:type="array"> + <item name="dataset" xsi:type="string">custom_attribute_set</item> + </field> + <field name="price" xsi:type="array"> + <item name="value" xsi:type="string">40</item> + <item name="dataset" xsi:type="string">price_40</item> + </field> + <field name="checkout_data" xsi:type="array"> + <item name="dataset" xsi:type="string">two_text_swatches</item> + </field> + </dataset> + <dataset name="product_with_text_swatch_and_size"> + <field name="name" xsi:type="string">Test configurable product with color and size %isolation%</field> + <field name="sku" xsi:type="string">sku_test_configurable_product_%isolation%</field> + <field name="product_has_weight" xsi:type="string">This item has weight</field> + <field name="weight" xsi:type="string">30</field> + <field name="status" xsi:type="string">Yes</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">configurable-product-%isolation%</field> + <field name="configurable_attributes_data" xsi:type="array"> + <item name="dataset" xsi:type="string">text_swatch_with_dropdown</item> + </field> + <field name="quantity_and_stock_status" xsi:type="array"> + <item name="is_in_stock" xsi:type="string">In Stock</item> + </field> + <field name="category_ids" xsi:type="array"> + <item name="dataset" xsi:type="string">default_subcategory</item> + </field> + <field name="website_ids" xsi:type="array"> + <item name="0" xsi:type="array"> + <item name="dataset" xsi:type="string">default</item> + </item> + </field> + <field name="attribute_set_id" xsi:type="array"> + <item name="dataset" xsi:type="string">custom_attribute_set</item> + </field> + <field name="price" xsi:type="array"> + <item name="value" xsi:type="string">40</item> + <item name="dataset" xsi:type="string">price_40</item> + </field> + <field name="checkout_data" xsi:type="array"> + <item name="dataset" xsi:type="string">swatches_with_dropdown</item> + </field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/CheckoutData.xml new file mode 100644 index 0000000000000000000000000000000000000000..9b369d5a536f0de9e41bb302910526dd8f5023fb --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/CheckoutData.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2016 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\ConfigurableProduct\Test\Repository\ConfigurableProduct\CheckoutData"> + <dataset name="two_text_swatches"> + <field name="options" xsi:type="array"> + <item name="configurable_options" xsi:type="array"> + <item name="0" xsi:type="array"> + <item name="title" xsi:type="string">attribute_key_0</item> + <item name="value" xsi:type="string">option_key_1</item> + </item> + <item name="1" xsi:type="array"> + <item name="title" xsi:type="string">attribute_key_1</item> + <item name="value" xsi:type="string">option_key_2</item> + </item> + </item> + </field> + <field name="qty" xsi:type="string">1</field> + <field name="cartItem" xsi:type="array"> + <item name="price" xsi:type="string">42</item> + <item name="qty" xsi:type="string">1</item> + <item name="subtotal" xsi:type="string">47</item> + </field> + </dataset> + <dataset name="swatches_with_dropdown"> + <field name="options" xsi:type="array"> + <item name="configurable_options" xsi:type="array"> + <item name="0" xsi:type="array"> + <item name="title" xsi:type="string">attribute_key_0</item> + <item name="value" xsi:type="string">option_key_1</item> + </item> + </item> + </field> + <field name="qty" xsi:type="string">1</field> + <field name="cartItem" xsi:type="array"> + <item name="price" xsi:type="string">42</item> + <item name="qty" xsi:type="string">1</item> + <item name="subtotal" xsi:type="string">47</item> + </field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml new file mode 100644 index 0000000000000000000000000000000000000000..492fda6b751c664bdfde231d813a866e24073f7b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml @@ -0,0 +1,151 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2016 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\ConfigurableProduct\Test\Repository\ConfigurableProduct\ConfigurableAttributesData"> + <dataset name="text_swatch"> + <field name="attributes_data" xsi:type="array"> + <item name="attribute_key_0" xsi:type="array"> + <item name="options" xsi:type="array"> + <item name="option_key_0" xsi:type="array"> + <item name="pricing_value" xsi:type="string">12.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_1" xsi:type="array"> + <item name="pricing_value" xsi:type="string">20.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_2" xsi:type="array"> + <item name="pricing_value" xsi:type="string">18.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + </item> + </item> + <item name="attribute_key_1" xsi:type="array"> + <item name="options" xsi:type="array"> + <item name="option_key_0" xsi:type="array"> + <item name="pricing_value" xsi:type="string">42.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_1" xsi:type="array"> + <item name="pricing_value" xsi:type="string">40.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_2" xsi:type="array"> + <item name="pricing_value" xsi:type="string">48.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + </item> + </item> + </field> + <field name="attributes" xsi:type="array"> + <item name="attribute_key_0" xsi:type="string">swatchesProductAttribute::attribute_type_text_swatch</item> + <item name="attribute_key_1" xsi:type="string">swatchesProductAttribute::attribute_type_text_swatch</item> + </field> + <field name="matrix" xsi:type="array"> + <item name="attribute_key_0:option_key_0 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_0 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_0 attribute_key_1:option_key_2" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_1 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_1 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_1 attribute_key_1:option_key_2" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_2 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_2 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_2 attribute_key_1:option_key_2" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + </field> + </dataset> + <dataset name="text_swatch_with_dropdown"> + <field name="attributes_data" xsi:type="array"> + <item name="attribute_key_0" xsi:type="array"> + <item name="options" xsi:type="array"> + <item name="option_key_0" xsi:type="array"> + <item name="pricing_value" xsi:type="string">12.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_1" xsi:type="array"> + <item name="pricing_value" xsi:type="string">20.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_2" xsi:type="array"> + <item name="pricing_value" xsi:type="string">18.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + </item> + </item> + <item name="attribute_key_1" xsi:type="array"> + <item name="options" xsi:type="array"> + <item name="option_key_0" xsi:type="array"> + <item name="pricing_value" xsi:type="string">42.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + <item name="option_key_1" xsi:type="array"> + <item name="pricing_value" xsi:type="string">40.00</item> + <item name="include" xsi:type="string">Yes</item> + </item> + </item> + </item> + </field> + <field name="attributes" xsi:type="array"> + <item name="attribute_key_0" xsi:type="string">swatchesProductAttribute::attribute_type_text_swatch</item> + <item name="attribute_key_1" xsi:type="string">catalogProductAttribute::size</item> + </field> + <field name="matrix" xsi:type="array"> + <item name="attribute_key_0:option_key_0 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_0 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_1 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_1 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_2 attribute_key_1:option_key_0" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + <item name="attribute_key_0:option_key_2 attribute_key_1:option_key_1" xsi:type="array"> + <item name="qty" xsi:type="string">10</item> + <item name="weight" xsi:type="string">1</item> + </item> + </field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/SwatchProductAttribute.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/SwatchProductAttribute.xml new file mode 100644 index 0000000000000000000000000000000000000000..fc92146861d1e89e5ef32666c67b8c63882d9691 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/Repository/SwatchProductAttribute.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2016 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\Swatches\Test\Repository\SwatchProductAttribute"> + <dataset name="attribute_type_text_swatch"> + <field name="attribute_code" xsi:type="string">sw_color%isolation%</field> + <field name="frontend_input" xsi:type="string" >Text Swatch</field> + <field name="frontend_label" xsi:type="string" >Text Swatch</field> + <field name="options" xsi:type="array"> + <item name="0" xsi:type="array"> + <item name="is_default" xsi:type="string">No</item> + <item name="admin" xsi:type="string">R</item> + <item name="view" xsi:type="string">R</item> + </item> + <item name="1" xsi:type="array"> + <item name="is_default" xsi:type="string">No</item> + <item name="admin" xsi:type="string">G</item> + <item name="view" xsi:type="string">G</item> + </item> + <item name="2" xsi:type="array"> + <item name="is_default" xsi:type="string">No</item> + <item name="admin" xsi:type="string">B</item> + <item name="view" xsi:type="string">B</item> + </item> + </field> + <field name="is_global" xsi:type="string">Global</field> + <field name="used_in_product_listing" xsi:type="string">Yes</field> + </dataset> + </repository> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.php new file mode 100644 index 0000000000000000000000000000000000000000..60cc61f7f0f79319336d57d0d81289de6fe31cab --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\TestCase; + +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Configure text swatch attribute. + * 2. Create configurable product with this attribute + * 3. Open it on catalog page + * 4. Click on 'Add to Cart' button + * + * Steps: + * 1. Go to Frontend. + * 2. Open category page with created product + * 3. Click on 'Add to Cart' button + * 4. Perform asserts + * + * @group Configurable_Product + * @ZephyrId MAGETWO-59958 + */ +class AddConfigurableProductWithSwatchToShopingCartTest extends Scenario +{ + /** + * Runs add configurable product with swatches attributes test. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..adf8d71395ccb9c4b714ad58887ec741391871a2 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/AddConfigurableProductWithSwatchToShopingCartTest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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\Swatches\Test\TestCase\AddConfigurableProductWithSwatchToShopingCartTest" summary="Create text swatch attribute" ticketId="MAGETWO-47017"> + <variation name="AddConfigurableProductWithSwatchToShopingCartTest1"> + <data name="attributeTypeAction" xsi:type="string">addOptions</data> + <data name="product" xsi:type="string">configurableProductSwatch::product_with_text_swatch</data> + <constraint name="Magento\Checkout\Test\Constraint\AssertCartItemsOptions" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ac3016ade3f016b82a856677715db6c93736c1ef --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\TestCase; + +use Magento\Mtf\TestCase\Scenario; + +/** + * Preconditions: + * 1. Configure text swatch attribute. + * 2. Create configurable product with this attribute + * 3. Open it on catalog page + * 4. Click on 'Add to Cart' button + * + * Steps: + * 1. Go to Frontend. + * 2. Open category page with created product + * 3. Click on 'Add to Cart' button + * 4. Perform asserts + * + * @group Configurable_Product + * @ZephyrId TODO: MAGETWO-59979 + */ +class TryToAddConfigurableProductWithSwatchToShopingCartTest extends Scenario +{ + /** + * Runs add configurable product with swatches attributes test. + * + * @return void + */ + public function test() + { + $this->executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..4cb7a3e01676f09c6c3e6b9ffcd3d85fb9abbe4a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestCase/TryToAddConfigurableProductWithSwatchToShopingCartTest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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\Swatches\Test\TestCase\TryToAddConfigurableProductWithSwatchToShopingCartTest" summary="Create text swatch attribute" ticketId="MAGETWO-47017"> + <variation name="TryToAddConfigurableProductWithSwatchToShopingCartTest1"> + <data name="attributeTypeAction" xsi:type="string">addOptions</data> + <data name="product" xsi:type="string">configurableProductSwatch::product_with_text_swatch_and_size</data> + <constraint name="Magento\Swatches\Test\Constraint\AssertSwatchConfigurableProductPage" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/TestStep/AddProductToCartFromCatalogCategoryPageStep.php b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestStep/AddProductToCartFromCatalogCategoryPageStep.php new file mode 100644 index 0000000000000000000000000000000000000000..e19f9d7b3c362ca61d5869ea409c20359b4b4ffb --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/TestStep/AddProductToCartFromCatalogCategoryPageStep.php @@ -0,0 +1,96 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Swatches\Test\TestStep; + +use Magento\Mtf\TestStep\TestStepInterface; +use Magento\Mtf\Fixture\FixtureFactory; +use Magento\Swatches\Test\Block\Product\ProductList\ProductItem; +use Magento\Mtf\Fixture\InjectableFixture; +use Magento\Catalog\Test\Page\Category\CatalogCategoryView; +use Magento\Cms\Test\Page\CmsIndex; + +/** + * Add configurable product to cart. + */ +class AddProductToCartFromCatalogCategoryPageStep implements TestStepInterface +{ + /** + * Fixture of configurable product with swatches configuration. + * + * @var \Magento\Swatches\Test\Fixture\ConfigurableProduct + */ + private $product; + + /** + * Fixture factory for create/get fixtures. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Page of catalog category view. + * + * @var CatalogCategoryView + */ + private $categoryView; + + /** + * CMS index page. + * + * @var CmsIndex + */ + private $cmsIndex; + + /** + * @constructor + * @param FixtureFactory $fixtureFactory + * @param CmsIndex $cmsIndex + * @param InjectableFixture $product + * @param CatalogCategoryView $categoryView + */ + public function __construct( + FixtureFactory $fixtureFactory, + CmsIndex $cmsIndex, + CatalogCategoryView $categoryView, + InjectableFixture $product + ) { + $this->fixtureFactory = $fixtureFactory; + $this->cmsIndex = $cmsIndex; + $this->categoryView = $categoryView; + $this->product = $product; + } + + /** + * Update configurable product. + * + * @return array + */ + public function run() + { + $categoryName = $this->product->getCategoryIds()[0]; + $this->cmsIndex->open(); + $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName); + /** @var \Magento\Swatches\Test\Block\Product\ListProduct $productsList */ + $productsList = $this->categoryView->getListSwatchesProductBlock(); + /** @var ProductItem $productItemBlock */ + $productItemBlock = $productsList->getProductItem($this->product); + $productItemBlock->fillData($this->product); + $productItemBlock->clickAddToCart(); + $cart = [ + 'data' => [ + 'items' => [ + 'products' => [$this->product] + ] + ] + ]; + + return [ + 'cart' => $this->fixtureFactory->createByCode('cart', $cart) + ]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/curl/di.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/curl/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..ac3ad40f804e1abac634c135228d89fca3a90876 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/curl/di.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<!-- +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <preference for="Magento\Swatches\Test\Handler\SwatchProductAttribute\SwatchProductAttributeInterface" type="\Magento\Swatches\Test\Handler\SwatchProductAttribute\Curl" /> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/testcase.xml new file mode 100644 index 0000000000000000000000000000000000000000..f2e30c42a7a859e52ad129eda213aa8b1e597aad --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Swatches/Test/etc/testcase.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2016 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="AddConfigurableProductWithSwatchToShopingCartTest" firstStep="createProduct"> + <step name="createProduct" module="Magento_Catalog" next="addProductToCartFromCatalogCategoryPage" /> + <step name="addProductToCartFromCatalogCategoryPage" module="Magento_Swatches" /> + </scenario> + <scenario name="TryToAddConfigurableProductWithSwatchToShopingCartTest" firstStep="createProduct"> + <step name="createProduct" module="Magento_Catalog" /> + </scenario> +</config>