diff --git a/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml b/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml index e6782dca897d7..f9d3c49d509e9 100644 --- a/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml +++ b/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml @@ -17,11 +17,11 @@ - - - - - + + + + + diff --git a/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessageActionGroup.xml b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessageActionGroup.xml new file mode 100644 index 0000000000000..a37bb443224b4 --- /dev/null +++ b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessageActionGroup.xml @@ -0,0 +1,22 @@ + + + + + + + Check error message in validation message box + + + + + + + + + diff --git a/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessagesCountActionGroup.xml b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessagesCountActionGroup.xml new file mode 100644 index 0000000000000..35ac68b602a5e --- /dev/null +++ b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/AssertStorefrontBundleValidationMessagesCountActionGroup.xml @@ -0,0 +1,20 @@ + + + + + + + Check if there's a validation message box on page and asserts the validation messages number + + + + + + + diff --git a/app/code/Magento/Bundle/Test/Mftf/ActionGroup/StorefrontAddToTheCartButtonActionGroup.xml b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/StorefrontAddToTheCartButtonActionGroup.xml new file mode 100644 index 0000000000000..f0afcffca816c --- /dev/null +++ b/app/code/Magento/Bundle/Test/Mftf/ActionGroup/StorefrontAddToTheCartButtonActionGroup.xml @@ -0,0 +1,20 @@ + + + + + + + Clicks 'Add to Cart' on a Storefront Bundled Product page. + + + + + + + diff --git a/app/code/Magento/Bundle/Test/Mftf/Section/BundleStorefrontSection.xml b/app/code/Magento/Bundle/Test/Mftf/Section/BundleStorefrontSection.xml index 7a188fd58e1af..739c2839e990d 100644 --- a/app/code/Magento/Bundle/Test/Mftf/Section/BundleStorefrontSection.xml +++ b/app/code/Magento/Bundle/Test/Mftf/Section/BundleStorefrontSection.xml @@ -14,8 +14,8 @@ - - + + diff --git a/app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml b/app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml index c47cf6095c777..1dea8958c3552 100644 --- a/app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml +++ b/app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml @@ -17,7 +17,7 @@ - + @@ -38,5 +38,6 @@ + diff --git a/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontBundleCheckBoxOptionValidationTest.xml b/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontBundleCheckBoxOptionValidationTest.xml new file mode 100644 index 0000000000000..91cc58ee0119b --- /dev/null +++ b/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontBundleCheckBoxOptionValidationTest.xml @@ -0,0 +1,57 @@ + + + + + + + + + + <description value="Customer should be able to see only one validation message for checkbox option group"/> + <testCaseId value="MC-35133"/> + <severity value="MINOR"/> + <group value="Bundle"/> + </annotations> + <before> + <createData entity="ApiProductWithDescription" stepKey="simpleProduct1" before="bundleProduct"/> + <createData entity="ApiProductWithDescription" stepKey="simpleProduct2" after="simpleProduct1"/> + <createData entity="ApiBundleProduct" stepKey="bundleProduct"/> + <createData entity="CheckboxOption" stepKey="checkboxBundleOption"> + <requiredEntity createDataKey="bundleProduct"/> + </createData> + <createData entity="ApiBundleLink" stepKey="createBundleLink1"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="checkboxBundleOption"/> + <requiredEntity createDataKey="simpleProduct1"/> + <field key="qty">2</field> + </createData> + <createData entity="ApiBundleLink" stepKey="createBundleLink2"> + <requiredEntity createDataKey="bundleProduct"/> + <requiredEntity createDataKey="checkboxBundleOption"/> + <requiredEntity createDataKey="simpleProduct2"/> + <field key="qty">4</field> + </createData> + <magentoCron stepKey="runCronIndex" groups="index"/> + </before> + <after> + <deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/> + <deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/> + <deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/> + </after> + <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductStorefront"> + <argument name="productUrl" value="$$bundleProduct.custom_attributes[url_key]$$"/> + </actionGroup> + <actionGroup ref="StorefrontSelectCustomizeAndAddToTheCartButtonActionGroup" stepKey="customizeBundleProduct"/> + <actionGroup ref="StorefrontAddToTheCartButtonActionGroup" stepKey="addToCartBundleProduct"/> + <actionGroup ref="AssertStorefrontBundleValidationMessagesCountActionGroup" stepKey="assertBundleValidationCount"/> + <actionGroup ref="AssertStorefrontBundleValidationMessageActionGroup" stepKey="assertBundleValidationMessage"> + <argument name="message" value="Please select one of the options."/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml b/app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml index 5b56598dc58e2..4ba6fd6183653 100644 --- a/app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml +++ b/app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml @@ -8,40 +8,55 @@ <?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox */ ?> <?php $_option = $block->getOption() ?> <?php $_selections = $_option->getSelections() ?> +<?php $inputClass = 'checkbox product bundle option bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?> +<?php $inputId = 'bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?> +<?php $inputName = 'bundle_option[' . $block->escapeHtmlAttr($_option->getId()) . ']' ?> +<?php $dataValidation = 'data-validate="{\'validate-one-required-by-name\':\'input[name^="bundle_option[' . + $block->escapeHtmlAttr($_option->getId()) . ']"]:checked\'}"' ?> + <div class="field option <?= ($_option->getRequired()) ? ' required': '' ?>"> <label class="label"> <span><?= $block->escapeHtml($_option->getTitle()) ?></span> </label> <div class="control"> <div class="nested options-list"> - <?php if ($block->showSingle()) : ?> + <?php if ($block->showSingle()): ?> <?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selections[0]) ?> <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($_selections[0]) ?> <input type="hidden" class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?> product bundle option" name="bundle_option[<?= $block->escapeHtml($_option->getId()) ?>]" value="<?= $block->escapeHtmlAttr($_selections[0]->getSelectionId()) ?>"/> - <?php else :?> - <?php foreach ($_selections as $_selection) : ?> + <?php else: ?> + <?php foreach ($_selections as $selection): ?> + <?php $sectionId = $selection->getSelectionId() ?> <div class="field choice"> - <input class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?> checkbox product bundle option change-container-classname" - id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>" + <input class="<?=/* @noEscape */ $inputClass ?> change-container-classname" + id="<?=/* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId)?>" type="checkbox" - <?php if ($_option->getRequired()) { echo 'data-validate="{\'validate-one-required-by-name\':\'input[name^="bundle_option[' . $block->escapeHtmlAttr($_option->getId()) . ']"]:checked\'}"'; } ?> - name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][<?= $block->escapeHtmlAttr($_selection->getId()) ?>]" - data-selector="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][<?= $block->escapeHtmlAttr($_selection->getId()) ?>]" - <?php if ($block->isSelected($_selection)) { echo ' checked="checked"'; } ?> - <?php if (!$_selection->isSaleable()) { echo ' disabled="disabled"'; } ?> - value="<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"/> + <?php if ($_option->getRequired()): ?> + <?= /* @noEscape */ $dataValidation ?> + <?php endif;?> + name="<?=/* @noEscape */ $inputName .'['. $block->escapeHtmlAttr($sectionId)?>]" + data-selector="<?= /* @noEscape */ $inputName.'['.$block->escapeHtmlAttr($sectionId)?>]" + <?php if ($block->isSelected($selection)): ?> + <?= ' checked="checked"' ?> + <?php endif; ?> + <?php if (!$selection->isSaleable()): ?> + <?= ' disabled="disabled"' ?> + <?php endif; ?> + value="<?= $block->escapeHtmlAttr($sectionId) ?>" + data-errors-message-box="#validation-message-box"/> <label class="label" - for="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"> - <span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selection) ?></span> + for="<?= /* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId) ?>"> + <span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($selection) ?></span> <br/> - <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($_selection) ?> + <?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($selection) ?> </label> </div> <?php endforeach; ?> <div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div> + <div id="validation-message-box"></div> <?php endif; ?> </div> </div> diff --git a/app/code/Magento/Captcha/Test/Mftf/Section/CaptchaFormsDisplayingSection.xml b/app/code/Magento/Captcha/Test/Mftf/Section/CaptchaFormsDisplayingSection.xml index 9103c4191544c..030c9f5efcf50 100644 --- a/app/code/Magento/Captcha/Test/Mftf/Section/CaptchaFormsDisplayingSection.xml +++ b/app/code/Magento/Captcha/Test/Mftf/Section/CaptchaFormsDisplayingSection.xml @@ -14,7 +14,7 @@ <element name="customer" type="button" selector="//div[@class='admin__page-nav-title title _collapsible']//strong[text()='Customers']"/> <element name="customerConfig" type="text" selector="//span[text()='Customer Configuration']"/> <element name="captcha" type="button" selector="#customer_captcha-head"/> - <element name="dependent" type="button" selector="//a[@id='customer_captcha-head' and @class='open']"/> + <element name="dependent" type="button" selector="a#customer_captcha-head.open"/> <element name="forms" type="multiselect" selector="#customer_captcha_forms"/> <element name="createUser" type="multiselect" selector="//select[@id='customer_captcha_forms']/option[@value='user_create']"/> <element name="forgotpassword" type="multiselect" selector="//select[@id='customer_captcha_forms']/option[@value='user_forgotpassword']"/> diff --git a/app/code/Magento/Catalog/Model/Product/SalabilityChecker.php b/app/code/Magento/Catalog/Model/Product/SalabilityChecker.php deleted file mode 100644 index 404760a51eff5..0000000000000 --- a/app/code/Magento/Catalog/Model/Product/SalabilityChecker.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Catalog\Model\Product; - -use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Store\Model\StoreManagerInterface; - -/** - * Class to check that product is saleable. - */ -class SalabilityChecker -{ - /** - * @var ProductRepositoryInterface - */ - private $productRepository; - - /** - * @var StoreManagerInterface - */ - private $storeManager; - - /** - * @param ProductRepositoryInterface $productRepository - * @param StoreManagerInterface $storeManager - */ - public function __construct( - ProductRepositoryInterface $productRepository, - StoreManagerInterface $storeManager - ) { - $this->productRepository = $productRepository; - $this->storeManager = $storeManager; - } - - /** - * Check if product is salable. - * - * @param int|string $productId - * @param int|null $storeId - * @return bool - */ - public function isSalable($productId, $storeId = null): bool - { - if ($storeId === null) { - $storeId = $this->storeManager->getStore()->getId(); - } - /** @var \Magento\Catalog\Model\Product $product */ - $product = $this->productRepository->getById($productId, false, $storeId); - - return $product->isSalable(); - } -} diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php index cf5760b0c33a9..8d03eb3ccafc9 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/CategoryLink.php @@ -147,7 +147,7 @@ private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositi * @param bool $insert * @return array */ - private function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false) + public function updateCategoryLinks(ProductInterface $product, array $insertLinks, $insert = false) { if (empty($insertLinks)) { return []; diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameActionGroup.xml new file mode 100644 index 0000000000000..020fb27063be7 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameActionGroup.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminChangeCategoryNameActionGroup"> + <annotations> + <description>Switch the Storefront to the provided Store.</description> + </annotations> + <arguments> + <argument name="categoryName" type="string" defaultValue="{{_defaultCategory.name}}"/> + </arguments> + <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="{{categoryName}}" stepKey="updateCategoryName"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameOnStoreViewLevelActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameOnStoreViewLevelActionGroup.xml new file mode 100644 index 0000000000000..14a7967422332 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminChangeCategoryNameOnStoreViewLevelActionGroup.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminChangeCategoryNameOnStoreViewLevelActionGroup"> + <annotations> + <description>Updates the Category Name for proper Store View.</description> + </annotations> + <arguments> + <argument name="categoryName" type="string"/> + </arguments> + + <uncheckOption selector="{{AdminCategoryBasicFieldSection.categoryNameUseDefault}}" stepKey="uncheckUseDefaultValueENStoreView"/> + <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="{{categoryName}}" stepKey="changeNameField"/> + <click selector="{{AdminCategorySEOSection.SectionHeader}}" stepKey="clickOnSectionHeader"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml new file mode 100644 index 0000000000000..84e14269d24c2 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertStorefrontCategoryCurrentPageIsNthActionGroup.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AssertStorefrontCategoryCurrentPageIsNthActionGroup"> + <arguments> + <argument name="expectedPage" type="string"/> + </arguments> + + <grabTextFrom selector="{{StorefrontCategoryBottomToolbarSection.currentPage}}" stepKey="currentPageText"/> + <assertEquals stepKey="assertIsPageNth"> + <expectedResult type="string">{{expectedPage}}</expectedResult> + <actualResult type="variable">currentPageText</actualResult> + </assertEquals> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml new file mode 100644 index 0000000000000..cead98091d268 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsNotShownInMenuActionGroup.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="StorefrontAssertCategoryNameIsNotShownInMenuActionGroup"> + <annotations> + <description>Validate that the Category is not present in menu on Frontend.</description> + </annotations> + <arguments> + <argument name="categoryName" type="string"/> + </arguments> + + <dontSeeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(categoryName)}}" + stepKey="doNotSeeCatergoryInStoreFront"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml new file mode 100644 index 0000000000000..c56a18b4895a4 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertCategoryNameIsShownInMenuActionGroup.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="StorefrontAssertCategoryNameIsShownInMenuActionGroup"> + <annotations> + <description>Validate that the Category is present in menu on Frontend.</description> + </annotations> + <arguments> + <argument name="categoryName" type="string"/> + </arguments> + + <seeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(categoryName)}}" + stepKey="seeCatergoryInStoreFront"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontClickOnProductFromSidebarCompareListActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontClickOnProductFromSidebarCompareListActionGroup.xml new file mode 100644 index 0000000000000..5b7dd3026a905 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontClickOnProductFromSidebarCompareListActionGroup.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="StorefrontClickOnProductFromSidebarCompareListActionGroup"> + <annotations> + <description>Click on the product item from the sidebar comparing list.</description> + </annotations> + + <arguments> + <argument name="product" type="entity"/> + </arguments> + + <waitForElementVisible selector="{{StorefrontComparisonSidebarSection.ProductTitleByName((product.name)}}" stepKey="waitForAddedCompareProduct"/> + <click selector="{{StorefrontComparisonSidebarSection.ProductTitleByName((product.name))}}" stepKey="clickOnProductLink"/> + <waitForPageLoad stepKey="waitForProductPageLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml new file mode 100644 index 0000000000000..4776c9d32a34d --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontNavigateCategoryNextPageActionGroup.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="StorefrontNavigateCategoryNextPageActionGroup"> + <annotations> + <description>Navigates storefront category next page from toolbar</description> + </annotations> + <scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/> + <click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/> + <waitForPageLoad stepKey="waitForNextCategoryPageLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductDescriptionWYSIWYGToolbarSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductDescriptionWYSIWYGToolbarSection.xml index 26946692ce050..7a829a5475758 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductDescriptionWYSIWYGToolbarSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductDescriptionWYSIWYGToolbarSection.xml @@ -8,7 +8,7 @@ <sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> <section name="ProductDescriptionWYSIWYGToolbarSection"> - <element name="TinyMCE4" type="button" selector="//div[@id='editorproduct_form_description']//*[contains(@class,'mce-branding')]"/> + <element name="TinyMCE4" type="button" selector="div#editorproduct_form_description .mce-branding"/> <element name="showHideBtn" type="button" selector="#toggleproduct_form_description"/> <element name="InsertImageBtn" type="button" selector="#buttonsproduct_form_description > .scalable.action-add-image.plugin"/> <element name="Style" type="button" selector="//div[@id='editorproduct_form_description']//span[text()='Paragraph']"/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductWYSIWYGSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductWYSIWYGSection.xml index 544bdf85681c9..b919cdff2bb92 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductWYSIWYGSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/ProductWYSIWYGSection.xml @@ -8,12 +8,12 @@ <sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> <section name="ProductWYSIWYGSection"> - <element name="Switcher" type="button" selector="//select[@id='dropdown-switcher']"/> + <element name="Switcher" type="button" selector="select#dropdown-switcher"/> <element name="v436" type="button" selector="//select[@id='dropdown-switcher']/option[text()='TinyMCE 4.3.6']"/> <element name="v3" type="button" selector="//select[@id='dropdown-switcher']/option[text()='TinyMCE 3.6(Deprecated)']"/> <element name="TinymceDescription3" type="button" selector="//span[text()='Description']"/> <element name="SaveConfig" type="button" selector="#save"/> <element name="v4" type="button" selector="#category_form_description_v4"/> - <element name="WYSIWYGBtn" type="button" selector=".//button[@class='action-default scalable action-wysiwyg']"/> + <element name="WYSIWYGBtn" type="button" selector="button.action-default.scalable.action-wysiwyg"/> </section> </sections> diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml index 09eb4ad954274..c27a6107e5e35 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryBottomToolbarSection.xml @@ -12,6 +12,6 @@ <element name="previousPage" type="button" selector=".//*[@class='toolbar toolbar-products'][2]//a[contains(@class, 'previous')]" timeout="30"/> <element name="pageNumber" type="text" selector="//*[@class='toolbar toolbar-products'][2]//a[contains(@class, 'page')]//span[2][contains(text() ,'{{var1}}')]" parameterized="true"/> <element name="perPage" type="select" selector="//*[@class='toolbar toolbar-products'][2]//select[@id='limiter']"/> - <element name="currentPage" type="text" selector=".products.wrapper + .toolbar-products .pages .current span:nth-of-type(2)"/> + <element name="currentPage" type="text" selector=".//*[@class='toolbar toolbar-products'][2]//li[contains(@class, 'current')]//span[2]" timeout="30"/> </section> </sections> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryTest/AdminCreateCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryTest/AdminCreateCategoryTest.xml index b8e58eae8a98a..83404391abca9 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryTest/AdminCreateCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateCategoryTest/AdminCreateCategoryTest.xml @@ -23,16 +23,13 @@ <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin1"/> <actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="navigateToCategoryPage"/> - <click selector="{{AdminCategorySidebarActionSection.AddSubcategoryButton}}" stepKey="clickOnAddSubCategory"/> - <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="{{SimpleSubCategory.name}}" stepKey="enterCategoryName"/> - <click selector="{{AdminCategorySEOSection.SectionHeader}}" stepKey="openSEO"/> - <fillField selector="{{AdminCategorySEOSection.UrlKeyInput}}" userInput="{{SimpleSubCategory.name_lwr}}" stepKey="enterURLKey"/> - <click selector="{{AdminCategoryMainActionsSection.SaveButton}}" stepKey="saveCategory"/> - <seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="assertSuccess"/> + <actionGroup ref="CreateCategoryActionGroup" stepKey="createSubcategory"> + <argument name="categoryEntity" value="SimpleSubCategory"/> + </actionGroup> - <!-- Literal URL below, need to refactor line + StorefrontCategoryPage when support for variable URL is implemented--> - <amOnPage url="/{{SimpleSubCategory.name_lwr}}.html" stepKey="goToCategoryFrontPage"/> - <seeInTitle userInput="{{SimpleSubCategory.name}}" stepKey="assertTitle"/> - <see selector="{{StorefrontCategoryMainSection.CategoryTitle}}" userInput="{{SimpleSubCategory.name_lwr}}" stepKey="assertInfo1"/> + <!--Go to storefront and verify created category on frontend--> + <actionGroup ref="CheckCategoryOnStorefrontActionGroup" stepKey="checkCreatedCategoryOnFrontend"> + <argument name="categoryEntity" value="SimpleSubCategory"/> + </actionGroup> </test> </tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryNameWithStoreViewTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryNameWithStoreViewTest.xml index 0ca8e74c4e59e..f4d464455491b 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryNameWithStoreViewTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateCategoryNameWithStoreViewTest.xml @@ -32,16 +32,12 @@ <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> </after> - <!--Open store page --> - <amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/> - <waitForPageLoad stepKey="waitForSystemStorePage"/> - <!--Create Custom Store --> - <click selector="{{AdminStoresMainActionsSection.createStoreButton}}" stepKey="selectCreateStore"/> - <fillField userInput="{{customStore.name}}" selector="{{AdminNewStoreGroupSection.storeGrpNameTextField}}" stepKey="fillStoreName"/> - <fillField userInput="{{customStore.code}}" selector="{{AdminNewStoreGroupSection.storeGrpCodeTextField}}" stepKey="fillStoreCode"/> - <selectOption userInput="{{NewRootCategory.name}}" selector="{{AdminNewStoreGroupSection.storeRootCategoryDropdown}}" stepKey="selectStoreStatus"/> - <click selector="{{AdminStoresMainActionsSection.saveButton}}" stepKey="clickSaveStoreButton"/> + <actionGroup ref="CreateCustomStoreActionGroup" stepKey="createCustomStore"> + <argument name="website" value="{{_defaultWebsite.name}}"/> + <argument name="store" value="{{customStore.name}}"/> + <argument name="rootCategory" value="$$rootCategory.name$$"/> + </actionGroup> <!--Create Store View--> <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createStoreView"> @@ -50,32 +46,40 @@ </actionGroup> <!--Verify created SubCAtegory is present on Store Front --> - <amOnPage url="/{{NewRootCategory.name}}/{{SimpleRootSubCategory.name}}.html" stepKey="seeTheCategoryInStoreFront"/> - <waitForPageLoad stepKey="waitForPageToLoad"/> - <click selector="{{StorefrontFooterSection.switchStoreButton}}" stepKey="ClickSwitchStoreButtonOnDefaultStore"/> - <click selector="{{StorefrontFooterSection.storeLink(customStore.name)}}" stepKey="SelectSecondStoreToSwitchOn"/> - <seeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(SimpleRootSubCategory.name)}}" stepKey="seeCatergoryInStoreFront"/> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToHomepage"/> + <actionGroup ref="StorefrontSwitchStoreActionGroup" stepKey="seeCustomStore"> + <argument name="storeName" value="{{customStore.name}}"/> + </actionGroup> + <actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="goToCategoryPage"> + <argument name="categoryName" value="$$category.name$$"/> + </actionGroup> + <actionGroup ref="StorefrontAssertCategoryNameIsShownInMenuActionGroup" stepKey="seeCatergoryInStoreFront"> + <argument name="categoryName" value="$$category.name$$"/> + </actionGroup> <!--Open Category Page--> <actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openAdminCategoryIndexPage"/> - <!--Update Category--> - <click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="expandToSeeAllCategories"/> - <click selector="{{AdminCategorySidebarTreeSection.categoryInTreeUnderRoot(SimpleRootSubCategory.name)}}" stepKey="clickOnSubcategoryIsUndeRootCategory"/> - <waitForPageLoad stepKey="waitForPageToLoad1"/> - <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="{{_defaultCategory.name}}" stepKey="updateCategoryName"/> - <click selector="{{AdminCategoryMainActionsSection.SaveButton}}" stepKey="saveUpdatedCategory"/> - <waitForPageLoad stepKey="waitForCateforyToSave"/> - <seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="seeSuccessMessage"/> + <actionGroup ref="AdminExpandCategoryTreeActionGroup" stepKey="expandCategoryTree"/> + <actionGroup ref="AdminCategoriesOpenCategoryActionGroup" stepKey="openCategory"> + <argument name="category" value="$$category$$"/> + </actionGroup> + <actionGroup ref="AdminChangeCategoryNameActionGroup" stepKey="updateCategoryName"/> + <actionGroup ref="AdminSaveCategoryActionGroup" stepKey="saveCategory"/> + <actionGroup ref="AssertAdminCategorySaveSuccessMessageActionGroup" stepKey="assertSuccessMessage"/> <!--Verify the Category is not present in Store Front--> - <amOnPage url="/{{NewRootCategory.name}}/{{SimpleRootSubCategory.name}}.html" stepKey="seeTheCategoryInStoreFront1"/> - <waitForPageLoad stepKey="waitForPageToLoaded2"/> - <dontSeeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(SimpleRootSubCategory.name)}}" stepKey="dontSeeCatergoryInStoreFront"/> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openHomepage"/> + <actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPage"> + <argument name="categoryName" value="{{_defaultCategory.name}}"/> + </actionGroup> + <actionGroup ref="StorefrontAssertCategoryNameIsNotShownInMenuActionGroup" stepKey="doNotSeeOldCategoryNameInStoreFront"> + <argument name="categoryName" value="{{SimpleRootSubCategory.name}}"/> + </actionGroup> <!--Verify the Updated Category is present in Store Front--> - <amOnPage url="/{{NewRootCategory.name}}/{{_defaultCategory.name}}.html" stepKey="seeTheUpdatedCategoryInStoreFront"/> - <waitForPageLoad stepKey="waitForPageToLoaded3"/> - <seeElement selector="{{StorefrontHeaderSection.NavigationCategoryByName(_defaultCategory.name)}}" stepKey="seeUpdatedCatergoryInStoreFront"/> + <actionGroup ref="StorefrontAssertCategoryNameIsShownInMenuActionGroup" stepKey="seeUpdatedCatergoryNameInStoreFront"> + <argument name="categoryName" value="{{_defaultCategory.name}}"/> + </actionGroup> </test> </tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontCheckNoAppearDefaultOptionConfigurableProductTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontCheckNoAppearDefaultOptionConfigurableProductTest.xml new file mode 100644 index 0000000000000..8d66427c5392e --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontCheckNoAppearDefaultOptionConfigurableProductTest.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontCheckNoAppearDefaultOptionConfigurableProductTest"> + <annotations> + <stories value="Configurable Product"/> + <title value="Check for Configurable Product the default option doesn't appear."/> + <description value="Check for Configurable Product the default option doesn't appear on the list options product when an option use."/> + <testCaseId value="MC-35074"/> + </annotations> + <before> + <createData entity="ApiCategory" stepKey="createCategory"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin1"/> + </before> + <after> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <actionGroup ref="AdminDeleteProductAttributeByLabelActionGroup" stepKey="deleteAttribute"> + <argument name="productAttributeLabel" value="{{colorProductAttribute.default_label}}" /> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + </after> + + <actionGroup ref="AdminFillBasicValueConfigurableProductActionGroup" stepKey="fillBasicValue"> + <argument name="product" value="_defaultProduct"/> + <argument name="category" value="$$createCategory$$"/> + </actionGroup> + <actionGroup ref="AdminAddOptionsToAttributeWithDefaultLayeredNavigationActionGroup" stepKey="createOptions"/> + <actionGroup ref="AdminGotoSelectValueAttributePageActionGroup" stepKey="gotoSelectValuePage"> + <argument name="defaultLabelAttribute" value="{{colorProductAttribute.default_label}}"/> + </actionGroup> + <actionGroup ref="AdminSelectValueFromAttributeActionGroup" stepKey="selectColorProductAttribute2"> + <argument name="option" value="colorProductAttribute2"/> + </actionGroup> + <actionGroup ref="AdminSelectValueFromAttributeActionGroup" stepKey="selectColorProductAttribute3"> + <argument name="option" value="colorProductAttribute3"/> + </actionGroup> + <actionGroup ref="AdminSetQuantityToEachSkusConfigurableProductActionGroup" stepKey="saveConfigurable"/> + <grabValueFrom selector="{{NewProductPageSection.sku}}" stepKey="grabSkuProduct"/> + <magentoCLI command="indexer:reindex" stepKey="reindex"/> + + <actionGroup ref="SelectStorefrontSideBarAttributeOption" stepKey="expandOption"> + <argument name="categoryName" value="$$createCategory.name$$"/> + <argument name="attributeDefaultLabel" value="{{colorProductAttribute.default_label}}"/> + </actionGroup> + <dontSeeElement selector="{{LayeredNavigationSection.filterOptionContent(colorProductAttribute.default_label,colorProductAttribute1.name)}}" stepKey="dontSeeCaptchaField"/> + <actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteConfigurableProduct"> + <argument name="sku" value="$grabSkuProduct"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontRemoveProductFromCompareSidebarTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontRemoveProductFromCompareSidebarTest.xml new file mode 100644 index 0000000000000..914ac3444db22 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontRemoveProductFromCompareSidebarTest.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontRemoveProductFromCompareSidebarTest"> + <annotations> + <title value="Verify that the product isn't removed on clicking the product name"/> + <stories value="Verify that the product isn't removed on clicking the product name"/> + <description value="Verify that the product isn't removed on clicking the product name, but it's redirected to product page"/> + <features value="Catalog"/> + <severity value="MINOR"/> + <group value="Catalog"/> + <testCaseId value="MC-35068"/> + </annotations> + <before> + <createData entity="_defaultCategory" stepKey="defaultCategory"/> + <createData entity="SimpleProduct" stepKey="simpleProduct"> + <requiredEntity createDataKey="defaultCategory"/> + </createData> + </before> + <after> + <deleteData createDataKey="simpleProduct" stepKey="deleteProduct"/> + <deleteData createDataKey="defaultCategory" stepKey="deleteCategory"/> + </after> + <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="openCategoryPage"> + <argument name="category" value="$$defaultCategory$$"/> + </actionGroup> + <actionGroup ref="StorefrontAddCategoryProductToCompareActionGroup" stepKey="addProductToCompareList"> + <argument name="productVar" value="$$simpleProduct$$"/> + </actionGroup> + <actionGroup ref="StorefrontClickOnProductFromSidebarCompareListActionGroup" stepKey="clickOnComparingProductLink"> + <argument name="product" value="$$simpleProduct$$"/> + </actionGroup> + <actionGroup ref="StorefrontCheckProductUrlActionGroup" stepKey="checkProductPageUrl"> + <argument name="productUrl" value="$$simpleProduct.custom_attributes[url_key]$$"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php index 0295e778f2b9b..dd757841410e2 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php @@ -40,7 +40,7 @@ use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory as AttributeCollectionFactory; /** - * Data provider for eav attributes on product page + * Class Eav data provider for product editing form * * @api * @@ -791,7 +791,9 @@ private function getAttributeDefaultValue(ProductAttributeInterface $attribute) \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->storeManager->getStore() ); - $attribute->setDefaultValue($defaultValue); + if ($defaultValue !== null) { + $attribute->setDefaultValue($defaultValue); + } } return $attribute->getDefaultValue(); } diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php b/app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php index a45338c391a58..78ff26675930e 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php @@ -89,7 +89,6 @@ public function saveLinks( $resource = $this->linkFactory->create(); $mainTable = $resource->getMainTable(); $positionAttrId = []; - $nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable); // pre-load 'position' attributes ID for each link type once foreach ($this->linkNameToId as $linkId) { @@ -103,6 +102,7 @@ public function saveLinks( $positionAttrId[$linkId] = $importEntity->getConnection()->fetchOne($select, $bind); } while ($bunch = $dataSourceModel->getNextBunch()) { + $nextLinkId = $this->resourceHelper->getNextAutoincrement($mainTable); $this->processLinkBunches($importEntity, $linkField, $bunch, $resource, $nextLinkId, $positionAttrId); } } diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml index c33b784fcd20c..192f20653f8c3 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml @@ -105,7 +105,7 @@ <item name="trigger" xsi:type="string">opc-new-shipping-address</item> <item name="buttons" xsi:type="array"> <item name="save" xsi:type="array"> - <item name="text" xsi:type="string" translate="true">Ship here</item> + <item name="text" xsi:type="string" translate="true">Ship Here</item> <item name="class" xsi:type="string">action primary action-save-address</item> </item> <item name="cancel" xsi:type="array"> diff --git a/app/code/Magento/Cms/Test/Mftf/Section/CmsPagesPageActionsSection.xml b/app/code/Magento/Cms/Test/Mftf/Section/CmsPagesPageActionsSection.xml index 6f16fa54a6ebf..ebf024490cce6 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/CmsPagesPageActionsSection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/CmsPagesPageActionsSection.xml @@ -12,7 +12,7 @@ <element name="filterButton" type="input" selector="//button[text()='Filters']"/> <element name="URLKey" type="input" selector="//div[@class='admin__form-field-control']/input[@name='identifier']"/> <element name="ApplyFiltersBtn" type="button" selector="//span[text()='Apply Filters']"/> - <element name="searchInput" type="input" selector="//*[@id='fulltext']"/> + <element name="searchInput" type="input" selector="#fulltext"/> <element name="searchButton" type="button" selector="//*[@id='fulltext']/parent::*/button"/> <element name="addNewPageButton" type="button" selector="#add" timeout="30"/> <element name="select" type="button" selector="//div[text()='{{var1}}']/parent::td//following-sibling::td[@class='data-grid-actions-cell']//button[text()='Select']" parameterized="true"/> diff --git a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/MediaGallerySection.xml b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/MediaGallerySection.xml index 112335e726270..a6f4e7780d096 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/MediaGallerySection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/MediaGallerySection.xml @@ -9,7 +9,7 @@ xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> <section name="MediaGallerySection"> <element name="Browse" type="button" selector=".mce-i-browse"/> - <element name="browseForImage" type="button" selector="//*[@id='srcbrowser']"/> + <element name="browseForImage" type="button" selector="#srcbrowser"/> <element name="BrowseUploadImage" type="file" selector=".fileupload"/> <element name="image" type="text" selector="//small[text()='{{var1}}']" parameterized="true"/> <element name="imageOrImageCopy" type="text" selector="//div[contains(@class,'media-gallery-modal')]//img[contains(@alt, '{{arg1}}.{{arg2}}')]|//img[contains(@alt,'{{arg1}}_') and contains(@alt,'.{{arg2}}')]" parameterized="true"/> diff --git a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml index 1869a6544c3d3..5be91f61e1e1e 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml @@ -38,6 +38,8 @@ <element name="PageSize" type="input" selector="input[name='parameters[page_size]']"/> <element name="ProductAttribute" type="multiselect" selector="select[name='parameters[show_attributes][]']"/> <element name="ButtonToShow" type="multiselect" selector="select[name='parameters[show_buttons][]']"/> + <element name="InputAnchorCustomText" type="input" selector="input[name='parameters[anchor_text]']"/> + <element name="InputAnchorCustomTitle" type="input" selector="input[name='parameters[title]']"/> <!--Compare on Storefront--> <element name="ProductName" type="text" selector=".product.name.product-item-name"/> <element name="CompareBtn" type="button" selector=".action.tocompare"/> diff --git a/app/code/Magento/Config/Model/Config.php b/app/code/Magento/Config/Model/Config.php index 356c6ca17da18..f61e99529c3cc 100644 --- a/app/code/Magento/Config/Model/Config.php +++ b/app/code/Magento/Config/Model/Config.php @@ -208,6 +208,7 @@ public function save() ); $groupChangedPaths = $this->getChangedPaths($sectionId, $groupId, $groupData, $oldConfig, $extraOldGroups); + // phpcs:ignore Magento2.Performance.ForeachArrayMerge $changedPaths = \array_merge($changedPaths, $groupChangedPaths); } @@ -370,6 +371,7 @@ private function getChangedPaths( $oldConfig, $extraOldGroups ); + // phpcs:ignore Magento2.Performance.ForeachArrayMerge $changedPaths = \array_merge($changedPaths, $subGroupChangedPaths); } } @@ -435,11 +437,11 @@ protected function _processGroup( if (!isset($fieldData['value'])) { $fieldData['value'] = null; } - + if ($field->getType() == 'multiline' && is_array($fieldData['value'])) { $fieldData['value'] = trim(implode(PHP_EOL, $fieldData['value'])); } - + $data = [ 'field' => $fieldId, 'groups' => $groups, @@ -453,7 +455,7 @@ protected function _processGroup( $backendModel->addData($data); $this->_checkSingleStoreMode($field, $backendModel); - $path = $this->getFieldPath($field, $fieldId, $extraOldGroups, $oldConfig); + $path = $this->getFieldPath($field, $fieldId, $oldConfig, $extraOldGroups); $backendModel->setPath($path)->setValue($fieldData['value']); $inherit = !empty($fieldData['inherit']); diff --git a/app/code/Magento/ConfigurableProduct/Block/DataProviders/PermissionsData.php b/app/code/Magento/ConfigurableProduct/Block/DataProviders/PermissionsData.php new file mode 100644 index 0000000000000..fbc45a9cfc791 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Block/DataProviders/PermissionsData.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\ConfigurableProduct\Block\DataProviders; + +use Magento\Framework\AuthorizationInterface; +use Magento\Framework\View\Element\Block\ArgumentInterface; + +/** + * Provides permissions data into template. + */ +class PermissionsData implements ArgumentInterface +{ + /** + * @var AuthorizationInterface + */ + private $authorization; + + /** + * Constructor + * + * @param AuthorizationInterface $authorization + */ + public function __construct(AuthorizationInterface $authorization) + { + $this->authorization = $authorization; + } + + /** + * Check that user is allowed to manage attributes + * + * @return bool + */ + public function isAllowedToManageAttributes(): bool + { + return $this->authorization->isAllowed('Magento_Catalog::attributes_attributes'); + } +} diff --git a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php index 1555e88700a45..2f333e7ca6f6e 100644 --- a/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php +++ b/app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php @@ -4,11 +4,21 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\ConfigurableProduct\Plugin\Model\ResourceModel; +use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; +use Magento\ConfigurableProduct\Api\Data\OptionInterface; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Indexer\ActionInterface; +/** + * Plugin product resource model + */ class Product { /** @@ -21,18 +31,45 @@ class Product */ private $productIndexer; + /** + * @var ProductAttributeRepositoryInterface + */ + private $productAttributeRepository; + + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + /** + * @var FilterBuilder + */ + private $filterBuilder; + /** * Initialize Product dependencies. * * @param Configurable $configurable * @param ActionInterface $productIndexer + * @param ProductAttributeRepositoryInterface $productAttributeRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param FilterBuilder $filterBuilder */ public function __construct( Configurable $configurable, - ActionInterface $productIndexer + ActionInterface $productIndexer, + ProductAttributeRepositoryInterface $productAttributeRepository = null, + SearchCriteriaBuilder $searchCriteriaBuilder = null, + FilterBuilder $filterBuilder = null ) { $this->configurable = $configurable; $this->productIndexer = $productIndexer; + $this->productAttributeRepository = $productAttributeRepository ?: ObjectManager::getInstance() + ->get(ProductAttributeRepositoryInterface::class); + $this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance() + ->get(SearchCriteriaBuilder::class); + $this->filterBuilder = $filterBuilder ?: ObjectManager::getInstance() + ->get(FilterBuilder::class); } /** @@ -41,6 +78,7 @@ public function __construct( * @param \Magento\Catalog\Model\ResourceModel\Product $subject * @param \Magento\Framework\DataObject $object * @return void + * @throws \Magento\Framework\Exception\NoSuchEntityException * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ @@ -51,6 +89,39 @@ public function beforeSave( /** @var \Magento\Catalog\Model\Product $object */ if ($object->getTypeId() == Configurable::TYPE_CODE) { $object->getTypeInstance()->getSetAttributes($object); + $this->resetConfigurableOptionsData($object); + } + } + + /** + * Set null for configurable options attribute of configurable product + * + * @param \Magento\Catalog\Model\Product $object + * @return void + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + private function resetConfigurableOptionsData($object) + { + $extensionAttribute = $object->getExtensionAttributes(); + if ($extensionAttribute && $extensionAttribute->getConfigurableProductOptions()) { + $attributeIds = []; + /** @var OptionInterface $option */ + foreach ($extensionAttribute->getConfigurableProductOptions() as $option) { + $attributeIds[] = $option->getAttributeId(); + } + + $filter = $this->filterBuilder + ->setField(ProductAttributeInterface::ATTRIBUTE_ID) + ->setConditionType('in') + ->setValue($attributeIds) + ->create(); + $this->searchCriteriaBuilder->addFilters([$filter]); + $searchCriteria = $this->searchCriteriaBuilder->create(); + $optionAttributes = $this->productAttributeRepository->getList($searchCriteria)->getItems(); + + foreach ($optionAttributes as $optionAttribute) { + $object->setData($optionAttribute->getAttributeCode(), null); + } } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminAddOptionsToAttributeWithDefaultLayeredNavigationActionGroup.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminAddOptionsToAttributeWithDefaultLayeredNavigationActionGroup.xml new file mode 100644 index 0000000000000..c48f22a3656d5 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminAddOptionsToAttributeWithDefaultLayeredNavigationActionGroup.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminAddOptionsToAttributeWithDefaultLayeredNavigationActionGroup"> + <annotations> + <description>Adds 3 provided Options to a new Attribute on the Configurable Product creation/edit page. Selected default first option. Set "Use in Layered Navigation" to "Yes".</description> + </annotations> + <arguments> + <argument name="label" defaultValue="colorProductAttribute" /> + <argument name="option1" defaultValue="colorProductAttribute1"/> + <argument name="option2" defaultValue="colorProductAttribute2"/> + <argument name="option3" defaultValue="colorProductAttribute3"/> + </arguments> + + <click selector="{{AdminProductFormConfigurationsSection.createConfigurations}}" stepKey="clickOnCreateConfigurations"/> + <click selector="{{AdminCreateProductConfigurationsPanel.createNewAttribute}}" stepKey="clickOnNewAttribute"/> + <waitForPageLoad stepKey="waitForIFrame"/> + <switchToIFrame selector="{{AdminNewAttributePanel.newAttributeIFrame}}" stepKey="switchToNewAttributeIFrame"/> + <fillField selector="{{AdminNewAttributePanel.defaultLabel}}" userInput="{{label.default_label}}" stepKey="fillDefaultLabel"/> + + <!--Add option 1 to attribute--> + <click selector="{{AdminNewAttributePanel.addOption}}" stepKey="clickAddOption1"/> + <waitForElementVisible selector="{{AdminNewAttributePanel.isDefault('1')}}" time="30" stepKey="waitForOptionRow1" after="clickAddOption1"/> + <fillField selector="{{AdminNewAttributePanel.optionAdminValue('0')}}" userInput="{{option1.name}}" stepKey="fillAdminLabel1" after="waitForOptionRow1"/> + <click selector="{{AdminNewAttributePanel.isDefault('1')}}" stepKey="selectDefault" after="fillAdminLabel1"/> + + <!--Add option 2 to attribute--> + <click selector="{{AdminNewAttributePanel.addOption}}" stepKey="clickAddOption2" after="selectDefault"/> + <waitForElementVisible selector="{{AdminNewAttributePanel.isDefault('2')}}" time="30" stepKey="waitForOptionRow2" after="clickAddOption2"/> + <fillField selector="{{AdminNewAttributePanel.optionAdminValue('1')}}" userInput="{{option2.name}}" stepKey="fillAdminLabel2" after="waitForOptionRow2"/> + + <!--Add option 3 to attribute--> + <click selector="{{AdminNewAttributePanel.addOption}}" stepKey="clickAddOption3" after="fillAdminLabel2"/> + <waitForElementVisible selector="{{AdminNewAttributePanel.isDefault('3')}}" time="30" stepKey="waitForOptionRow3" after="clickAddOption3"/> + <fillField selector="{{AdminNewAttributePanel.optionAdminValue('2')}}" userInput="{{option3.name}}" stepKey="fillAdminLabel3" after="waitForOptionRow3"/> + + <!-- Set Use In Layered Navigation --> + <click selector="{{AdminNewAttributePanel.storefrontPropertiesTab}}" stepKey="goToStorefrontPropertiesTab" after="fillAdminLabel3"/> + <waitForElementVisible selector="{{AdminNewAttributePanel.storefrontPropertiesTitle}}" stepKey="waitTabLoad" after="goToStorefrontPropertiesTab"/> + <selectOption selector="{{AdminNewAttributePanel.useInLayeredNavigation}}" stepKey="selectUseInLayer" userInput="Filterable (with results)" after="waitTabLoad"/> + + <!--Save attribute--> + <click selector="{{AdminNewAttributePanel.saveAttribute}}" stepKey="clickSaveAttribute"/> + <waitForPageLoad stepKey="waitForSavingAttribute"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminFillBasicValueConfigurableProductActionGroup.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminFillBasicValueConfigurableProductActionGroup.xml new file mode 100644 index 0000000000000..cc709b80efebb --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminFillBasicValueConfigurableProductActionGroup.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminFillBasicValueConfigurableProductActionGroup"> + <annotations> + <description>Goes to the Admin Product grid page. Fill basic value for Configurable Product using the default Product Options.</description> + </annotations> + <arguments> + <argument name="product" defaultValue="_defaultProduct"/> + <argument name="category" defaultValue="_defaultCategory"/> + </arguments> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="amOnProductGridPage"/> + <waitForPageLoad time="30" stepKey="wait1"/> + <click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickOnAddProductToggle"/> + <click selector="{{AdminProductGridActionSection.addConfigurableProduct}}" stepKey="clickOnAddConfigurableProduct"/> + <fillField userInput="{{product.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/> + <fillField userInput="{{product.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/> + <fillField userInput="{{product.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/> + <fillField userInput="{{product.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/> + <searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="fillCategory"/> + <selectOption userInput="{{product.visibility}}" selector="{{AdminProductFormSection.visibility}}" stepKey="fillVisibility"/> + <click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/> + <fillField userInput="{{product.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminGotoSelectValueAttributePageActionGroup.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminGotoSelectValueAttributePageActionGroup.xml new file mode 100644 index 0000000000000..969a41e27d459 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminGotoSelectValueAttributePageActionGroup.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminGotoSelectValueAttributePageActionGroup"> + <annotations> + <description>Goes to the select values page from each attribute to include in the product.</description> + </annotations> + + <arguments> + <argument name="defaultLabelAttribute" type="string" defaultValue="{{colorProductAttribute.default_label}}"/> + </arguments> + + <click selector="{{AdminCreateProductConfigurationsPanel.filters}}" stepKey="clickOnFilters"/> + <fillField selector="{{AdminCreateProductConfigurationsPanel.attributeCode}}" userInput="{{defaultLabelAttribute}}" stepKey="fillFilterAttributeCodeField"/> + <click selector="{{AdminCreateProductConfigurationsPanel.applyFilters}}" stepKey="clickApplyFiltersButton"/> + <click selector="{{AdminCreateProductConfigurationsPanel.firstCheckbox}}" stepKey="clickOnFirstCheckbox"/> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton"/> + + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSelectValueFromAttributeActionGroup.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSelectValueFromAttributeActionGroup.xml new file mode 100644 index 0000000000000..cc2ff9a63ae40 --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSelectValueFromAttributeActionGroup.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminSelectValueFromAttributeActionGroup"> + <annotations> + <description>Click to check option.</description> + </annotations> + + <arguments> + <argument name="option" defaultValue="colorProductAttribute1"/> + </arguments> + <click selector="{{AdminCreateProductConfigurationsPanel.attributeOption(option.name)}}" stepKey="clickOnCreateNewValue2"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSetQuantityToEachSkusConfigurableProductActionGroup.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSetQuantityToEachSkusConfigurableProductActionGroup.xml new file mode 100644 index 0000000000000..3cca319d9569c --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/ActionGroup/AdminSetQuantityToEachSkusConfigurableProductActionGroup.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminSetQuantityToEachSkusConfigurableProductActionGroup"> + <annotations> + <description>Set quantity 1 to all child skus for configurable product. Save a configurable product and confirm.</description> + </annotations> + + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton2"/> + <click selector="{{AdminCreateProductConfigurationsPanel.applySingleQuantityToEachSkus}}" stepKey="clickOnApplySingleQuantityToEachSku"/> + <fillField selector="{{AdminCreateProductConfigurationsPanel.quantity}}" userInput="1" stepKey="enterAttributeQuantity"/> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton3"/> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton4"/> + <click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickOnSaveButton2"/> + <click selector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" stepKey="clickOnConfirmInPopup"/> + <seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/ProductTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/ProductTest.php index abab103fa6d37..3d5a0d1cc6a3f 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/ProductTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/Model/ResourceModel/ProductTest.php @@ -7,20 +7,38 @@ namespace Magento\ConfigurableProduct\Test\Unit\Plugin\Model\ResourceModel; +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; +use Magento\Catalog\Model\Product as ModelProduct; use Magento\Catalog\Model\Product\Type; +use Magento\Catalog\Model\ProductAttributeSearchResults; +use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute; +use Magento\Catalog\Model\ResourceModel\Product as ResourceModelProduct; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; -use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Product; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute as ConfigurableAttribute; +use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Product as PluginResourceModelProduct; +use Magento\Framework\Api\ExtensionAttributesInterface; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\SearchCriteria; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Indexer\ActionInterface; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ProductTest extends TestCase { /** - * @var ObjectManager + * @var PluginResourceModelProduct */ - private $objectManager; + private $model; + + /** + * @var ObjectManagerHelper + */ + private $objectManagerHelper; /** * @var Configurable|MockObject @@ -33,39 +51,128 @@ class ProductTest extends TestCase private $actionMock; /** - * @var Product + * @var ProductAttributeRepositoryInterface|MockObject */ - private $model; + private $productAttributeRepositoryMock; + + /** + * @var SearchCriteriaBuilder|MockObject + */ + private $searchCriteriaBuilderMock; + + /** + * @var FilterBuilder|MockObject + */ + private $filterBuilderMock; protected function setUp(): void { - $this->objectManager = new ObjectManager($this); $this->configurableMock = $this->createMock(Configurable::class); $this->actionMock = $this->getMockForAbstractClass(ActionInterface::class); - - $this->model = $this->objectManager->getObject( - Product::class, + $this->productAttributeRepositoryMock = $this->getMockBuilder(ProductAttributeRepositoryInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getList']) + ->getMockForAbstractClass(); + $this->searchCriteriaBuilderMock = $this->createPartialMock( + SearchCriteriaBuilder::class, + ['addFilters', 'create'] + ); + $this->filterBuilderMock = $this->createPartialMock( + FilterBuilder::class, + ['setField', 'setConditionType', 'setValue', 'create'] + ); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->model = $this->objectManagerHelper->getObject( + PluginResourceModelProduct::class, [ 'configurable' => $this->configurableMock, 'productIndexer' => $this->actionMock, + 'productAttributeRepository' => $this->productAttributeRepositoryMock, + 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, + 'filterBuilder' => $this->filterBuilderMock ] ); } - public function testBeforeSaveConfigurable() + public function testBeforeSaveConfigurable(): void { - /** @var \Magento\Catalog\Model\ResourceModel\Product|MockObject $subject */ - $subject = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class); - /** @var \Magento\Catalog\Model\Product|MockObject $object */ - $object = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getTypeId', 'getTypeInstance']); + /** @var ResourceModelProduct|MockObject $subject */ + $subject = $this->createMock(ResourceModelProduct::class); + /** @var ModelProduct|MockObject $object */ + $object = $this->createPartialMock( + ModelProduct::class, + [ + 'getTypeId', + 'getTypeInstance', + 'getExtensionAttributes', + 'setData' + ] + ); $type = $this->createPartialMock( Configurable::class, ['getSetAttributes'] ); - $type->expects($this->once())->method('getSetAttributes')->with($object); - - $object->expects($this->once())->method('getTypeId')->willReturn(Configurable::TYPE_CODE); - $object->expects($this->once())->method('getTypeInstance')->willReturn($type); + $extensionAttributes = $this->getMockBuilder(ExtensionAttributesInterface::class) + ->disableOriginalConstructor() + ->addMethods(['getConfigurableProductOptions']) + ->getMock(); + $option = $this->createPartialMock( + ConfigurableAttribute::class, + ['getAttributeId'] + ); + $extensionAttributes->expects($this->exactly(2)) + ->method('getConfigurableProductOptions') + ->willReturn([$option]); + $object->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($extensionAttributes); + + $this->filterBuilderMock->expects($this->atLeastOnce()) + ->method('setField') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->atLeastOnce()) + ->method('setValue') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->atLeastOnce()) + ->method('setConditionType') + ->willReturnSelf(); + $this->filterBuilderMock->expects($this->atLeastOnce()) + ->method('create') + ->willReturnSelf(); + $searchCriteria = $this->createMock(SearchCriteria::class); + $this->searchCriteriaBuilderMock->expects($this->once()) + ->method('create') + ->willReturn($searchCriteria); + $searchResultMockClass = $this->createPartialMock( + ProductAttributeSearchResults::class, + ['getItems'] + ); + $this->productAttributeRepositoryMock->expects($this->once()) + ->method('getList') + ->with($searchCriteria) + ->willReturn($searchResultMockClass); + $optionAttribute = $this->createPartialMock( + EavAttribute::class, + ['getAttributeCode'] + ); + $searchResultMockClass->expects($this->once()) + ->method('getItems') + ->willReturn([$optionAttribute]); + $type->expects($this->once()) + ->method('getSetAttributes') + ->with($object); + $object->expects($this->once()) + ->method('getTypeId') + ->will($this->returnValue(Configurable::TYPE_CODE)); + $object->expects($this->once()) + ->method('getTypeInstance') + ->will($this->returnValue($type)); + $object->expects($this->once()) + ->method('setData'); + $option->expects($this->once()) + ->method('getAttributeId'); + $optionAttribute->expects($this->once()) + ->method('getAttributeCode'); $this->model->beforeSave( $subject, @@ -73,14 +180,23 @@ public function testBeforeSaveConfigurable() ); } - public function testBeforeSaveSimple() + public function testBeforeSaveSimple(): void { - /** @var \Magento\Catalog\Model\ResourceModel\Product|MockObject $subject */ - $subject = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class); - /** @var \Magento\Catalog\Model\Product|MockObject $object */ - $object = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getTypeId', 'getTypeInstance']); - $object->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_SIMPLE); - $object->expects($this->never())->method('getTypeInstance'); + /** @var ResourceModelProduct|MockObject$subject */ + $subject = $this->createMock(ResourceModelProduct::class); + /** @var ModelProduct|MockObject $object */ + $object = $this->createPartialMock( + ModelProduct::class, + [ + 'getTypeId', + 'getTypeInstance' + ] + ); + $object->expects($this->once()) + ->method('getTypeId') + ->will($this->returnValue(Type::TYPE_SIMPLE)); + $object->expects($this->never()) + ->method('getTypeInstance'); $this->model->beforeSave( $subject, @@ -88,29 +204,35 @@ public function testBeforeSaveSimple() ); } - public function testAroundDelete() + public function testAroundDelete(): void { $productId = '1'; $parentConfigId = ['2']; - /** @var \Magento\Catalog\Model\ResourceModel\Product|MockObject $subject */ - $subject = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class); - /** @var \Magento\Catalog\Model\Product|MockObject $product */ + /** @var ResourceModelProduct|MockObject $subject */ + $subject = $this->createMock(ResourceModelProduct::class); + /** @var ModelProduct|MockObject $product */ $product = $this->createPartialMock( - \Magento\Catalog\Model\Product::class, + ModelProduct::class, ['getId', 'delete'] ); - $product->expects($this->once())->method('getId')->willReturn($productId); - $product->expects($this->once())->method('delete')->willReturn(true); + $product->expects($this->once()) + ->method('getId') + ->willReturn($productId); + $product->expects($this->once()) + ->method('delete') + ->willReturn(true); $this->configurableMock->expects($this->once()) ->method('getParentIdsByChild') ->with($productId) ->willReturn($parentConfigId); - $this->actionMock->expects($this->once())->method('executeList')->with($parentConfigId); + $this->actionMock->expects($this->once()) + ->method('executeList') + ->with($parentConfigId); $return = $this->model->aroundDelete( $subject, - /** @var \Magento\Catalog\Model\Product|MockObject $prod */ - function (\Magento\Catalog\Model\Product $prod) use ($subject) { + /** @var ModelProduct|MockObject $prod */ + function (ModelProduct $prod) use ($subject) { $prod->delete(); return $subject; }, diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_wizard.xml b/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_wizard.xml index a084abfc31eaa..ffd17a8bf4734 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_wizard.xml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/layout/catalog_product_wizard.xml @@ -48,6 +48,7 @@ <item name="modal" xsi:type="string">configurableModal</item> <item name="dataScope" xsi:type="string">productFormConfigurable</item> </argument> + <argument name="permissions" xsi:type="object">Magento\ConfigurableProduct\Block\DataProviders\PermissionsData</argument> </arguments> </block> <block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\Bulk" name="step3" template="Magento_ConfigurableProduct::catalog/product/edit/attribute/steps/bulk.phtml"> diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml index e996df8260719..e94d94e0ded55 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/attributes_values.phtml @@ -5,6 +5,9 @@ */ /* @var $block \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues */ +$isAllowedToManageAttributes = $block->getPermissions()->isAllowedToManageAttributes(); +$attributesUrl = $block->getUrl('catalog/product_attribute/getAttributes'); +$optionsUrl = $block->getUrl('catalog/product_attribute/createOptions'); ?> <div data-bind="scope: '<?= /* @noEscape */ $block->getComponentName() ?>'"> <h2 class="steps-wizard-title"><?= $block->escapeHtml( @@ -12,7 +15,8 @@ ); ?></h2> <div class="steps-wizard-info"> <span><?= $block->escapeHtml( - __('Select values from each attribute to include in this product. Each unique combination of values creates a unique product SKU.') + __('Select values from each attribute to include in this product. ' . + 'Each unique combination of values creates a unique product SKU.') );?></span> </div> <div data-bind="foreach: attributes, sortableList: attributes"> @@ -72,7 +76,8 @@ <label data-bind="text: label, visible: label, attr:{for:id}" class="admin__field-label"></label> </div> - <div class="admin__field admin__field-create-new" data-bind="attr:{'data-role':id}, visible: !label"> + <div class="admin__field admin__field-create-new" + data-bind="attr:{'data-role':id}, visible: !label"> <div class="admin__field-control"> <input class="admin__control-text" name="label" @@ -101,14 +106,14 @@ </li> </ul> </fieldset> - <button class="action-create-new action-tertiary" - type="button" - data-action="addOption" - data-bind="click: $parent.createOption, visible: canCreateOption"> - <span><?= $block->escapeHtml( - __('Create New Value') - ); ?></span> - </button> + <?php if ($isAllowedToManageAttributes): ?> + <button class="action-create-new action-tertiary" + type="button" + data-action="addOption" + data-bind="click: $parent.createOption, visible: canCreateOption"> + <span><?= $block->escapeHtml(__('Create New Value')); ?></span> + </button> + <?php endif; ?> </div> </div> </div> @@ -120,8 +125,8 @@ "<?= /* @noEscape */ $block->getComponentName() ?>": { "component": "Magento_ConfigurableProduct/js/variations/steps/attributes_values", "appendTo": "<?= /* @noEscape */ $block->getParentComponentName() ?>", - "optionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/getAttributes') ?>", - "createOptionsUrl": "<?= /* @noEscape */ $block->getUrl('catalog/product_attribute/createOptions') ?>" + "optionsUrl": "<?= /* @noEscape */ $attributesUrl ?>", + "createOptionsUrl": "<?= /* @noEscape */ $optionsUrl ?>" } } } diff --git a/app/code/Magento/Customer/Observer/UpgradeOrderCustomerEmailObserver.php b/app/code/Magento/Customer/Observer/UpgradeOrderCustomerEmailObserver.php new file mode 100644 index 0000000000000..c2b7189b808a3 --- /dev/null +++ b/app/code/Magento/Customer/Observer/UpgradeOrderCustomerEmailObserver.php @@ -0,0 +1,78 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Customer\Observer; + +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Event\Observer; +use Magento\Framework\Event\ObserverInterface; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\ResourceModel\Order\Collection; +use Magento\Customer\Model\Data\Customer; + +/** + * Class observer UpgradeOrderCustomerEmailObserver + * Update orders customer email after corresponding customer email changed + */ +class UpgradeOrderCustomerEmailObserver implements ObserverInterface +{ + /** + * @var OrderRepositoryInterface + */ + private $orderRepository; + + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + /** + * @param OrderRepositoryInterface $orderRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + */ + public function __construct( + OrderRepositoryInterface $orderRepository, + SearchCriteriaBuilder $searchCriteriaBuilder + ) { + $this->orderRepository = $orderRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * Upgrade order customer email when customer has changed email + * + * @param Observer $observer + * @return void + */ + public function execute(Observer $observer): void + { + /** @var Customer $originalCustomer */ + $originalCustomer = $observer->getEvent()->getOrigCustomerDataObject(); + if (!$originalCustomer) { + return; + } + + /** @var Customer $customer */ + $customer = $observer->getEvent()->getCustomerDataObject(); + $customerEmail = $customer->getEmail(); + + if ($customerEmail === $originalCustomer->getEmail()) { + return; + } + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(OrderInterface::CUSTOMER_ID, $customer->getId()) + ->create(); + + /** + * @var Collection $orders + */ + $orders = $this->orderRepository->getList($searchCriteria); + $orders->setDataToAll(OrderInterface::CUSTOMER_EMAIL, $customerEmail); + $orders->save(); + } +} diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/CreateCustomerOrderActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/CreateCustomerOrderActionGroup.xml new file mode 100644 index 0000000000000..34d01d09b42cf --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/CreateCustomerOrderActionGroup.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="CreateCustomerOrderActionGroup"> + <annotations> + <description>Create Order via API assigned to Customer.</description> + </annotations> + <arguments> + <argument name="Customer" /> + <argument name="Product" /> + </arguments> + + <createData entity="CustomerCart" stepKey="CustomerCart"> + <requiredEntity createDataKey="Customer"/> + </createData> + + <createData entity="CustomerCartItem" stepKey="addCartItem"> + <requiredEntity createDataKey="CustomerCart"/> + <requiredEntity createDataKey="Product"/> + </createData> + + <createData entity="CustomerAddressInformation" stepKey="addCustomerOrderAddress"> + <requiredEntity createDataKey="CustomerCart"/> + </createData> + + <updateData createDataKey="CustomerCart" entity="CustomerOrderPaymentMethod" stepKey="sendCustomerPaymentInformation"> + <requiredEntity createDataKey="CustomerCart"/> + </updateData> + + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderSection.xml index ec5141d84b1bd..61ce050aa3ef2 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderSection.xml @@ -17,5 +17,9 @@ <element name="viewOrder" type="button" selector="//td[contains(concat(' ',normalize-space(@class),' '),' col actions ')]/a[contains(concat(' ',normalize-space(@class),' '),' action view ')]"/> <element name="tabRefund" type="button" selector="//a[text()='Refunds']"/> <element name="grandTotalRefund" type="text" selector="td[data-th='Grand Total'] > strong > span.price"/> + <element name="currentPage" type="text" selector=".order-products-toolbar .pages .current span:nth-of-type(2)"/> + <element name="pageNumber" type="text" selector="//*[@class='order-products-toolbar toolbar bottom']//a[contains(@class, 'page')]//span[2][contains(text() ,'{{var1}}')]" parameterized="true"/> + <element name="perPage" type="select" selector="//*[@class='order-products-toolbar toolbar bottom']//select[@id='limiter']"/> + <element name="rowsInColumn" type="text" selector="//tbody/tr/td[contains(@class, '{{column}}')]" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCustomerAccountOrderListTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCustomerAccountOrderListTest.xml new file mode 100644 index 0000000000000..ba113c739d706 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontCustomerAccountOrderListTest.xml @@ -0,0 +1,144 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontCustomerAccountOrderListTest"> + <annotations> + <stories value="Frontend Customer Account Orders list"/> + <title value="Verify that the list of Orders is displayed in the grid after changing the number of items on the page"/> + <description value="Verify that the list of Orders is displayed in the grid after changing the number of items on the page."/> + <severity value="CRITICAL"/> + <testCaseId value="MC-34953"/> + <group value="customer"/> + </annotations> + + <before> + + <!--Create Product via API--> + <createData entity="SimpleProduct2" stepKey="Product"/> + + <!--Create Customer via API--> + <createData entity="Simple_US_Customer" stepKey="Customer"/> + + <!--Create Orders via API--> + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder1"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder2"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder3"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder4"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder5"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder6"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder7"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder8"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder9"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder10"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder11"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder12"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder13"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder14"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + + <actionGroup ref="CreateCustomerOrderActionGroup" stepKey="createCustomerOrder15"> + <argument name="Customer" value="Customer"/> + <argument name="Product" value="Product"/> + </actionGroup> + <!--Create Orders via API--> + + </before> + + <after> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customerLogout"/> + <deleteData createDataKey="Product" stepKey="deleteProduct"/> + <deleteData createDataKey="Customer" stepKey="deleteCustomer"/> + </after> + + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefront"> + <argument name="Customer" value="$$Customer$$"/> + </actionGroup> + + <actionGroup ref="StorefrontCustomerGoToSidebarMenu" stepKey="goToSidebarMenu"> + <argument name="menu" value="My Orders"/> + </actionGroup> + + <seeElement selector="{{StorefrontCustomerOrderSection.isMyOrdersSection}}" stepKey="waitOrderHistoryPage"/> + + <scrollTo selector="{{StorefrontCustomerOrderSection.currentPage}}" stepKey="scrollToBottomToolbarSection"/> + + <click selector="{{StorefrontCustomerOrderSection.pageNumber('2')}}" stepKey="clickOnPage2"/> + + <scrollTo selector="{{StorefrontCustomerOrderSection.perPage}}" stepKey="scrollToLimiter"/> + + <selectOption userInput="20" selector="{{StorefrontCustomerOrderSection.perPage}}" stepKey="selectLimitOnPage"/> + + <waitForPageLoad stepKey="waitForLoadPage"/> + + <seeElement selector="{{StorefrontCustomerOrderSection.isMyOrdersSection}}" + stepKey="seeElementOrderHistoryPage"/> + + <dontSee selector="{{StorefrontOrderInformationMainSection.emptyMessage}}" + userInput="You have placed no orders." stepKey="dontSeeEmptyMessage"/> + + <seeNumberOfElements selector="{{StorefrontCustomerOrderSection.rowsInColumn('id')}}" userInput="15" + stepKey="seeRowsCount"/> + + </test> +</tests> diff --git a/app/code/Magento/Customer/Test/Unit/Observer/UpgradeOrderCustomerEmailObserverTest.php b/app/code/Magento/Customer/Test/Unit/Observer/UpgradeOrderCustomerEmailObserverTest.php new file mode 100644 index 0000000000000..d05c10c00e6c3 --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Observer/UpgradeOrderCustomerEmailObserverTest.php @@ -0,0 +1,222 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Customer\Test\Unit\Observer; + +use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver; +use Magento\Framework\Api\SearchCriteria; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Event; +use Magento\Framework\Event\Observer; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\ResourceModel\Order\Collection; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * For testing upgrade order customer email + */ +class UpgradeOrderCustomerEmailObserverTest extends TestCase +{ + private const NEW_CUSTOMER_EMAIL = "test@test.com"; + private const ORIGINAL_CUSTOMER_EMAIL = "origtest@test.com"; + + /** + * @var UpgradeOrderCustomerEmailObserver + */ + private $orderCustomerEmailObserver; + + /** + * @var Observer|MockObject + */ + private $observerMock; + + /** + * @var OrderRepositoryInterface|MockObject + */ + private $orderRepositoryMock; + + /** + * @var SearchCriteriaBuilder|MockObject + */ + private $searchCriteriaBuilderMock; + + /** + * @var Event|MockObject + */ + private $eventMock; + + /** + * @var ObjectManagerHelper + */ + private $objectManagerHelper; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class) + ->getMock(); + + $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->eventMock = $this->getMockBuilder(Event::class) + ->disableOriginalConstructor() + ->setMethods(['getCustomerDataObject', 'getOrigCustomerDataObject']) + ->getMock(); + + $this->observerMock = $this->getMockBuilder(Observer::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->observerMock->expects($this->any())->method('getEvent')->willReturn($this->eventMock); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + + $this->orderCustomerEmailObserver = $this->objectManagerHelper->getObject( + UpgradeOrderCustomerEmailObserver::class, + [ + 'orderRepository' => $this->orderRepositoryMock, + 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, + ] + ); + } + + /** + * Verifying that the order email is not updated when the customer email is not updated + * + */ + public function testUpgradeOrderCustomerEmailWhenMailIsNotChanged(): void + { + $customer = $this->createCustomerMock(); + $originalCustomer = $this->createCustomerMock(); + + $this->setCustomerToEventMock($customer); + $this->setOriginalCustomerToEventMock($originalCustomer); + + $this->setCustomerEmail($originalCustomer, self::ORIGINAL_CUSTOMER_EMAIL); + $this->setCustomerEmail($customer, self::ORIGINAL_CUSTOMER_EMAIL); + + $this->whenOrderRepositoryGetListIsNotCalled(); + + $this->orderCustomerEmailObserver->execute($this->observerMock); + } + + /** + * Verifying that the order email is updated after the customer updates their email + * + */ + public function testUpgradeOrderCustomerEmail(): void + { + $customer = $this->createCustomerMock(); + $originalCustomer = $this->createCustomerMock(); + $orderCollectionMock = $this->createOrderMock(); + + $this->setCustomerToEventMock($customer); + $this->setOriginalCustomerToEventMock($originalCustomer); + + $this->setCustomerEmail($originalCustomer, self::ORIGINAL_CUSTOMER_EMAIL); + $this->setCustomerEmail($customer, self::NEW_CUSTOMER_EMAIL); + + $this->whenOrderRepositoryGetListIsCalled($orderCollectionMock); + + $this->whenOrderCollectionSetDataToAllIsCalled($orderCollectionMock); + + $this->whenOrderCollectionSaveIsCalled($orderCollectionMock); + + $this->orderCustomerEmailObserver->execute($this->observerMock); + } + + private function createCustomerMock(): MockObject + { + $customer = $this->getMockBuilder(CustomerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + return $customer; + } + + private function createOrderMock(): MockObject + { + $orderCollectionMock = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->getMock(); + + return $orderCollectionMock; + } + + private function setCustomerToEventMock(MockObject $customer): void + { + $this->eventMock->expects($this->once()) + ->method('getCustomerDataObject') + ->willReturn($customer); + } + + private function setOriginalCustomerToEventMock(MockObject $originalCustomer): void + { + $this->eventMock->expects($this->once()) + ->method('getOrigCustomerDataObject') + ->willReturn($originalCustomer); + } + + private function setCustomerEmail(MockObject $originalCustomer, string $email): void + { + $originalCustomer->expects($this->once()) + ->method('getEmail') + ->willReturn($email); + } + + private function whenOrderRepositoryGetListIsCalled(MockObject $orderCollectionMock): void + { + $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->searchCriteriaBuilderMock->expects($this->once()) + ->method('create') + ->willReturn($searchCriteriaMock); + + $this->searchCriteriaBuilderMock->expects($this->once()) + ->method('addFilter') + ->willReturn($this->searchCriteriaBuilderMock); + + $this->orderRepositoryMock->expects($this->once()) + ->method('getList') + ->with($searchCriteriaMock) + ->willReturn($orderCollectionMock); + } + + private function whenOrderCollectionSetDataToAllIsCalled(MockObject $orderCollectionMock): void + { + $orderCollectionMock->expects($this->once()) + ->method('setDataToAll') + ->with(OrderInterface::CUSTOMER_EMAIL, self::NEW_CUSTOMER_EMAIL); + } + + private function whenOrderCollectionSaveIsCalled(MockObject $orderCollectionMock): void + { + $orderCollectionMock->expects($this->once()) + ->method('save'); + } + + private function whenOrderRepositoryGetListIsNotCalled(): void + { + $this->searchCriteriaBuilderMock->expects($this->never()) + ->method('addFilter'); + $this->searchCriteriaBuilderMock->expects($this->never()) + ->method('create'); + + $this->orderRepositoryMock->expects($this->never()) + ->method('getList'); + } +} diff --git a/app/code/Magento/Customer/etc/events.xml b/app/code/Magento/Customer/etc/events.xml index 2a724498a0359..0194f91c591f5 100644 --- a/app/code/Magento/Customer/etc/events.xml +++ b/app/code/Magento/Customer/etc/events.xml @@ -16,6 +16,7 @@ <observer name="customer_visitor" instance="Magento\Customer\Observer\Visitor\BindQuoteCreateObserver" /> </event> <event name="customer_save_after_data_object"> + <observer name="upgrade_order_customer_email" instance="Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver"/> <observer name="upgrade_quote_customer_email" instance="Magento\Customer\Observer\UpgradeQuoteCustomerEmailObserver"/> </event> </config> diff --git a/app/code/Magento/Downloadable/Controller/Download/LinkSample.php b/app/code/Magento/Downloadable/Controller/Download/LinkSample.php index c0bc825a8285b..c449f8f54872f 100644 --- a/app/code/Magento/Downloadable/Controller/Download/LinkSample.php +++ b/app/code/Magento/Downloadable/Controller/Download/LinkSample.php @@ -7,8 +7,9 @@ namespace Magento\Downloadable\Controller\Download; -use Magento\Catalog\Model\Product\SalabilityChecker; use Magento\Downloadable\Helper\Download as DownloadHelper; +use Magento\Downloadable\Model\Link as LinkModel; +use Magento\Downloadable\Model\RelatedProductRetriever; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ResponseInterface; @@ -20,20 +21,21 @@ class LinkSample extends \Magento\Downloadable\Controller\Download { /** - * @var SalabilityChecker + * @var RelatedProductRetriever */ - private $salabilityChecker; + private $relatedProductRetriever; /** * @param Context $context - * @param SalabilityChecker|null $salabilityChecker + * @param RelatedProductRetriever $relatedProductRetriever */ public function __construct( Context $context, - SalabilityChecker $salabilityChecker = null + RelatedProductRetriever $relatedProductRetriever ) { parent::__construct($context); - $this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class); + + $this->relatedProductRetriever = $relatedProductRetriever; } /** @@ -44,9 +46,10 @@ public function __construct( public function execute() { $linkId = $this->getRequest()->getParam('link_id', 0); - /** @var \Magento\Downloadable\Model\Link $link */ - $link = $this->_objectManager->create(\Magento\Downloadable\Model\Link::class)->load($linkId); - if ($link->getId() && $this->salabilityChecker->isSalable($link->getProductId())) { + /** @var LinkModel $link */ + $link = $this->_objectManager->create(LinkModel::class); + $link->load($linkId); + if ($link->getId() && $this->isProductSalable($link)) { $resource = ''; $resourceType = ''; if ($link->getSampleType() == DownloadHelper::LINK_TYPE_URL) { @@ -74,4 +77,16 @@ public function execute() return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } + + /** + * Check is related product salable. + * + * @param LinkModel $link + * @return bool + */ + private function isProductSalable(LinkModel $link): bool + { + $product = $this->relatedProductRetriever->getProduct((int) $link->getProductId()); + return $product ? $product->isSalable() : false; + } } diff --git a/app/code/Magento/Downloadable/Controller/Download/Sample.php b/app/code/Magento/Downloadable/Controller/Download/Sample.php index b95ec510fdd9b..e2561092a7592 100644 --- a/app/code/Magento/Downloadable/Controller/Download/Sample.php +++ b/app/code/Magento/Downloadable/Controller/Download/Sample.php @@ -7,8 +7,9 @@ namespace Magento\Downloadable\Controller\Download; -use Magento\Catalog\Model\Product\SalabilityChecker; use Magento\Downloadable\Helper\Download as DownloadHelper; +use Magento\Downloadable\Model\RelatedProductRetriever; +use Magento\Downloadable\Model\Sample as SampleModel; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ResponseInterface; @@ -20,20 +21,21 @@ class Sample extends \Magento\Downloadable\Controller\Download { /** - * @var SalabilityChecker + * @var RelatedProductRetriever */ - private $salabilityChecker; + private $relatedProductRetriever; /** * @param Context $context - * @param SalabilityChecker|null $salabilityChecker + * @param RelatedProductRetriever $relatedProductRetriever */ public function __construct( Context $context, - SalabilityChecker $salabilityChecker = null + RelatedProductRetriever $relatedProductRetriever ) { parent::__construct($context); - $this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class); + + $this->relatedProductRetriever = $relatedProductRetriever; } /** @@ -44,9 +46,10 @@ public function __construct( public function execute() { $sampleId = $this->getRequest()->getParam('sample_id', 0); - /** @var \Magento\Downloadable\Model\Sample $sample */ - $sample = $this->_objectManager->create(\Magento\Downloadable\Model\Sample::class)->load($sampleId); - if ($sample->getId() && $this->salabilityChecker->isSalable($sample->getProductId())) { + /** @var SampleModel $sample */ + $sample = $this->_objectManager->create(SampleModel::class); + $sample->load($sampleId); + if ($sample->getId() && $this->isProductSalable($sample)) { $resource = ''; $resourceType = ''; if ($sample->getSampleType() == DownloadHelper::LINK_TYPE_URL) { @@ -71,4 +74,16 @@ public function execute() return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } + + /** + * Check is related product salable. + * + * @param SampleModel $sample + * @return bool + */ + private function isProductSalable(SampleModel $sample): bool + { + $product = $this->relatedProductRetriever->getProduct((int) $sample->getProductId()); + return $product ? $product->isSalable() : false; + } } diff --git a/app/code/Magento/Downloadable/Model/RelatedProductRetriever.php b/app/code/Magento/Downloadable/Model/RelatedProductRetriever.php new file mode 100644 index 0000000000000..f701f96b910e7 --- /dev/null +++ b/app/code/Magento/Downloadable/Model/RelatedProductRetriever.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Downloadable\Model; + +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Api\ProductRepositoryInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\EntityManager\MetadataPool; + +/** + * Related parent product retriever. + */ +class RelatedProductRetriever +{ + /** + * @var ProductRepositoryInterface + */ + private $productRepository; + + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + /** + * @var MetadataPool + */ + private $metadataPool; + + /** + * @param ProductRepositoryInterface $productRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param MetadataPool $metadataPool + */ + public function __construct( + ProductRepositoryInterface $productRepository, + SearchCriteriaBuilder $searchCriteriaBuilder, + MetadataPool $metadataPool + ) { + $this->productRepository = $productRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->metadataPool = $metadataPool; + } + + /** + * Get related product. + * + * @param int $productId + * @return ProductInterface|null + */ + public function getProduct(int $productId): ?ProductInterface + { + $productMetadata = $this->metadataPool->getMetadata(ProductInterface::class); + + $searchCriteria = $this->searchCriteriaBuilder->addFilter($productMetadata->getLinkField(), $productId) + ->create(); + $items = $this->productRepository->getList($searchCriteria) + ->getItems(); + $product = $items ? array_shift($items) : null; + + return $product; + } +} diff --git a/app/code/Magento/Downloadable/Model/ResourceModel/Sample.php b/app/code/Magento/Downloadable/Model/ResourceModel/Sample.php index 8d30322745b8d..b7b079d208d97 100644 --- a/app/code/Magento/Downloadable/Model/ResourceModel/Sample.php +++ b/app/code/Magento/Downloadable/Model/ResourceModel/Sample.php @@ -24,7 +24,7 @@ class Sample extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb /** * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool - * @param null $connectionName + * @param string|null $connectionName */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, @@ -126,7 +126,7 @@ public function getSearchableData($productId, $storeId) )->join( ['cpe' => $this->getTable('catalog_product_entity')], sprintf( - 'cpe.entity_id = m.product_id', + 'cpe.%s = m.product_id', $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField() ), [] diff --git a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkSampleTest.php b/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkSampleTest.php deleted file mode 100644 index 725c06004f117..0000000000000 --- a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkSampleTest.php +++ /dev/null @@ -1,237 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Downloadable\Test\Unit\Controller\Download; - -use Magento\Catalog\Model\Product; -use Magento\Catalog\Model\Product\SalabilityChecker; -use Magento\Downloadable\Controller\Download\LinkSample; -use Magento\Downloadable\Helper\Data; -use Magento\Downloadable\Helper\Download; -use Magento\Downloadable\Helper\File; -use Magento\Downloadable\Model\Link; -use Magento\Framework\App\Request\Http; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\RedirectInterface; -use Magento\Framework\App\ResponseInterface; -use Magento\Framework\Message\ManagerInterface; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; -use Magento\Framework\UrlInterface; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; - -/** - * Unit tests for \Magento\Downloadable\Controller\Download\LinkSample. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class LinkSampleTest extends TestCase -{ - /** @var LinkSample */ - protected $linkSample; - - /** @var ObjectManagerHelper */ - protected $objectManagerHelper; - - /** - * @var MockObject|Http - */ - protected $request; - - /** - * @var MockObject|ResponseInterface - */ - protected $response; - - /** - * @var MockObject|\Magento\Framework\ObjectManager\ObjectManager - */ - protected $objectManager; - - /** - * @var MockObject|ManagerInterface - */ - protected $messageManager; - - /** - * @var MockObject|RedirectInterface - */ - protected $redirect; - - /** - * @var MockObject|Data - */ - protected $helperData; - - /** - * @var MockObject|\Magento\Downloadable\Helper\Download - */ - protected $downloadHelper; - - /** - * @var MockObject|Product - */ - protected $product; - - /** - * @var MockObject|UrlInterface - */ - protected $urlInterface; - - /** - * @var SalabilityChecker|MockObject - */ - private $salabilityCheckerMock; - - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function setUp(): void - { - $this->objectManagerHelper = new ObjectManagerHelper($this); - - $this->request = $this->getMockForAbstractClass(RequestInterface::class); - $this->response = $this->getMockBuilder(ResponseInterface::class) - ->addMethods(['setHttpResponseCode', 'clearBody', 'sendHeaders', 'setHeader', 'setRedirect']) - ->onlyMethods(['sendResponse']) - ->getMockForAbstractClass(); - - $this->helperData = $this->createPartialMock( - Data::class, - ['getIsShareable'] - ); - $this->downloadHelper = $this->createPartialMock( - Download::class, - [ - 'setResource', - 'getFilename', - 'getContentType', - 'getFileSize', - 'getContentDisposition', - 'output' - ] - ); - $this->product = $this->getMockBuilder(Product::class) - ->addMethods(['_wakeup']) - ->onlyMethods(['load', 'getId', 'getProductUrl', 'getName']) - ->disableOriginalConstructor() - ->getMock(); - $this->messageManager = $this->getMockForAbstractClass(ManagerInterface::class); - $this->redirect = $this->getMockForAbstractClass(RedirectInterface::class); - $this->urlInterface = $this->getMockForAbstractClass(UrlInterface::class); - $this->salabilityCheckerMock = $this->createMock(SalabilityChecker::class); - $this->objectManager = $this->createPartialMock( - \Magento\Framework\ObjectManager\ObjectManager::class, - ['create', 'get'] - ); - $this->linkSample = $this->objectManagerHelper->getObject( - LinkSample::class, - [ - 'objectManager' => $this->objectManager, - 'request' => $this->request, - 'response' => $this->response, - 'messageManager' => $this->messageManager, - 'redirect' => $this->redirect, - 'salabilityChecker' => $this->salabilityCheckerMock, - ] - ); - } - - /** - * Execute Download link's sample action with Url link. - * - * @return void - */ - public function testExecuteLinkTypeUrl() - { - $linkMock = $this->getMockBuilder(Link::class) - ->disableOriginalConstructor() - ->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl']) - ->getMock(); - - $this->request->expects($this->once())->method('getParam')->with('link_id', 0)->willReturn('some_link_id'); - $this->objectManager->expects($this->once()) - ->method('create') - ->with(Link::class) - ->willReturn($linkMock); - $linkMock->expects($this->once())->method('load')->with('some_link_id')->willReturnSelf(); - $linkMock->expects($this->once())->method('getId')->willReturn('some_link_id'); - $this->salabilityCheckerMock->expects($this->once())->method('isSalable')->willReturn(true); - $linkMock->expects($this->once())->method('getSampleType')->willReturn( - Download::LINK_TYPE_URL - ); - $linkMock->expects($this->once())->method('getSampleUrl')->willReturn('sample_url'); - $this->objectManager->expects($this->at(1)) - ->method('get') - ->with(Download::class) - ->willReturn($this->downloadHelper); - $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); - $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); - $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); - $this->messageManager->expects($this->once()) - ->method('addError') - ->with('Sorry, there was an error getting requested content. Please contact the store owner.') - ->willReturnSelf(); - $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); - $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); - - $this->assertEquals($this->response, $this->linkSample->execute()); - } - - /** - * Execute Download link's sample action with File link. - * - * @return void - */ - public function testExecuteLinkTypeFile() - { - $linkMock = $this->getMockBuilder(Link::class) - ->disableOriginalConstructor() - ->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath']) - ->getMock(); - $fileMock = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->setMethods(['getFilePath', 'load', 'getSampleType', 'getSampleUrl']) - ->getMock(); - - $this->request->expects($this->once())->method('getParam')->with('link_id', 0)->willReturn('some_link_id'); - $this->objectManager->expects($this->at(0)) - ->method('create') - ->with(Link::class) - ->willReturn($linkMock); - $linkMock->expects($this->once())->method('load')->with('some_link_id')->willReturnSelf(); - $linkMock->expects($this->once())->method('getId')->willReturn('some_link_id'); - $this->salabilityCheckerMock->expects($this->once())->method('isSalable')->willReturn(true); - $linkMock->expects($this->any())->method('getSampleType')->willReturn( - Download::LINK_TYPE_FILE - ); - $this->objectManager->expects($this->at(1)) - ->method('get') - ->with(File::class) - ->willReturn($fileMock); - $this->objectManager->expects($this->at(2)) - ->method('get') - ->with(Link::class) - ->willReturn($linkMock); - $linkMock->expects($this->once())->method('getBaseSamplePath')->willReturn('downloadable/files/link_samples'); - $this->objectManager->expects($this->at(3)) - ->method('get') - ->with(Download::class) - ->willReturn($this->downloadHelper); - $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); - $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); - $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); - $this->messageManager->expects($this->once()) - ->method('addError') - ->with('Sorry, there was an error getting requested content. Please contact the store owner.') - ->willReturnSelf(); - $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); - $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); - - $this->assertEquals($this->response, $this->linkSample->execute()); - } -} diff --git a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/SampleTest.php b/app/code/Magento/Downloadable/Test/Unit/Controller/Download/SampleTest.php deleted file mode 100644 index 6dcd09a91dd2e..0000000000000 --- a/app/code/Magento/Downloadable/Test/Unit/Controller/Download/SampleTest.php +++ /dev/null @@ -1,232 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Downloadable\Test\Unit\Controller\Download; - -use Magento\Catalog\Model\Product; -use Magento\Catalog\Model\Product\SalabilityChecker; -use Magento\Downloadable\Controller\Download\Sample; -use Magento\Downloadable\Helper\Data; -use Magento\Downloadable\Helper\Download; -use Magento\Downloadable\Helper\File; -use Magento\Framework\App\Request\Http; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\App\Response\RedirectInterface; -use Magento\Framework\App\ResponseInterface; -use Magento\Framework\Message\ManagerInterface; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; -use Magento\Framework\UrlInterface; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; - -/** - * Unit tests for \Magento\Downloadable\Controller\Download\Sample. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class SampleTest extends TestCase -{ - /** @var \Magento\Downloadable\Controller\Download\Sample */ - protected $sample; - - /** @var ObjectManagerHelper */ - protected $objectManagerHelper; - - /** - * @var MockObject|Http - */ - protected $request; - - /** - * @var MockObject|ResponseInterface - */ - protected $response; - - /** - * @var MockObject|\Magento\Framework\ObjectManager\ObjectManager - */ - protected $objectManager; - - /** - * @var MockObject|ManagerInterface - */ - protected $messageManager; - - /** - * @var MockObject|RedirectInterface - */ - protected $redirect; - - /** - * @var MockObject|Data - */ - protected $helperData; - - /** - * @var MockObject|\Magento\Downloadable\Helper\Download - */ - protected $downloadHelper; - - /** - * @var MockObject|Product - */ - protected $product; - - /** - * @var MockObject|UrlInterface - */ - protected $urlInterface; - - /** - * @var SalabilityChecker|MockObject - */ - private $salabilityCheckerMock; - - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function setUp(): void - { - $this->objectManagerHelper = new ObjectManagerHelper($this); - - $this->request = $this->getMockForAbstractClass(RequestInterface::class); - $this->response = $this->getMockBuilder(ResponseInterface::class) - ->addMethods(['setHttpResponseCode', 'clearBody', 'sendHeaders', 'setHeader', 'setRedirect']) - ->onlyMethods(['sendResponse']) - ->getMockForAbstractClass(); - - $this->helperData = $this->createPartialMock( - Data::class, - ['getIsShareable'] - ); - $this->downloadHelper = $this->createPartialMock( - Download::class, - [ - 'setResource', - 'getFilename', - 'getContentType', - 'getFileSize', - 'getContentDisposition', - 'output' - ] - ); - $this->product = $this->getMockBuilder(Product::class) - ->addMethods(['_wakeup']) - ->onlyMethods(['load', 'getId', 'getProductUrl', 'getName']) - ->disableOriginalConstructor() - ->getMock(); - $this->messageManager = $this->getMockForAbstractClass(ManagerInterface::class); - $this->redirect = $this->getMockForAbstractClass(RedirectInterface::class); - $this->urlInterface = $this->getMockForAbstractClass(UrlInterface::class); - $this->salabilityCheckerMock = $this->createMock(SalabilityChecker::class); - $this->objectManager = $this->createPartialMock( - \Magento\Framework\ObjectManager\ObjectManager::class, - ['create', 'get'] - ); - $this->sample = $this->objectManagerHelper->getObject( - Sample::class, - [ - 'objectManager' => $this->objectManager, - 'request' => $this->request, - 'response' => $this->response, - 'messageManager' => $this->messageManager, - 'redirect' => $this->redirect, - 'salabilityChecker' => $this->salabilityCheckerMock, - ] - ); - } - - /** - * Execute Download sample action with Sample Url. - * - * @return void - */ - public function testExecuteSampleWithUrlType() - { - $sampleMock = $this->getMockBuilder(\Magento\Downloadable\Model\Sample::class) - ->disableOriginalConstructor() - ->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl']) - ->getMock(); - - $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id'); - $this->objectManager->expects($this->once()) - ->method('create') - ->with(\Magento\Downloadable\Model\Sample::class) - ->willReturn($sampleMock); - $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf(); - $sampleMock->expects($this->once())->method('getId')->willReturn('some_link_id'); - $this->salabilityCheckerMock->expects($this->once())->method('isSalable')->willReturn(true); - $sampleMock->expects($this->once())->method('getSampleType')->willReturn( - Download::LINK_TYPE_URL - ); - $sampleMock->expects($this->once())->method('getSampleUrl')->willReturn('sample_url'); - $this->objectManager->expects($this->at(1)) - ->method('get') - ->with(Download::class) - ->willReturn($this->downloadHelper); - $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); - $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); - $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); - $this->messageManager->expects($this->once()) - ->method('addError') - ->with('Sorry, there was an error getting requested content. Please contact the store owner.') - ->willReturnSelf(); - $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); - $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); - - $this->assertEquals($this->response, $this->sample->execute()); - } - - /** - * Execute Download sample action with Sample File. - * - * @return void - */ - public function testExecuteSampleWithFileType() - { - $sampleMock = $this->getMockBuilder(\Magento\Downloadable\Model\Sample::class) - ->disableOriginalConstructor() - ->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath']) - ->getMock(); - $fileHelperMock = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->setMethods(['getFilePath']) - ->getMock(); - - $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id'); - $this->objectManager->expects($this->at(0)) - ->method('create') - ->with(\Magento\Downloadable\Model\Sample::class) - ->willReturn($sampleMock); - $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf(); - $sampleMock->expects($this->once())->method('getId')->willReturn('some_sample_id'); - $this->salabilityCheckerMock->expects($this->once())->method('isSalable')->willReturn(true); - $sampleMock->expects($this->any())->method('getSampleType')->willReturn( - Download::LINK_TYPE_FILE - ); - $this->objectManager->expects($this->at(1)) - ->method('get') - ->with(File::class) - ->willReturn($fileHelperMock); - $fileHelperMock->expects($this->once())->method('getFilePath')->willReturn('file_path'); - $this->objectManager->expects($this->at(2)) - ->method('get') - ->with(Download::class) - ->willReturn($this->downloadHelper); - $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); - $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); - $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); - $this->messageManager->expects($this->once()) - ->method('addError') - ->with('Sorry, there was an error getting requested content. Please contact the store owner.') - ->willReturnSelf(); - $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); - $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); - - $this->assertEquals($this->response, $this->sample->execute()); - } -} diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index 39148f990b714..4366ef7aaf969 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -1019,6 +1019,13 @@ public function collectShippingRates() */ public function requestShippingRates(AbstractItem $item = null) { + $storeId = $this->getQuote()->getStoreId() ?: $this->storeManager->getStore()->getId(); + $taxInclude = $this->_scopeConfig->getValue( + 'tax/calculation/price_includes_tax', + ScopeInterface::SCOPE_STORE, + $storeId + ); + /** @var $request RateRequest */ $request = $this->_rateRequestFactory->create(); $request->setAllItems($item ? [$item] : $this->getAllItems()); @@ -1028,9 +1035,11 @@ public function requestShippingRates(AbstractItem $item = null) $request->setDestStreet($this->getStreetFull()); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); - $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); + $baseSubtotal = $taxInclude ? $this->getBaseSubtotalTotalInclTax() : $this->getBaseSubtotal(); + $request->setPackageValue($item ? $item->getBaseRowTotal() : $baseSubtotal); + $baseSubtotalWithDiscount = $baseSubtotal + $this->getBaseDiscountAmount(); $packageWithDiscount = $item ? $item->getBaseRowTotal() - - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); + $item->getBaseDiscountAmount() : $baseSubtotalWithDiscount; $request->setPackageValueWithDiscount($packageWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); @@ -1038,8 +1047,7 @@ public function requestShippingRates(AbstractItem $item = null) /** * Need for shipping methods that use insurance based on price of physical products */ - $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - - $this->getBaseVirtualAmount(); + $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $baseSubtotal - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); @@ -1047,12 +1055,10 @@ public function requestShippingRates(AbstractItem $item = null) /** * Store and website identifiers specified from StoreManager */ + $request->setStoreId($storeId); if ($this->getQuote()->getStoreId()) { - $storeId = $this->getQuote()->getStoreId(); - $request->setStoreId($storeId); $request->setWebsiteId($this->storeManager->getStore($storeId)->getWebsiteId()); } else { - $request->setStoreId($this->storeManager->getStore()->getId()); $request->setWebsiteId($this->storeManager->getWebsite()->getId()); } $request->setFreeShipping($this->getFreeShipping()); diff --git a/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartData.xml b/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartData.xml new file mode 100755 index 0000000000000..a14be3b533fa8 --- /dev/null +++ b/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartData.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd"> + <entity name="CustomerCart" type="CustomerCart"> + <var key="customer_id" entityType="customer" entityKey="id"/> + </entity> + + <entity name="CustomerAddressInformation" type="CustomerAddressInformation"> + <var key="cart_id" entityKey="return" entityType="CustomerCart"/> + <requiredEntity type="shipping_address">ShippingAddressTX</requiredEntity> + <requiredEntity type="billing_address">BillingAddressTX</requiredEntity> + <data key="shipping_method_code">flatrate</data> + <data key="shipping_carrier_code">flatrate</data> + </entity> + + <entity name="CustomerOrderPaymentMethod" type="CustomerPaymentInformation"> + <var key="cart_id" entityKey="return" entityType="CustomerCart"/> + <requiredEntity type="payment_method">PaymentMethodCheckMoneyOrder</requiredEntity> + <requiredEntity type="billing_address">BillingAddressTX</requiredEntity> + </entity> +</entities> diff --git a/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartItemData.xml b/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartItemData.xml new file mode 100644 index 0000000000000..3681245311188 --- /dev/null +++ b/app/code/Magento/Quote/Test/Mftf/Data/CustomerCartItemData.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd"> + <entity name="CustomerCartItem" type="CustomerCartItem"> + <var key="quote_id" entityKey="return" entityType="CustomerCart"/> + <var key="sku" entityKey="sku" entityType="product"/> + <data key="qty">1</data> + </entity> +</entities> diff --git a/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartItemMeta.xml b/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartItemMeta.xml new file mode 100644 index 0000000000000..f5555394f8d4d --- /dev/null +++ b/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartItemMeta.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataOperation.xsd"> + + <operation name="CreateCustomerCartItem" dataType="CustomerCartItem" type="create" auth="adminOauth" url="/V1/carts/mine/items" method="POST"> + <contentType>application/json</contentType> + <object key="cartItem" dataType="CustomerCartItem"> + <field key="quote_id" type="string">string</field> + <field key="sku" type="string">string</field> + <field key="qty">integer</field> + </object> + </operation> +</operations> diff --git a/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartMeta.xml b/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartMeta.xml new file mode 100644 index 0000000000000..f233954f2cdcf --- /dev/null +++ b/app/code/Magento/Quote/Test/Mftf/Metadata/CustomerCartMeta.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataOperation.xsd"> + <operation name="CreateCustomerCart" dataType="CustomerCart" type="create" + auth="adminOauth" url="/V1/carts/mine" method="POST" > + <contentType>application/json</contentType> + <field key="customer_id">string</field> + </operation> + + <operation name="AddAddressInfoToCustomerCart" dataType="CustomerAddressInformation" type="create" auth="adminOauth" url="/V1/carts/mine/shipping-information" method="POST"> + <contentType>application/json</contentType> + <field key="cart_id">string</field> + <object key="addressInformation" dataType="CustomerAddressInformation"> + <object key="shipping_address" dataType="shipping_address"> + <field key="city">string</field> + <field key="region">string</field> + <field key="region_code">string</field> + <field key="region_id">integer</field> + <field key="country_id">string</field> + <array key="street"> + <value>string</value> + </array> + <field key="postcode">string</field> + <field key="firstname">string</field> + <field key="lastname">string</field> + <field key="email">string</field> + <field key="telephone">string</field> + </object> + <object key="billing_address" dataType="billing_address"> + <field key="city">string</field> + <field key="region">string</field> + <field key="region_code">string</field> + <field key="region_id">integer</field> + <field key="country_id">string</field> + <array key="street"> + <value>string</value> + </array> + <field key="postcode">string</field> + <field key="firstname">string</field> + <field key="lastname">string</field> + <field key="email">string</field> + <field key="telephone">string</field> + </object> + <field key="shipping_method_code">string</field> + <field key="shipping_carrier_code">string</field> + </object> + </operation> + + <operation name="SendCustomerPaymentInformation" dataType="CustomerPaymentInformation" type="update" auth="adminOauth" url="/V1/carts/mine/payment-information" method="POST"> + <contentType>application/json</contentType> + <field key="cart_id">string</field> + <object key="paymentMethod" dataType="payment_method"> + <field key="method">string</field> + </object> + </operation> +</operations> diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index a8fd794c08757..d4f6778a2ccb8 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -352,10 +352,40 @@ public function testRequestShippingRates() $currentCurrencyCode = 'UAH'; + $this->quote->expects($this->any()) + ->method('getStoreId') + ->willReturn($storeId); + + $this->storeManager->expects($this->at(0)) + ->method('getStore') + ->with($storeId) + ->willReturn($this->store); + $this->store->expects($this->any()) + ->method('getWebsiteId') + ->willReturn($webSiteId); + + $this->scopeConfig->expects($this->exactly(1)) + ->method('getValue') + ->with( + 'tax/calculation/price_includes_tax', + ScopeInterface::SCOPE_STORE, + $storeId + ) + ->willReturn(1); + /** @var RateRequest */ $request = $this->getMockBuilder(RateRequest::class) ->disableOriginalConstructor() - ->setMethods(['setStoreId', 'setWebsiteId', 'setBaseCurrency', 'setPackageCurrency']) + ->setMethods( + [ + 'setStoreId', + 'setWebsiteId', + 'setBaseCurrency', + 'setPackageCurrency', + 'getBaseSubtotalTotalInclTax', + 'getBaseSubtotal' + ] + ) ->getMock(); /** @var Collection */ @@ -434,13 +464,6 @@ public function testRequestShippingRates() $this->storeManager->method('getStore') ->willReturn($this->store); - $this->storeManager->expects($this->once()) - ->method('getWebsite') - ->willReturn($this->website); - - $this->store->method('getId') - ->willReturn($storeId); - $this->store->method('getBaseCurrency') ->willReturn($baseCurrency); @@ -452,10 +475,6 @@ public function testRequestShippingRates() ->method('getCurrentCurrencyCode') ->willReturn($currentCurrencyCode); - $this->website->expects($this->once()) - ->method('getId') - ->willReturn($webSiteId); - $this->addressRateFactory->expects($this->once()) ->method('create') ->willReturn($rate); diff --git a/app/code/Magento/Sales/view/frontend/email/order_new_guest.html b/app/code/Magento/Sales/view/frontend/email/order_new_guest.html index dc3a8e9f69aca..0529c66a04d8c 100644 --- a/app/code/Magento/Sales/view/frontend/email/order_new_guest.html +++ b/app/code/Magento/Sales/view/frontend/email/order_new_guest.html @@ -8,7 +8,7 @@ <!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order_data.email_customer_note|escape|nl2br":"Email Order Note", -"var order.billing_address.name":"Guest Customer Name", +"var order_data.customer_name":"Guest Customer Name", "var created_at_formatted":"Order Created At (datetime)", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid", @@ -29,7 +29,7 @@ <table> <tr class="email-intro"> <td> - <p class="greeting">{{trans "%name," name=$order.billing_address.name}}</p> + <p class="greeting">{{trans "%name," name=$order_data.customer_name}}</p> <p> {{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}} {{trans "Once your package ships we will send an email with a link to track your order."}} diff --git a/app/code/Magento/Security/Model/Plugin/Auth.php b/app/code/Magento/Security/Model/Plugin/Auth.php index 833b4e4c1b774..b388ef6115867 100644 --- a/app/code/Magento/Security/Model/Plugin/Auth.php +++ b/app/code/Magento/Security/Model/Plugin/Auth.php @@ -35,6 +35,8 @@ public function __construct( } /** + * Add warning message if other sessions terminated + * * @param \Magento\Backend\Model\Auth $authModel * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -43,11 +45,13 @@ public function afterLogin(\Magento\Backend\Model\Auth $authModel) { $this->sessionsManager->processLogin(); if ($this->sessionsManager->getCurrentSession()->isOtherSessionsTerminated()) { - $this->messageManager->addWarning(__('All other open sessions for this account were terminated.')); + $this->messageManager->addWarningMessage(__('All other open sessions for this account were terminated.')); } } /** + * Handle logout process + * * @param \Magento\Backend\Model\Auth $authModel * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) diff --git a/app/code/Magento/Security/Test/Unit/Model/Plugin/AuthTest.php b/app/code/Magento/Security/Test/Unit/Model/Plugin/AuthTest.php index c431f1ecda332..dd86b3b574ead 100644 --- a/app/code/Magento/Security/Test/Unit/Model/Plugin/AuthTest.php +++ b/app/code/Magento/Security/Test/Unit/Model/Plugin/AuthTest.php @@ -64,7 +64,7 @@ protected function setUp(): void $this->messageManager = $this->getMockForAbstractClass( ManagerInterface::class, - ['addWarning'], + ['addWarningMessage'], '', false ); @@ -100,7 +100,7 @@ public function testAfterLogin() ->method('isOtherSessionsTerminated') ->willReturn(true); $this->messageManager->expects($this->once()) - ->method('addWarning') + ->method('addWarningMessage') ->with($warningMessage); $this->model->afterLogin($this->authMock); diff --git a/app/code/Magento/Store/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml b/app/code/Magento/Store/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml new file mode 100644 index 0000000000000..4a403364a91e3 --- /dev/null +++ b/app/code/Magento/Store/Test/Mftf/ActionGroup/StorefrontSwitchStoreActionGroup.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="StorefrontSwitchStoreActionGroup"> + <annotations> + <description>Switch the Storefront to the provided Store.</description> + </annotations> + <arguments> + <argument name="storeName" type="string"/> + </arguments> + <click selector="{{StorefrontFooterSection.switchStoreButton}}" stepKey="clickOnSwitchStoreButton"/> + <click selector="{{StorefrontFooterSection.storeLink(storeName)}}" stepKey="selectStoreToSwitchOn"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php index fc13372520945..9ba1083adab74 100644 --- a/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php +++ b/app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php @@ -5,11 +5,17 @@ */ namespace Magento\Swatches\Block\LayeredNavigation; -use Magento\Eav\Model\Entity\Attribute; +use Magento\Catalog\Model\Layer\Filter\AbstractFilter; +use Magento\Catalog\Model\Layer\Filter\Item as FilterItem; use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory; -use Magento\Framework\View\Element\Template; +use Magento\Eav\Model\Entity\Attribute; use Magento\Eav\Model\Entity\Attribute\Option; -use Magento\Catalog\Model\Layer\Filter\Item as FilterItem; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\View\Element\Template; +use Magento\Framework\View\Element\Template\Context; +use Magento\Swatches\Helper\Data; +use Magento\Swatches\Helper\Media; +use Magento\Theme\Block\Html\Pager; /** * Class RenderLayered Render Swatches at Layered Navigation @@ -37,7 +43,7 @@ class RenderLayered extends Template protected $eavAttribute; /** - * @var \Magento\Catalog\Model\Layer\Filter\AbstractFilter + * @var AbstractFilter */ protected $filter; @@ -47,41 +53,52 @@ class RenderLayered extends Template protected $layerAttribute; /** - * @var \Magento\Swatches\Helper\Data + * @var Data */ protected $swatchHelper; /** - * @var \Magento\Swatches\Helper\Media + * @var Media */ protected $mediaHelper; /** - * @param Template\Context $context + * @var Pager + */ + private $htmlPagerBlock; + + /** + * @param Context $context * @param Attribute $eavAttribute * @param AttributeFactory $layerAttribute - * @param \Magento\Swatches\Helper\Data $swatchHelper - * @param \Magento\Swatches\Helper\Media $mediaHelper + * @param Data $swatchHelper + * @param Media $mediaHelper * @param array $data + * @param Pager|null $htmlPagerBlock */ public function __construct( - \Magento\Framework\View\Element\Template\Context $context, + Context $context, Attribute $eavAttribute, AttributeFactory $layerAttribute, - \Magento\Swatches\Helper\Data $swatchHelper, - \Magento\Swatches\Helper\Media $mediaHelper, - array $data = [] + Data $swatchHelper, + Media $mediaHelper, + array $data = [], + ?Pager $htmlPagerBlock = null ) { $this->eavAttribute = $eavAttribute; $this->layerAttribute = $layerAttribute; $this->swatchHelper = $swatchHelper; $this->mediaHelper = $mediaHelper; + $this->htmlPagerBlock = $htmlPagerBlock ?? ObjectManager::getInstance()->get(Pager::class); parent::__construct($context, $data); } /** + * Set filter and attribute objects + * * @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter + * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ @@ -94,6 +111,8 @@ public function setSwatchFilter(\Magento\Catalog\Model\Layer\Filter\AbstractFilt } /** + * Get attribute swatch data + * * @return array */ public function getSwatchData() @@ -114,30 +133,46 @@ public function getSwatchData() $attributeOptionIds = array_keys($attributeOptions); $swatches = $this->swatchHelper->getSwatchesByOptionsId($attributeOptionIds); - $data = [ + return [ 'attribute_id' => $this->eavAttribute->getId(), 'attribute_code' => $this->eavAttribute->getAttributeCode(), 'attribute_label' => $this->eavAttribute->getStoreLabel(), 'options' => $attributeOptions, 'swatches' => $swatches, ]; - - return $data; } /** + * Build filter option url + * * @param string $attributeCode * @param int $optionId + * * @return string */ public function buildUrl($attributeCode, $optionId) { - $query = [$attributeCode => $optionId]; - return $this->_urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]); + $query = [ + $attributeCode => $optionId, + // exclude current page from urls + $this->htmlPagerBlock->getPageVarName() => null + ]; + + return $this->_urlBuilder->getUrl( + '*/*/*', + [ + '_current' => true, + '_use_rewrite' => true, + '_query' => $query + ] + ); } /** + * Get view data for option with no results + * * @param Option $swatchOption + * * @return array */ protected function getUnusedOption(Option $swatchOption) @@ -150,8 +185,11 @@ protected function getUnusedOption(Option $swatchOption) } /** + * Get option data if visible + * * @param FilterItem[] $filterItems * @param Option $swatchOption + * * @return array */ protected function getFilterOption(array $filterItems, Option $swatchOption) @@ -166,8 +204,11 @@ protected function getFilterOption(array $filterItems, Option $swatchOption) } /** + * Get view data for option + * * @param FilterItem $filterItem * @param Option $swatchOption + * * @return array */ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOption) @@ -187,15 +228,20 @@ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOptio } /** + * Check if option should be visible + * * @param FilterItem $filterItem + * * @return bool */ protected function isOptionVisible(FilterItem $filterItem) { - return $this->isOptionDisabled($filterItem) && $this->isShowEmptyResults() ? false : true; + return !($this->isOptionDisabled($filterItem) && $this->isShowEmptyResults()); } /** + * Check if attribute values should be visible with no results + * * @return bool */ protected function isShowEmptyResults() @@ -204,7 +250,10 @@ protected function isShowEmptyResults() } /** + * Check if option should be disabled + * * @param FilterItem $filterItem + * * @return bool */ protected function isOptionDisabled(FilterItem $filterItem) @@ -213,8 +262,11 @@ protected function isOptionDisabled(FilterItem $filterItem) } /** + * Retrieve filter item by id + * * @param FilterItem[] $filterItems * @param integer $id + * * @return bool|FilterItem */ protected function getFilterItemById(array $filterItems, $id) @@ -228,14 +280,15 @@ protected function getFilterItemById(array $filterItems, $id) } /** + * Get swatch image path + * * @param string $type * @param string $filename + * * @return string */ public function getSwatchPath($type, $filename) { - $imagePath = $this->mediaHelper->getSwatchAttributeImage($type, $filename); - - return $imagePath; + return $this->mediaHelper->getSwatchAttributeImage($type, $filename); } } diff --git a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml index 97a391137d8e3..5f3ec07bd4983 100644 --- a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml +++ b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductActionGroup.xml @@ -19,6 +19,7 @@ <argument name="option2" defaultValue="textSwatchOption2" type="string"/> <argument name="option3" defaultValue="textSwatchOption3" type="string"/> <argument name="usedInProductListing" defaultValue="No" type="string"/> + <argument name="usedInLayeredNavigation" defaultValue="No" type="string"/> </arguments> <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> @@ -41,6 +42,7 @@ <click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/> <waitForElementVisible selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" stepKey="waitForTabSwitch"/> <selectOption selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" userInput="{{usedInProductListing}}" stepKey="useInProductListing"/> + <selectOption selector="{{AttributePropertiesSection.useInLayeredNavigation}}" userInput="{{usedInLayeredNavigation}}" stepKey="useInLayeredNavigation"/> <click selector="{{AttributePropertiesSection.SaveAndEdit}}" stepKey="clickSave"/> </actionGroup> </actionGroups> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml new file mode 100644 index 0000000000000..c6266e034bffc --- /dev/null +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontRedirectToFirstPageOnFilteringBySwatchTest.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> + <test name="StorefrontRedirectToFirstPageOnFilteringBySwatchTest"> + <annotations> + <features value="Swatches"/> + <stories value="Filter by swatch attribute on plp layered navigation"/> + <title value="Customers are redirected to first plp page after filtering by swatch"/> + <description value="Customers are redirected to first plp page after filtering by swatch"/> + <severity value="MINOR"/> + <group value="Swatches"/> + </annotations> + + <before> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createSimpleProduct1"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="createSimpleProduct2"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="createSimpleProduct3"> + <requiredEntity createDataKey="createCategory"/> + </createData> + + <magentoCLI command="config:set catalog/frontend/grid_per_page 1" stepKey="setOneProductPerPage"/> + <magentoCLI command="config:set catalog/frontend/grid_per_page_values 1" stepKey="setGridPerPage"/> + + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <actionGroup ref="AddTextSwatchToProductActionGroup" stepKey="addSwatchAttribute"> + <argument name="usedInLayeredNavigation" value="1"/> + </actionGroup> + </before> + + <after> + <actionGroup ref="DeleteProductAttributeActionGroup" stepKey="deleteSwatchAttribute"> + <argument name="ProductAttribute" value="textSwatchAttribute"/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + + <magentoCLI command="config:set catalog/frontend/grid_per_page 12" stepKey="setDefaultProductsPerPage"/> + <magentoCLI command="config:set catalog/frontend/grid_per_page_values 12,24,36" stepKey="setDefaultGridPerPage"/> + <magentoCLI command="cache:clean config full_page" stepKey="cleanInvalidatedCaches"/> + + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct1"/> + <deleteData createDataKey="createSimpleProduct2" stepKey="deleteSimpleProduct2"/> + <deleteData createDataKey="createSimpleProduct3" stepKey="deleteSimpleProduct3"/> + </after> + + <amOnPage url="{{AdminProductAttributeSetEditPage.url}}/{{AddToDefaultSet.attributeSetId}}/" stepKey="onAttributeSetEdit"/> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup"> + <argument name="group" value="Product Details"/> + <argument name="attribute" value="{{textSwatchAttribute.attribute_code}}"/> + </actionGroup> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="SaveAttributeSet"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductIndexPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFiltersOnProductIndexPage"/> + + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct1EditPage"> + <argument name="product" value="$$createSimpleProduct1$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption1" stepKey="selectProduct1AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct1"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage2"/> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct2EditPage"> + <argument name="product" value="$$createSimpleProduct2$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption1" stepKey="selectProduct2AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct2"/> + + <actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductsGridPage3"/> + <actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="goToProduct3EditPage"> + <argument name="product" value="$$createSimpleProduct3$$"/> + </actionGroup> + <selectOption selector="{{AdminProductAttributesSection.attributeDropdownByCode(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption2" stepKey="selectProduct3AttributeOption"/> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct3"/> + + <magentoCron groups="index" stepKey="runCronIndexer"/> + + <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage"> + <argument name="category" value="$$createCategory$$"/> + </actionGroup> + <actionGroup ref="StorefrontNavigateCategoryNextPageActionGroup" stepKey="navigateToCategoryNextPage"/> + + <click selector="{{StorefrontCategorySidebarSection.filterOptionTitle(textSwatchAttribute.default_label)}}" stepKey="expandAttribute"/> + <click selector="{{StorefrontCategorySidebarSection.attributeNthOption(textSwatchAttribute.attribute_code, '1')}}" stepKey="filterBySwatch1"/> + <waitForPageLoad stepKey="waitForPageToLoad2"/> + + <actionGroup ref="AssertStorefrontCategoryCurrentPageIsNthActionGroup" stepKey="assertCurrentPageIsFirst"> + <argument name="expectedPage" value="1"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php b/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php index 4056bf27f571e..06960c409b476 100644 --- a/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Block/LayeredNavigation/RenderLayeredTest.php @@ -18,6 +18,7 @@ use Magento\Swatches\Block\LayeredNavigation\RenderLayered; use Magento\Swatches\Helper\Data; use Magento\Swatches\Helper\Media; +use Magento\Theme\Block\Html\Pager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -28,35 +29,60 @@ */ class RenderLayeredTest extends TestCase { - /** @var MockObject */ - protected $contextMock; - - /** @var MockObject */ - protected $requestMock; - - /** @var MockObject */ - protected $urlBuilder; - - /** @var MockObject */ - protected $eavAttributeMock; - - /** @var MockObject */ - protected $layerAttributeFactoryMock; - - /** @var MockObject */ - protected $layerAttributeMock; - - /** @var MockObject */ - protected $swatchHelperMock; - - /** @var MockObject */ - protected $mediaHelperMock; - - /** @var MockObject */ - protected $filterMock; - - /** @var MockObject */ - protected $block; + /** + * @var RenderLayered|MockObject + */ + private $block; + + /** + * @var Context|MockObject + */ + private $contextMock; + + /** + * @var RequestInterface|MockObject + */ + private $requestMock; + + /** + * @var Url|MockObject + */ + private $urlBuilder; + + /** + * @var Attribute|MockObject + */ + private $eavAttributeMock; + + /** + * @var AttributeFactory|MockObject + */ + private $layerAttributeFactoryMock; + + /** + * @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute|MockObject + */ + private $layerAttributeMock; + + /** + * @var Data|MockObject + */ + private $swatchHelperMock; + + /** + * @var Media|MockObject + */ + private $mediaHelperMock; + + /** + * @var AbstractFilter|MockObject + */ + private $filterMock; + + /** + * @var Pager|MockObject + */ + private $htmlBlockPagerMock; protected function setUp(): void { @@ -66,8 +92,8 @@ protected function setUp(): void Url::class, ['getCurrentUrl', 'getRedirectUrl', 'getUrl'] ); - $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); - $this->contextMock->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder); + $this->contextMock->method('getRequest')->willReturn($this->requestMock); + $this->contextMock->method('getUrlBuilder')->willReturn($this->urlBuilder); $this->eavAttributeMock = $this->createMock(Attribute::class); $this->layerAttributeFactoryMock = $this->createPartialMock( AttributeFactory::class, @@ -80,6 +106,7 @@ protected function setUp(): void $this->swatchHelperMock = $this->createMock(Data::class); $this->mediaHelperMock = $this->createMock(Media::class); $this->filterMock = $this->createMock(AbstractFilter::class); + $this->htmlBlockPagerMock = $this->createMock(Pager::class); $this->block = $this->getMockBuilder(RenderLayered::class) ->setMethods(['filter', 'eavAttribute']) @@ -91,6 +118,7 @@ protected function setUp(): void $this->swatchHelperMock, $this->mediaHelperMock, [], + $this->htmlBlockPagerMock ] ) ->getMock(); @@ -114,7 +142,7 @@ public function testGetSwatchData() $item3 = $this->createMock(Item::class); $item4 = $this->createMock(Item::class); - $item1->expects($this->any())->method('__call')->withConsecutive( + $item1->method('__call')->withConsecutive( ['getValue'], ['getCount'], ['getValue'], @@ -128,9 +156,9 @@ public function testGetSwatchData() 'Yellow' ); - $item2->expects($this->any())->method('__call')->with('getValue')->willReturn('blue'); + $item2->method('__call')->with('getValue')->willReturn('blue'); - $item3->expects($this->any())->method('__call')->withConsecutive( + $item3->method('__call')->withConsecutive( ['getValue'], ['getCount'] )->willReturnOnConsecutiveCalls( @@ -138,7 +166,7 @@ public function testGetSwatchData() 0 ); - $item4->expects($this->any())->method('__call')->withConsecutive( + $item4->method('__call')->withConsecutive( ['getValue'], ['getCount'], ['getValue'], @@ -162,22 +190,22 @@ public function testGetSwatchData() $this->block->method('filter')->willReturn($this->filterMock); $option1 = $this->createMock(Option::class); - $option1->expects($this->any())->method('getValue')->willReturn('yellow'); + $option1->method('getValue')->willReturn('yellow'); $option2 = $this->createMock(Option::class); - $option2->expects($this->any())->method('getValue')->willReturn(null); + $option2->method('getValue')->willReturn(null); $option3 = $this->createMock(Option::class); - $option3->expects($this->any())->method('getValue')->willReturn('red'); + $option3->method('getValue')->willReturn('red'); $option4 = $this->createMock(Option::class); - $option4->expects($this->any())->method('getValue')->willReturn('green'); + $option4->method('getValue')->willReturn('green'); $eavAttribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class); $eavAttribute->expects($this->once()) ->method('getOptions') ->willReturn([$option1, $option2, $option3, $option4]); - $eavAttribute->expects($this->any())->method('getIsFilterable')->willReturn(0); + $eavAttribute->method('getIsFilterable')->willReturn(0); $this->filterMock->expects($this->once())->method('getAttributeModel')->willReturn($eavAttribute); $this->block->method('eavAttribute')->willReturn($eavAttribute); @@ -200,7 +228,7 @@ public function testGetSwatchDataException() { $this->block->method('filter')->willReturn($this->filterMock); $this->block->setSwatchFilter($this->filterMock); - $this->expectException('\RuntimeException'); + $this->expectException(\RuntimeException::class); $this->block->getSwatchData(); } diff --git a/app/code/Magento/Theme/Block/Html/Pager.php b/app/code/Magento/Theme/Block/Html/Pager.php index 5798b94e31a70..764b2e9ca42f0 100644 --- a/app/code/Magento/Theme/Block/Html/Pager.php +++ b/app/code/Magento/Theme/Block/Html/Pager.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Theme\Block\Html; /** @@ -466,7 +467,26 @@ public function getPageUrl($page) */ public function getLimitUrl($limit) { - return $this->getPagerUrl([$this->getLimitVarName() => $limit]); + return $this->getPagerUrl($this->getPageLimitParams($limit)); + } + + /** + * Return page limit params + * + * @param int $limit + * @return array + */ + private function getPageLimitParams(int $limit): array + { + $data = [$this->getLimitVarName() => $limit]; + + $currentPage = $this->getCurrentPage(); + $availableCount = (int) ceil($this->getTotalNum() / $limit); + if ($currentPage !== 1 && $availableCount < $currentPage) { + $data = array_merge($data, [$this->getPageVarName() => $availableCount === 1 ? null : $availableCount]); + } + + return $data; } /** diff --git a/app/code/Magento/Theme/Model/Config/Customization.php b/app/code/Magento/Theme/Model/Config/Customization.php index 6a6872d794b1b..7430730451110 100644 --- a/app/code/Magento/Theme/Model/Config/Customization.php +++ b/app/code/Magento/Theme/Model/Config/Customization.php @@ -5,23 +5,34 @@ */ namespace Magento\Theme\Model\Config; +use Magento\Framework\App\Area; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\View\Design\Theme\ThemeProviderInterface; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Theme\Model\ResourceModel\Theme\Collection; +use Magento\Theme\Model\Theme\StoreThemesResolverInterface; +use Magento\Theme\Model\Theme\StoreUserAgentThemeResolver; + /** * Theme customization config model */ class Customization { /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Framework\View\DesignInterface + * @var DesignInterface */ protected $_design; /** - * @var \Magento\Framework\View\Design\Theme\ThemeProviderInterface + * @var ThemeProviderInterface */ protected $themeProvider; @@ -40,20 +51,28 @@ class Customization * @see self::_prepareThemeCustomizations() */ protected $_unassignedTheme; + /** + * @var StoreUserAgentThemeResolver|mixed|null + */ + private $storeThemesResolver; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\View\DesignInterface $design - * @param \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider + * @param StoreManagerInterface $storeManager + * @param DesignInterface $design + * @param ThemeProviderInterface $themeProvider + * @param StoreThemesResolverInterface|null $storeThemesResolver */ public function __construct( - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\View\DesignInterface $design, - \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider + StoreManagerInterface $storeManager, + DesignInterface $design, + ThemeProviderInterface $themeProvider, + ?StoreThemesResolverInterface $storeThemesResolver = null ) { $this->_storeManager = $storeManager; $this->_design = $design; $this->themeProvider = $themeProvider; + $this->storeThemesResolver = $storeThemesResolver + ?? ObjectManager::getInstance()->get(StoreThemesResolverInterface::class); } /** @@ -93,13 +112,14 @@ public function getStoresByThemes() { $storesByThemes = []; $stores = $this->_storeManager->getStores(); - /** @var $store \Magento\Store\Model\Store */ + /** @var $store Store */ foreach ($stores as $store) { - $themeId = $this->_getConfigurationThemeId($store); - if (!isset($storesByThemes[$themeId])) { - $storesByThemes[$themeId] = []; + foreach ($this->storeThemesResolver->getThemes($store) as $themeId) { + if (!isset($storesByThemes[$themeId])) { + $storesByThemes[$themeId] = []; + } + $storesByThemes[$themeId][] = $store; } - $storesByThemes[$themeId][] = $store; } return $storesByThemes; } @@ -107,8 +127,8 @@ public function getStoresByThemes() /** * Check if current theme has assigned to any store * - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @param null|\Magento\Store\Model\Store $store + * @param ThemeInterface $theme + * @param null|Store $store * @return bool */ public function isThemeAssignedToStore($theme, $store = null) @@ -133,8 +153,8 @@ public function hasThemeAssigned() /** * Is theme assigned to specific store * - * @param \Magento\Framework\View\Design\ThemeInterface $theme - * @param \Magento\Store\Model\Store $store + * @param ThemeInterface $theme + * @param Store $store * @return bool */ protected function _isThemeAssignedToSpecificStore($theme, $store) @@ -145,21 +165,21 @@ protected function _isThemeAssignedToSpecificStore($theme, $store) /** * Get configuration theme id * - * @param \Magento\Store\Model\Store $store + * @param Store $store * @return int */ protected function _getConfigurationThemeId($store) { return $this->_design->getConfigurationDesignTheme( - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, ['store' => $store] ); } /** * Fetch theme customization and sort them out to arrays: - * self::_assignedTheme and self::_unassignedTheme. * + * Set self::_assignedTheme and self::_unassignedTheme. * NOTE: To get into "assigned" list theme customization not necessary should be assigned to store-view directly. * It can be set to website or as default theme and be used by store-view via config fallback mechanism. * @@ -167,15 +187,15 @@ protected function _getConfigurationThemeId($store) */ protected function _prepareThemeCustomizations() { - /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */ - $themeCollection = $this->themeProvider->getThemeCustomizations(\Magento\Framework\App\Area::AREA_FRONTEND); + /** @var Collection $themeCollection */ + $themeCollection = $this->themeProvider->getThemeCustomizations(Area::AREA_FRONTEND); $assignedThemes = $this->getStoresByThemes(); $this->_assignedTheme = []; $this->_unassignedTheme = []; - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + /** @var $theme ThemeInterface */ foreach ($themeCollection as $theme) { if (isset($assignedThemes[$theme->getId()])) { $theme->setAssignedStores($assignedThemes[$theme->getId()]); diff --git a/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php b/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php new file mode 100644 index 0000000000000..26bd5604294d1 --- /dev/null +++ b/app/code/Magento/Theme/Model/Theme/StoreDefaultThemeResolver.php @@ -0,0 +1,90 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Model\Theme; + +use Magento\Framework\App\Area; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; + +/** + * Store default theme resolver. + * + * Use system config fallback mechanism if no theme is directly assigned to the store-view. + */ +class StoreDefaultThemeResolver implements StoreThemesResolverInterface +{ + /** + * @var CollectionFactory + */ + private $themeCollectionFactory; + /** + * @var DesignInterface + */ + private $design; + /** + * @var ThemeInterface[] + */ + private $registeredThemes; + + /** + * @param CollectionFactory $themeCollectionFactory + * @param DesignInterface $design + */ + public function __construct( + CollectionFactory $themeCollectionFactory, + DesignInterface $design + ) { + $this->design = $design; + $this->themeCollectionFactory = $themeCollectionFactory; + } + + /** + * @inheritDoc + */ + public function getThemes(StoreInterface $store): array + { + $theme = $this->design->getConfigurationDesignTheme( + Area::AREA_FRONTEND, + ['store' => $store] + ); + $themes = []; + if ($theme) { + if (!is_numeric($theme)) { + $registeredThemes = $this->getRegisteredThemes(); + if (isset($registeredThemes[$theme])) { + $themes[] = $registeredThemes[$theme]->getId(); + } + } else { + $themes[] = $theme; + } + } + return $themes; + } + + /** + * Get system registered themes. + * + * @return ThemeInterface[] + */ + private function getRegisteredThemes(): array + { + if ($this->registeredThemes === null) { + $this->registeredThemes = []; + /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $collection */ + $collection = $this->themeCollectionFactory->create(); + $themes = $collection->loadRegisteredThemes(); + /** @var ThemeInterface $theme */ + foreach ($themes as $theme) { + $this->registeredThemes[$theme->getCode()] = $theme; + } + } + return $this->registeredThemes; + } +} diff --git a/app/code/Magento/Theme/Model/Theme/StoreThemesResolver.php b/app/code/Magento/Theme/Model/Theme/StoreThemesResolver.php new file mode 100644 index 0000000000000..5be86c08f7c51 --- /dev/null +++ b/app/code/Magento/Theme/Model/Theme/StoreThemesResolver.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Model\Theme; + +use InvalidArgumentException; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; + +/** + * Store associated themes resolver. + */ +class StoreThemesResolver implements StoreThemesResolverInterface +{ + /** + * @var StoreThemesResolverInterface[] + */ + private $resolvers; + + /** + * @param StoreThemesResolverInterface[] $resolvers + */ + public function __construct( + array $resolvers + ) { + foreach ($resolvers as $resolver) { + if (!$resolver instanceof StoreThemesResolverInterface) { + throw new InvalidArgumentException( + sprintf( + 'Instance of %s is expected, got %s instead.', + StoreThemesResolverInterface::class, + get_class($resolver) + ) + ); + } + } + $this->resolvers = $resolvers; + } + + /** + * @inheritDoc + */ + public function getThemes(StoreInterface $store): array + { + $themes = []; + foreach ($this->resolvers as $resolver) { + foreach ($resolver->getThemes($store) as $theme) { + $themes[] = $theme; + } + } + return array_values(array_unique($themes)); + } +} diff --git a/app/code/Magento/Theme/Model/Theme/StoreThemesResolverInterface.php b/app/code/Magento/Theme/Model/Theme/StoreThemesResolverInterface.php new file mode 100644 index 0000000000000..bb2cd73300c02 --- /dev/null +++ b/app/code/Magento/Theme/Model/Theme/StoreThemesResolverInterface.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Model\Theme; + +use Magento\Store\Api\Data\StoreInterface; + +/** + * Store associated themes resolver. + */ +interface StoreThemesResolverInterface +{ + /** + * Get themes associated with a store view + * + * @param StoreInterface $store + * @return int[] + */ + public function getThemes(StoreInterface $store): array; +} diff --git a/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php b/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php new file mode 100644 index 0000000000000..fb5d68e37c99b --- /dev/null +++ b/app/code/Magento/Theme/Model/Theme/StoreUserAgentThemeResolver.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Model\Theme; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; + +/** + * Store associated themes in user-agent rules resolver, + */ +class StoreUserAgentThemeResolver implements StoreThemesResolverInterface +{ + private const XML_PATH_THEME_USER_AGENT = 'design/theme/ua_regexp'; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** + * @var Json + */ + private $serializer; + + /** + * @param ScopeConfigInterface $scopeConfig + * @param Json $serializer + */ + public function __construct( + ScopeConfigInterface $scopeConfig, + Json $serializer + ) { + $this->scopeConfig = $scopeConfig; + $this->serializer = $serializer; + } + + /** + * @inheritDoc + */ + public function getThemes(StoreInterface $store): array + { + $config = $this->scopeConfig->getValue( + self::XML_PATH_THEME_USER_AGENT, + ScopeInterface::SCOPE_STORE, + $store + ); + $rules = $config ? $this->serializer->unserialize($config) : []; + $themes = []; + if ($rules) { + $themes = array_values(array_unique(array_column($rules, 'value'))); + } + return $themes; + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php index ac16c56b17f1b..fd0ef1db0219a 100644 --- a/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php +++ b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php @@ -91,6 +91,60 @@ public function testGetPages(): void $this->assertEquals($expectedPages, $this->pager->getPages()); } + /** + * Test get limit url. + * + * @dataProvider limitUrlDataProvider + * + * @param int $page + * @param int $size + * @param int $limit + * @param array $expectedParams + * @return void + */ + public function testGetLimitUrl(int $page, int $size, int $limit, array $expectedParams): void + { + $expectedArray = [ + '_current' => true, + '_escape' => true, + '_use_rewrite' => true, + '_fragment' => null, + '_query' => $expectedParams, + ]; + + $collectionMock = $this->createMock(Collection::class); + $collectionMock->expects($this->once()) + ->method('getCurPage') + ->willReturn($page); + $collectionMock->expects($this->once()) + ->method('getSize') + ->willReturn($size); + $this->setCollectionProperty($collectionMock); + + $this->urlBuilderMock->expects($this->once()) + ->method('getUrl') + ->with('*/*/*', $expectedArray); + + $this->pager->getLimitUrl($limit); + } + + /** + * DataProvider for testGetLimitUrl + * + * @return array + */ + public function limitUrlDataProvider(): array + { + return [ + [2, 21, 10, ['limit' => 10]], + [3, 21, 10, ['limit' => 10]], + [2, 21, 20, ['limit' => 20]], + [3, 21, 50, ['limit' => 50, 'p' => null]], + [2, 11, 20, ['limit' => 20, 'p' => null]], + [4, 40, 20, ['limit' => 20, 'p' => 2]], + ]; + } + /** * Set Collection * diff --git a/app/code/Magento/Theme/Test/Unit/Model/Config/CustomizationTest.php b/app/code/Magento/Theme/Test/Unit/Model/Config/CustomizationTest.php index 82678d4b4277d..438853b9935e6 100644 --- a/app/code/Magento/Theme/Test/Unit/Model/Config/CustomizationTest.php +++ b/app/code/Magento/Theme/Test/Unit/Model/Config/CustomizationTest.php @@ -13,9 +13,10 @@ use Magento\Framework\App\Area; use Magento\Framework\DataObject; use Magento\Framework\View\DesignInterface; +use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Theme\Model\Config\Customization; -use Magento\Theme\Model\ResourceModel\Theme\Collection; +use Magento\Theme\Model\Theme\StoreThemesResolverInterface; use Magento\Theme\Model\Theme\ThemeProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -32,47 +33,37 @@ class CustomizationTest extends TestCase */ protected $designPackage; - /** - * @var Collection - */ - protected $themeCollection; - /** * @var Customization */ protected $model; /** - * @var ThemeProvider|\PHPUnit\Framework\MockObject_MockBuilder + * @var ThemeProvider|MockObject */ protected $themeProviderMock; + /** + * @var StoreThemesResolverInterface|MockObject + */ + private $storeThemesResolver; protected function setUp(): void { - $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class) - ->getMock(); - $this->designPackage = $this->getMockBuilder(DesignInterface::class) - ->getMock(); - $this->themeCollection = $this->getMockBuilder(Collection::class) - ->disableOriginalConstructor() - ->getMock(); - - $collectionFactory = $this->getMockBuilder(\Magento\Theme\Model\ResourceModel\Theme\CollectionFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $collectionFactory->expects($this->any())->method('create')->willReturn($this->themeCollection); + $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)->getMock(); + $this->designPackage = $this->getMockBuilder(DesignInterface::class)->getMock(); $this->themeProviderMock = $this->getMockBuilder(ThemeProvider::class) ->disableOriginalConstructor() ->setMethods(['getThemeCustomizations', 'getThemeByFullPath']) ->getMock(); + $this->storeThemesResolver = $this->createMock(StoreThemesResolverInterface::class); + $this->model = new Customization( $this->storeManager, $this->designPackage, - $this->themeProviderMock + $this->themeProviderMock, + $this->storeThemesResolver ); } @@ -84,13 +75,15 @@ protected function setUp(): void */ public function testGetAssignedThemeCustomizations() { - $this->designPackage->expects($this->once()) - ->method('getConfigurationDesignTheme') - ->willReturn($this->getAssignedTheme()->getId()); - + $store = $this->getStore(); $this->storeManager->expects($this->once()) ->method('getStores') - ->willReturn([$this->getStore()]); + ->willReturn([$store]); + + $this->storeThemesResolver->expects($this->once()) + ->method('getThemes') + ->with($store) + ->willReturn([$this->getAssignedTheme()->getId()]); $this->themeProviderMock->expects($this->once()) ->method('getThemeCustomizations') @@ -108,13 +101,15 @@ public function testGetAssignedThemeCustomizations() */ public function testGetUnassignedThemeCustomizations() { + $store = $this->getStore(); $this->storeManager->expects($this->once()) ->method('getStores') - ->willReturn([$this->getStore()]); + ->willReturn([$store]); - $this->designPackage->expects($this->once()) - ->method('getConfigurationDesignTheme') - ->willReturn($this->getAssignedTheme()->getId()); + $this->storeThemesResolver->expects($this->once()) + ->method('getThemes') + ->with($store) + ->willReturn([$this->getAssignedTheme()->getId()]); $this->themeProviderMock->expects($this->once()) ->method('getThemeCustomizations') @@ -131,13 +126,15 @@ public function testGetUnassignedThemeCustomizations() */ public function testGetStoresByThemes() { + $store = $this->getStore(); $this->storeManager->expects($this->once()) ->method('getStores') - ->willReturn([$this->getStore()]); + ->willReturn([$store]); - $this->designPackage->expects($this->once()) - ->method('getConfigurationDesignTheme') - ->willReturn($this->getAssignedTheme()->getId()); + $this->storeThemesResolver->expects($this->once()) + ->method('getThemes') + ->with($store) + ->willReturn([$this->getAssignedTheme()->getId()]); $stores = $this->model->getStoresByThemes(); $this->assertArrayHasKey($this->getAssignedTheme()->getId(), $stores); @@ -148,15 +145,17 @@ public function testGetStoresByThemes() * @covers \Magento\Theme\Model\Config\Customization::_getConfigurationThemeId * @covers \Magento\Theme\Model\Config\Customization::__construct */ - public function testIsThemeAssignedToDefaultStore() + public function testIsThemeAssignedToAnyStore() { + $store = $this->getStore(); $this->storeManager->expects($this->once()) ->method('getStores') - ->willReturn([$this->getStore()]); + ->willReturn([$store]); - $this->designPackage->expects($this->once()) - ->method('getConfigurationDesignTheme') - ->willReturn($this->getAssignedTheme()->getId()); + $this->storeThemesResolver->expects($this->once()) + ->method('getThemes') + ->with($store) + ->willReturn([$this->getAssignedTheme()->getId()]); $this->themeProviderMock->expects($this->once()) ->method('getThemeCustomizations') @@ -198,10 +197,10 @@ protected function getUnassignedTheme() } /** - * @return DataObject + * @return StoreInterface|MockObject */ protected function getStore() { - return new DataObject(['id' => 55]); + return $this->createConfiguredMock(StoreInterface::class, ['getId' => 55]); } } diff --git a/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreDefaultThemeResolverTest.php b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreDefaultThemeResolverTest.php new file mode 100644 index 0000000000000..939b47a42ce85 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreDefaultThemeResolverTest.php @@ -0,0 +1,115 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Test\Unit\Model\Theme; + +use ArrayIterator; +use Magento\Framework\App\Area; +use Magento\Framework\View\Design\ThemeInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Theme\Model\ResourceModel\Theme\Collection; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; +use Magento\Theme\Model\Theme\StoreDefaultThemeResolver; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * Test store default theme resolver. + */ +class StoreDefaultThemeResolverTest extends TestCase +{ + /** + * @var DesignInterface|MockObject + */ + private $design; + /** + * @var StoreDefaultThemeResolver + */ + private $model; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $themeCollectionFactory = $this->createMock(CollectionFactory::class); + $this->design = $this->createMock(DesignInterface::class); + $this->model = new StoreDefaultThemeResolver( + $themeCollectionFactory, + $this->design + ); + $registeredThemes = []; + $registeredThemes[] = $this->createConfiguredMock( + ThemeInterface::class, + [ + 'getId' => 1, + 'getCode' => 'Magento/luma', + ] + ); + $registeredThemes[] = $this->createConfiguredMock( + ThemeInterface::class, + [ + 'getId' => 2, + 'getCode' => 'Magento/blank', + ] + ); + $collection = $this->createMock(Collection::class); + $collection->method('getIterator') + ->willReturn(new ArrayIterator($registeredThemes)); + $collection->method('loadRegisteredThemes') + ->willReturnSelf(); + $themeCollectionFactory->method('create') + ->willReturn($collection); + } + + /** + * Test that method returns default theme associated to given store. + * + * @param string|null $defaultTheme + * @param array $expected + * @dataProvider getThemesDataProvider + */ + public function testGetThemes(?string $defaultTheme, array $expected): void + { + $store = $this->createMock(StoreInterface::class); + $this->design->expects($this->once()) + ->method('getConfigurationDesignTheme') + ->with( + Area::AREA_FRONTEND, + ['store' => $store] + ) + ->willReturn($defaultTheme); + $this->assertEquals($expected, $this->model->getThemes($store)); + } + + /** + * @return array + */ + public function getThemesDataProvider(): array + { + return [ + [ + null, + [] + ], + [ + '1', + [1] + ], + [ + 'Magento/blank', + [2] + ], + [ + 'Magento/theme', + [] + ] + ]; + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreThemesResolverTest.php b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreThemesResolverTest.php new file mode 100644 index 0000000000000..b80ec4ae83887 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreThemesResolverTest.php @@ -0,0 +1,115 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Test\Unit\Model\Theme; + +use Magento\Store\Api\Data\StoreInterface; +use Magento\Theme\Model\Theme\StoreThemesResolver; +use Magento\Theme\Model\Theme\StoreThemesResolverInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * Test store composite themes resolver model. + */ +class StoreThemesResolverTest extends TestCase +{ + /** + * @var StoreThemesResolverInterface[]|MockObject[] + */ + private $resolvers; + /** + * @var StoreThemesResolver + */ + private $model; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $this->resolvers = []; + $this->resolvers[] = $this->createMock(StoreThemesResolverInterface::class); + $this->resolvers[] = $this->createMock(StoreThemesResolverInterface::class); + $this->resolvers[] = $this->createMock(StoreThemesResolverInterface::class); + $this->model = new StoreThemesResolver($this->resolvers); + } + + /** + * Test that constructor SHOULD throw an exception when resolver is not instance of StoreThemesResolverInterface. + */ + public function testInvalidConstructorArguments(): void + { + $resolver = $this->createMock(StoreInterface::class); + $this->expectExceptionObject( + new \InvalidArgumentException( + sprintf( + 'Instance of %s is expected, got %s instead.', + StoreThemesResolverInterface::class, + get_class($resolver) + ) + ) + ); + $this->model = new StoreThemesResolver( + [ + $resolver + ] + ); + } + + /** + * Test that method returns aggregated themes from resolvers + * + * @param array $themes + * @param array $expected + * @dataProvider getThemesDataProvider + */ + public function testGetThemes(array $themes, array $expected): void + { + $store = $this->createMock(StoreInterface::class); + foreach ($this->resolvers as $key => $resolver) { + $resolver->expects($this->once()) + ->method('getThemes') + ->willReturn($themes[$key]); + } + $this->assertEquals($expected, $this->model->getThemes($store)); + } + + /** + * @return array + */ + public function getThemesDataProvider(): array + { + return [ + [ + [ + [], + [], + [] + ], + [] + ], + [ + [ + ['1'], + [], + ['1'] + ], + ['1'] + ], + [ + [ + ['1'], + ['2'], + ['1'] + ], + ['1', '2'] + ] + ]; + } +} diff --git a/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreUserAgentThemeResolverTest.php b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreUserAgentThemeResolverTest.php new file mode 100644 index 0000000000000..1ef4b17ca6562 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Model/Theme/StoreUserAgentThemeResolverTest.php @@ -0,0 +1,105 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Test\Unit\Model\Theme; + +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Store\Api\Data\StoreInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Theme\Model\Theme\StoreUserAgentThemeResolver; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * Test store associated themes in user-agent rules resolver. + */ +class StoreUserAgentThemeResolverTest extends TestCase +{ + /** + * @var ScopeConfigInterface|MockObject + */ + private $scopeConfig; + /** + * @var Json + */ + private $serializer; + /** + * @var StoreUserAgentThemeResolver + */ + private $model; + + protected function setUp(): void + { + parent::setUp(); + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); + $this->serializer = new Json(); + $this->model = new StoreUserAgentThemeResolver( + $this->scopeConfig, + $this->serializer + ); + } + + /** + * Test that method returns user-agent rules associated themes. + * + * @param array|null $config + * @param array $expected + * @dataProvider getThemesDataProvider + */ + public function testGetThemes(?array $config, array $expected): void + { + $store = $this->createMock(StoreInterface::class); + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with('design/theme/ua_regexp', ScopeInterface::SCOPE_STORE, $store) + ->willReturn($config !== null ? $this->serializer->serialize($config) : $config); + $this->assertEquals($expected, $this->model->getThemes($store)); + } + + /** + * @return array + */ + public function getThemesDataProvider(): array + { + return [ + [ + null, + [] + ], + [ + [], + [] + ], + [ + [ + [ + 'search' => '\/Chrome\/i', + 'regexp' => '\/Chrome\/i', + 'value' => '1', + ], + ], + ['1'] + ], + [ + [ + [ + 'search' => '\/Chrome\/i', + 'regexp' => '\/Chrome\/i', + 'value' => '1', + ], + [ + 'search' => '\/mozila\/i', + 'regexp' => '\/mozila\/i', + 'value' => '2', + ], + ], + ['1', '2'] + ] + ]; + } +} diff --git a/app/code/Magento/Theme/etc/di.xml b/app/code/Magento/Theme/etc/di.xml index 921e6bfc6ecf1..c4da1f860870e 100644 --- a/app/code/Magento/Theme/etc/di.xml +++ b/app/code/Magento/Theme/etc/di.xml @@ -18,6 +18,7 @@ <preference for="Magento\Theme\Api\DesignConfigRepositoryInterface" type="Magento\Theme\Model\DesignConfigRepository"/> <preference for="Magento\Framework\View\Model\PageLayout\Config\BuilderInterface" type="Magento\Theme\Model\PageLayout\Config\Builder"/> <preference for="Magento\Theme\Model\Design\Config\MetadataProviderInterface" type="Magento\Theme\Model\Design\Config\MetadataProvider"/> + <preference for="Magento\Theme\Model\Theme\StoreThemesResolverInterface" type="Magento\Theme\Model\Theme\StoreThemesResolver"/> <type name="Magento\Theme\Model\Config"> <arguments> <argument name="configCache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument> @@ -309,4 +310,12 @@ <argument name="cache" xsi:type="object">configured_design_cache</argument> </arguments> </type> + <type name="Magento\Theme\Model\Theme\StoreThemesResolver"> + <arguments> + <argument name="resolvers" xsi:type="array"> + <item name="storeDefaultTheme" xsi:type="object">Magento\Theme\Model\Theme\StoreDefaultThemeResolver</item> + <item name="storeUserAgentTheme" xsi:type="object">Magento\Theme\Model\Theme\StoreUserAgentThemeResolver</item> + </argument> + </arguments> + </type> </config> diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminTargetPathInUrlRewriteGrigActionGroup.xml b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminTargetPathInUrlRewriteGrigActionGroup.xml new file mode 100644 index 0000000000000..a409860811837 --- /dev/null +++ b/app/code/Magento/UrlRewrite/Test/Mftf/ActionGroup/AssertAdminTargetPathInUrlRewriteGrigActionGroup.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AssertAdminTargetPathInUrlRewriteGrigActionGroup"> + <annotations> + <description>Assert the target path is shown in the URL Rewrite grid.</description> + </annotations> + <arguments> + <argument name="targetPath" type="string"/> + </arguments> + + <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', targetPath)}}" + stepKey="seeValueInGrid"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminCheckUrlRewritesCorrectlyGeneratedForMultipleStoreviewsDuringProductImportTest/AdminCheckUrlRewritesMultipleStoreviewsProductImportTest.xml b/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminCheckUrlRewritesCorrectlyGeneratedForMultipleStoreviewsDuringProductImportTest/AdminCheckUrlRewritesMultipleStoreviewsProductImportTest.xml index 4e46ed8e4fc79..3b140aed5f572 100644 --- a/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminCheckUrlRewritesCorrectlyGeneratedForMultipleStoreviewsDuringProductImportTest/AdminCheckUrlRewritesMultipleStoreviewsProductImportTest.xml +++ b/app/code/Magento/UrlRewrite/Test/Mftf/Test/AdminCheckUrlRewritesCorrectlyGeneratedForMultipleStoreviewsDuringProductImportTest/AdminCheckUrlRewritesMultipleStoreviewsProductImportTest.xml @@ -47,84 +47,103 @@ <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFiltersIfSet"/> <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> </after> + <!--Change category name and URL key for EN Store View--> <actionGroup ref="SwitchCategoryStoreViewActionGroup" stepKey="switchToStoreViewEn"> <argument name="Store" value="customStoreENNotUnique.name"/> <argument name="CatName" value="$$createCategory.name$$"/> </actionGroup> - <uncheckOption selector="{{AdminCategoryBasicFieldSection.categoryNameUseDefault}}" stepKey="uncheckUseDefaultValueENStoreView"/> - <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="category-english" stepKey="changeNameField"/> - <click selector="{{AdminCategorySEOSection.SectionHeader}}" stepKey="clickOnSectionHeader"/> + <actionGroup ref="AdminChangeCategoryNameOnStoreViewLevelActionGroup" stepKey="changeCategoryNameForENStoreView"> + <argument name="categoryName" value="categoryEN"/> + </actionGroup> <actionGroup ref="ChangeSeoUrlKeyForSubCategoryActionGroup" stepKey="changeSeoUrlKeyENStoreView"> <argument name="value" value="category-english"/> </actionGroup> + + <!--Change category name and URL key for NL Store View--> <actionGroup ref="SwitchCategoryStoreViewActionGroup" stepKey="switchToStoreViewNl"> <argument name="Store" value="customStoreNLNotUnique.name"/> <argument name="CatName" value="$$createCategory.name$$"/> </actionGroup> - <uncheckOption selector="{{AdminCategoryBasicFieldSection.categoryNameUseDefault}}" stepKey="uncheckUseDefaultValue1"/> - <fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="category-dutch" stepKey="changeNameFieldNLStoreView"/> - <click selector="{{AdminCategorySEOSection.SectionHeader}}" stepKey="clickOnSectionHeader2"/> + <actionGroup ref="AdminChangeCategoryNameOnStoreViewLevelActionGroup" stepKey="changeCategoryNameForNLStoreView"> + <argument name="categoryName" value="categoryNL"/> + </actionGroup> <actionGroup ref="ChangeSeoUrlKeyForSubCategoryActionGroup" stepKey="changeSeoUrlKeyNLStoreView"> <argument name="value" value="category-dutch"/> </actionGroup> - <amOnPage url="{{AdminImportIndexPage.url}}" stepKey="navigateToSystemImport"/> - <selectOption selector="{{AdminImportMainSection.entityType}}" userInput="Products" stepKey="selectProductsOption"/> - <waitForElementVisible selector="{{AdminImportMainSection.importBehavior}}" stepKey="waitForImportBehaviorElementVisible"/> - <selectOption selector="{{AdminImportMainSection.importBehavior}}" userInput="Add/Update" stepKey="selectAddUpdateOption"/> - <attachFile selector="{{AdminImportMainSection.selectFileToImport}}" userInput="import_updated.csv" stepKey="attachFileForImport"/> - <click selector="{{AdminImportHeaderSection.checkDataButton}}" stepKey="clickCheckDataButton"/> - <see selector="{{AdminImportValidationMessagesSection.notice}}" userInput="Checked rows: 3, checked entities: 1, invalid rows: 0, total errors: 0" stepKey="assertNotice"/> - <see selector="{{AdminImportValidationMessagesSection.success}}" userInput="File is valid! To start import process press "Import" button" stepKey="assertSuccessMessage"/> - <click selector="{{AdminImportMainSection.importButton}}" stepKey="clickImportButton"/> - <see selector="{{AdminImportValidationMessagesSection.success}}" userInput="Import successfully done" stepKey="assertSuccessMessage1"/> - <see selector="{{AdminImportValidationMessagesSection.notice}}" userInput="Created: 1, Updated: 0, Deleted: 0" stepKey="assertNotice1"/> - <actionGroup ref="SearchForProductOnBackendByNameActionGroup" stepKey="searchForProductOnBackend"> - <argument name="productName" value="productformagetwo68980"/> - </actionGroup> - <click selector="{{AdminProductGridSection.productRowBySku('productformagetwo68980')}}" stepKey="clickOnProductRow"/> + + <!-- Import products with add/update behavior --> + <actionGroup ref="AdminImportProductsWithCheckValidationResultActionGroup" stepKey="importProduct"> + <argument name="behavior" value="Add/Update"/> + <argument name="importFile" value="import_updated.csv"/> + <argument name="importNoticeMessage" value="Created: 1, Updated: 0, Deleted: 0"/> + <argument name="validationNoticeMessage" value="Checked rows: 3, checked entities: 1, invalid rows: 0, total errors: 0"/> + </actionGroup> + + <!--Filter Product in product page and get the Product ID --> + <actionGroup ref="FilterAndSelectProductActionGroup" stepKey="filterProduct"> + <argument name="productSku" value="productformagetwo68980"/> + </actionGroup> <grabFromCurrentUrl regex="~/id/(\d+)/~" stepKey="grabProductIdFromUrl"/> - <amOnPage url="{{AdminUrlRewriteIndexPage.url}}" stepKey="goToUrlRewritesIndexPage"/> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="category-english.html" stepKey="inputCategoryUrlForENStoreView"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters"/> - <waitForPageLoad stepKey="waitForPageToLoad"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'category-english.html')}}" stepKey="seeUrlInRequestPathColumn"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', catalog/category/view/id/$$createCategory.id$$)}}" stepKey="seeUrlInTargetPathColumn"/> + <!--Open Marketing - SEO & Search - URL Rewrites--> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingCategoryUrlRewriteForENStoreView"> + <argument name="requestPath" value="category-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeCategoryUrlInRequestPathColumnForENStoreView"> + <argument name="requestPath" value="category-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeCategoryUrlInTargetPathColumnForENStoreView"> + <argument name="targetPath" value="catalog/category/view/id/$$createCategory.id$$"/> + </actionGroup> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters1"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="category-dutch.html" stepKey="inputCategoryUrlForNLStoreView"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters1"/> - <waitForPageLoad stepKey="waitForPageToLoad1"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'category-dutch.html')}}" stepKey="seeUrlInRequestPathColumn1"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', catalog/category/view/id/$$createCategory.id$$)}}" stepKey="seeUrlInTargetPathColumn1"/> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingCategoryUrlRewriteForNLStoreView"> + <argument name="requestPath" value="category-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeCategoryUrlInRequestPathColumnForNLStoreView"> + <argument name="requestPath" value="category-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeCategoryUrlInTargetPathColumnForNLStoreView"> + <argument name="targetPath" value="catalog/category/view/id/$$createCategory.id$$"/> + </actionGroup> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters2"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="productformagetwo68980-english.html" stepKey="inputProductUrlForENStoreView"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters2"/> - <waitForPageLoad stepKey="waitForPageToLoad2"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'productformagetwo68980-english.html')}}" stepKey="seeUrlInRequestPathColumn2"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', 'catalog/product/view/id/$grabProductIdFromUrl')}}" stepKey="seeUrlInTargetPathColumn2"/> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingProductUrlRewriteForENStoreView"> + <argument name="requestPath" value="productformagetwo68980-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeProductUrlInRequestPathColumnForENStoreView"> + <argument name="requestPath" value="productformagetwo68980-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeProductUrlInTargetPathColumnForENStoreView"> + <argument name="targetPath" value="catalog/product/view/id/$grabProductIdFromUrl"/> + </actionGroup> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters3"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="productformagetwo68980-dutch.html" stepKey="inputProductUrlForENStoreView1"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters3"/> - <waitForPageLoad stepKey="waitForPageToLoad3"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'productformagetwo68980-dutch.html')}}" stepKey="seeUrlInRequestPathColumn3"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', 'catalog/product/view/id/$grabProductIdFromUrl')}}" stepKey="seeUrlInTargetPathColumn3"/> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingProductUrlRewriteForNLStoreView"> + <argument name="requestPath" value="productformagetwo68980-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeProductUrlInRequestPathColumnForNLStoreView"> + <argument name="requestPath" value="productformagetwo68980-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeProductUrlInTargetPathColumnForNLStoreView"> + <argument name="targetPath" value="catalog/product/view/id/$grabProductIdFromUrl"/> + </actionGroup> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters4"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="category-english/productformagetwo68980-english.html" stepKey="inputProductUrlForENStoreView2"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters4"/> - <waitForPageLoad stepKey="waitForPageToLoad4"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'category-english/productformagetwo68980-english.html')}}" stepKey="seeUrlInRequestPathColumn4"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', catalog/product/view/id/$grabProductIdFromUrl/category/$$createCategory.id$$)}}" stepKey="seeUrlInTargetPathColumn4"/> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingUrlRewriteForENStoreView"> + <argument name="requestPath" value="category-english/productformagetwo68980-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeUrlInRequestPathColumnForENStoreView"> + <argument name="requestPath" value="category-english/productformagetwo68980-english.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeUrlInTargetPathColumnForENStoreView"> + <argument name="targetPath" value="catalog/product/view/id/$grabProductIdFromUrl/category/$$createCategory.id$$"/> + </actionGroup> - <click selector="{{AdminDataGridHeaderSection.filters}}" stepKey="openUrlRewriteGridFilters5"/> - <fillField selector="{{AdminDataGridHeaderSection.filterFieldInput('request_path')}}" userInput="category-dutch/productformagetwo68980-dutch.html" stepKey="inputProductUrlForENStoreView3"/> - <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickOrderApplyFilters5"/> - <waitForPageLoad stepKey="waitForPageToLoad5"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Request Path', 'category-dutch/productformagetwo68980-dutch.html')}}" stepKey="seeUrlInRequestPathColumn5"/> - <seeElement selector="{{AdminUrlRewriteIndexSection.gridCellByColumnValue('Target Path', catalog/product/view/id/$grabProductIdFromUrl/category/$$createCategory.id$$)}}" stepKey="seeUrlInTargetPathColumn5"/> + <actionGroup ref="AdminSearchUrlRewriteByRequestPathActionGroup" stepKey="searchingUrlRewriteForNLStoreView"> + <argument name="requestPath" value="category-dutch/productformagetwo68980-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminRequestPathInUrlRewriteGrigActionGroup" stepKey="seeUrlInRequestPathColumnForNLStoreView"> + <argument name="requestPath" value="category-dutch/productformagetwo68980-dutch.html"/> + </actionGroup> + <actionGroup ref="AssertAdminTargetPathInUrlRewriteGrigActionGroup" stepKey="seeUrlInTargetPathColumnForNLStoreView"> + <argument name="targetPath" value="catalog/product/view/id/$grabProductIdFromUrl/category/$$createCategory.id$$"/> + </actionGroup> </test> </tests> diff --git a/app/code/Magento/User/Model/Notificator.php b/app/code/Magento/User/Model/Notificator.php index 3a5522db4c533..3e36cd1387e39 100644 --- a/app/code/Magento/User/Model/Notificator.php +++ b/app/code/Magento/User/Model/Notificator.php @@ -107,6 +107,7 @@ public function sendForgotPassword(UserInterface $user): void $this->sendNotification( 'admin/emails/forgot_email_template', [ + 'username' => $user->getFirstName().' '.$user->getLastName(), 'user' => $user, 'store' => $this->storeManager->getStore( Store::DEFAULT_STORE_ID diff --git a/app/code/Magento/User/Test/Mftf/ActionGroup/AdminUserActionGroup.xml b/app/code/Magento/User/Test/Mftf/ActionGroup/LoginNewUserActionGroup.xml similarity index 83% rename from app/code/Magento/User/Test/Mftf/ActionGroup/AdminUserActionGroup.xml rename to app/code/Magento/User/Test/Mftf/ActionGroup/LoginNewUserActionGroup.xml index 4049e60e83455..d41ed63678783 100644 --- a/app/code/Magento/User/Test/Mftf/ActionGroup/AdminUserActionGroup.xml +++ b/app/code/Magento/User/Test/Mftf/ActionGroup/LoginNewUserActionGroup.xml @@ -5,10 +5,8 @@ * See COPYING.txt for license details. */ --> -<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> - <!--Login New User--> - <actionGroup name="LoginNewUser"> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="LoginNewUserActionGroup" deprecated="Use AdminLoginActionGroup instead"> <annotations> <description>Goes to the Backend Admin Login page. Fill Username and Password. Click on Sign In.</description> </annotations> diff --git a/app/code/Magento/User/view/adminhtml/email/password_reset_confirmation.html b/app/code/Magento/User/view/adminhtml/email/password_reset_confirmation.html index dacfa640464a3..42240bff3b8db 100644 --- a/app/code/Magento/User/view/adminhtml/email/password_reset_confirmation.html +++ b/app/code/Magento/User/view/adminhtml/email/password_reset_confirmation.html @@ -4,16 +4,17 @@ * See COPYING.txt for license details. */ --> -<!--@subject {{trans "Password Reset Confirmation for %name" name=$user.name}} @--> +<!--@subject {{trans "Password Reset Confirmation for %name" name=$username}} @--> <!--@vars { "var store.frontend_name":"Store Name", "var user.id":"Account Holder Id", "var user.rp_token":"Reset Password Token", "var user.name":"Account Holder Name", -"store url=\"admin\/auth\/resetpassword\/\" _query_id=$user.id _query_token=$user.rp_token":"Reset Password URL" +"store url=\"admin\/auth\/resetpassword\/\" _query_id=$user.id _query_token=$user.rp_token":"Reset Password URL", +"var username":"Account Holder Name" } @--> -{{trans "%name," name=$user.name}} +{{trans "%name," name=$username}} {{trans "There was recently a request to change the password for your account."}} diff --git a/app/code/Magento/Wishlist/Model/Wishlist.php b/app/code/Magento/Wishlist/Model/Wishlist.php index 9b7ff5177afae..cb1a7d956570b 100644 --- a/app/code/Magento/Wishlist/Model/Wishlist.php +++ b/app/code/Magento/Wishlist/Model/Wishlist.php @@ -181,6 +181,7 @@ class Wishlist extends AbstractModel implements IdentityInterface * @param Json|null $serializer * @param StockRegistryInterface|null $stockRegistry * @param ScopeConfigInterface|null $scopeConfig + * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -226,6 +227,7 @@ public function __construct( * * @param int $customerId * @param bool $create Create wishlist if don't exists + * * @return $this */ public function loadByCustomerId($customerId, $create = false) @@ -274,6 +276,7 @@ public function generateSharingCode() * Load by sharing code * * @param string $code + * * @return $this */ public function loadByCode($code) @@ -370,6 +373,7 @@ protected function _addCatalogProduct(Product $product, $qty = 1, $forciblySetQt * Retrieve wishlist item collection * * @return \Magento\Wishlist\Model\ResourceModel\Item\Collection + * * @throws NoSuchEntityException */ public function getItemCollection() @@ -389,6 +393,7 @@ public function getItemCollection() * Retrieve wishlist item collection * * @param int $itemId + * * @return false|Item */ public function getItem($itemId) @@ -403,7 +408,9 @@ public function getItem($itemId) * Adding item to wishlist * * @param Item $item + * * @return $this + * * @throws Exception */ public function addItem(Item $item) @@ -424,9 +431,12 @@ public function addItem(Item $item) * @param int|Product $product * @param DataObject|array|string|null $buyRequest * @param bool $forciblySetQty + * * @return Item|string + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) + * * @throws LocalizedException * @throws InvalidArgumentException */ @@ -529,7 +539,9 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false * Set customer id * * @param int $customerId + * * @return $this + * * @throws LocalizedException */ public function setCustomerId($customerId) @@ -541,6 +553,7 @@ public function setCustomerId($customerId) * Retrieve customer id * * @return int + * * @throws LocalizedException */ public function getCustomerId() @@ -552,6 +565,7 @@ public function getCustomerId() * Retrieve data for save * * @return array + * * @throws LocalizedException */ public function getDataForSave() @@ -567,6 +581,7 @@ public function getDataForSave() * Retrieve shared store ids for current website or all stores if $current is false * * @return array + * * @throws NoSuchEntityException */ public function getSharedStoreIds() @@ -590,6 +605,7 @@ public function getSharedStoreIds() * Set shared store ids * * @param array $storeIds + * * @return $this */ public function setSharedStoreIds($storeIds) @@ -602,6 +618,7 @@ public function setSharedStoreIds($storeIds) * Retrieve wishlist store object * * @return \Magento\Store\Model\Store + * * @throws NoSuchEntityException */ public function getStore() @@ -616,6 +633,7 @@ public function getStore() * Set wishlist store * * @param Store $store + * * @return $this */ public function setStore($store) @@ -653,6 +671,7 @@ public function isSalable() * Retrieve if product has stock or config is set for showing out of stock products * * @param int $productId + * * @return bool */ private function isInStock($productId) @@ -671,7 +690,9 @@ private function isInStock($productId) * Check customer is owner this wishlist * * @param int $customerId + * * @return bool + * * @throws LocalizedException */ public function isOwner($customerId) @@ -696,10 +717,13 @@ public function isOwner($customerId) * @param int|Item $itemId * @param DataObject $buyRequest * @param null|array|DataObject $params + * * @return $this + * * @throws LocalizedException * * @see \Magento\Catalog\Helper\Product::addParamsToBuyRequest() + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -748,10 +772,11 @@ public function updateItem($itemId, $buyRequest, $params = null) throw new LocalizedException(__($resultItem)); } + if ($resultItem->getDescription() != $item->getDescription()) { + $resultItem->setDescription($item->getDescription())->save(); + } + if ($resultItem->getId() != $itemId) { - if ($resultItem->getDescription() != $item->getDescription()) { - $resultItem->setDescription($item->getDescription())->save(); - } $item->isDeleted(true); $this->setDataChanges(true); } else { diff --git a/app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less b/app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less index f57420deb621d..4b48bbe99ced2 100644 --- a/app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less +++ b/app/design/frontend/Magento/blank/Magento_Catalog/web/css/source/_module.less @@ -457,11 +457,26 @@ .action { &.delete { &:extend(.abs-remove-button-for-blocks all); - line-height: unset; position: absolute; right: 0; top: -1px; - width: auto; + } + } + + .block-wishlist { + .action { + &.delete { + line-height: unset; + width: auto; + } + } + } + + .block-compare { + .action { + &.delete { + right: initial; + } } } @@ -814,6 +829,7 @@ &:extend(.abs-remove-button-for-blocks all); left: -6px; position: absolute; + right: 0; top: 0; } diff --git a/app/design/frontend/Magento/blank/Magento_Newsletter/web/css/source/_module.less b/app/design/frontend/Magento/blank/Magento_Newsletter/web/css/source/_module.less index 09759d95c4b10..8434812f20719 100644 --- a/app/design/frontend/Magento/blank/Magento_Newsletter/web/css/source/_module.less +++ b/app/design/frontend/Magento/blank/Magento_Newsletter/web/css/source/_module.less @@ -82,6 +82,10 @@ .field { margin-right: 5px; + &.newsletter { + max-width: 220px; + } + .control { width: 100%; } diff --git a/app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less b/app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less index d0b7aa1523ad6..e205b20efd17c 100644 --- a/app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less +++ b/app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/_module.less @@ -998,6 +998,15 @@ } } } + + .block-compare { + .action { + &.delete { + left: 0; + right: initial; + } + } + } } } @@ -1005,6 +1014,7 @@ .compare.wrapper { display: none; } + .catalog-product_compare-index { .columns { .column { diff --git a/app/design/frontend/Magento/luma/Magento_Newsletter/web/css/source/_module.less b/app/design/frontend/Magento/luma/Magento_Newsletter/web/css/source/_module.less index a72f31d72ce48..21ed451a69d10 100644 --- a/app/design/frontend/Magento/luma/Magento_Newsletter/web/css/source/_module.less +++ b/app/design/frontend/Magento/luma/Magento_Newsletter/web/css/source/_module.less @@ -81,6 +81,10 @@ .block.newsletter { max-width: 44%; width: max-content; + + .field.newsletter { + max-width: 220px; + } .form.subscribe { > .field, diff --git a/app/design/frontend/Magento/luma/Magento_Sales/email/order_new_guest.html b/app/design/frontend/Magento/luma/Magento_Sales/email/order_new_guest.html index 024f6daf76ace..e51b952281ed5 100644 --- a/app/design/frontend/Magento/luma/Magento_Sales/email/order_new_guest.html +++ b/app/design/frontend/Magento/luma/Magento_Sales/email/order_new_guest.html @@ -8,7 +8,7 @@ <!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var order_data.email_customer_note|escape|nl2br":"Email Order Note", -"var order.billing_address.name":"Guest Customer Name", +"var order_data.customer_name":"Guest Customer Name", "var created_at_formatted":"Order Created At (datetime)", "var order.increment_id":"Order Id", "layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid", @@ -27,7 +27,7 @@ <table> <tr class="email-intro"> <td> - <p class="greeting">{{trans "%name," name=$order.billing_address.name}}</p> + <p class="greeting">{{trans "%name," name=$order_data.customer_name}}</p> <p> {{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}} {{trans "Once your package ships we will send you a tracking number."}} diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShipmentEstimationWithExtensionAttributesTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShipmentEstimationWithExtensionAttributesTest.php new file mode 100644 index 0000000000000..dc59a571aa136 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShipmentEstimationWithExtensionAttributesTest.php @@ -0,0 +1,121 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Quote\Api; + +use Magento\Framework\Api\ExtensibleDataInterface; +use Magento\TestFramework\ObjectManager; +use Magento\TestFramework\TestCase\WebapiAbstract; +use Magento\Quote\Api\Data\AddressInterface; + +class GuestShipmentEstimationWithExtensionAttributesTest extends WebapiAbstract +{ + const SERVICE_VERSION = 'V1'; + const SERVICE_NAME = 'quoteGuestShipmentEstimationV1'; + const RESOURCE_PATH = '/V1/guest-carts/'; + + /** + * @var ObjectManager + */ + private $objectManager; + + protected function setUp(): void + { + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation disabled + * @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_free_shipping.php + * @magentoApiDataFixture Magento/Sales/_files/quote.php + */ + public function testEstimateByExtendedAddress(): void + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); + $quote->load('test01', '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::class) + ->create(); + $quoteIdMask->load($cartId, 'quote_id'); + //Use masked cart Id + $cartId = $quoteIdMask->getMaskedId(); + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => '/V1/guest-carts/' . $cartId . '/estimate-shipping-methods', + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, + ], + 'soap' => [ + 'service' => self::SERVICE_NAME, + 'serviceVersion' => 'V1', + 'operation' => self::SERVICE_NAME . 'EstimateByExtendedAddress', + ], + ]; + if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { + /** @var \Magento\Quote\Model\Quote\Address $address */ + $address = $quote->getShippingAddress(); + + $data = [ + AddressInterface::KEY_ID => (int)$address->getId(), + AddressInterface::KEY_REGION => $address->getRegion(), + AddressInterface::KEY_REGION_ID => $address->getRegionId(), + AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), + AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), + 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_CUSTOMER_ID => $address->getCustomerId(), + AddressInterface::KEY_EMAIL => $address->getEmail(), + AddressInterface::SAME_AS_BILLING => $address->getSameAsBilling(), + AddressInterface::CUSTOMER_ADDRESS_ID => $address->getCustomerAddressId(), + AddressInterface::SAVE_IN_ADDRESS_BOOK => $address->getSaveInAddressBook(), + ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => [ + 'discounts' => [] + ] + ]; + + $requestData = [ + 'cartId' => $cartId, + 'address' => $data + ]; + } else { + + $requestData = [ + 'address' => [ + 'country_id' => "US", + 'postcode' => null, + 'region' => null, + 'region_id' => null, + 'extension_attributes' => [ + 'discounts' => [] + ] + ] + ]; + } + + // Cart must be anonymous (see fixture) + $this->assertEmpty($quote->getCustomerId()); + + $result = $this->_webApiCall($serviceInfo, $requestData); + + $this->assertNotEmpty($result); + $this->assertEquals(1, count($result)); + foreach ($result as $rate) { + $this->assertEquals("flatrate", $rate['carrier_code']); + $this->assertEquals(0, $rate['amount']); + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/EavTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/EavTest.php index 1c709ffcacec7..72d96334e0335 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/EavTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/EavTest.php @@ -9,6 +9,7 @@ use Magento\Eav\Api\AttributeSetRepositoryInterface; use Magento\Eav\Model\AttributeSetRepository; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\TestFramework\Eav\Model\GetAttributeGroupByName; use Magento\TestFramework\Eav\Model\ResourceModel\GetEntityIdByAttributeId; @@ -34,6 +35,9 @@ class EavTest extends AbstractEavTest */ private $setRepository; + /** @var ScopeConfigInterface */ + private $config; + /** * @inheritdoc */ @@ -43,6 +47,7 @@ protected function setUp(): void $this->attributeGroupByName = $this->objectManager->get(GetAttributeGroupByName::class); $this->getEntityIdByAttributeId = $this->objectManager->get(GetEntityIdByAttributeId::class); $this->setRepository = $this->objectManager->get(AttributeSetRepositoryInterface::class); + $this->config = $this->objectManager->get(ScopeConfigInterface::class); } /** @@ -217,4 +222,92 @@ private function prepareAttributeSet(array $additional): void $set->organizeData(array_merge($data, $additional)); $this->setRepository->save($set); } + + /** + * @magentoDataFixture Magento/Catalog/_files/attribute_page_layout_default.php + * @dataProvider testModifyMetaNewProductPageLayoutDefaultProvider + * @return void + */ + public function testModifyMetaNewProductPageLayoutDefault($attributesMeta): void + { + $defaultLayout = $this->config->getValue('web/default_layouts/default_product_layout'); + if ($defaultLayout) { + $attributesMeta = array_merge($attributesMeta, ['default' => $defaultLayout]); + } + $expectedMeta = $this->addMetaNesting( + $attributesMeta, + 'design', + 'page_layout' + ); + $this->callModifyMetaAndAssert($this->getNewProduct(), $expectedMeta); + } + + /** + * @return array + */ + public function testModifyMetaNewProductPageLayoutDefaultProvider(): array + { + return [ + 'attributes_meta' => [ + [ + 'dataType' => 'select', + 'formElement' => 'select', + 'visible' => '1', + 'required' => false, + 'label' => 'Layout', + 'code' => 'page_layout', + 'source' => 'design', + 'scopeLabel' => '[STORE VIEW]', + 'globalScope' => false, + 'sortOrder' => '__placeholder__', + 'options' => + [ + 0 => + [ + 'value' => '', + 'label' => 'No layout updates', + '__disableTmpl' => true, + ], + 1 => + [ + 'label' => 'Empty', + 'value' => 'empty', + '__disableTmpl' => true, + ], + 2 => + [ + 'label' => '1 column', + 'value' => '1column', + '__disableTmpl' => true, + ], + 3 => + [ + 'label' => '2 columns with left bar', + 'value' => '2columns-left', + '__disableTmpl' => true, + ], + 4 => + [ + 'label' => '2 columns with right bar', + 'value' => '2columns-right', + '__disableTmpl' => true, + ], + 5 => + [ + 'label' => '3 columns', + 'value' => '3columns', + '__disableTmpl' => true, + ], + ], + 'componentType' => 'field', + 'disabled' => true, + 'validation' => + [ + 'required' => false, + ], + 'serviceDisabled' => true, + ] + ] + ]; + } } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default.php new file mode 100644 index 0000000000000..c8222ac565dc7 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default.php @@ -0,0 +1,21 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; +use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory; +use Magento\Catalog\Setup\CategorySetup; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); +$installer = $objectManager->create(CategorySetup::class); +$attribute = $objectManager->create(AttributeFactory::class)->create(); +$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class); +$entityType = $installer->getEntityTypeId(ProductAttributeInterface::ENTITY_TYPE_CODE); +$attribute->loadByCode($entityType, 'page_layout'); +$attribute->setData('default_value', '1column'); +$attributeRepository->save($attribute); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default_rollback.php new file mode 100644 index 0000000000000..f762574a2efd1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_page_layout_default_rollback.php @@ -0,0 +1,21 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; +use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory; +use Magento\Catalog\Setup\CategorySetup; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); +$installer = $objectManager->create(CategorySetup::class); +$attribute = $objectManager->create(AttributeFactory::class)->create(); +$attributeRepository = $objectManager->create(ProductAttributeRepositoryInterface::class); +$entityType = $installer->getEntityTypeId(ProductAttributeInterface::ENTITY_TYPE_CODE); +$attribute->loadByCode($entityType, 'page_layout'); +$attribute->setData('default_value', null); +$attributeRepository->save($attribute); diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php index 4d08d71793cbb..9dee418f010a8 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php @@ -3127,4 +3127,73 @@ public function testCheckDoubleImportOfProducts() $productsAfterSecondImport = $this->productRepository->getList($searchCriteria)->getItems(); $this->assertCount(3, $productsAfterSecondImport); } + + /** + * Checks that product related links added for all bunches properly after products import + */ + public function testImportProductsWithLinksInDifferentBunches() + { + $this->importedProducts = [ + 'simple1', + 'simple2', + 'simple3', + 'simple4', + 'simple5', + 'simple6', + ]; + $importExportData = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->getMock(); + $importExportData->expects($this->atLeastOnce()) + ->method('getBunchSize') + ->willReturn(5); + $this->_model = $this->objectManager->create( + \Magento\CatalogImportExport\Model\Import\Product::class, + ['importExportData' => $importExportData] + ); + $linksData = [ + 'related' => [ + 'simple1' => '2', + 'simple2' => '1' + ] + ]; + $pathToFile = __DIR__ . '/_files/products_to_import_with_related.csv'; + $filesystem = $this->objectManager->create(Filesystem::class); + + $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); + $source = $this->objectManager->create( + Csv::class, + [ + 'file' => $pathToFile, + 'directory' => $directory + ] + ); + $errors = $this->_model->setSource($source) + ->setParameters( + [ + 'behavior' => Import::BEHAVIOR_APPEND, + 'entity' => 'catalog_product' + ] + ) + ->validateData(); + + $this->assertTrue($errors->getErrorsCount() == 0); + $this->_model->importData(); + + $resource = $this->objectManager->get(ProductResource::class); + $productId = $resource->getIdBySku('simple6'); + /** @var Product $product */ + $product = $this->objectManager->create(Product::class); + $product->load($productId); + $productLinks = [ + 'related' => $product->getRelatedProducts() + ]; + $importedProductLinks = []; + foreach ($productLinks as $linkType => $linkedProducts) { + foreach ($linkedProducts as $linkedProductData) { + $importedProductLinks[$linkType][$linkedProductData->getSku()] = $linkedProductData->getPosition(); + } + } + $this->assertEquals($linksData, $importedProductLinks); + } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_related.csv b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_related.csv new file mode 100644 index 0000000000000..3627cdc24ec41 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_related.csv @@ -0,0 +1,7 @@ +sku,product_type,store_view_code,name,price,qty,attribute_set_code,related_skus,related_position +simple1,simple,,simple 1,25,10,Default,, +simple2,simple,,simple 2,34,10,Default,, +simple3,simple,,simple 3,58,10,Default,"simple1,simple2","1,2" +simple4,simple,,simple 4,67,10,Default,"simple1,simple2","2,1" +simple5,simple,,simple 5,58,10,Default,"simple1,simple2","1,2" +simple6,simple,,simple 6,67,10,Default,"simple1,simple2","2,1" \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php index 66b452d234366..ee99ec96bbf2c 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php @@ -3,9 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); + +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + $agreement->setData([ 'name' => 'Checkout Agreement (active)', 'content' => 'Checkout agreement content: <b>HTML</b>', @@ -15,4 +28,4 @@ 'is_html' => true, 'stores' => [0, 1], ]); -$agreement->save(); +$agreementResource->save($agreement); diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content_rollback.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content_rollback.php index da65dcae7d8f4..10879d3d91306 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content_rollback.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_active_with_html_content_rollback.php @@ -3,10 +3,23 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); -$agreement->load('Checkout Agreement (active)', 'name'); + +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + +$agreementResource->load($agreement, 'Checkout Agreement (active)', 'name'); if ($agreement->getId()) { - $agreement->delete(); + $agreementResource->delete($agreement); } diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php index e60c754d66a3c..29b01163df514 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php @@ -3,9 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); + +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + $agreement->setData([ 'name' => 'Checkout Agreement (inactive)', 'content' => 'Checkout agreement content: TEXT', @@ -15,4 +28,4 @@ 'is_html' => false, 'stores' => [0, 1], ]); -$agreement->save(); +$agreementResource->save($agreement); diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content_rollback.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content_rollback.php index 39ba6cf30be26..3fda82782ebc5 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content_rollback.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content_rollback.php @@ -4,10 +4,22 @@ * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); -$agreement->load('Checkout Agreement (inactive)', 'name'); +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + +$agreementResource->load($agreement, 'Checkout Agreement (inactive)', 'name'); if ($agreement->getId()) { - $agreement->delete(); + $agreementResource->delete($agreement); } diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text.php index 3be16338110a1..8d15bf6e9b74f 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text.php @@ -3,9 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); + +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + $agreement->setData([ 'name' => 'First Checkout Agreement (active)', 'content' => 'Checkout agreement content: TEXT', @@ -16,8 +29,9 @@ 'mode' => 1, 'stores' => [0, 1], ]); -$agreement->save(); -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); +$agreementResource->save($agreement); + +$agreement = $objectManager->create(Agreement::class); $agreement->setData([ 'name' => 'Second Checkout Agreement (active)', 'content' => 'Checkout agreement content: TEXT', @@ -28,4 +42,5 @@ 'mode' => 1, 'stores' => [0, 1], ]); -$agreement->save(); + +$agreementResource->save($agreement); diff --git a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text_rollback.php b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text_rollback.php index 9c594c0c22b65..f43f7a5ba9a51 100644 --- a/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text_rollback.php +++ b/dev/tests/integration/testsuite/Magento/CheckoutAgreements/_files/multi_agreements_active_with_text_rollback.php @@ -4,15 +4,28 @@ * See COPYING.txt for license details. */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -/** @var $agreement \Magento\CheckoutAgreements\Model\Agreement */ -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); -$agreement->load('First Checkout Agreement (active)', 'name'); +declare(strict_types=1); + +use Magento\CheckoutAgreements\Model\Agreement; +use Magento\CheckoutAgreements\Model\ResourceModel\Agreement as AgreementResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $agreement Agreement + * @var $agreementResource AgreementResource + */ +$agreement = $objectManager->create(Agreement::class); +$agreementResource = $objectManager->create(AgreementResource::class); + +$agreementResource->load($agreement, 'First Checkout Agreement (active)', 'name'); if ($agreement->getId()) { - $agreement->delete(); + $agreementResource->delete($agreement); } -$agreement = $objectManager->create(\Magento\CheckoutAgreements\Model\Agreement::class); -$agreement->load('Second Checkout Agreement (active)', 'name'); + +$agreement = $objectManager->create(Agreement::class); +$agreementResource->load($agreement, 'Second Checkout Agreement (active)', 'name'); if ($agreement->getId()) { - $agreement->delete(); + $agreementResource->delete($agreement); } diff --git a/dev/tests/integration/testsuite/Magento/Config/Model/ConfigTest.php b/dev/tests/integration/testsuite/Magento/Config/Model/ConfigTest.php index 1b7a504959d54..eedb93099b8c3 100644 --- a/dev/tests/integration/testsuite/Magento/Config/Model/ConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Config/Model/ConfigTest.php @@ -5,12 +5,18 @@ */ namespace Magento\Config\Model; +use Magento\Backend\App\Area\FrontNameResolver; +use Magento\Config\Model\ResourceModel\Config\Data\Collection; +use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory; +use Magento\Framework\Config\ScopeInterface; +use Magento\Framework\Encryption\EncryptorInterface; use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; /** * @magentoAppArea adminhtml */ -class ConfigTest extends \PHPUnit\Framework\TestCase +class ConfigTest extends TestCase { /** * @covers \Magento\Config\Model\Config::save @@ -22,25 +28,25 @@ class ConfigTest extends \PHPUnit\Framework\TestCase public function testSaveWithSingleStoreModeEnabled($groups) { Bootstrap::getObjectManager()->get( - \Magento\Framework\Config\ScopeInterface::class + ScopeInterface::class )->setCurrentScope( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE + FrontNameResolver::AREA_CODE ); - /** @var $_configDataObject \Magento\Config\Model\Config */ - $_configDataObject = Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config::class); + /** @var $_configDataObject Config */ + $_configDataObject = Bootstrap::getObjectManager()->create(Config::class); $_configData = $_configDataObject->setSection('dev')->setWebsite('base')->load(); $this->assertEmpty($_configData); - $_configDataObject = Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config::class); + $_configDataObject = Bootstrap::getObjectManager()->create(Config::class); $_configDataObject->setSection('dev')->setGroups($groups)->save(); - /** @var $_configDataObject \Magento\Config\Model\Config */ - $_configDataObject = Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config::class); + /** @var $_configDataObject Config */ + $_configDataObject = Bootstrap::getObjectManager()->create(Config::class); $_configData = $_configDataObject->setSection('dev')->load(); $this->assertArrayHasKey('dev/debug/template_hints_admin', $_configData); $this->assertArrayHasKey('dev/debug/template_hints_blocks', $_configData); - $_configDataObject = Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config::class); + $_configDataObject = Bootstrap::getObjectManager()->create(Config::class); $_configData = $_configDataObject->setSection('dev')->setWebsite('base')->load(); $this->assertArrayNotHasKey('dev/debug/template_hints_admin', $_configData); $this->assertArrayNotHasKey('dev/debug/template_hints_blocks', $_configData); @@ -63,16 +69,16 @@ public function testSave($section, $groups, $expected) { $objectManager = Bootstrap::getObjectManager(); - /** @var $_configDataObject \Magento\Config\Model\Config */ - $_configDataObject = $objectManager->create(\Magento\Config\Model\Config::class); + /** @var $_configDataObject Config */ + $_configDataObject = $objectManager->create(Config::class); $_configDataObject->setSection($section)->setWebsite('base')->setGroups($groups)->save(); foreach ($expected as $group => $expectedData) { - $_configDataObject = $objectManager->create(\Magento\Config\Model\Config::class); + $_configDataObject = $objectManager->create(Config::class); $_configData = $_configDataObject->setSection($group)->setWebsite('base')->load(); if (array_key_exists('payment/payflow_link/pwd', $_configData)) { $_configData['payment/payflow_link/pwd'] = $objectManager->get( - \Magento\Framework\Encryption\EncryptorInterface::class + EncryptorInterface::class )->decrypt( $_configData['payment/payflow_link/pwd'] ); @@ -85,4 +91,102 @@ public function saveDataProvider() { return require __DIR__ . '/_files/config_section.php'; } + + /** + * @param string $website + * @param string $section + * @param array $override + * @param array $inherit + * @param array $expected + * @dataProvider saveWebsiteScopeDataProvider + */ + public function testSaveUseDefault( + string $website, + string $section, + array $override, + array $inherit, + array $expected + ): void { + $objectManager = Bootstrap::getObjectManager(); + /** @var Config $config*/ + $configFactory = $objectManager->create(ConfigFactory::class); + $config = $configFactory->create() + ->setSection($section) + ->setWebsite($website) + ->setGroups($override['groups']) + ->save(); + + $paths = array_keys($expected); + + $this->assertEquals( + $expected, + $this->getConfigValues($config->getScope(), $config->getScopeId(), $paths) + ); + + $config = $configFactory->create() + ->setSection($section) + ->setWebsite($website) + ->setGroups($inherit['groups']) + ->save(); + + $this->assertEmpty( + $this->getConfigValues($config->getScope(), $config->getScopeId(), $paths) + ); + } + + /** + * @return array + */ + public function saveWebsiteScopeDataProvider(): array + { + return [ + [ + 'website' => 'base', + 'section' => 'payment', + [ + 'groups' => [ + 'account' => [ + 'fields' => [ + 'merchant_country' => ['value' => 'GB'], + ], + ], + ] + ], + [ + 'groups' => [ + 'account' => [ + 'fields' => [ + 'merchant_country' => ['inherit' => 1], + ], + ], + ], + ], + 'expected' => [ + 'paypal/general/merchant_country' => 'GB', + ], + ] + ]; + } + + /** + * @param string $scope + * @param int $scopeId + * @param array $paths + * @return array + */ + private function getConfigValues(string $scope, int $scopeId, array $paths): array + { + $objectManager = Bootstrap::getObjectManager(); + /** @var Collection $configCollection */ + $configCollectionFactory = $objectManager->create(CollectionFactory::class); + $configCollection = $configCollectionFactory->create(); + $configCollection->addFieldToFilter('scope', $scope); + $configCollection->addFieldToFilter('scope_id', $scopeId); + $configCollection->addFieldToFilter('path', ['in' => $paths]); + $result = []; + foreach ($configCollection as $data) { + $result[$data->getPath()] = $data->getValue(); + } + return $result; + } } diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/AttributeValuesTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/AttributeValuesTest.php new file mode 100644 index 0000000000000..b0a1c81857221 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/AttributeValuesTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps; + +use Magento\Backend\Model\Auth\Session; +use Magento\ConfigurableProduct\Block\DataProviders\PermissionsData; +use Magento\Framework\View\Layout; +use Magento\Framework\View\LayoutInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\User\Model\User; +use PHPUnit\Framework\TestCase; + +/** + * @magentoAppArea adminhtml + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ +class AttributeValuesTest extends TestCase +{ + /** + * @magentoDataFixture Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions.php + */ + public function testRestrictedUserNotAllowedToManageAttributes() + { + $user = Bootstrap::getObjectManager()->create( + User::class + )->loadByUsername( + 'admincatalog_user' + ); + + /** @var $session Session */ + $session = Bootstrap::getObjectManager()->get( + Session::class + ); + $session->setUser($user); + + /** @var $layout Layout */ + $layout = Bootstrap::getObjectManager()->get( + LayoutInterface::class + ); + + /** @var \Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\AttributeValues */ + $block = $layout->createBlock( + AttributeValues::class, + 'step2', + [ + 'data' => [ + 'config' => [ + 'form' => 'product_form.product_form', + 'modal' => 'configurableModal', + 'dataScope' => 'productFormConfigurable', + ], + 'permissions' => Bootstrap::getObjectManager()->get(PermissionsData::class) + ] + ] + ); + $isAllowedToManageAttributes = $block->getPermissions()->isAllowedToManageAttributes(); + $html = $block->toHtml(); + $this->assertFalse($isAllowedToManageAttributes); + $this->assertStringNotContainsString('<button class="action-create-new action-tertiary"', $html); + } +} diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions.php new file mode 100644 index 0000000000000..7fd64c95f9942 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Authorization\Model\Acl\Role\Group; +use Magento\Authorization\Model\RoleFactory; +use Magento\Authorization\Model\Role; +use Magento\Authorization\Model\Rules; +use Magento\Authorization\Model\UserContextInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\User\Model\User; + +/** @var Role $role */ +$role = Bootstrap::getObjectManager()->get(RoleFactory::class)->create(); +$role->setName('role_catalog_permissions'); +$role->setData('role_name', $role->getName()); +$role->setRoleType(Group::ROLE_TYPE); +$role->setUserType((string)UserContextInterface::USER_TYPE_ADMIN); +$role->save(); + +/** @var $rule Rules */ +$rule = Bootstrap::getObjectManager()->create(Rules::class); +$rule->setRoleId($role->getId())->setResources(['Magento_Catalog::catalog'])->saveRel(); + +/** @var User $user */ +$user = Bootstrap::getObjectManager()->create(User::class); +$user->setData( + [ + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'email' => 'admincatalog@example.com', + 'username' => 'admincatalog_user', + 'password' => 'admincatalog_password1', + 'is_active' => 1, + ] +); +$user->setRoleId($role->getId())->save(); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions_rollback.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions_rollback.php new file mode 100644 index 0000000000000..743503d1bd388 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/restricted_admin_with_catalog_permissions_rollback.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +use Magento\Authorization\Model\Role; +use Magento\Authorization\Model\RoleFactory; +use Magento\Authorization\Model\Rules; +use Magento\Authorization\Model\RulesFactory; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\User\Model\User; + +// Deleting the user and the role. +/** @var User $user */ +$user = Bootstrap::getObjectManager()->create(User::class); +$user->loadByUsername('admincatalog_user')->delete(); +/** @var Role $role */ +$role = Bootstrap::getObjectManager()->get(RoleFactory::class)->create(); +$role->load('role_catalog_permissions', 'role_name'); +if ($role->getId()) { + /** @var Rules $rules */ + $rules = Bootstrap::getObjectManager()->get(RulesFactory::class)->create(); + $rules->load($role->getId(), 'role_id'); + $rules->delete(); + $role->delete(); +} diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php index 00b5d2bc6f279..8651db95ae645 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php @@ -19,6 +19,11 @@ use Magento\Framework\Api\SortOrder; use Magento\Framework\Config\CacheInterface; use Magento\Framework\ObjectManagerInterface; +use Magento\Sales\Api\Data\InvoiceInterface; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Api\InvoiceOrderInterface; +use Magento\Sales\Api\InvoiceRepositoryInterface; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\Customer\Api\Data\AddressInterface; use Magento\Framework\Api\SearchCriteriaBuilder; @@ -34,12 +39,18 @@ */ class CustomerRepositoryTest extends \PHPUnit\Framework\TestCase { + const NEW_CUSTOMER_EMAIL = 'new.customer@example.com'; + const CUSTOMER_ID = 1; + /** @var AccountManagementInterface */ private $accountManagement; /** @var CustomerRepositoryInterface */ private $customerRepository; + /** @var OrderRepositoryInterface */ + private $orderRepository; + /** @var ObjectManagerInterface */ private $objectManager; @@ -71,6 +82,7 @@ protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class); + $this->orderRepository = $this->objectManager->create(OrderRepositoryInterface::class); $this->customerFactory = $this->objectManager->create(CustomerInterfaceFactory::class); $this->addressFactory = $this->objectManager->create(AddressInterfaceFactory::class); $this->regionFactory = $this->objectManager->create(RegionInterfaceFactory::class); @@ -625,4 +637,55 @@ public function testUpdateDefaultShippingAndDefaultBillingTest() 'Default shipping should not be overridden' ); } + + /** + * Test that UpgradeOrderCustomerEmailObserver is executed + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoDbIsolation enabled + */ + public function testUpgradeOrderCustomerEmailObserverWhenEmailIsModified() + { + $customer = $this->customerRepository->getById(self::CUSTOMER_ID); + $customer->setEmail(self::NEW_CUSTOMER_EMAIL); + + $this->customerRepository->save($customer); + + /** @var SearchCriteriaBuilder $searchBuilder */ + $searchBuilder = $this->objectManager->create(SearchCriteriaBuilder::class); + $searchCriteria = $searchBuilder + ->addFilter(OrderInterface::CUSTOMER_ID, $customer->getId()) + ->create(); + + $customerOrders = $this->orderRepository->getList($searchCriteria); + + foreach ($customerOrders as $customerOrder) { + $this->assertEquals(self::NEW_CUSTOMER_EMAIL, $customerOrder->getCustomerEmail()); + } + } + + /** + * Test that UpgradeOrderCustomerEmailObserver is executed but does not update orders + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoDbIsolation enabled + */ + public function testUpgradeOrderCustomerEmailObserverWhenEmailIsNotModified(): void + { + $customer = $this->customerRepository->getById(self::CUSTOMER_ID); + + $this->customerRepository->save($customer); + + /** @var SearchCriteriaBuilder $searchBuilder */ + $searchBuilder = $this->objectManager->create(SearchCriteriaBuilder::class); + $searchCriteria = $searchBuilder + ->addFilter(OrderInterface::CUSTOMER_ID, $customer->getId()) + ->create(); + + $customerOrders = $this->orderRepository->getList($searchCriteria); + + foreach ($customerOrders as $customerOrder) { + $this->assertEquals('customer@null.com', $customerOrder->getCustomerEmail()); + } + } } diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer.php b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer.php index 3a39e62af0ccb..9c24e4b5ff3bd 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer.php @@ -3,39 +3,41 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -//Create customer -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -); -$customer->setWebsiteId( - 1 -)->setEntityId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'CharlesTAlston@teleworm.us' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Charles' -)->setLastname( - 'Alston' -)->setGender( - '2' -); + +declare(strict_types=1); + +use Magento\Customer\Model\Address; +use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; +use Magento\Framework\Registry; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var $customer Customer + * @var $customerResource CustomerResource + */ +$customer = $objectManager->create(Customer::class); +$customerResource = $objectManager->create(CustomerResource::class); + +$customer->setWebsiteId(1) + ->setEntityId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('CharlesTAlston@teleworm.us') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Charles') + ->setLastname('Alston') + ->setGender('2'); + $customer->isObjectNew(true); // Create address -$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Address::class); +$address = $objectManager->create(Address::class); // default_billing and default_shipping information would not be saved, it is needed only for simple check $address->addData( [ @@ -54,14 +56,12 @@ // Assign customer and address $customer->addAddress($address); -$customer->save(); +$customerResource->save($customer); // Mark last address as default billing and default shipping for current customer $customer->setDefaultBilling($address->getId()); $customer->setDefaultShipping($address->getId()); -$customer->save(); +$customerResource->save($customer); -/** @var $objectManager \Magento\TestFramework\ObjectManager */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -$objectManager->get(\Magento\Framework\Registry::class)->unregister('_fixture/Magento_ImportExport_Customer'); -$objectManager->get(\Magento\Framework\Registry::class)->register('_fixture/Magento_ImportExport_Customer', $customer); +$objectManager->get(Registry::class)->unregister('_fixture/Magento_ImportExport_Customer'); +$objectManager->get(Registry::class)->register('_fixture/Magento_ImportExport_Customer', $customer); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer_with_addresses.php b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer_with_addresses.php index b8a69def69d6b..46086e00244ee 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer_with_addresses.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customer_with_addresses.php @@ -3,41 +3,44 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + +use Magento\Customer\Model\Address; +use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; +use Magento\Framework\Registry; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; + +/** @var $objectManager ObjectManager */ +$objectManager = Bootstrap::getObjectManager(); + $customers = []; -//Create customer -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -); -$customer->setWebsiteId( - 1 -)->setEntityId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'BetsyParker@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Betsy' -)->setLastname( - 'Parker' -)->setGender( - 2 -); +/** + * @var $customer Customer + * @var $customerResource CustomerResource + */ +$customer = $objectManager->create(Customer::class); +$customerResource = $objectManager->create(CustomerResource::class); + +$customer->setWebsiteId(1) + ->setEntityId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('BetsyParker@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Betsy') + ->setLastname('Parker') + ->setGender(2); $customer->isObjectNew(true); // Create address -$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Address::class); +$address = $objectManager->create(Address::class); // default_billing and default_shipping information would not be saved, it is needed only for simple check $address->addData( [ @@ -56,46 +59,31 @@ // Assign customer and address $customer->addAddress($address); -$customer->save(); +$customerResource->save($customer); // Mark last address as default billing and default shipping for current customer $customer->setDefaultBilling($address->getId()); $customer->setDefaultShipping($address->getId()); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -); -$customer->setWebsiteId( - 1 -)->setEntityId( - 2 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'AnthonyNealy@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Anthony' -)->setLastname( - 'Nealy' -)->setGender( - 1 -); +$customer = $objectManager->create(Customer::class); +$customer->setWebsiteId(1) + ->setEntityId(2) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('AnthonyNealy@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Anthony') + ->setLastname('Nealy') + ->setGender(1); $customer->isObjectNew(true); -$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Address::class); +$address = $objectManager->create(Address::class); $address->addData( [ 'firstname' => 'Anthony', @@ -112,7 +100,7 @@ ); $customer->addAddress($address); -$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Address::class); +$address = $objectManager->create(Address::class); $address->addData( [ 'firstname' => 'Anthony', @@ -129,45 +117,30 @@ ); $customer->addAddress($address); -$customer->save(); +$customerResource->save($customer); $customer->setDefaultBilling($address->getId()); $customer->setDefaultShipping($address->getId()); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -); -$customer->setWebsiteId( - 1 -)->setEntityId( - 3 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'LoriBanks@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Lori' -)->setLastname( - 'Banks' -)->setGender( - 2 -); +$customer = $objectManager->create(Customer::class); +$customer->setWebsiteId(1) + ->setEntityId(3) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('LoriBanks@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Lori') + ->setLastname('Banks') + ->setGender(2); $customer->isObjectNew(true); -$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Address::class); +$address = $objectManager->create(Address::class); $address->addData( [ 'firstname' => 'Lori', @@ -183,17 +156,13 @@ ] ); $customer->addAddress($address); -$customer->save(); +$customerResource->save($customer); $customer->setDefaultBilling($address->getId()); $customer->setDefaultShipping($address->getId()); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; -/** @var $objectManager \Magento\TestFramework\ObjectManager */ -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -$objectManager->get(\Magento\Framework\Registry::class) - ->unregister('_fixture/Magento_ImportExport_Customers_Array'); -$objectManager->get(\Magento\Framework\Registry::class) - ->register('_fixture/Magento_ImportExport_Customers_Array', $customers); +$objectManager->get(Registry::class)->unregister('_fixture/Magento_ImportExport_Customers_Array'); +$objectManager->get(Registry::class)->register('_fixture/Magento_ImportExport_Customers_Array', $customers); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers.php b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers.php index 9b989779e4cbd..302ac055f61ca 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers.php @@ -4,107 +4,75 @@ * See COPYING.txt for license details. */ -use Magento\TestFramework\Helper\Bootstrap; -use Magento\Framework\ObjectManagerInterface; +declare(strict_types=1); + use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Registry; +use Magento\TestFramework\Helper\Bootstrap; /** @var $objectManager ObjectManagerInterface */ $objectManager = Bootstrap::getObjectManager(); $customers = []; + +/** + * @var $customer Customer + * @var $customerResource CustomerResource + */ $customer = $objectManager->create(Customer::class); +$customerResource = $objectManager->create(CustomerResource::class); -$customer->setWebsiteId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'customer@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Firstname' -)->setLastname( - 'Lastname' -)->setDefaultBilling( - 1 -)->setDefaultShipping( - 1 -); +$customer->setWebsiteId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('customer@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Firstname') + ->setLastname('Lastname') + ->setDefaultBilling(1) + ->setDefaultShipping(1); $customer->isObjectNew(true); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; $customer = $objectManager->create(Customer::class); -$customer->setWebsiteId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'julie.worrell@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'Julie' -)->setLastname( - 'Worrell' -)->setDefaultBilling( - 1 -)->setDefaultShipping( - 1 -); +$customer->setWebsiteId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('julie.worrell@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('Julie') + ->setLastname('Worrell') + ->setDefaultBilling(1) + ->setDefaultShipping(1); $customer->isObjectNew(true); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; $customer = $objectManager->create(Customer::class); -$customer->setWebsiteId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'david.lamar@example.com' -)->setPassword( - 'password' -)->setGroupId( - 1 -)->setStoreId( - 1 -)->setIsActive( - 1 -)->setFirstname( - 'David' -)->setLastname( - 'Lamar' -)->setDefaultBilling( - 1 -)->setDefaultShipping( - 1 -); +$customer->setWebsiteId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('david.lamar@example.com') + ->setPassword('password') + ->setGroupId(1) + ->setStoreId(1) + ->setIsActive(1) + ->setFirstname('David') + ->setLastname('Lamar') + ->setDefaultBilling(1) + ->setDefaultShipping(1); $customer->isObjectNew(true); -$customer->save(); +$customerResource->save($customer); $customers[] = $customer; -$objectManager->get(Registry::class) - ->unregister('_fixture/Magento_ImportExport_Customer_Collection'); -$objectManager->get(Registry::class) - ->register('_fixture/Magento_ImportExport_Customer_Collection', $customers); +$objectManager->get(Registry::class)->unregister('_fixture/Magento_ImportExport_Customer_Collection'); +$objectManager->get(Registry::class)->register('_fixture/Magento_ImportExport_Customer_Collection', $customers); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers_for_address_import.php b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers_for_address_import.php index 9a90061a6de76..ca32958e66639 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers_for_address_import.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers_for_address_import.php @@ -3,43 +3,39 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -//Create customer -/** @var Magento\Customer\Model\Customer $customer */ -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -); -$customer->setWebsiteId( - 0 -)->setEntityId( - 1 -)->setEntityTypeId( - 1 -)->setAttributeSetId( - 0 -)->setEmail( - 'BetsyParker@example.com' -)->setPassword( - 'password' -)->setGroupId( - 0 -)->setStoreId( - 0 -)->setIsActive( - 1 -)->setFirstname( - 'Betsy' -)->setLastname( - 'Parker' -)->setGender( - 2 -); + +declare(strict_types=1); + +use Magento\Customer\Model\Address; +use Magento\Customer\Model\Customer; +use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; +use Magento\TestFramework\Helper\Bootstrap; + +$objectManager = Bootstrap::getObjectManager(); + +/** + * @var Customer $customer + * @var CustomerResource $customerResource + */ +$customer = Bootstrap::getObjectManager()->create(Customer::class); +$customerResource = $objectManager->create(CustomerResource::class); + +$customer->setWebsiteId(0) + ->setEntityId(1) + ->setEntityTypeId(1) + ->setAttributeSetId(0) + ->setEmail('BetsyParker@example.com') + ->setPassword('password') + ->setGroupId(0) + ->setStoreId(0) + ->setIsActive(1) + ->setFirstname('Betsy') + ->setLastname('Parker') + ->setGender(2); $customer->isObjectNew(true); -$customer->save(); +$customerResource->save($customer); -// Create and set addresses -$addressFirst = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Address::class -); +$addressFirst = $objectManager->create(Address::class); $addressFirst->addData( [ 'entity_id' => 1, @@ -57,9 +53,7 @@ $customer->addAddress($addressFirst); $customer->setDefaultBilling($addressFirst->getId()); -$addressSecond = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Address::class -); +$addressSecond = $objectManager->create(Address::class); $addressSecond->addData( [ 'entity_id' => 2, @@ -76,4 +70,4 @@ $addressSecond->isObjectNew(true); $customer->addAddress($addressSecond); $customer->setDefaultShipping($addressSecond->getId()); -$customer->save(); +$customerResource->save($customer); diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/sales_order.php b/dev/tests/integration/testsuite/Magento/Customer/_files/sales_order.php deleted file mode 100644 index 2ea0e58fddaba..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/sales_order.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -/** @var \Magento\Customer\Model\Customer $customer */ -$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class -)->load( - 1 -); - -/** @var \Magento\Sales\Model\Order $order */ -$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Sales\Model\Order::class -)->loadByIncrementId( - '100000001' -); -$order->setCustomerIsGuest(false)->setCustomerId($customer->getId())->setCustomerEmail($customer->getEmail()); -$order->save(); diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/CreditmemoSenderTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/CreditmemoSenderTest.php index 72e741493d8f8..bc51f8acb2f6f 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/CreditmemoSenderTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/CreditmemoSenderTest.php @@ -5,10 +5,33 @@ */ namespace Magento\Sales\Model\Order\Email\Sender; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\ResourceModel\CustomerRepository; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Email\Container\CreditmemoIdentity; use Magento\TestFramework\Helper\Bootstrap; class CreditmemoSenderTest extends \PHPUnit\Framework\TestCase { + const NEW_CUSTOMER_EMAIL = 'new.customer@example.com'; + const OLD_CUSTOMER_EMAIL = 'customer@null.com'; + const ORDER_EMAIL = 'customer@null.com'; + + /** + * @var CustomerRepository + */ + private $customerRepository; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $this->customerRepository = Bootstrap::getObjectManager() + ->get(CustomerRepositoryInterface::class); + } + /** * @magentoDataFixture Magento/Sales/_files/order.php */ @@ -35,4 +58,110 @@ public function testSend() $this->assertTrue($result); $this->assertNotEmpty($creditmemo->getEmailSent()); } + + /** + * Test that when a customer email is modified, the credit memo is sent to the new email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasModified() + { + $customer = $this->customerRepository->getById(1); + $customer->setEmail(self::NEW_CUSTOMER_EMAIL); + $this->customerRepository->save($customer); + + $order = $this->createOrder(); + $creditmemo = $this->createCreditmemo($order); + + $this->assertEmpty($creditmemo->getEmailSent()); + + $craditmemoIdentity = $this->createCreditMemoIdentity(); + $creditmemoSender = $this->createCreditMemoSender($craditmemoIdentity); + $result = $creditmemoSender->send($creditmemo, true); + + $this->assertEquals(self::NEW_CUSTOMER_EMAIL, $craditmemoIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($creditmemo->getEmailSent()); + } + + /** + * Test that when a customer email is not modified, the credit memo is sent to the old customer email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasNotModified() + { + $order = $this->createOrder(); + $creditmemo = $this->createCreditmemo($order); + + $this->assertEmpty($creditmemo->getEmailSent()); + + $craditmemoIdentity = $this->createCreditMemoIdentity(); + $creditmemoSender = $this->createCreditMemoSender($craditmemoIdentity); + $result = $creditmemoSender->send($creditmemo, true); + + $this->assertEquals(self::OLD_CUSTOMER_EMAIL, $craditmemoIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($creditmemo->getEmailSent()); + } + + /** + * Test that when an order has not customer the credit memo is sent to the order email + * + * @magentoDataFixture Magento/Sales/_files/order.php + * @magentoAppArea frontend + */ + public function testSendWithoutCustomer() + { + $order = $this->createOrder(); + $creditmemo = $this->createCreditmemo($order); + + $this->assertEmpty($creditmemo->getEmailSent()); + + $creditmemoIdentity = $this->createCreditMemoIdentity(); + $creditmemoSender = $this->createCreditMemoSender($creditmemoIdentity); + $result = $creditmemoSender->send($creditmemo, true); + + $this->assertEquals(self::ORDER_EMAIL, $creditmemoIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($creditmemo->getEmailSent()); + } + + private function createCreditmemo(Order $order): Order\Creditmemo + { + $creditmemo = Bootstrap::getObjectManager()->create( + \Magento\Sales\Model\Order\Creditmemo::class + ); + $creditmemo->setOrder($order); + return $creditmemo; + } + + private function createOrder(): Order + { + $order = Bootstrap::getObjectManager() + ->create(Order::class); + $order->loadByIncrementId('100000001'); + + return $order; + } + + private function createCreditMemoIdentity(): CreditmemoIdentity + { + return Bootstrap::getObjectManager()->create( + CreditmemoIdentity::class + ); + } + + private function createCreditMemoSender(CreditmemoIdentity $creditmemoIdentity): CreditmemoSender + { + return Bootstrap::getObjectManager() + ->create( + CreditmemoSender::class, + [ + 'identityContainer' => $creditmemoIdentity, + ] + ); + } } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/InvoiceSenderTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/InvoiceSenderTest.php index fa3421fe9cc94..60021c7086267 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/InvoiceSenderTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/InvoiceSenderTest.php @@ -5,8 +5,35 @@ */ namespace Magento\Sales\Model\Order\Email\Sender; -class InvoiceSenderTest extends \PHPUnit\Framework\TestCase +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\ResourceModel\CustomerRepository; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Email\Container\InvoiceIdentity; +use Magento\Sales\Model\Order\Invoice; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; + +class InvoiceSenderTest extends TestCase { + const NEW_CUSTOMER_EMAIL = 'new.customer@example.com'; + const OLD_CUSTOMER_EMAIL = 'customer@null.com'; + const ORDER_EMAIL = 'customer@null.com'; + + /** + * @var CustomerRepository + */ + private $customerRepository; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $this->customerRepository = Bootstrap::getObjectManager() + ->get(CustomerRepositoryInterface::class); + } + /** * @magentoDataFixture Magento/Sales/_files/order.php */ @@ -34,4 +61,111 @@ public function testSend() $this->assertTrue($result); $this->assertNotEmpty($invoice->getEmailSent()); } + + /** + * Test that when a customer email is modified, the invoice is sent to the new email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasModified() + { + $customer = $this->customerRepository->getById(1); + $customer->setEmail(self::NEW_CUSTOMER_EMAIL); + $this->customerRepository->save($customer); + + $order = $this->createOrder(); + $invoice = $this->createInvoice($order); + $invoiceIdentity = $this->createInvoiceEntity(); + $invoiceSender = $this->createInvoiceSender($invoiceIdentity); + + $this->assertEmpty($invoice->getEmailSent()); + $result = $invoiceSender->send($invoice, true); + + $this->assertEquals(self::NEW_CUSTOMER_EMAIL, $invoiceIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($invoice->getEmailSent()); + } + + /** + * Test that when a customer email is not modified, the invoice is sent to the old customer email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasNotModified() + { + $order = $this->createOrder(); + $invoice = $this->createInvoice($order); + $invoiceIdentity = $this->createInvoiceEntity(); + $invoiceSender = $this->createInvoiceSender($invoiceIdentity); + + $this->assertEmpty($invoice->getEmailSent()); + $result = $invoiceSender->send($invoice, true); + + $this->assertEquals(self::OLD_CUSTOMER_EMAIL, $invoiceIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($invoice->getEmailSent()); + } + + /** + * Test that when an order has not customer the invoice is sent to the order email + * + * @magentoDataFixture Magento/Sales/_files/order.php + * @magentoAppArea frontend + */ + public function testSendWithoutCustomer() + { + $order = $this->createOrder(); + $invoice = $this->createInvoice($order); + + /** @var InvoiceIdentity $invoiceIdentity */ + $invoiceIdentity = $this->createInvoiceEntity(); + /** @var InvoiceSender $invoiceSender */ + $invoiceSender = $this->createInvoiceSender($invoiceIdentity); + + $this->assertEmpty($invoice->getEmailSent()); + $result = $invoiceSender->send($invoice, true); + + $this->assertEquals(self::ORDER_EMAIL, $invoiceIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($invoice->getEmailSent()); + } + + private function createInvoice(Order $order): Invoice + { + $invoice = Bootstrap::getObjectManager()->create( + Invoice::class + ); + $invoice->setOrder($order); + + return $invoice; + } + + private function createOrder(): Order + { + $order = Bootstrap::getObjectManager() + ->create(Order::class); + $order->loadByIncrementId('100000001'); + + return $order; + } + + private function createInvoiceEntity(): InvoiceIdentity + { + return Bootstrap::getObjectManager()->create( + InvoiceIdentity::class + ); + } + + private function createInvoiceSender(InvoiceIdentity $invoiceIdentity): InvoiceSender + { + return Bootstrap::getObjectManager() + ->create( + InvoiceSender::class, + [ + 'identityContainer' => $invoiceIdentity, + ] + ); + } } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/ShipmentSenderTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/ShipmentSenderTest.php index 83bc7e10647b4..42d8e2bc0bcbb 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/ShipmentSenderTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/ShipmentSenderTest.php @@ -5,6 +5,11 @@ */ namespace Magento\Sales\Model\Order\Email\Sender; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\ResourceModel\CustomerRepository; +use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Email\Container\ShipmentIdentity; +use Magento\Sales\Model\Order\Shipment; use Magento\Sales\Model\Order\ShipmentFactory; use Magento\TestFramework\Helper\Bootstrap; @@ -16,6 +21,25 @@ */ class ShipmentSenderTest extends \PHPUnit\Framework\TestCase { + const NEW_CUSTOMER_EMAIL = 'new.customer@example.com'; + const OLD_CUSTOMER_EMAIL = 'customer@null.com'; + const ORDER_EMAIL = 'customer@null.com'; + + /** + * @var CustomerRepository + */ + private $customerRepository; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $this->customerRepository = Bootstrap::getObjectManager() + ->get(CustomerRepositoryInterface::class); + } + /** * @magentoDataFixture Magento/Sales/_files/order.php */ @@ -39,6 +63,76 @@ public function testSend() $this->assertNotEmpty($shipment->getEmailSent()); } + /** + * Test that when a customer email is modified, the shipment is sent to the new email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasModified() + { + $customer = $this->customerRepository->getById(1); + $customer->setEmail(self::NEW_CUSTOMER_EMAIL); + $this->customerRepository->save($customer); + + $order = $this->createOrder(); + $shipment = $this->createShipment($order); + $shipmentIdentity = $this->createShipmentEntity(); + $shipmentSender = $this->createShipmentSender($shipmentIdentity); + + $this->assertEmpty($shipment->getEmailSent()); + $result = $shipmentSender->send($shipment, true); + + $this->assertEquals(self::NEW_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($shipment->getEmailSent()); + } + + /** + * Test that when a customer email is not modified, the shipment is sent to the old customer email + * + * @magentoDataFixture Magento/Sales/_files/order_with_customer.php + * @magentoAppArea frontend + */ + public function testSendWhenCustomerEmailWasNotModified() + { + $order = $this->createOrder(); + $shipment = $this->createShipment($order); + $shipmentIdentity = $this->createShipmentEntity(); + $shipmentSender = $this->createShipmentSender($shipmentIdentity); + + $this->assertEmpty($shipment->getEmailSent()); + $result = $shipmentSender->send($shipment, true); + + $this->assertEquals(self::OLD_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($shipment->getEmailSent()); + } + + /** + * Test that when an order has not customer the shipment is sent to the order email + * + * @magentoDataFixture Magento/Sales/_files/order.php + * @magentoAppArea frontend + */ + public function testSendWithoutCustomer() + { + $order = $this->createOrder(); + $shipment = $this->createShipment($order); + + /** @var ShipmentIdentity $shipmentIdentity */ + $shipmentIdentity = $this->createShipmentEntity(); + /** @var ShipmentSender $shipmentSender */ + $shipmentSender = $this->createShipmentSender($shipmentIdentity); + + $this->assertEmpty($shipment->getEmailSent()); + $result = $shipmentSender->send($shipment, true); + + $this->assertEquals(self::ORDER_EMAIL, $shipmentIdentity->getCustomerEmail()); + $this->assertTrue($result); + $this->assertNotEmpty($shipment->getEmailSent()); + } + /** * Check the correctness and stability of set/get packages of shipment * @@ -65,4 +159,41 @@ public function testPackages() $shipment->load($shipment->getId()); $this->assertEquals($packages, $shipment->getPackages()); } + + private function createShipment(Order $order): Shipment + { + $shipment = Bootstrap::getObjectManager()->create( + Shipment::class + ); + $shipment->setOrder($order); + + return $shipment; + } + + private function createOrder(): Order + { + $order = Bootstrap::getObjectManager() + ->create(Order::class); + $order->loadByIncrementId('100000001'); + + return $order; + } + + private function createShipmentEntity(): ShipmentIdentity + { + return Bootstrap::getObjectManager()->create( + ShipmentIdentity::class + ); + } + + private function createShipmentSender(ShipmentIdentity $shipmentIdentity): ShipmentSender + { + return Bootstrap::getObjectManager() + ->create( + ShipmentSender::class, + [ + 'identityContainer' => $shipmentIdentity, + ] + ); + } } diff --git a/dev/tests/integration/testsuite/Magento/Theme/Model/Theme/StoreThemesResolverInterfaceTest.php b/dev/tests/integration/testsuite/Magento/Theme/Model/Theme/StoreThemesResolverInterfaceTest.php new file mode 100644 index 0000000000000..2f25d99bad6d2 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Theme/Model/Theme/StoreThemesResolverInterfaceTest.php @@ -0,0 +1,147 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Theme\Model\Theme; + +use Magento\Framework\App\Config\MutableScopeConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory; +use Magento\Theme\Model\ResourceModel\Theme\Collection; +use PHPUnit\Framework\TestCase; + +class StoreThemesResolverInterfaceTest extends TestCase +{ + const XML_PATH_THEME_USER_AGENT = 'design/theme/ua_regexp'; + /** + * @var StoreThemesResolverInterface + */ + private $model; + /** + * @var Collection + */ + private $themesCollection; + /** + * @var MutableScopeConfigInterface + */ + private $mutableScopeConfig; + /** + * @var Json + */ + private $serializer; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** + * @var string + */ + private $userAgentDesignConfig; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + parent::setUp(); + $objectManager = Bootstrap::getObjectManager(); + $this->model = $objectManager->get(StoreThemesResolverInterface::class); + $themesCollectionFactory = $objectManager->get(CollectionFactory::class); + $this->themesCollection = $themesCollectionFactory->create(); + $this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class); + $this->serializer = $objectManager->get(Json::class); + $this->storeManager = $objectManager->get(StoreManagerInterface::class); + $scopeConfig = $objectManager->get(ScopeConfigInterface::class); + $this->userAgentDesignConfig = $scopeConfig->getValue( + self::XML_PATH_THEME_USER_AGENT, + ScopeInterface::SCOPE_STORE + ); + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + $this->mutableScopeConfig->setValue( + self::XML_PATH_THEME_USER_AGENT, + $this->userAgentDesignConfig, + ScopeInterface::SCOPE_STORE + ); + parent::tearDown(); + } + + /** + * @param array $config + * @param array $expected + * @dataProvider getThemesDataProvider + */ + public function testGetThemes(array $config, array $expected): void + { + $store = $this->storeManager->getStore(); + $registeredThemes = []; + foreach ($this->themesCollection as $theme) { + $registeredThemes[$theme->getCode()] = $theme->getId(); + } + // convert themes code to id + foreach ($config as $key => $item) { + $config[$key]['value'] = $registeredThemes[$item['value']]; + } + $this->mutableScopeConfig->setValue( + self::XML_PATH_THEME_USER_AGENT, + $config ? $this->serializer->serialize($config) : null, + ScopeInterface::SCOPE_STORE, + $store->getCode() + ); + $expected = array_map( + function ($theme) use ($registeredThemes) { + return $registeredThemes[$theme]; + }, + $expected + ); + $this->assertEquals( + $expected, + $this->model->getThemes($store), + '', + 0.0, + 10, + true + ); + } + + /** + * @return array + */ + public function getThemesDataProvider(): array + { + return [ + [ + [ + ], + [ + 'Magento/luma' + ] + ], + [ + [ + [ + 'search' => '\/Chrome\/i', + 'regexp' => '\/Chrome\/i', + 'value' => 'Magento/blank', + ] + ], + [ + 'Magento/luma', + 'Magento/blank' + ] + ] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php index 84ee7d8984cc4..cab007aa6af9c 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php @@ -217,6 +217,27 @@ public function testUpdateItemQtyInWishList(): void $this->assertEquals(55, $updatedItem->getQty()); } + /** + * Update description of wishlist item + * + * @magentoDataFixture Magento/Wishlist/_files/wishlist.php + * + * @return void + */ + public function testUpdateItemDescriptionInWishList(): void + { + $itemDescription = 'Test Description'; + $wishlist = $this->getWishlistByCustomerId->execute(1); + $item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple'); + $item->setDescription($itemDescription); + $this->assertNotNull($item); + $buyRequest = $this->dataObjectFactory->create(['data' => ['qty' => 55]]); + $wishlist->updateItem($item, $buyRequest); + $updatedItem = $this->getWishlistByCustomerId->getItemBySku(1, 'simple'); + $this->assertEquals(55, $updatedItem->getQty()); + $this->assertEquals($itemDescription, $updatedItem->getDescription()); + } + /** * @return void */ diff --git a/lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php b/lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php index cd53516290252..d0c05613fbddd 100644 --- a/lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php +++ b/lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php @@ -237,7 +237,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false) $dataToSave = $data; $remHash = $this->loadRemoteDataVersion($id); - if ($remHash !== false) { + if ($remHash !== false && $this->getDataVersion($data) === $remHash) { $dataToSave = $this->remote->load($id); } else { $this->remote->save($data, $id, $tags, $specificLifetime); diff --git a/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php b/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php index bf936c9eb7994..fee9d0a2e15e0 100644 --- a/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php +++ b/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php @@ -248,7 +248,7 @@ public function testClean() $this->remoteSyncCacheInstance->clean(); } - public function testSaveWithRemoteData() + public function testSaveWithEqualRemoteData() { $remoteData = 1; @@ -270,6 +270,21 @@ public function testSaveWithRemoteData() $this->remoteSyncCacheInstance->save($remoteData, 1); } + public function testSaveWithMismatchedRemoteData() + { + $remoteData = '1'; + + $this->remoteCacheMockExample + ->expects($this->at(0)) + ->method('load') + ->willReturn(\hash('sha256', $remoteData)); + + $this->remoteCacheMockExample->expects($this->exactly(2))->method('save'); + $this->localCacheMockExample->expects($this->once())->method('save'); + + $this->remoteSyncCacheInstance->save(2, 1); + } + public function testSaveWithoutRemoteData() { $this->remoteCacheMockExample diff --git a/lib/web/css/source/lib/_navigation.less b/lib/web/css/source/lib/_navigation.less index 38cd042591722..551e138ea06ec 100644 --- a/lib/web/css/source/lib/_navigation.less +++ b/lib/web/css/source/lib/_navigation.less @@ -470,6 +470,8 @@ li { margin: 0; + position: relative; + &.parent { > a { > .ui-menu-icon {