From 9104cb571ef4a41bd03cfaa8dc68b487ccb8946f Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 9 Jun 2020 23:47:36 +0300 Subject: [PATCH 1/9] Remove redundant method --- .../AdvancedPricing/Validator/TierPrice.php | 28 ++++++++++------ .../Validator/TierPriceType.php | 14 +++----- .../AdvancedPricing/Validator/Website.php | 32 +++++++++---------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php index b1f99bb1fc05f..e936244d242dc 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php @@ -3,15 +3,22 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator; use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface; +use Magento\CatalogImportExport\Model\Import\Product\StoreResolver; +use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractPrice; +use Magento\Customer\Api\GroupRepositoryInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; -class TierPrice extends \Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractPrice +class TierPrice extends AbstractPrice { /** - * @var \Magento\CatalogImportExport\Model\Import\Product\StoreResolver + * @var StoreResolver */ protected $storeResolver; @@ -27,14 +34,14 @@ class TierPrice extends \Magento\CatalogImportExport\Model\Import\Product\Valida ]; /** - * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository - * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder - * @param \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver + * @param GroupRepositoryInterface $groupRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param StoreResolver $storeResolver */ public function __construct( - \Magento\Customer\Api\GroupRepositoryInterface $groupRepository, - \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, - \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver + GroupRepositoryInterface $groupRepository, + SearchCriteriaBuilder $searchCriteriaBuilder, + StoreResolver $storeResolver ) { $this->storeResolver = $storeResolver; parent::__construct($groupRepository, $searchCriteriaBuilder); @@ -53,6 +60,7 @@ public function init($context) /** * @param string $attribute + * * @return void */ protected function addDecimalError($attribute) @@ -83,12 +91,12 @@ public function getCustomerGroups() } /** - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * Validation * * @param mixed $value * @return bool * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function isValid($value) { @@ -133,6 +141,7 @@ public function isValid($value) * Check if at list one value and length are valid * * @param array $value + * * @return bool */ protected function isValidValueAndLength(array $value) @@ -150,6 +159,7 @@ protected function isValidValueAndLength(array $value) * Check if value has empty columns * * @param array $value + * * @return bool */ protected function hasEmptyColumns(array $value) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPriceType.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPriceType.php index 6aa59e6227a05..71b5271a90fa2 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPriceType.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPriceType.php @@ -4,28 +4,24 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator; use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface; +use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator; /** * Class TierPriceType validates tier price type. */ -class TierPriceType extends \Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator +class TierPriceType extends AbstractImportValidator { - /** - * {@inheritdoc} - */ - public function init($context) - { - return parent::init($context); - } - /** * Validate tier price type. * * @param array $value + * * @return bool */ public function isValid($value) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php index 0f3f8b3389c7d..a6c6bbb4cd49b 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php @@ -3,49 +3,47 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator; use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing; -use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface; +use Magento\CatalogImportExport\Model\Import\Product\StoreResolver; +use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator; +use Magento\Store\Model\Website as WebsiteModel; class Website extends AbstractImportValidator implements RowValidatorInterface { /** - * @var \Magento\CatalogImportExport\Model\Import\Product\StoreResolver + * @var StoreResolver */ protected $storeResolver; /** - * @var \Magento\Store\Model\Website + * @var WebsiteModel */ protected $websiteModel; /** - * @param \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver - * @param \Magento\Store\Model\Website $websiteModel + * @param StoreResolver $storeResolver + * @param WebsiteModel $websiteModel */ public function __construct( - \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver, - \Magento\Store\Model\Website $websiteModel + StoreResolver $storeResolver, + WebsiteModel $websiteModel ) { $this->storeResolver = $storeResolver; $this->websiteModel = $websiteModel; } - /** - * {@inheritdoc} - */ - public function init($context) - { - return parent::init($context); - } - /** * Validate by website type * * @param array $value * @param string $websiteCode + * * @return bool */ protected function isWebsiteValid($value, $websiteCode) @@ -63,6 +61,7 @@ protected function isWebsiteValid($value, $websiteCode) * Validate value * * @param mixed $value + * * @return bool */ public function isValid($value) @@ -85,6 +84,7 @@ public function isValid($value) */ public function getAllWebsitesValue() { - return AdvancedPricing::VALUE_ALL_WEBSITES . ' ['.$this->websiteModel->getBaseCurrency()->getCurrencyCode().']'; + return AdvancedPricing::VALUE_ALL_WEBSITES . + ' [' . $this->websiteModel->getBaseCurrency()->getCurrencyCode() . ']'; } } From f1516ba52826d8b9a3c1c83538d8fa5bac90cb09 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 10 Jun 2020 00:45:43 +0300 Subject: [PATCH 2/9] fixed static issues --- .../Import/AdvancedPricing/Validator/TierPrice.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php index e936244d242dc..2ad96cfeab1d9 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/TierPrice.php @@ -9,11 +9,14 @@ namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator; use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing; +use Magento\CatalogImportExport\Model\Import\Product; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface; use Magento\CatalogImportExport\Model\Import\Product\StoreResolver; +use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator; use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractPrice; use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Exception\LocalizedException; class TierPrice extends AbstractPrice { @@ -48,7 +51,12 @@ public function __construct( } /** - * {@inheritdoc} + * Initialize method + * + * @param Product $context + * + * @return RowValidatorInterface|AbstractImportValidator|void + * @throws LocalizedException */ public function init($context) { @@ -59,6 +67,8 @@ public function init($context) } /** + * Add decimal error + * * @param string $attribute * * @return void From 6d43eb149677be44be5b76400a1c4b9cba97a1aa Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 10 Jun 2020 11:17:31 +0300 Subject: [PATCH 3/9] add type to parameter --- .../Model/Import/AdvancedPricing/Validator/Website.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php index a6c6bbb4cd49b..93c63dcbcab28 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator/Website.php @@ -60,7 +60,7 @@ protected function isWebsiteValid($value, $websiteCode) /** * Validate value * - * @param mixed $value + * @param array $value * * @return bool */ From fcb60426aa34cd92b88cbd2e994e52dc1adba7b3 Mon Sep 17 00:00:00 2001 From: Dmitry Tsymbal Date: Fri, 19 Jun 2020 14:45:46 +0300 Subject: [PATCH 4/9] Sharing Wishlist with more than allowed Text Length Limit --- ...eThanMaximumAllowedTextLengthLimitTest.xml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml diff --git a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml new file mode 100644 index 0000000000000..807906301466a --- /dev/null +++ b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml @@ -0,0 +1,57 @@ + + + + + + + + + + <description value="Customer should not have a possibility share wishlist with more than maximum allowed Email Text Length Limit"/> + <group value="wishlist"/> + <group value="configuration"/> + </annotations> + <before> + <magentoCLI command="config:set wishlist/email/text_limit 10" stepKey="changeTextLengthLimit"/> + <magentoCLI command="cache:clean config" stepKey="cleanCache"/> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <magentoCLI command="cron:run --group=index" stepKey="runCronIndexer"/> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + </before> + <after> + <magentoCLI command="config:set wishlist/email/text_limit 255" stepKey="returnDefaultValue"/> + <magentoCLI command="cache:clean config" stepKey="cacheClean"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createProduct" stepKey="deleteProduct"/> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + </after> + + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount"> + <argument name="Customer" value="$createCustomer$"/> + </actionGroup> + <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage"> + <argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/> + </actionGroup> + <actionGroup ref="StorefrontCustomerAddProductToWishlistActionGroup" stepKey="addToWishlistProduct"> + <argument name="productVar" value="$createProduct$"/> + </actionGroup> + <actionGroup ref="StorefrontShareCustomerWishlistActionGroup" stepKey="shareWishList"> + <argument name="email" value="{{Wishlist.shareInfo_emails}}"/> + <argument name="message" value="{{Wishlist.shareInfo_message}}"/> + </actionGroup> + <actionGroup ref="AssertMessageCustomerChangeAccountInfoActionGroup" stepKey="assertMessage"> + <argument name="message" value="Message length must not exceed 10 symbols"/> + <argument name="messageType" value="error"/> + </actionGroup> + </test> +</tests> From df84abf89b84520859f9a13b757fabdaaf0c7aac Mon Sep 17 00:00:00 2001 From: Oleh Usik <o.usik@atwix.com> Date: Tue, 23 Jun 2020 16:20:47 +0300 Subject: [PATCH 5/9] MFTF remove redundant cron run --- ...dminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml | 5 ++--- .../Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml | 5 ++--- .../Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml | 5 ++--- .../Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml | 3 +-- .../Test/ApplyCatalogPriceRuleByProductAttributeTest.xml | 5 ++--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml index f8346f5a9dd5c..c5126769cc8c9 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml @@ -37,9 +37,8 @@ <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 1"/> <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> - <!-- Run cron twice --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron1"/> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron2"/> + <!-- Run cron --> + <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml index 0aa89bdfd45b6..8bb47fbc1cb2e 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml @@ -37,9 +37,8 @@ <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 1"/> <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> - <!-- Run cron twice --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron1"/> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron2"/> + <!-- Run cron --> + <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml index 171d15fe6ed4f..b7e94cfbb8679 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml @@ -37,9 +37,8 @@ <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 1"/> <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> - <!-- Run cron twice --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron1"/> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron2"/> + <!-- Run cron --> + <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml index 1950b385c4a68..741e98fa3336b 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml @@ -38,9 +38,8 @@ <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 1"/> <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> - <!-- Run cron twice --> + <!-- Run cron --> <magentoCLI command="cron:run" stepKey="runCron1"/> - <magentoCLI command="cron:run" stepKey="runCron2"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml b/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml index 1919f7d5cc544..2c4e41b8151cf 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml @@ -232,9 +232,8 @@ <see userInput="You saved the rule." selector="{{ContentManagementSection.StoreConfigurationPageSuccessMessage}}" stepKey="seeMessage"/> <see userInput="Updated rules applied." selector="{{ContentManagementSection.StoreConfigurationPageSuccessMessage}}" stepKey="seeSuccessMessage"/> - <!-- Run cron twice --> - <magentoCLI command="cron:run" stepKey="runCron1"/> - <magentoCLI command="cron:run" stepKey="runCron2"/> + <!-- Run cron --> + <magentoCLI command="cron:run" stepKey="runCron"/> <magentoCLI command="cache:flush" stepKey="flushCache"/> <!-- Go to Frontend and open the simple product --> From 2355d97168f0471426b79198ef67e3fca8f626e5 Mon Sep 17 00:00:00 2001 From: Oleh Usik <o.usik@atwix.com> Date: Wed, 24 Jun 2020 22:16:32 +0300 Subject: [PATCH 6/9] changed method for call cron job --- .../AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml | 2 +- .../Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml | 2 +- .../Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml | 2 +- .../Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml | 2 +- .../Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml index c5126769cc8c9..bf9aa5509fa50 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryAndUpdateAsInactiveTest.xml @@ -38,7 +38,7 @@ <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> <!-- Run cron --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> + <magentoCron stepKey="runIndexCronJobs" groups="index"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml index 8bb47fbc1cb2e..3f54f60f382e4 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveFlatCategoryTest.xml @@ -38,7 +38,7 @@ <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> <!-- Run cron --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> + <magentoCron stepKey="runIndexCronJobs" groups="index"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml index b7e94cfbb8679..df9d28637f727 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateInactiveInMenuFlatCategoryTest.xml @@ -38,7 +38,7 @@ <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> <!-- Run cron --> - <magentoCLI command="cron:run" arguments="--group=index" stepKey="runCron"/> + <magentoCron stepKey="runIndexCronJobs" groups="index"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml index 741e98fa3336b..011eae0572a9a 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminUpdateFlatCategoryAndAddProductsTest.xml @@ -39,7 +39,7 @@ <!--Open Index Management Page and Select Index mode "Update by Schedule" --> <magentoCLI stepKey="setIndexerMode" command="indexer:set-mode" arguments="schedule" /> <!-- Run cron --> - <magentoCLI command="cron:run" stepKey="runCron1"/> + <magentoCron stepKey="runAllCronJobs"/> </before> <after> <magentoCLI stepKey="setFlatCatalogCategory" command="config:set catalog/frontend/flat_catalog_category 0 "/> diff --git a/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml b/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml index 2c4e41b8151cf..56144b5908868 100644 --- a/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml +++ b/app/code/Magento/CatalogRule/Test/Mftf/Test/ApplyCatalogPriceRuleByProductAttributeTest.xml @@ -233,7 +233,7 @@ <see userInput="Updated rules applied." selector="{{ContentManagementSection.StoreConfigurationPageSuccessMessage}}" stepKey="seeSuccessMessage"/> <!-- Run cron --> - <magentoCLI command="cron:run" stepKey="runCron"/> + <magentoCron stepKey="runAllCronJobs"/> <magentoCLI command="cache:flush" stepKey="flushCache"/> <!-- Go to Frontend and open the simple product --> From f9d4e0abb7d019b1745f9d85fd20927af1c22c42 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" <engcom-vendorworker-charlie@adobe.com> Date: Fri, 26 Jun 2020 13:22:16 +0300 Subject: [PATCH 7/9] fix samples accessible when product is out of stock --- .../Controller/Download/Sample.php | 103 +++++++++++++----- .../Test/Mftf/Data/ProductData.xml | 11 ++ ...oadableProductSamplesAreAccessibleTest.xml | 78 +++++++++++++ 3 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml diff --git a/app/code/Magento/Downloadable/Controller/Download/Sample.php b/app/code/Magento/Downloadable/Controller/Download/Sample.php index e2561092a7592..839083b320878 100644 --- a/app/code/Magento/Downloadable/Controller/Download/Sample.php +++ b/app/code/Magento/Downloadable/Controller/Download/Sample.php @@ -3,14 +3,21 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + declare(strict_types=1); namespace Magento\Downloadable\Controller\Download; +use Magento\Downloadable\Controller\Download; use Magento\Downloadable\Helper\Download as DownloadHelper; +use Magento\Downloadable\Helper\File; use Magento\Downloadable\Model\RelatedProductRetriever; use Magento\Downloadable\Model\Sample as SampleModel; +use Magento\Downloadable\Model\SampleFactory; use Magento\Framework\App\Action\Context; +use Magento\Catalog\Model\Product\Attribute\Source\Status; +use Magento\CatalogInventory\Api\StockConfigurationInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ResponseInterface; /** @@ -18,24 +25,49 @@ * * @SuppressWarnings(PHPMD.AllPurposeAction) */ -class Sample extends \Magento\Downloadable\Controller\Download +class Sample extends Download { /** * @var RelatedProductRetriever */ private $relatedProductRetriever; + /** + * @var File + */ + private $file; + + /** + * @var SampleFactory + */ + private $sampleFactory; + + /** + * @var StockConfigurationInterface + */ + private $stockConfiguration; + /** * @param Context $context * @param RelatedProductRetriever $relatedProductRetriever + * @param File|null $file + * @param SampleFactory|null $sampleFactory + * @param StockConfigurationInterface|null $stockConfiguration */ public function __construct( Context $context, - RelatedProductRetriever $relatedProductRetriever + RelatedProductRetriever $relatedProductRetriever, + ?File $file = null, + ?SampleFactory $sampleFactory = null, + ?StockConfigurationInterface $stockConfiguration = null ) { parent::__construct($context); $this->relatedProductRetriever = $relatedProductRetriever; + $this->file = $file ?: ObjectManager::getInstance()->get(File::class); + $this->sampleFactory = $sampleFactory ?: ObjectManager::getInstance()->get(SampleFactory::class); + $this->stockConfiguration = $stockConfiguration + ?: ObjectManager::getInstance()->get(StockConfigurationInterface::class); } /** @@ -47,43 +79,60 @@ public function execute() { $sampleId = $this->getRequest()->getParam('sample_id', 0); /** @var SampleModel $sample */ - $sample = $this->_objectManager->create(SampleModel::class); + $sample = $this->sampleFactory->create(); $sample->load($sampleId); - if ($sample->getId() && $this->isProductSalable($sample)) { - $resource = ''; - $resourceType = ''; - if ($sample->getSampleType() == DownloadHelper::LINK_TYPE_URL) { - $resource = $sample->getSampleUrl(); - $resourceType = DownloadHelper::LINK_TYPE_URL; - } elseif ($sample->getSampleType() == DownloadHelper::LINK_TYPE_FILE) { - /** @var \Magento\Downloadable\Helper\File $helper */ - $helper = $this->_objectManager->get(\Magento\Downloadable\Helper\File::class); - $resource = $helper->getFilePath($sample->getBasePath(), $sample->getSampleFile()); - $resourceType = DownloadHelper::LINK_TYPE_FILE; - } - try { - $this->_processDownload($resource, $resourceType); - // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage - exit(0); - } catch (\Exception $e) { - $this->messageManager->addError( - __('Sorry, there was an error getting requested content. Please contact the store owner.') - ); - } + if ($this->isCanDownload($sample)) { + $this->download($sample); } return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl()); } /** - * Check is related product salable. + * Is sample can be downloaded * * @param SampleModel $sample * @return bool */ - private function isProductSalable(SampleModel $sample): bool + private function isCanDownload(SampleModel $sample): bool { $product = $this->relatedProductRetriever->getProduct((int) $sample->getProductId()); - return $product ? $product->isSalable() : false; + if ($product && $sample->getId()) { + $isProductEnabled = (int) $product->getStatus() === Status::STATUS_ENABLED; + + return $product->isSalable() || $this->stockConfiguration->isShowOutOfStock() && $isProductEnabled; + } + + return false; + } + + /** + * Download process + * + * @param SampleModel $sample + * @return void + */ + private function download(SampleModel $sample): void + { + $resource = ''; + $resourceType = ''; + + if ($sample->getSampleType() === DownloadHelper::LINK_TYPE_URL) { + $resource = $sample->getSampleUrl(); + $resourceType = DownloadHelper::LINK_TYPE_URL; + } elseif ($sample->getSampleType() === DownloadHelper::LINK_TYPE_FILE) { + $resource = $this->file->getFilePath($sample->getBasePath(), $sample->getSampleFile()); + $resourceType = DownloadHelper::LINK_TYPE_FILE; + } + + try { + $this->_processDownload($resource, $resourceType); + // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage + exit(0); + } catch (\Exception $e) { + $this->messageManager->addErrorMessage( + __('Sorry, there was an error getting requested content. Please contact the store owner.') + ); + } } } diff --git a/app/code/Magento/Downloadable/Test/Mftf/Data/ProductData.xml b/app/code/Magento/Downloadable/Test/Mftf/Data/ProductData.xml index 2986532ef1138..9dca730dfd5c5 100644 --- a/app/code/Magento/Downloadable/Test/Mftf/Data/ProductData.xml +++ b/app/code/Magento/Downloadable/Test/Mftf/Data/ProductData.xml @@ -105,4 +105,15 @@ <requiredEntity type="downloadable_link">downloadableLink1</requiredEntity> <requiredEntity type="downloadable_link">downloadableLink2</requiredEntity> </entity> + <entity name="DownloadableProductWithoutLinksOutOfStock" type="product"> + <data key="sku" unique="suffix">downloadableproduct</data> + <data key="type_id">downloadable</data> + <data key="attribute_set_id">4</data> + <data key="name" unique="suffix">DownloadableProduct</data> + <data key="price">99.99</data> + <data key="quantity">50</data> + <data key="status">1</data> + <data key="is_in_stock">0</data> + <data key="urlKey" unique="suffix">downloadableproduct</data> + </entity> </entities> diff --git a/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml b/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml new file mode 100644 index 0000000000000..8913ff574264f --- /dev/null +++ b/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml @@ -0,0 +1,78 @@ +<?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="VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest"> + <annotations> + <features value="Downloadable"/> + <stories value="Downloadable product"/> + <title value="Samples of Downloadable Products are accessible, if product is out of stock"/> + <description value="Samples of Downloadable Products are accessible, if product is out of stock"/> + <severity value="MAJOR"/> + <group value="downloadable"/> + <group value="catalog"/> + </annotations> + <before> + <!-- Enable show out of stock product --> + <magentoCLI stepKey="enableShowOutOfStockProduct" command="config:set cataloginventory/options/show_out_of_stock 1"/> + + <!-- Add downloadable domains --> + <magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add example.com static.magento.com"/> + + <!-- Create category --> + <createData entity="_defaultCategory" stepKey="createCategory"/> + + <!-- Create downloadable product --> + <createData entity="DownloadableProductWithoutLinksOutOfStock" stepKey="createProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + + <!-- Add downloadable link --> + <createData entity="downloadableLink1" stepKey="addDownloadableLink"> + <requiredEntity createDataKey="createProduct"/> + </createData> + + <!-- Add downloadable sample --> + <createData entity="DownloadableSample" stepKey="addDownloadableSample"> + <requiredEntity createDataKey="createProduct"/> + </createData> + </before> + <after> + <!-- Disable show out of stock product --> + <magentoCLI stepKey="enableShowOutOfStockProduct" command="config:set cataloginventory/options/show_out_of_stock 0"/> + + <!-- Remove downloadable domains --> + <magentoCLI stepKey="removeDownloadableDomain" command="downloadable:domains:remove example.com static.magento.com"/> + + <!-- Delete product --> + <deleteData createDataKey="createProduct" stepKey="deleteDownloadableProduct"/> + + <!-- Delete category --> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + + <!-- Admin logout --> + <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + </after> + + <!-- Open Downloadable product from precondition on Storefront --> + <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openStorefrontProductPage"> + <argument name="productUrl" value="$createProduct.custom_attributes[url_key]$"/> + </actionGroup> + + <!-- Sample url is accessible --> + <actionGroup ref="AssertStorefrontSeeElementActionGroup" stepKey="seeDownloadableSample"> + <argument name="selector" value="{{StorefrontDownloadableProductSection.downloadableSampleLabel(DownloadableSample.title)}}"/> + </actionGroup> + <click selector="{{StorefrontDownloadableProductSection.downloadableSampleLabel(DownloadableSample.title)}}" stepKey="clickDownloadableSample"/> + <switchToNextTab stepKey="switchToSampleTab"/> + <wait time="2" stepKey="waitToMakeSureThereWillBeNoRedirectToHomePage"/> + <seeInCurrentUrl url="downloadable/download/sample/sample_id/" stepKey="amOnSampleDownloadPage"/> + <closeTab stepKey="closeSampleTab"/> + </test> +</tests> From 0ea00f04b8dab17c396d8248280fed9ab08e5230 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich <51681435+engcom-Echo@users.noreply.github.com> Date: Mon, 6 Jul 2020 16:26:13 +0300 Subject: [PATCH 8/9] add testCaseId --- ...rifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml b/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml index 8913ff574264f..337d4c7dd38b5 100644 --- a/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml +++ b/app/code/Magento/Downloadable/Test/Mftf/Test/VerifyOutOfStockDownloadableProductSamplesAreAccessibleTest.xml @@ -15,6 +15,7 @@ <title value="Samples of Downloadable Products are accessible, if product is out of stock"/> <description value="Samples of Downloadable Products are accessible, if product is out of stock"/> <severity value="MAJOR"/> + <testCaseId value="MC-35639"/> <group value="downloadable"/> <group value="catalog"/> </annotations> From 03253e32852d298c7b5858f2d196d113246d0a3f Mon Sep 17 00:00:00 2001 From: Vadim Malesh <51680850+engcom-Charlie@users.noreply.github.com> Date: Mon, 6 Jul 2020 17:30:21 +0300 Subject: [PATCH 9/9] add test case id --- ...hareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml index 807906301466a..aa69a56cb7cae 100644 --- a/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml +++ b/app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontShareWishlistWithMoreThanMaximumAllowedTextLengthLimitTest.xml @@ -14,6 +14,7 @@ <stories value="Sharing wishlist with more than Maximum Allowed Text Length Limit"/> <title value="Sharing wishlist with more than Maximum Allowed Text Length Limit"/> <description value="Customer should not have a possibility share wishlist with more than maximum allowed Email Text Length Limit"/> + <testCaseId value="MC-35647"/> <group value="wishlist"/> <group value="configuration"/> </annotations>