diff --git a/app/code/Magento/Backend/Model/Auth/Session.php b/app/code/Magento/Backend/Model/Auth/Session.php index e65caf13f2ea3..ec813472695d7 100644 --- a/app/code/Magento/Backend/Model/Auth/Session.php +++ b/app/code/Magento/Backend/Model/Auth/Session.php @@ -114,6 +114,16 @@ public function __construct( ); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_isFirstAfterLogin = null; + $this->acl = null; + } + /** * Refresh ACL resources stored in session * diff --git a/app/code/Magento/Backend/Model/Session/Quote.php b/app/code/Magento/Backend/Model/Session/Quote.php index ed0312874565c..b3067d3c98851 100644 --- a/app/code/Magento/Backend/Model/Session/Quote.php +++ b/app/code/Magento/Backend/Model/Session/Quote.php @@ -139,6 +139,17 @@ public function __construct( } } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_quote = null; + $this->_store = null; + $this->_order = null; + } + /** * Retrieve quote model object * @@ -154,7 +165,7 @@ public function getQuote() $this->_quote->setCustomerGroupId($customerGroupId); $this->_quote->setIsActive(false); $this->_quote->setStoreId($this->getStoreId()); - + $this->quoteRepository->save($this->_quote); $this->setQuoteId($this->_quote->getId()); $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]); diff --git a/app/code/Magento/Backend/Test/Mftf/Section/LocaleOptionsSection.xml b/app/code/Magento/Backend/Test/Mftf/Section/LocaleOptionsSection.xml index 41c8812e7b1e0..268ff07850f43 100644 --- a/app/code/Magento/Backend/Test/Mftf/Section/LocaleOptionsSection.xml +++ b/app/code/Magento/Backend/Test/Mftf/Section/LocaleOptionsSection.xml @@ -18,5 +18,8 @@ + + + diff --git a/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php b/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php index 864e5f4b37721..252ca89ae411b 100644 --- a/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php +++ b/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php @@ -6,9 +6,10 @@ */ namespace Magento\Backup\Controller\Adminhtml\Index; +use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; -class Download extends \Magento\Backup\Controller\Adminhtml\Index +class Download extends \Magento\Backup\Controller\Adminhtml\Index implements HttpGetActionInterface { /** * @var \Magento\Framework\Controller\Result\RawFactory @@ -66,17 +67,12 @@ public function execute() $fileName = $this->_objectManager->get(\Magento\Backup\Helper\Data::class)->generateBackupDownloadName($backup); - $this->_fileFactory->create( + return $this->_fileFactory->create( $fileName, - null, + ['type' => 'filename', 'value' => $backup->getPath() . DIRECTORY_SEPARATOR . $backup->getFileName()], DirectoryList::VAR_DIR, 'application/octet-stream', $backup->getSize() ); - - /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ - $resultRaw = $this->resultRawFactory->create(); - $resultRaw->setContents($backup->output()); - return $resultRaw; } } diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php index 4ae20c711327f..b9c6b67cf1bc7 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php @@ -115,7 +115,7 @@ protected function setUp(): void ->getMock(); $this->backupModelMock = $this->getMockBuilder(Backup::class) ->disableOriginalConstructor() - ->setMethods(['getTime', 'exists', 'getSize', 'output']) + ->setMethods(['getTime', 'exists', 'getSize', 'output', 'getPath', 'getFileName']) ->getMock(); $this->dataHelperMock = $this->getMockBuilder(Data::class) ->disableOriginalConstructor() @@ -169,8 +169,13 @@ public function testExecuteBackupFound() $type = 'db'; $filename = 'filename'; $size = 10; - $output = 'test'; - + $path = 'testpath'; + $this->backupModelMock->expects($this->atLeastOnce()) + ->method('getPath') + ->willReturn($path); + $this->backupModelMock->expects($this->atLeastOnce()) + ->method('getFileName') + ->willReturn($filename); $this->backupModelMock->expects($this->atLeastOnce()) ->method('getTime') ->willReturn($time); @@ -180,9 +185,6 @@ public function testExecuteBackupFound() $this->backupModelMock->expects($this->atLeastOnce()) ->method('getSize') ->willReturn($size); - $this->backupModelMock->expects($this->atLeastOnce()) - ->method('output') - ->willReturn($output); $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnMap( @@ -206,20 +208,14 @@ public function testExecuteBackupFound() $this->fileFactoryMock->expects($this->once()) ->method('create')->with( $filename, - null, + ['type' => 'filename', 'value' => $path . '/' . $filename], DirectoryList::VAR_DIR, 'application/octet-stream', $size ) ->willReturn($this->responseMock); - $this->resultRawMock->expects($this->once()) - ->method('setContents') - ->with($output); - $this->resultRawFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($this->resultRawMock); - $this->assertSame($this->resultRawMock, $this->downloadController->execute()); + $this->assertSame($this->responseMock, $this->downloadController->execute()); } /** diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php index 303c33b571d35..04f4305bdf77d 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php @@ -128,7 +128,6 @@ public function __construct( $metadataPool, $tableMaintainer ); - $this->stockItem = $stockItem ?? ObjectManager::getInstance()->get(\Magento\CatalogInventory\Model\ResourceModel\Stock\Item::class); } @@ -145,6 +144,17 @@ protected function _construct() $this->_selectionTable = $this->getTable('catalog_product_bundle_selection'); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->itemPrototype = null; + $this->catalogRuleProcessor = null; + $this->websiteScopePriceJoined = false; + } + /** * Set store id for each collection item when collection was loaded. * phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod @@ -355,8 +365,6 @@ public function addPriceFilter($product, $searchMin, $useRegularPrice = false) * Get Catalog Rule Processor. * * @return \Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor - * - * @deprecated 100.2.0 */ private function getCatalogRuleProcessor() { diff --git a/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaOnOnepageCheckoutPyamentTest.xml b/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaOnOnepageCheckoutPyamentTest.xml index 912e637dc534e..4ab4ec7f055f9 100644 --- a/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaOnOnepageCheckoutPyamentTest.xml +++ b/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaOnOnepageCheckoutPyamentTest.xml @@ -21,6 +21,7 @@ + 20 @@ -62,6 +63,7 @@ + diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php index 0b1ef98c386c4..ea14dbc1ce627 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php @@ -4,18 +4,21 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Catalog\Controller\Adminhtml\Product; -use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; -use Magento\Backend\App\Action; use Magento\Catalog\Controller\Adminhtml\Product; +use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\RegexValidator; class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface { /** * @var Initialization\StockDataFilter * @deprecated 101.0.0 + * @see Initialization\StockDataFilter */ protected $stockFilter; @@ -30,23 +33,32 @@ class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product implements protected $resultForwardFactory; /** - * @param Action\Context $context + * @var RegexValidator + */ + private RegexValidator $regexValidator; + + /** + * @param Context $context * @param Builder $productBuilder * @param Initialization\StockDataFilter $stockFilter * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + * @param RegexValidator|null $regexValidator */ public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, Initialization\StockDataFilter $stockFilter, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, + RegexValidator $regexValidator = null ) { $this->stockFilter = $stockFilter; parent::__construct($context, $productBuilder); $this->resultPageFactory = $resultPageFactory; $this->resultForwardFactory = $resultForwardFactory; + $this->regexValidator = $regexValidator + ?: ObjectManager::getInstance()->get(RegexValidator::class); } /** @@ -56,6 +68,11 @@ public function __construct( */ public function execute() { + $typeId = $this->getRequest()->getParam('type'); + if (!$this->regexValidator->validateParamRegex($typeId)) { + return $this->resultForwardFactory->create()->forward('noroute'); + } + if (!$this->getRequest()->getParam('set')) { return $this->resultForwardFactory->create()->forward('noroute'); } diff --git a/app/code/Magento/Catalog/Model/Layer/Resolver.php b/app/code/Magento/Catalog/Model/Layer/Resolver.php index a4224aeafe7e0..b6ca16f1ac029 100644 --- a/app/code/Magento/Catalog/Model/Layer/Resolver.php +++ b/app/code/Magento/Catalog/Model/Layer/Resolver.php @@ -9,15 +9,17 @@ namespace Magento\Catalog\Model\Layer; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; + /** * Layer Resolver * * @api */ -class Resolver +class Resolver implements ResetAfterRequestInterface { - const CATALOG_LAYER_CATEGORY = 'category'; - const CATALOG_LAYER_SEARCH = 'search'; + public const CATALOG_LAYER_CATEGORY = 'category'; + public const CATALOG_LAYER_SEARCH = 'search'; /** * Catalog view layer models list @@ -79,4 +81,12 @@ public function get() } return $this->layer; } + + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->layer = null; + } } diff --git a/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php index 4034c75f7373c..85a69a9e69be0 100644 --- a/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php +++ b/app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php @@ -6,6 +6,7 @@ namespace Magento\Catalog\Model\Product\Gallery; +use Magento\AwsS3\Driver\AwsS3; use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface; use Magento\Catalog\Api\Data\ProductInterfaceFactory; use Magento\Catalog\Api\ProductRepositoryInterface; @@ -287,10 +288,18 @@ private function getImageContent($product, $entry): ImageContentInterface $mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); $path = $mediaDirectory->getAbsolutePath($product->getMediaConfig()->getMediaPath($entry->getFile())); $fileName = $this->file->getPathInfo($path)['basename']; - $imageFileContent = $mediaDirectory->getDriver()->fileGetContents($path); + $fileDriver = $mediaDirectory->getDriver(); + $imageFileContent = $fileDriver->fileGetContents($path); + + if ($fileDriver instanceof AwsS3) { + $remoteMediaMimeType = $fileDriver->getMetadata($path); + $mediaMimeType = $remoteMediaMimeType['mimetype']; + } else { + $mediaMimeType = $this->mime->getMimeType($path); + } return $this->imageContentInterface->create() ->setName($fileName) ->setBase64EncodedData(base64_encode($imageFileContent)) - ->setType($this->mime->getMimeType($path)); + ->setType($mediaMimeType); } } diff --git a/app/code/Magento/Catalog/Model/Product/Media/Config.php b/app/code/Magento/Catalog/Model/Product/Media/Config.php index 25c05dad46817..99c2513f5187a 100644 --- a/app/code/Magento/Catalog/Model/Product/Media/Config.php +++ b/app/code/Magento/Catalog/Model/Product/Media/Config.php @@ -30,7 +30,7 @@ class Config implements ConfigInterface, ResetAfterRequestInterface private $attributeHelper; /** - * @var string[] + * @var string[]|null */ private $mediaAttributeCodes; @@ -206,6 +206,6 @@ private function getAttributeHelper() */ public function _resetState(): void { - $this->mediaAttributeCodes = []; + $this->mediaAttributeCodes = null; } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php index 56fb7290b81a6..9df0a3a9b3831 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php @@ -137,6 +137,18 @@ protected function _construct() $this->_init(Category::class, \Magento\Catalog\Model\ResourceModel\Category::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_productTable = null; + $this->_productStoreId = null; + $this->_productWebsiteTable = null; + $this->_loadWithProductCount = false; + } + /** * Add Id filter * diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php b/app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php index a121648b7acba..89dacf5361a69 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php @@ -76,6 +76,15 @@ public function __construct( ); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_storeId = null; + } + /** * Retrieve Entity Primary Key * diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php index 79636c55c0f56..6756aac0786a9 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php @@ -102,6 +102,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac */ protected $_productLimitationFilters; + /** + * @var ProductLimitationFactory + */ + private $productLimitationFactory; + /** * Category product count select * @@ -354,10 +359,10 @@ public function __construct( $this->_resourceHelper = $resourceHelper; $this->dateTime = $dateTime; $this->_groupManagement = $groupManagement; - $productLimitationFactory = $productLimitationFactory ?: ObjectManager::getInstance()->get( + $this->productLimitationFactory = $productLimitationFactory ?: ObjectManager::getInstance()->get( \Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory::class ); - $this->_productLimitationFilters = $productLimitationFactory->create(); + $this->_productLimitationFilters = $this->productLimitationFactory->create(); $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class); parent::__construct( $entityFactory, @@ -387,6 +392,36 @@ public function __construct( ->get(Gallery::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_flatEnabled = []; + $this->_addUrlRewrite = false; + $this->_urlRewriteCategory = ''; + $this->_addFinalPrice = false; + $this->_allIdsCache = null; + $this->_addTaxPercents = false; + $this->_productLimitationFilters = $this->productLimitationFactory->create(); + $this->_productCountSelect = null; + $this->_isWebsiteFilter = false; + $this->_priceDataFieldFilters = []; + $this->_priceExpression = null; + $this->_additionalPriceExpression = null; + $this->_maxPrice = null; + $this->_minPrice = null; + $this->_priceStandardDeviation = null; + $this->_pricesCount = null; + $this->_catalogPreparePriceSelect = null; + $this->needToAddWebsiteNamesToResult = null; + $this->linkField = null; + $this->backend = null; + $this->emptyItem = null; + $this->_construct(); + } + /** * Get cloned Select after dispatching 'catalog_prepare_price_select' event * diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php index 76f566a364769..7100f20ecd96f 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php @@ -46,15 +46,11 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection protected $_comparableAttributes; /** - * Catalog product compare - * * @var \Magento\Catalog\Helper\Product\Compare */ protected $_catalogProductCompare = null; /** - * Catalog product compare item - * * @var \Magento\Catalog\Model\ResourceModel\Product\Compare\Item */ protected $_catalogProductCompareItem; @@ -150,6 +146,18 @@ protected function _construct() $this->_initTables(); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_customerId = 0; + $this->_visitorId = 0; + $this->listId = 0; + $this->_comparableAttributes = null; + } + /** * Set customer filter to collection * @@ -287,7 +295,6 @@ public function getProductsByListId(int $listId): array return $this->getConnection()->fetchCol($select); } - /** * Set list_id for customer compare item * diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php index bca919e700364..cac549e0a17c9 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Link/Product/Collection.php @@ -183,6 +183,21 @@ public function __construct( } } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_product = null; + $this->_linkModel = null; + $this->_linkTypeId = null; + $this->_isStrongMode = null; + $this->_hasLinkFilter = false; + $this->productIds = null; + $this->linkField = null; + } + /** * Declare link model and initialize type attributes join * diff --git a/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminDeleteCreatedColorSpecificAttributeActionGroup.xml b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminDeleteCreatedColorSpecificAttributeActionGroup.xml new file mode 100644 index 0000000000000..2907f88446ec2 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminDeleteCreatedColorSpecificAttributeActionGroup.xml @@ -0,0 +1,29 @@ + + + + + + + Delete the created new colors in color attribute + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeGridSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeGridSection.xml index 455cde4c1d70c..8e2877b47b64a 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeGridSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductAttributeGridSection.xml @@ -24,6 +24,7 @@ + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/AdminProductFormSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/AdminProductFormSection.xml index 0a3c67bc00d5b..f0a1b0f2e9452 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/AdminProductFormSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection/AdminProductFormSection.xml @@ -83,5 +83,9 @@ + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategorySidebarSection/StorefrontCategorySidebarSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategorySidebarSection/StorefrontCategorySidebarSection.xml index 26a5452ee018c..6edef36fd98f4 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategorySidebarSection/StorefrontCategorySidebarSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategorySidebarSection/StorefrontCategorySidebarSection.xml @@ -27,5 +27,9 @@ + + + + diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductInfoMainSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductInfoMainSection.xml index 5ec949332a36b..370487075c3c0 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductInfoMainSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductInfoMainSection.xml @@ -30,6 +30,7 @@ + diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AddNewProductAttributeInProductPageTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AddNewProductAttributeInProductPageTest.xml index 38fc09c9cafb7..1aaa26d893fcb 100755 --- a/app/code/Magento/Catalog/Test/Mftf/Test/AddNewProductAttributeInProductPageTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/AddNewProductAttributeInProductPageTest.xml @@ -22,6 +22,7 @@ + @@ -99,11 +100,11 @@ - + + - diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/EndToEndB2CAdminTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/EndToEndB2CAdminTest.xml index 3b0fad592fed8..7a10c0e949e31 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/EndToEndB2CAdminTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/EndToEndB2CAdminTest.xml @@ -18,13 +18,16 @@ + + + + - diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyCategoryPageNotCachedTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyCategoryPageNotCachedTest.xml new file mode 100644 index 0000000000000..6c79b40b3ff94 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyCategoryPageNotCachedTest.xml @@ -0,0 +1,147 @@ + + + + + + + + + <stories value="Product Categories Indexer"/> + <description value="Verify that the category page is NOT cached for customers with different tax rates"/> + <severity value="AVERAGE"/> + <group value="Catalog"/> + <group value="indexer"/> + </annotations> + <before> + <!--Login to Admin Panel--> + <actionGroup ref="AdminLoginActionGroup" stepKey="logInAsAdmin"/> + <!-- Create tax rate for CA --> + <createData entity="US_CA_Rate_1" stepKey="createTaxRateCA"/> + <!-- Create tax rate for TX --> + <createData entity="ThirdTaxRateTexas" stepKey="createTaxRateTX"/> + <!-- Create Tax Rules --> + <actionGroup ref="AdminCreateTaxRuleActionGroup" stepKey="createTaxRule1"> + <argument name="taxRate" value="$$createTaxRateCA$$"/> + <argument name="taxRule" value="SimpleTaxRule"/> + </actionGroup> + <actionGroup ref="AdminCreateTaxRuleActionGroup" stepKey="createTaxRule2"> + <argument name="taxRate" value="$$createTaxRateTX$$"/> + <argument name="taxRule" value="SimpleTaxRule2"/> + </actionGroup> + <!--Create Customers--> + <createData entity="Simple_US_CA_Customer" stepKey="createCustomerCA"/> + <createData entity="Simple_US_Customer" stepKey="createCustomerTX"/> + <!--Create Category--> + <createData entity="_defaultCategory" stepKey="createCategory"/> + <!--Create Products--> + <createData entity="SimpleProduct" stepKey="simpleProduct"> + <field key="price">100</field> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="SimpleProduct" stepKey="simpleProduct2"> + <field key="price">200</field> + <requiredEntity createDataKey="createCategory"/> + </createData> + <!--Display product price including and excluding tax in catalog--> + <magentoCLI command="config:set tax/display/type 3" stepKey="enableShowIncludingExcludingTax"/> + </before> + <after> + <magentoCLI command="config:set tax/display/type 0" stepKey="disableShowIncludingExcludingTax"/> + <!--Delete Products--> + <deleteData createDataKey="simpleProduct" stepKey="deleteProductOne"/> + <deleteData createDataKey="simpleProduct2" stepKey="deleteProductTwo"/> + <!--Delete Category--> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <!--Delete Tax Rules--> + <actionGroup ref="AdminDeleteTaxRule" stepKey="deleteTaxRule1"> + <argument name="taxRuleCode" value="{{SimpleTaxRule.code}}"/> + </actionGroup> + <actionGroup ref="AdminDeleteTaxRule" stepKey="deleteTaxRule2"> + <argument name="taxRuleCode" value="{{SimpleTaxRule2.code}}"/> + </actionGroup> + <!--Delete Tax Rates--> + <deleteData createDataKey="createTaxRateCA" stepKey="deleteTaxRate1"/> + <deleteData createDataKey="createTaxRateTX" stepKey="deleteTaxRate2"/> + <!--Delete Customers--> + <deleteData createDataKey="createCustomerCA" stepKey="deleteCustomer1"/> + <deleteData createDataKey="createCustomerTX" stepKey="deleteCustomer2"/> + <!--Logout Admin--> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAdmin"/> + </after> + + <!-- Login as customer 1--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="storefrontCustomer1Login"> + <argument name="Customer" value="$$createCustomerCA$$"/> + </actionGroup> + <!-- Assert Customer Name --> + <actionGroup ref="AssertCustomerWelcomeMessageActionGroup" stepKey="assertCustomerName"> + <argument name="customerFullName" value="$$createCustomerCA.firstname$$ $$createCustomerCA.lastname$$" /> + </actionGroup> + <!-- Navigate to category page --> + <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage"> + <argument name="category" value="$$createCategory$$"/> + </actionGroup> + <!-- Assert Product Prices --> + <actionGroup ref="StorefrontAssertProductPriceOnCategoryPageActionGroup" stepKey="seeProduct1TaxInclusivePriceCustomer1"> + <argument name="productName" value="$$simpleProduct.name$$"/> + <argument name="productPrice" value="$108.25"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductPriceOnCategoryPageActionGroup" stepKey="seeProduct2TaxInclusivePriceCustomer1"> + <argument name="productName" value="$$simpleProduct2.name$$"/> + <argument name="productPrice" value="$216.50"/> + </actionGroup> + <!--Add first product to compare list and cart --> + <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openFirstProductPage"> + <argument name="productUrl" value="$$simpleProduct.custom_attributes[url_key]$$"/> + </actionGroup> + <actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addFirstProductToCompare"> + <argument name="productVar" value="$$simpleProduct$$"/> + </actionGroup> + <actionGroup ref="StorefrontClickAddToCartOnProductPageActionGroup" stepKey="addFirstProductToCart"/> + <!--Add second product to compare list --> + <actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openSecondProductPage"> + <argument name="productUrl" value="$$simpleProduct2.custom_attributes[url_key]$$"/> + </actionGroup> + <actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addSecondProductToCompare"> + <argument name="productVar" value="$$simpleProduct2$$"/> + </actionGroup> + <!--Add second product to wishlist --> + <actionGroup ref="StorefrontCustomerAddProductToWishlistActionGroup" stepKey="addSecondProductToWishlist"> + <argument name="productVar" value="$$simpleProduct2$$"/> + </actionGroup> + <!-- Customer 1 logout --> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customer1Logout"/> + <!-- Customer 2 login --> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="storefrontCustomer2Login"> + <argument name="Customer" value="$$createCustomerTX$$"/> + </actionGroup> + <!-- Assert Wishlist is empty --> + <actionGroup ref="NavigateThroughCustomerTabsActionGroup" stepKey="navigateToWishlist"> + <argument name="navigationItemName" value="My Wish List"/> + </actionGroup> + <actionGroup ref="StorefrontAssertCustomerWishlistIsEmptyActionGroup" stepKey="assertNoItemsInWishlist"/> + <!-- Assert minicart is empty --> + <actionGroup ref="AssertMiniCartEmptyActionGroup" stepKey="assertMiniCartIsEmpty"/> + <!-- Navigate to category page --> + <actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage2"> + <argument name="category" value="$$createCategory$$"/> + </actionGroup> + <!-- Assert Compare list is empty --> + <seeElement selector="{{StorefrontComparisonSidebarSection.NoItemsMessage}}" stepKey="assertCompareListIsEmpty"/> + <!-- Assert Product Prices --> + <actionGroup ref="StorefrontAssertProductPriceOnCategoryPageActionGroup" stepKey="seeProduct1TaxInclusivePriceCustomer2"> + <argument name="productName" value="$$simpleProduct.name$$"/> + <argument name="productPrice" value="$120"/> + </actionGroup> + <actionGroup ref="StorefrontAssertProductPriceOnCategoryPageActionGroup" stepKey="seeProduct2TaxInclusivePriceCustomer2"> + <argument name="productName" value="$$simpleProduct2.name$$"/> + <argument name="productPrice" value="$240"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php old mode 100644 new mode 100755 index 974c85b2b5c98..cad43f39f0261 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/NewActionTest.php @@ -16,6 +16,9 @@ use Magento\Catalog\Controller\Adminhtml\Product\NewAction; use Magento\Catalog\Model\Product; use Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTest; +use Magento\Framework\RegexValidator; +use Magento\Framework\Validator\Regex; +use Magento\Framework\Validator\RegexFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\Result\PageFactory; use PHPUnit\Framework\MockObject\MockObject; @@ -42,6 +45,26 @@ class NewActionTest extends ProductTest */ protected $initializationHelper; + /** + * @var RegexValidator|MockObject + */ + private $regexValidator; + + /** + * @var RegexFactory + */ + private $regexValidatorFactoryMock; + + /** + * @var Regex|MockObject + */ + private $regexValidatorMock; + + /** + * @var ForwardFactory&MockObject|MockObject + */ + private $resultForwardFactory; + protected function setUp(): void { $this->productBuilder = $this->createPartialMock( @@ -63,37 +86,78 @@ protected function setUp(): void ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $resultPageFactory->expects($this->atLeastOnce()) - ->method('create') - ->willReturn($this->resultPage); $this->resultForward = $this->getMockBuilder(Forward::class) ->disableOriginalConstructor() ->getMock(); - $resultForwardFactory = $this->getMockBuilder(ForwardFactory::class) + $this->resultForwardFactory = $this->getMockBuilder(ForwardFactory::class) + ->disableOriginalConstructor() + ->onlyMethods(['create']) + ->getMock(); + + $this->regexValidatorFactoryMock = $this->getMockBuilder(RegexFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $resultForwardFactory->expects($this->any()) - ->method('create') - ->willReturn($this->resultForward); + $this->regexValidatorMock = $this->createMock(Regex::class); + $this->regexValidatorFactoryMock->method('create') + ->willReturn($this->regexValidatorMock); + $this->regexValidator = new regexValidator($this->regexValidatorFactoryMock); $this->action = (new ObjectManager($this))->getObject( NewAction::class, [ 'context' => $this->initContext(), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, - 'resultForwardFactory' => $resultForwardFactory, + 'resultForwardFactory' => $this->resultForwardFactory, + 'regexValidator' => $this->regexValidator, ] ); } - public function testExecute() + /** + * Test execute method input validation. + * + * @param string $value + * @param bool $exceptionThrown + * @dataProvider validationCases + */ + public function testExecute(string $value, bool $exceptionThrown): void + { + if ($exceptionThrown) { + $this->action->getRequest()->expects($this->any()) + ->method('getParam') + ->willReturn($value); + $this->resultForwardFactory->expects($this->any()) + ->method('create') + ->willReturn($this->resultForward); + $this->resultForward->expects($this->once()) + ->method('forward') + ->with('noroute') + ->willReturn(true); + $this->assertTrue($this->action->execute()); + } else { + $this->action->getRequest()->expects($this->any())->method('getParam')->willReturn($value); + $this->regexValidatorMock->expects($this->any()) + ->method('isValid') + ->with($value) + ->willReturn(true); + + $this->assertEquals(true, $this->regexValidator->validateParamRegex($value)); + } + } + + /** + * Validation cases. + * + * @return array + */ + public function validationCases(): array { - $this->action->getRequest()->expects($this->any())->method('getParam')->willReturn(true); - $this->action->getRequest()->expects($this->any())->method('getFullActionName') - ->willReturn('catalog_product_new'); - $this->action->execute(); + return [ + 'execute-with-exception' => ['simple\' and true()]|*[self%3a%3ahandle%20or%20self%3a%3alayout',true], + 'execute-without-exception' => ['catalog_product_new',false] + ]; } } diff --git a/app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php b/app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php index 2b98e35b52de1..eadf47601585d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php @@ -15,8 +15,11 @@ use Magento\Catalog\Pricing\Render\FinalPriceBox; use Magento\Framework\App\Cache\StateInterface; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\State; +use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Event\Test\Unit\ManagerStub; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Pricing\Amount\AmountInterface; use Magento\Framework\Pricing\Price\PriceInterface; use Magento\Framework\Pricing\PriceInfoInterface; @@ -96,11 +99,27 @@ class FinalPriceBoxTest extends TestCase */ private $minimalPriceCalculator; + /** + * @var DeploymentConfig|MockObject + */ + private $deploymentConfig; + + /** + * @var ObjectManagerInterface|MockObject + */ + private $objectManagerMock; + /** * @inheritDoc + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp(): void { + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->onlyMethods(['get']) + ->getMockForAbstractClass(); + \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock); $this->product = $this->getMockBuilder(Product::class) ->addMethods(['getCanShowPrice']) ->onlyMethods(['getPriceInfo', 'isSalable', 'getId']) @@ -183,6 +202,11 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMockForAbstractClass(); + $this->deploymentConfig = $this->createPartialMock( + DeploymentConfig::class, + ['get'] + ); + $this->minimalPriceCalculator = $this->getMockForAbstractClass(MinimalPriceCalculatorInterface::class); $this->object = $objectManager->getObject( FinalPriceBox::class, @@ -455,6 +479,15 @@ public function testHidePrice(): void */ public function testGetCacheKey(): void { + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with(DeploymentConfig::class) + ->willReturn($this->deploymentConfig); + + $this->deploymentConfig->expects($this->any()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY) + ->willReturn('448198e08af35844a42d3c93c1ef4e03'); $result = $this->object->getCacheKey(); $this->assertStringEndsWith('list-category-page', $result); } diff --git a/app/code/Magento/Catalog/composer.json b/app/code/Magento/Catalog/composer.json index 4421b2991266b..73f8d988bf270 100644 --- a/app/code/Magento/Catalog/composer.json +++ b/app/code/Magento/Catalog/composer.json @@ -31,7 +31,8 @@ "magento/module-ui": "*", "magento/module-url-rewrite": "*", "magento/module-widget": "*", - "magento/module-wishlist": "*" + "magento/module-wishlist": "*", + "magento/module-aws-s3": "*" }, "suggest": { "magento/module-cookie": "*", diff --git a/app/code/Magento/Catalog/i18n/en_US.csv b/app/code/Magento/Catalog/i18n/en_US.csv index defbf31a6b8f8..81e059adb3bb0 100644 --- a/app/code/Magento/Catalog/i18n/en_US.csv +++ b/app/code/Magento/Catalog/i18n/en_US.csv @@ -819,4 +819,5 @@ Details,Details "Failed to retrieve product links for ""%1""","Failed to retrieve product links for ""%1""" "The linked product SKU is invalid. Verify the data and try again.","The linked product SKU is invalid. Verify the data and try again." "The linked products data is invalid. Verify the data and try again.","The linked products data is invalid. Verify the data and try again." +"The url has invalid characters. Please correct and try again.","The url has invalid characters. Please correct and try again." diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js b/app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js index d292bd126593c..b4d4ed12d20ba 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js @@ -5,10 +5,9 @@ define([ 'jquery', - 'mageUtils', 'jquery/ui', 'jquery/jstree/jquery.jstree' -], function ($, utils) { +], function ($) { 'use strict'; $.widget('mage.categoryTree', { @@ -87,7 +86,7 @@ define([ // jscs:disable requireCamelCaseOrUpperCaseIdentifiers result = { id: node.id, - text: utils.unescape(node.name) + ' (' + node.product_count + ')', + text: node.name + ' (' + node.product_count + ')', li_attr: { class: node.cls + (!!node.disabled ? ' disabled' : '') //eslint-disable-line no-extra-boolean-cast }, diff --git a/app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php b/app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php index c9591d1cbcf6b..63a998022df80 100644 --- a/app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php +++ b/app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php @@ -10,6 +10,7 @@ use GraphQL\Language\AST\FieldNode; use GraphQL\Language\AST\InlineFragmentNode; use GraphQL\Language\AST\NodeKind; +use GraphQL\Language\AST\NodeList; use Magento\Eav\Model\Entity\Collection\AbstractCollection; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\ObjectManager\ResetAfterRequestInterface; @@ -69,37 +70,49 @@ public function getQueryFields(FieldNode $fieldNode, ResolveInfo $resolveInfo): { if (null === $this->getFieldNodeSelections($fieldNode)) { $query = $fieldNode->selectionSet->selections; - $selectedFields = []; - $fragmentFields = []; /** @var FieldNode $field */ - foreach ($query as $field) { - if ($field->kind === NodeKind::INLINE_FRAGMENT) { - $fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $field); - } elseif ($field->kind === NodeKind::FRAGMENT_SPREAD && - ($spreadFragmentNode = $resolveInfo->fragments[$field->name->value])) { - - foreach ($spreadFragmentNode->selectionSet->selections as $spreadNode) { - if (isset($spreadNode->selectionSet->selections) - && $spreadNode->kind === NodeKind::INLINE_FRAGMENT) { - $fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $spreadNode); - } elseif (isset($spreadNode->selectionSet->selections) - && $spreadNode->kind !== NodeKind::INLINE_FRAGMENT) { - $fragmentFields[] = $this->getQueryFields($spreadNode, $resolveInfo); - } else { + $result = $this->getQueryData($query, $resolveInfo); + if ($result['fragmentFields']) { + $result['selectedFields'] = array_merge([], $result['selectedFields'], ...$result['fragmentFields']); + } + $this->setSelectionsForFieldNode($fieldNode, array_unique($result['selectedFields'])); + } + return $this->getFieldNodeSelections($fieldNode); + } + + /** + * Get an array of queried data. + * + * @param NodeList $query + * @param ResolveInfo $resolveInfo + * @return array + */ + public function getQueryData(NodeList $query, ResolveInfo $resolveInfo): array + { + $selectedFields = $fragmentFields = $data = []; + foreach ($query as $field) { + if ($field->kind === NodeKind::INLINE_FRAGMENT) { + $fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $field); + } elseif ($field->kind === NodeKind::FRAGMENT_SPREAD && + ($spreadFragmentNode = $resolveInfo->fragments[$field->name->value])) { + foreach ($spreadFragmentNode->selectionSet->selections as $spreadNode) { + if (isset($spreadNode->selectionSet->selections)) { + if ($spreadNode->kind === NodeKind::FIELD && isset($spreadNode->name)) { $selectedFields[] = $spreadNode->name->value; } + $fragmentFields[] = $this->getQueryFields($spreadNode, $resolveInfo); + } else { + $selectedFields[] = $spreadNode->name->value; } - } else { - $selectedFields[] = $field->name->value; } + } else { + $selectedFields[] = $field->name->value; } - if ($fragmentFields) { - $selectedFields = array_merge([], $selectedFields, ...$fragmentFields); - } - $this->setSelectionsForFieldNode($fieldNode, array_unique($selectedFields)); } + $data['selectedFields'] = $selectedFields; + $data['fragmentFields'] = $fragmentFields; - return $this->getFieldNodeSelections($fieldNode); + return $data; } /** @@ -117,15 +130,22 @@ private function addInlineFragmentFields( ): array { $query = $inlineFragmentField->selectionSet->selections; /** @var FieldNode $field */ + $fragmentFields = []; foreach ($query as $field) { if ($field->kind === NodeKind::INLINE_FRAGMENT) { $this->addInlineFragmentFields($resolveInfo, $field, $inlineFragmentFields); } elseif (isset($field->selectionSet->selections)) { - continue; + if ($field->kind === NodeKind::FIELD && isset($field->name)) { + $inlineFragmentFields[] = $field->name->value; + } + $fragmentFields[] = $this->getQueryFields($field, $resolveInfo); } else { $inlineFragmentFields[] = $field->name->value; } } + if ($fragmentFields) { + $inlineFragmentFields = array_merge([], $inlineFragmentFields, ...$fragmentFields); + } return array_unique($inlineFragmentFields); } diff --git a/app/code/Magento/CatalogGraphQl/Model/Config/SortAttributeReader.php b/app/code/Magento/CatalogGraphQl/Model/Config/SortAttributeReader.php index 215b28be0579c..2f16e9ccb318f 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Config/SortAttributeReader.php +++ b/app/code/Magento/CatalogGraphQl/Model/Config/SortAttributeReader.php @@ -6,9 +6,11 @@ namespace Magento\CatalogGraphQl\Model\Config; +use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as AttributesCollection; +use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributesCollectionFactory; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Config\ReaderInterface; use Magento\Framework\GraphQl\Schema\Type\Entity\MapperInterface; -use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as AttributesCollection; /** * Adds custom/eav attribute to catalog products sorting in the GraphQL config. @@ -31,20 +33,24 @@ class SortAttributeReader implements ReaderInterface private $mapper; /** - * @var AttributesCollection + * @var AttributesCollectionFactory */ - private $attributesCollection; + private $attributesCollectionFactory; /** * @param MapperInterface $mapper - * @param AttributesCollection $attributesCollection + * @param AttributesCollection $attributesCollection @deprecated @see $attributesCollectionFactory + * @param AttributesCollectionFactory|null $attributesCollectionFactory + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( MapperInterface $mapper, - AttributesCollection $attributesCollection + AttributesCollection $attributesCollection, + ?AttributesCollectionFactory $attributesCollectionFactory = null ) { $this->mapper = $mapper; - $this->attributesCollection = $attributesCollection; + $this->attributesCollectionFactory = $attributesCollectionFactory + ?? ObjectManager::getInstance()->get(AttributesCollectionFactory::class); } /** @@ -58,7 +64,8 @@ public function read($scope = null) : array { $map = $this->mapper->getMappedTypes(self::ENTITY_TYPE); $config =[]; - $attributes = $this->attributesCollection->addSearchableAttributeFilter()->addFilter('used_for_sort_by', 1); + $attributes = $this->attributesCollectionFactory->create() + ->addSearchableAttributeFilter()->addFilter('used_for_sort_by', 1); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */ foreach ($attributes as $attribute) { $attributeCode = $attribute->getAttributeCode(); @@ -73,7 +80,6 @@ public function read($scope = null) : array ]; } } - return $config; } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductFieldsSelector.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductFieldsSelector.php index 3139c35774008..ab9fed035cc35 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductFieldsSelector.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductFieldsSelector.php @@ -7,7 +7,7 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; -use GraphQL\Language\AST\NodeKind; +use Magento\CatalogGraphQl\Model\AttributesJoiner; use Magento\Framework\GraphQl\Query\FieldTranslator; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -19,14 +19,23 @@ class ProductFieldsSelector /** * @var FieldTranslator */ - private $fieldTranslator; + private FieldTranslator $fieldTranslator; + + /** + * @var AttributesJoiner + */ + private AttributesJoiner $attributesJoiner; /** * @param FieldTranslator $fieldTranslator + * @param AttributesJoiner $attributesJoiner */ - public function __construct(FieldTranslator $fieldTranslator) - { + public function __construct( + FieldTranslator $fieldTranslator, + AttributesJoiner $attributesJoiner + ) { $this->fieldTranslator = $fieldTranslator; + $this->attributesJoiner = $attributesJoiner; } /** @@ -36,27 +45,17 @@ public function __construct(FieldTranslator $fieldTranslator) * @param string $productNodeName * @return string[] */ - public function getProductFieldsFromInfo(ResolveInfo $info, string $productNodeName = 'product') : array + public function getProductFieldsFromInfo(ResolveInfo $info, string $productNodeName = 'product'): array { $fieldNames = []; foreach ($info->fieldNodes as $node) { if ($node->name->value !== $productNodeName) { continue; } - foreach ($node->selectionSet->selections as $selectionNode) { - if ($selectionNode->kind === NodeKind::INLINE_FRAGMENT) { - foreach ($selectionNode->selectionSet->selections as $inlineSelection) { - if ($inlineSelection->kind === NodeKind::INLINE_FRAGMENT) { - continue; - } - $fieldNames[] = $this->fieldTranslator->translate($inlineSelection->name->value); - } - continue; - } - $fieldNames[] = $this->fieldTranslator->translate($selectionNode->name->value); - } + $queryFields = $this->attributesJoiner->getQueryFields($node, $info); + $fieldNames[] = $queryFields; } - return $fieldNames; + return array_merge(...$fieldNames); } } diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 9d050ce6170bf..a0ee8d77d69f3 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -51,6 +51,7 @@ */ class Product extends AbstractEntity { + private const COL_NAME_FORMAT = '/[\x00-\x1F\x7F]/'; private const DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR = ','; public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types'; @@ -1633,6 +1634,10 @@ protected function _saveProducts() // the bunch of products will pass for the event with url_key column. $bunch[$rowNum][self::URL_KEY] = $rowData[self::URL_KEY] = $urlKey; } + if (!empty($rowData[self::COL_NAME])) { + // remove null byte character + $rowData[self::COL_NAME] = preg_replace(self::COL_NAME_FORMAT, '', $rowData[self::COL_NAME]); + } $rowSku = $rowData[self::COL_SKU]; if (null === $rowSku) { $this->getErrorAggregator()->addRowToSkip($rowNum); diff --git a/app/code/Magento/CatalogInventory/Helper/Minsaleqty.php b/app/code/Magento/CatalogInventory/Helper/Minsaleqty.php index 96bf5bd965355..1ee8e1a97e89f 100644 --- a/app/code/Magento/CatalogInventory/Helper/Minsaleqty.php +++ b/app/code/Magento/CatalogInventory/Helper/Minsaleqty.php @@ -8,13 +8,14 @@ use Magento\Customer\Api\GroupManagementInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Magento\Framework\Serialize\Serializer\Json; use Magento\Store\Model\Store; /** * MinSaleQty value manipulation helper */ -class Minsaleqty +class Minsaleqty implements ResetAfterRequestInterface { /** * Core store config @@ -61,6 +62,14 @@ public function __construct( $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->minSaleQtyCache = []; + } + /** * Retrieve fixed qty value * diff --git a/app/code/Magento/CatalogInventory/Model/Configuration.php b/app/code/Magento/CatalogInventory/Model/Configuration.php index 8b0849c8874bc..9df634c225d71 100644 --- a/app/code/Magento/CatalogInventory/Model/Configuration.php +++ b/app/code/Magento/CatalogInventory/Model/Configuration.php @@ -9,98 +9,96 @@ use Magento\CatalogInventory\Helper\Minsaleqty as MinsaleqtyHelper; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Catalog\Model\ProductTypes\ConfigInterface; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; -/** - * Class Configuration - */ -class Configuration implements StockConfigurationInterface +class Configuration implements StockConfigurationInterface, ResetAfterRequestInterface { /** * Default website id */ - const DEFAULT_WEBSITE_ID = 1; + public const DEFAULT_WEBSITE_ID = 1; /** * Inventory options config path */ - const XML_PATH_GLOBAL = 'cataloginventory/options/'; + public const XML_PATH_GLOBAL = 'cataloginventory/options/'; /** * Subtract config path */ - const XML_PATH_CAN_SUBTRACT = 'cataloginventory/options/can_subtract'; + public const XML_PATH_CAN_SUBTRACT = 'cataloginventory/options/can_subtract'; /** * Back in stock config path */ - const XML_PATH_CAN_BACK_IN_STOCK = 'cataloginventory/options/can_back_in_stock'; + public const XML_PATH_CAN_BACK_IN_STOCK = 'cataloginventory/options/can_back_in_stock'; /** * Item options config path */ - const XML_PATH_ITEM = 'cataloginventory/item_options/'; + public const XML_PATH_ITEM = 'cataloginventory/item_options/'; /** * Max qty config path */ - const XML_PATH_MIN_QTY = 'cataloginventory/item_options/min_qty'; + public const XML_PATH_MIN_QTY = 'cataloginventory/item_options/min_qty'; /** * Min sale qty config path */ - const XML_PATH_MIN_SALE_QTY = 'cataloginventory/item_options/min_sale_qty'; + public const XML_PATH_MIN_SALE_QTY = 'cataloginventory/item_options/min_sale_qty'; /** * Max sale qty config path */ - const XML_PATH_MAX_SALE_QTY = 'cataloginventory/item_options/max_sale_qty'; + public const XML_PATH_MAX_SALE_QTY = 'cataloginventory/item_options/max_sale_qty'; /** * Back orders config path */ - const XML_PATH_BACKORDERS = 'cataloginventory/item_options/backorders'; + public const XML_PATH_BACKORDERS = 'cataloginventory/item_options/backorders'; /** * Notify stock config path */ - const XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty'; + public const XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty'; /** * Manage stock config path */ - const XML_PATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock'; + public const XML_PATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock'; /** * Enable qty increments config path */ - const XML_PATH_ENABLE_QTY_INCREMENTS = 'cataloginventory/item_options/enable_qty_increments'; + public const XML_PATH_ENABLE_QTY_INCREMENTS = 'cataloginventory/item_options/enable_qty_increments'; /** * Qty increments config path */ - const XML_PATH_QTY_INCREMENTS = 'cataloginventory/item_options/qty_increments'; + public const XML_PATH_QTY_INCREMENTS = 'cataloginventory/item_options/qty_increments'; /** * Show out of stock config path */ - const XML_PATH_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock'; + public const XML_PATH_SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock'; /** * Auto return config path */ - const XML_PATH_ITEM_AUTO_RETURN = 'cataloginventory/item_options/auto_return'; + public const XML_PATH_ITEM_AUTO_RETURN = 'cataloginventory/item_options/auto_return'; /** * Path to configuration option 'Display product stock status' */ - const XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS = 'cataloginventory/options/display_product_stock_status'; + public const XML_PATH_DISPLAY_PRODUCT_STOCK_STATUS = 'cataloginventory/options/display_product_stock_status'; /** * Threshold qty config path */ - const XML_PATH_STOCK_THRESHOLD_QTY = 'cataloginventory/options/stock_threshold_qty'; + public const XML_PATH_STOCK_THRESHOLD_QTY = 'cataloginventory/options/stock_threshold_qty'; /** * @var ConfigInterface @@ -122,7 +120,7 @@ class Configuration implements StockConfigurationInterface /** * All product types registry in scope of quantity availability * - * @var array + * @var array|null */ protected $isQtyTypeIds; @@ -151,6 +149,14 @@ public function __construct( $this->storeManager = $storeManager; } + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->isQtyTypeIds = null; + } + /** * @inheritdoc */ diff --git a/app/code/Magento/CatalogInventory/Test/Mftf/Section/AdminProductFormAdvancedInventorySection.xml b/app/code/Magento/CatalogInventory/Test/Mftf/Section/AdminProductFormAdvancedInventorySection.xml index 6f388c3e6c6d1..9a198dd571def 100644 --- a/app/code/Magento/CatalogInventory/Test/Mftf/Section/AdminProductFormAdvancedInventorySection.xml +++ b/app/code/Magento/CatalogInventory/Test/Mftf/Section/AdminProductFormAdvancedInventorySection.xml @@ -36,5 +36,7 @@ <element name="maxiQtyAllowedInCartError" type="text" selector="[name='product[stock_data][max_sale_qty]'] + label.admin__field-error"/> <element name="backorders" type="select" selector="//*[@name='product[stock_data][backorders]']"/> <element name="useConfigSettingsForBackorders" type="checkbox" selector="//input[@name='product[stock_data][use_config_backorders]']"/> + <element name="checkConfigSettingsAdvancedInventory" type="checkbox" selector="//input[@name='product[stock_data][{{args}}]']/..//label[text()='Use Config Settings']/..//input[@type='checkbox']" parameterized="true"/> + <element name="selectManageStockOption" type="select" selector="//select[@name='product[stock_data][manage_stock]']"/> </section> </sections> diff --git a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php index 9b66606d37a9e..d29928306f24b 100644 --- a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php +++ b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php @@ -219,10 +219,23 @@ public function __construct( ->get(DefaultFilterStrategyApplyChecker::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->queryText = null; + $this->search = null; + $this->searchCriteriaBuilder = null; + $this->searchResult = null; + $this->filterBuilder = null; + $this->searchOrders = null; + } + /** * Get search. * - * @deprecated 100.1.0 * @return \Magento\Search\Api\SearchInterface */ private function getSearch() @@ -237,6 +250,7 @@ private function getSearch() * Test search. * * @deprecated 100.1.0 + * @see __construct * @param \Magento\Search\Api\SearchInterface $object * @return void * @since 100.1.0 @@ -249,7 +263,6 @@ public function setSearch(\Magento\Search\Api\SearchInterface $object) /** * Set search criteria builder. * - * @deprecated 100.1.0 * @return \Magento\Framework\Api\Search\SearchCriteriaBuilder */ private function getSearchCriteriaBuilder() @@ -265,6 +278,7 @@ private function getSearchCriteriaBuilder() * Set search criteria builder. * * @deprecated 100.1.0 + * @see __construct * @param \Magento\Framework\Api\Search\SearchCriteriaBuilder $object * @return void * @since 100.1.0 @@ -277,7 +291,6 @@ public function setSearchCriteriaBuilder(\Magento\Framework\Api\Search\SearchCri /** * Get filter builder. * - * @deprecated 100.1.0 * @return \Magento\Framework\Api\FilterBuilder */ private function getFilterBuilder() @@ -292,6 +305,7 @@ private function getFilterBuilder() * Set filter builder. * * @deprecated 100.1.0 + * @see __construct * @param \Magento\Framework\Api\FilterBuilder $object * @return void * @since 100.1.0 diff --git a/app/code/Magento/CatalogSearch/Model/ResourceModel/Search/Collection.php b/app/code/Magento/CatalogSearch/Model/ResourceModel/Search/Collection.php index 7e9be408a3850..10e72e0155ff3 100644 --- a/app/code/Magento/CatalogSearch/Model/ResourceModel/Search/Collection.php +++ b/app/code/Magento/CatalogSearch/Model/ResourceModel/Search/Collection.php @@ -23,22 +23,16 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection private $indexUsageEnforcements; /** - * Attribute collection - * * @var array */ protected $_attributesCollection; /** - * Search query - * * @var string */ protected $_searchQuery; /** - * Attribute collection factory - * * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory */ protected $_attributeCollectionFactory; @@ -119,6 +113,16 @@ public function __construct( $this->indexUsageEnforcements = $indexUsageEnforcements; } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_attributesCollection = null; + $this->_searchQuery = null; + } + /** * Add search query filter * @@ -240,6 +244,8 @@ private function isIndexExists(string $table, string $index) : bool * @param mixed $query * @param bool $searchOnlyInCurrentStore Search only in current store or in all stores * @return string + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _getSearchEntityIdsSql($query, $searchOnlyInCurrentStore = true) { diff --git a/app/code/Magento/Checkout/Model/Session.php b/app/code/Magento/Checkout/Model/Session.php index 0addbf069cba3..3a2beb3b4371c 100644 --- a/app/code/Magento/Checkout/Model/Session.php +++ b/app/code/Magento/Checkout/Model/Session.php @@ -24,7 +24,7 @@ */ class Session extends \Magento\Framework\Session\SessionManager { - const CHECKOUT_STATE_BEGIN = 'begin'; + public const CHECKOUT_STATE_BEGIN = 'begin'; /** * Quote instance @@ -99,12 +99,12 @@ class Session extends \Magento\Framework\Session\SessionManager protected $customerRepository; /** - * @param QuoteIdMaskFactory + * @var QuoteIdMaskFactory */ protected $quoteIdMaskFactory; /** - * @param bool + * @var bool */ protected $isQuoteMasked; @@ -186,6 +186,19 @@ public function __construct( ->get(LoggerInterface::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_quote = null; + $this->_customer = null; + $this->_loadInactive = false; + $this->isLoading = false; + $this->_order = null; + } + /** * Set customer data. * diff --git a/app/code/Magento/Checkout/Model/ShippingInformationManagement.php b/app/code/Magento/Checkout/Model/ShippingInformationManagement.php index f397a8ddc9cf1..f08c48c55efa1 100644 --- a/app/code/Magento/Checkout/Model/ShippingInformationManagement.php +++ b/app/code/Magento/Checkout/Model/ShippingInformationManagement.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Checkout\Model; @@ -39,60 +40,62 @@ class ShippingInformationManagement implements ShippingInformationManagementInte /** * @var PaymentMethodManagementInterface */ - protected $paymentMethodManagement; + protected PaymentMethodManagementInterface $paymentMethodManagement; /** * @var PaymentDetailsFactory */ - protected $paymentDetailsFactory; + protected PaymentDetailsFactory $paymentDetailsFactory; /** * @var CartTotalRepositoryInterface */ - protected $cartTotalsRepository; + protected CartTotalRepositoryInterface $cartTotalsRepository; /** * @var CartRepositoryInterface */ - protected $quoteRepository; - + protected CartRepositoryInterface $quoteRepository; /** * @var Logger */ - protected $logger; + protected Logger $logger; /** * @var QuoteAddressValidator */ - protected $addressValidator; + protected QuoteAddressValidator $addressValidator; /** * @var AddressRepositoryInterface * @deprecated 100.2.0 + * @see AddressRepositoryInterface */ - protected $addressRepository; + protected AddressRepositoryInterface $addressRepository; /** * @var ScopeConfigInterface * @deprecated 100.2.0 + * @see ScopeConfigInterface */ - protected $scopeConfig; + protected ScopeConfigInterface $scopeConfig; /** * @var TotalsCollector * @deprecated 100.2.0 + * @see TotalsCollector */ - protected $totalsCollector; + protected TotalsCollector $totalsCollector; /** * @var CartExtensionFactory */ - private $cartExtensionFactory; + private CartExtensionFactory $cartExtensionFactory; /** * @var ShippingAssignmentFactory */ - protected $shippingAssignmentFactory; + protected ShippingAssignmentFactory $shippingAssignmentFactory; /** * @var ShippingFactory @@ -262,8 +265,11 @@ protected function validateQuote(Quote $quote): void * @param string $method * @return CartInterface */ - private function prepareShippingAssignment(CartInterface $quote, AddressInterface $address, $method): CartInterface - { + private function prepareShippingAssignment( + CartInterface $quote, + AddressInterface $address, + string $method + ): CartInterface { $cartExtension = $quote->getExtensionAttributes(); if ($cartExtension === null) { $cartExtension = $this->cartExtensionFactory->create(); diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutSuccessMainSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutSuccessMainSection.xml index abdb4ddac7343..e5e912af73343 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutSuccessMainSection.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutSuccessMainSection.xml @@ -21,5 +21,6 @@ <element name="printLink" type="button" selector=".print" timeout="30"/> <element name="orderNumberWithoutLink" type="text" selector="//div[contains(@class, 'checkout-success')]//p/span"/> <element name="orderLinkByOrderNumber" type="text" selector="//div[contains(@class,'success')]//a[contains(.,'{{orderNumber}}')]" parameterized="true" timeout="30"/> + <element name="purchaseOrderNumber" type="text" selector="div.checkout-success > p:nth-child(1) > a span"/> </section> </sections> diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingDefaultAddressTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingDefaultAddressTest.xml index a5734b35afc0a..f9ddee8284d8b 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingDefaultAddressTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingDefaultAddressTest.xml @@ -21,11 +21,11 @@ <group value="cloud"/> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <!-- Create Simple Product --> <createData entity="SimpleProduct2" stepKey="createSimpleProduct"> <field key="price">560</field> </createData> - <!-- Create customer --> <createData entity="Simple_US_Customer_Multiple_Addresses" stepKey="createCustomer"/> </before> @@ -41,6 +41,7 @@ <!-- Delete customer --> <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <!-- Add Simple Product to cart --> diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingNonDefaultAddressTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingNonDefaultAddressTest.xml index 1bd9b0c9229bc..8ccb7af5a334a 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingNonDefaultAddressTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/OnePageCheckoutAsCustomerUsingNonDefaultAddressTest.xml @@ -21,6 +21,7 @@ <group value="cloud"/> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <!-- Create Simple Product --> <createData entity="SimpleProduct2" stepKey="createSimpleProduct"> <field key="price">560</field> @@ -41,6 +42,7 @@ <!-- Delete customer --> <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <!-- Add Simple Product to cart --> diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckoutWithSpecialPriceProductsTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckoutWithSpecialPriceProductsTest.xml index 1a85bb0bee1ee..a176a7ccd27f3 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckoutWithSpecialPriceProductsTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckoutWithSpecialPriceProductsTest.xml @@ -18,6 +18,7 @@ </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/> <createData entity="Simple_US_Customer" stepKey="createCustomer"/> <createData entity="defaultSimpleProduct" stepKey="simpleProduct"> @@ -101,10 +102,14 @@ <deleteData createDataKey="createConfigProduct" stepKey="deleteConfigProduct"/> <deleteData createDataKey="createConfigProductAttribute" stepKey="deleteProductAttribute"/> <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <!--Remove Filter--> + <actionGroup ref="AdminClearFiltersActionGroup" stepKey="clearProductsGridFilters"/> + <waitForPageLoad stepKey="waitForClearProductsGridFilters"/> <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> <!-- Reindex invalidated indices after product attribute has been created/deleted --> <magentoCron groups="index" stepKey="reindexInvalidatedIndices"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <!--Open Product page in StoreFront and assert product and price range --> diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerLoginDuringCheckoutTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerLoginDuringCheckoutTest.xml index bc4f18a3ac9fc..d59af6328f736 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerLoginDuringCheckoutTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCustomerLoginDuringCheckoutTest.xml @@ -20,6 +20,7 @@ <group value="cloud"/> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <!-- Create simple product --> <createData entity="SimpleProduct2" stepKey="createProduct"/> @@ -40,9 +41,9 @@ <actionGroup ref="AdminDeleteCustomerActionGroup" stepKey="deleteCustomer"> <argument name="customerEmail" value="CustomerEntityOne.email"/> </actionGroup> - <!-- Logout admin --> <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <!-- Go to Storefront as Guest and create new account --> <actionGroup ref="StorefrontOpenCustomerAccountCreatePageActionGroup" stepKey="openCreateAccountPage"/> diff --git a/app/code/Magento/Checkout/etc/adminhtml/system.xml b/app/code/Magento/Checkout/etc/adminhtml/system.xml index b56566a043c3e..5bb0f37f3bc25 100644 --- a/app/code/Magento/Checkout/etc/adminhtml/system.xml +++ b/app/code/Magento/Checkout/etc/adminhtml/system.xml @@ -13,6 +13,11 @@ <resource>Magento_Checkout::checkout</resource> <group id="options" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Checkout Options</label> + <field id="enable_guest_checkout_login" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> + <label>Enable Guest Checkout Login</label> + <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> + <comment>Enabling this setting will allow unauthenticated users to query if an e-mail address is already associated with a customer account. This can be used to enhance the checkout workflow for guests that do not realize they already have an account but comes at the cost of exposing information to unauthenticated users.</comment> + </field> <field id="onepage_checkout_enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Enable Onepage Checkout</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> @@ -23,7 +28,7 @@ </field> <field id="display_billing_address_on" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Display Billing Address On</label> - <source_model>\Magento\Checkout\Model\Adminhtml\BillingAddressDisplayOptions</source_model> + <source_model>Magento\Checkout\Model\Adminhtml\BillingAddressDisplayOptions</source_model> </field> <field id="max_items_display_count" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Maximum Number of Items to Display in Order Summary</label> diff --git a/app/code/Magento/Checkout/etc/config.xml b/app/code/Magento/Checkout/etc/config.xml index eac0bd849da35..c85d68b35f714 100644 --- a/app/code/Magento/Checkout/etc/config.xml +++ b/app/code/Magento/Checkout/etc/config.xml @@ -9,6 +9,7 @@ <default> <checkout> <options> + <enable_guest_checkout_login>0</enable_guest_checkout_login> <onepage_checkout_enabled>1</onepage_checkout_enabled> <guest_checkout>1</guest_checkout> <display_billing_address_on>0</display_billing_address_on> diff --git a/app/code/Magento/Cms/Model/ResourceModel/Block/Collection.php b/app/code/Magento/Cms/Model/ResourceModel/Block/Collection.php index f22367393030a..7d30908a2d9d6 100644 --- a/app/code/Magento/Cms/Model/ResourceModel/Block/Collection.php +++ b/app/code/Magento/Cms/Model/ResourceModel/Block/Collection.php @@ -19,15 +19,11 @@ class Collection extends AbstractCollection protected $_idFieldName = 'block_id'; /** - * Event prefix - * * @var string */ protected $_eventPrefix = 'cms_block_collection'; /** - * Event object - * * @var string */ protected $_eventObject = 'block_collection'; diff --git a/app/code/Magento/Cms/Model/ResourceModel/Page/Collection.php b/app/code/Magento/Cms/Model/ResourceModel/Page/Collection.php index 96886a995b1c9..6aafb010fb625 100644 --- a/app/code/Magento/Cms/Model/ResourceModel/Page/Collection.php +++ b/app/code/Magento/Cms/Model/ResourceModel/Page/Collection.php @@ -26,15 +26,11 @@ class Collection extends AbstractCollection protected $_previewFlag; /** - * Event prefix - * * @var string */ protected $_eventPrefix = 'cms_page_collection'; /** - * Event object - * * @var string */ protected $_eventObject = 'page_collection'; diff --git a/app/code/Magento/Cms/Test/Mftf/Section/StorefrontCMSPageSection.xml b/app/code/Magento/Cms/Test/Mftf/Section/StorefrontCMSPageSection.xml index bb276b2adb0de..de70c5706360a 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/StorefrontCMSPageSection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/StorefrontCMSPageSection.xml @@ -16,5 +16,6 @@ <element name="mainContent" type="text" selector="#maincontent"/> <element name="footerTop" type="text" selector="footer.page-footer"/> <element name="title" type="text" selector="//div[@class='breadcrumbs']//ul/li[@class='item cms_page']"/> + <element name="widgetContentApostrophe" type="text" selector="//div[@class='widget block block-cms-link']//span[contains(text(),'{{var}}')]" parameterized="true"/> </section> </sections> 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 5be91f61e1e1e..c9ef757ca7477 100644 --- a/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml +++ b/app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection/WidgetSection.xml @@ -48,5 +48,8 @@ <element name="ChooserName" type="input" selector="input[name='chooser_name']"/> <element name="SelectPageButton" type="button" selector="//button[@title='Select Page...']"/> <element name="SelectPageFilterInput" type="input" selector="input.admin__control-text[name='{{filterName}}']" parameterized="true"/> + <element name="URLKeySelectPage" type="input" selector="//aside[@role='dialog']//input[@name='chooser_identifier']"/> + <element name="SearchButtonSelectPage" type="button" selector="//aside[@role='dialog']//button[@title='Search']"/> + <element name="SearchResultSelectPage" type="text" selector="//aside[@role='dialog']//td[contains(@class,'col-url col-chooser_identifier') and contains(text(),'{{var}}')]" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Cms/Test/Mftf/Test/AdminCmsPageGridUrlFilterApplierTest.xml b/app/code/Magento/Cms/Test/Mftf/Test/AdminCmsPageGridUrlFilterApplierTest.xml index 949ddc8c05deb..ca07a5cdd0bb5 100644 --- a/app/code/Magento/Cms/Test/Mftf/Test/AdminCmsPageGridUrlFilterApplierTest.xml +++ b/app/code/Magento/Cms/Test/Mftf/Test/AdminCmsPageGridUrlFilterApplierTest.xml @@ -33,6 +33,7 @@ </after> <amOnPage url="{{CmsPagesPage.url}}?filters[title]=$$createPage.title$$" stepKey="navigateToPageGridWithFilters"/> <waitForPageLoad stepKey="waitForPageGrid"/> + <seeInCurrentUrl url="{{CmsPagesPage.url}}?filters[title]=$$createPage.title$$" stepKey="assertUrl"/> <waitForText selector="{{CmsPagesPageActionsSection.pagesGridRowByTitle($$createPage.title$$)}}" userInput="$$createPage.title$$" stepKey="seePage"/> <seeInCurrentUrl url="admin/cms/page?filters" stepKey="seeAdminCMSPageFilters"/> <waitForElementVisible selector="{{CmsPagesPageActionsSection.activeFilter}}" stepKey="seeEnabledFilters"/> diff --git a/app/code/Magento/Cms/Test/Mftf/Test/AdminConfigureStoreInformationTest.xml b/app/code/Magento/Cms/Test/Mftf/Test/AdminConfigureStoreInformationTest.xml new file mode 100644 index 0000000000000..b06bb0341d517 --- /dev/null +++ b/app/code/Magento/Cms/Test/Mftf/Test/AdminConfigureStoreInformationTest.xml @@ -0,0 +1,109 @@ +<?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="AdminConfigureStoreInformationTest"> + <annotations> + <features value="Cms"/> + <stories value="able to configure store information data"/> + <title value="Admin Configure Store Information"/> + <description value="As a Merchant I want to be able to configure store information data"/> + <severity value="MAJOR"/> + <testCaseId value="AC-3963"/> + </annotations> + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginToBackend"/> + </before> + <after> + <actionGroup ref="AdminSetStoreInformationConfigurationActionGroup" stepKey="resetStoreInformationConfig"> + <argument name="storeName" value=""/> + <argument name="storeHoursOfOperation" value=""/> + <argument name="vatNumber" value=""/> + <argument name="telephone" value=""/> + <argument name="country" value=""/> + <argument name="state" value=""/> + <argument name="city" value=""/> + <argument name="postcode" value=""/> + <argument name="street" value=""/> + </actionGroup> + <actionGroup ref="DeletePageByUrlKeyActionGroup" stepKey="deletePage"> + <argument name="UrlKey" value="{{_defaultCmsPage.identifier}}"/> + </actionGroup> + <actionGroup ref="EuropeanCountriesSystemCheckBoxActionGroup" stepKey="checkSystemValueConfig"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!--Set StoreInformation configs data--> + <actionGroup ref="AdminSetStoreInformationConfigurationActionGroup" stepKey="setStoreInformationConfigData"> + <argument name="telephone" value="{{DE_Address_Berlin_Not_Default_Address.telephone}}"/> + <argument name="country" value="{{DE_Address_Berlin_Not_Default_Address.country_id}}"/> + <argument name="state" value="{{DE_Address_Berlin_Not_Default_Address.state}}"/> + <argument name="city" value="{{DE_Address_Berlin_Not_Default_Address.city}}"/> + <argument name="postcode" value="{{DE_Address_Berlin_Not_Default_Address.postcode}}"/> + <argument name="street" value="{{DE_Address_Berlin_Not_Default_Address.street[0]}}"/> + </actionGroup> + <magentoCLI command="config:set {{SetEuropeanUnionCountries.path}} {{SetEuropeanUnionCountries.value}}" stepKey="selectEUCountries"/> + <actionGroup ref="AdminOpenCMSPagesGridActionGroup" stepKey="navigateToCmsPageGrid"/> + <click selector="{{CmsPagesPageActionsSection.addNewPageButton}}" stepKey="clickAddNewPage"/> + <fillField selector="{{CmsNewPagePageBasicFieldsSection.pageTitle}}" userInput="{{_defaultCmsPage.title}}" stepKey="fillFieldTitle"/> + <actionGroup ref="SaveAndContinueEditCmsPageActionGroup" stepKey="saveAndContinueEditCmsPage"/> + <actionGroup ref="switchToPageBuilderStage" stepKey="switchToPageBuilderStage"/> + <actionGroup ref="dragContentTypeToStage" stepKey="dragRowToRootContainer"> + <argument name="contentType" value="PageBuilderRowContentType"/> + <argument name="containerTargetType" value="PageBuilderRootContainerContentType"/> + </actionGroup> + <actionGroup ref="expandPageBuilderPanelMenuSection" stepKey="expandPageBuilderPanelMenuSection"> + <argument name="contentType" value="PageBuilderTextContentType"/> + </actionGroup> + <actionGroup ref="dragContentTypeToStage" stepKey="dragToStage"> + <argument name="contentType" value="PageBuilderHtmlContentType"/> + </actionGroup> + <actionGroup ref="openPageBuilderEditPanel" stepKey="openEditMenuOnStage"> + <argument name="contentType" value="PageBuilderHtmlContentType"/> + </actionGroup> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="clickInsertVariableButton"/> + <waitForPageLoad stepKey="waitForPageToLoadForToInsertButtonForStoreName"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / Store Name')}}" stepKey="selectDefaultVariable"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableStoreName"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariableForStAds"/> + <waitForPageLoad stepKey="waitForPageToLoadToSelectInsertVariableButtonForStAds"/> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="againClickInsertVariableButtonForStAds"/> + <waitForPageLoad stepKey="againWaitForPageToLoadToSelectInsertVariableButtonForStAds"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / Street Address')}}" stepKey="selectDefaultVariableForStAds"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableStAds"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariableForStore"/> + <waitForPageLoad stepKey="waitForPageToLoadForToInsertButtonForStore"/> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="againClickInsertVariableForStore"/> + <waitForPageLoad stepKey="againWaitForPageToLoadToSelectInsertVariableButtonForStore"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / City')}}" stepKey="selectDefaultVariableForStore"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableStore"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariableForCode"/> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="clickInsertVariableAgainForCode"/> + <waitForPageLoad stepKey="WaitForPageToLoadToSelectInsertVariableButtonForCode"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / ZIP/Postal Code')}}" stepKey="selectDefaultVariableForCode"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableCode"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariableForState"/> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="clickInsertVariableAgainForState"/> + <waitForPageLoad stepKey="WaitForPageToLoadToSelectInsertVariableButtonForState"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / Region/State')}}" stepKey="selectDefaultVariableForState"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableForState"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariableForCountry"/> + <click selector="{{HtmlOnConfiguration.insertVariableButton}}" stepKey="clickInsertVariableAgainForCountry"/> + <waitForPageLoad stepKey="WaitForPageToLoadToSelectInsertVariableButtonForCountry"/> + <click selector="{{VariableSection.VariableRadio('General / Store Information / Country')}}" stepKey="selectDefaultVariableForCountry"/> + <waitForPageLoad stepKey="waitForPageToLoadForToSelectDefaultVariableForCountry"/> + <click selector="{{VariableSection.InsertWidget}}" stepKey="clickInsertVariable"/> + <waitForPageLoad stepKey="waitForLoad"/> + <actionGroup ref="saveEditPanelSettingsFullScreen" stepKey="saveEditPanelSettings"/> + <actionGroup ref="exitPageBuilderFullScreen" stepKey="exitPageBuilderFullScreen"/> + <click selector="{{CmsNewPagePageSeoSection.header}}" stepKey="clickExpandSearchEngineOptimisation"/> + <fillField selector="{{CmsNewPagePageSeoSection.urlKey}}" userInput="{{_defaultCmsPage.identifier}}" stepKey="fillFieldUrlKey"/> + <actionGroup ref="SaveAndContinueEditCmsPageActionGroup" stepKey="saveAndContinueEditCmsPageAgain"/> + <amOnPage url="{{_defaultCmsPage.identifier}}" stepKey="amOnPageTestPageRefresh"/> + <see userInput="New Store InformationAugsburger Strabe 41Berlin10789BerlinGermany" stepKey="seeCustomData" /> + </test> +</tests> diff --git a/app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php b/app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php index 48c53f8201bb2..0d56aca14fb0a 100644 --- a/app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php +++ b/app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php @@ -102,12 +102,8 @@ public function getPlaceholderValue($path, $scope, $scopeCode = null) public function getEnvValue($placeholder) { // phpcs:disable Magento2.Security.Superglobal - $environment = []; - foreach ($_ENV as $key => $value) { - $environment[strtolower($key)] = $value; - } - if ($this->placeholder->isApplicable($placeholder) && isset($environment[strtolower($placeholder)])) { - return $environment[strtolower($placeholder)]; + if ($this->placeholder->isApplicable($placeholder) && isset($_ENV[$placeholder])) { + return $_ENV[$placeholder]; } // phpcs:enable diff --git a/app/code/Magento/Config/Test/Mftf/ActionGroup/AdminChangeTimeZoneForDifferentWebsiteActionGroup.xml b/app/code/Magento/Config/Test/Mftf/ActionGroup/AdminChangeTimeZoneForDifferentWebsiteActionGroup.xml new file mode 100644 index 0000000000000..7b33c5229a869 --- /dev/null +++ b/app/code/Magento/Config/Test/Mftf/ActionGroup/AdminChangeTimeZoneForDifferentWebsiteActionGroup.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="AdminChangeTimeZoneForDifferentWebsiteActionGroup"> + <annotations> + <description>set the time zone for different website</description> + </annotations> + <arguments> + <argument name="websiteName" type="string" defaultValue="{{SimpleProduct.sku}}"/> + <argument name="timeZoneName" type="string"/> + </arguments> + <amOnPage url="{{GeneralConfigurationPage.url}}" stepKey="navigateToLocaleConfigurationPage"/> + <waitForPageLoad stepKey="waitForConfigPageLoad"/> + <click selector="{{LocaleOptionsSection.changeStoreConfigButton}}" stepKey="changeStoreButton"/> + <waitForPageLoad stepKey="waitForStoreOption"/> + <click selector="{{LocaleOptionsSection.changeStoreConfigToSpecificWebsite(websiteName)}}" stepKey="selectNewWebsite"/> + <waitForPageLoad stepKey="waitForWebsiteChange"/> + <!-- Accept the current popup visible on the page. --> + <click selector="{{LocaleOptionsSection.changeWebsiteConfirmButton}}" stepKey="confirmModal"/> + <waitForPageLoad stepKey="waitForSaveChange"/> + <conditionalClick stepKey="expandDefaultLayouts" selector="{{LocaleOptionsSection.sectionHeader}}" dependentSelector="{{LocaleOptionsSection.checkIfTabExpand}}" visible="true"/> + <click selector="{{LocaleOptionsSection.useDefault}}" stepKey="unCheckCheckbox"/> + <waitForElementVisible selector="{{LocaleOptionsSection.timezone}}" stepKey="waitForLocaleTimeZone"/> + <selectOption userInput="{{timeZoneName}}" selector="{{LocaleOptionsSection.timeZoneDropdown}}" stepKey="selectDefaultOption"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Config/Test/Mftf/ActionGroup/EuropeanCountriesSystemCheckBoxActionGroup.xml b/app/code/Magento/Config/Test/Mftf/ActionGroup/EuropeanCountriesSystemCheckBoxActionGroup.xml new file mode 100644 index 0000000000000..055715d71f93c --- /dev/null +++ b/app/code/Magento/Config/Test/Mftf/ActionGroup/EuropeanCountriesSystemCheckBoxActionGroup.xml @@ -0,0 +1,19 @@ +<?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="EuropeanCountriesSystemCheckBoxActionGroup" extends="EuropeanCountriesOptionActionGroup"> + <annotations> + <description>check system value european country option value</description> + </annotations> + + <remove keyForRemoval="uncheckConfigSetting"/> + <checkOption selector="{{CountriesFormSection.useConfigSettings}}" stepKey="checkConfigSetting" after="waitForLoad"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Config/Test/Mftf/ActionGroup/ResetBackTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.xml b/app/code/Magento/Config/Test/Mftf/ActionGroup/ResetBackTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.xml new file mode 100644 index 0000000000000..99bf20b3e671c --- /dev/null +++ b/app/code/Magento/Config/Test/Mftf/ActionGroup/ResetBackTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.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="ResetBackTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup"> + <annotations> + <description>Goes to the 'Configuration' page for 'Tax'. Resets 'Tax Class for Shipping' to 'Taxable Goods'. Updates the Shopping cart display settongs. Clicks on the Save button.</description> + </annotations> + <arguments> + <argument name="taxClassForGiftOptions" type="string" defaultValue="None"/> + <argument name="shoppingCartDisplayPrices" type="string" defaultValue="Excluding Tax"/> + <argument name="shoppingCartDisplaySubtotal" type="string" defaultValue="Excluding Tax"/> + <argument name="shoppingCartDisplayShippingAmt" type="string" defaultValue="Excluding Tax"/> + <argument name="shoppingCartDisplayGiftsWrappingPrices" type="string" defaultValue="Excluding Tax"/> + <argument name="shoppingCartDisplayPrintedCardPrices" type="string" defaultValue="Excluding Tax"/> + <argument name="shoppingCartDisplayFullTaxSummary" type="string" defaultValue="No"/> + </arguments> + <amOnPage url="{{AdminSalesTaxClassPage.url}}" stepKey="navigateToSalesTaxPage"/> + <waitForPageLoad stepKey="waitForPageLoad"/> + <conditionalClick selector="{{SalesConfigSection.TaxClassesTab}}" dependentSelector="{{SalesConfigSection.CheckIfTaxClassesTabExpand}}" visible="true" stepKey="expandTaxClassesTab"/> + <waitForElementVisible selector="{{SalesConfigSection.ShippingTaxClass}}" stepKey="seeShippingTaxClass"/> + <selectOption selector="{{SalesConfigSection.TaxClassForGiftOptions}}" userInput="{{taxClassForGiftOptions}}" stepKey="setShippingTaxClassForGiftOptions"/> + <click selector="{{SalesConfigSection.TaxClassesTab}}" stepKey="collapseTaxClassesTab"/> + <conditionalClick selector="{{SalesConfigSection.ShoppingCartDisplaySettingsTab}}" dependentSelector="{{SalesConfigSection.ShoppingCartDisplaySettingsTabExpand}}" visible="true" stepKey="expandShoppingCartDisplaySettingsTab"/> + <waitForElementVisible selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('price')}}" stepKey="seeDisplayPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('price')}}" stepKey="uncheckDisplayPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('subtotal')}}" stepKey="uncheckDisplaySubtotalCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('shipping')}}" stepKey="uncheckDisplayShippingAmountCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('gift_wrapping')}}" stepKey="uncheckDisplayGiftsWrappingPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('printed_card')}}" stepKey="uncheckDisplayPrintedCardPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('full_summary')}}" stepKey="uncheckDisplayFullTaxSummaryCheckbox"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('price')}}" userInput="{{shoppingCartDisplayPrices}}" stepKey="setDisplayPrices"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('subtotal')}}" userInput="{{shoppingCartDisplaySubtotal}}" stepKey="setDisplaySubtotal"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('shipping')}}" userInput="{{shoppingCartDisplayShippingAmt}}" stepKey="setDisplayShipping"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('gift_wrapping')}}" userInput="{{shoppingCartDisplayGiftsWrappingPrices}}" stepKey="setDisplayGiftsWrapping"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('printed_card')}}" userInput="{{shoppingCartDisplayPrintedCardPrices}}" stepKey="setDisplayPrintedCard"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('full_summary')}}" userInput="{{shoppingCartDisplayFullTaxSummary}}" stepKey="setDisplayFullSummary"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('price')}}" stepKey="checkDisplayPricesCheckbox"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('subtotal')}}" stepKey="checkDisplaySubtotalCheckbox"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('shipping')}}" stepKey="checkDisplayShippingAmountCheckbox"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('gift_wrapping')}}" stepKey="checkDisplayGiftsWrappingPricesCheckbox"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('printed_card')}}" stepKey="checkDisplayPrintedCardPricesCheckbox"/> + <checkOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('full_summary')}}" stepKey="checkDisplayFullTaxSummaryCheckbox"/> + <click selector="{{ContentManagementSection.Save}}" stepKey="saveConfig"/> + <see userInput="You saved the configuration." stepKey="seeSuccessMessagePostSavingTheConfig"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Config/Test/Mftf/ActionGroup/SetTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.xml b/app/code/Magento/Config/Test/Mftf/ActionGroup/SetTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.xml new file mode 100644 index 0000000000000..3a825ebfb511f --- /dev/null +++ b/app/code/Magento/Config/Test/Mftf/ActionGroup/SetTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup.xml @@ -0,0 +1,47 @@ +<?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="SetTaxClassForGiftOptionsAndShoppingCartDisplaySettingsActionGroup"> + <annotations> + <description>Goes to the 'Configuration' page for 'Tax'. Sets 'Tax Class for Shipping' to 'Taxable Goods'. Updates the Shopping cart display settongs. Clicks on the Save button.</description> + </annotations> + <arguments> + <argument name="taxClassForGiftOptions" type="string" defaultValue="Taxable Goods"/> + <argument name="shoppingCartDisplayPrices" type="string" defaultValue="Including and Excluding Tax"/> + <argument name="shoppingCartDisplaySubtotal" type="string" defaultValue="Including and Excluding Tax"/> + <argument name="shoppingCartDisplayShippingAmt" type="string" defaultValue="Including and Excluding Tax"/> + <argument name="shoppingCartDisplayGiftsWrappingPrices" type="string" defaultValue="Including and Excluding Tax"/> + <argument name="shoppingCartDisplayPrintedCardPrices" type="string" defaultValue="Including and Excluding Tax"/> + <argument name="shoppingCartDisplayFullTaxSummary" type="string" defaultValue="Yes"/> + </arguments> + <amOnPage url="{{AdminSalesTaxClassPage.url}}" stepKey="navigateToSalesTaxPage"/> + <waitForPageLoad stepKey="waitForPageLoad"/> + <conditionalClick selector="{{SalesConfigSection.TaxClassesTab}}" dependentSelector="{{SalesConfigSection.CheckIfTaxClassesTabExpand}}" visible="true" stepKey="expandTaxClassesTab"/> + <waitForElementVisible selector="{{SalesConfigSection.ShippingTaxClass}}" stepKey="seeShippingTaxClass"/> + <selectOption selector="{{SalesConfigSection.TaxClassForGiftOptions}}" userInput="{{taxClassForGiftOptions}}" stepKey="setShippingTaxClassForGiftOptions"/> + <click selector="{{SalesConfigSection.TaxClassesTab}}" stepKey="collapseTaxClassesTab"/> + <conditionalClick selector="{{SalesConfigSection.ShoppingCartDisplaySettingsTab}}" dependentSelector="{{SalesConfigSection.ShoppingCartDisplaySettingsTabExpand}}" visible="true" stepKey="expandShoppingCartDisplaySettingsTab"/> + <waitForElementVisible selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('price')}}" stepKey="seeDisplayPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('price')}}" stepKey="uncheckDisplayPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('subtotal')}}" stepKey="uncheckDisplaySubtotalCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('shipping')}}" stepKey="uncheckDisplayShippingAmountCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('gift_wrapping')}}" stepKey="uncheckDisplayGiftsWrappingPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('printed_card')}}" stepKey="uncheckDisplayPrintedCardPricesCheckbox"/> + <uncheckOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayCheckbox('full_summary')}}" stepKey="uncheckDisplayFullTaxSummaryCheckbox"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('price')}}" userInput="{{shoppingCartDisplayPrices}}" stepKey="setDisplayPrices"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('subtotal')}}" userInput="{{shoppingCartDisplaySubtotal}}" stepKey="setDisplaySubtotal"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('shipping')}}" userInput="{{shoppingCartDisplayShippingAmt}}" stepKey="setDisplayShipping"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('gift_wrapping')}}" userInput="{{shoppingCartDisplayGiftsWrappingPrices}}" stepKey="setDisplayGiftsWrapping"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('printed_card')}}" userInput="{{shoppingCartDisplayPrintedCardPrices}}" stepKey="setDisplayPrintedCard"/> + <selectOption selector="{{SalesConfigSection.ParameterizedShoppingCartDisplayDropdown('full_summary')}}" userInput="{{shoppingCartDisplayFullTaxSummary}}" stepKey="setDisplayFullSummary"/> + <click selector="{{ContentManagementSection.Save}}" stepKey="saveConfig"/> + <see userInput="You saved the configuration." stepKey="seeSuccessMessagePostSavingTheConfig"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Config/Test/Mftf/Data/CountryOptionConfigData.xml b/app/code/Magento/Config/Test/Mftf/Data/CountryOptionConfigData.xml index 378aa0bfc510c..59c70ff68f419 100644 --- a/app/code/Magento/Config/Test/Mftf/Data/CountryOptionConfigData.xml +++ b/app/code/Magento/Config/Test/Mftf/Data/CountryOptionConfigData.xml @@ -30,4 +30,8 @@ <data key="scope">websites</data> <data key="scope_code">base</data> </entity> + <entity name="SetEuropeanUnionCountries"> + <data key="path">general/country/eu_countries</data> + <data key="value">GB,DE,FR</data> + </entity> </entities> diff --git a/app/code/Magento/Config/Test/Mftf/Section/SalesConfigSection.xml b/app/code/Magento/Config/Test/Mftf/Section/SalesConfigSection.xml index 878a0c24f7331..f971b4dd03cec 100644 --- a/app/code/Magento/Config/Test/Mftf/Section/SalesConfigSection.xml +++ b/app/code/Magento/Config/Test/Mftf/Section/SalesConfigSection.xml @@ -13,5 +13,10 @@ <element name="CheckIfTaxClassesTabExpand" type="button" selector="#tax_classes-head:not(.open)"/> <element name="ShippingTaxClass" type="select" selector="#tax_classes_shipping_tax_class"/> <element name="EnableTaxClassForShipping" type="checkbox" selector="#tax_classes_shipping_tax_class_inherit"/> + <element name="TaxClassForGiftOptions" type="select" selector="#tax_classes_wrapping_tax_class"/> + <element name="ShoppingCartDisplaySettingsTab" type="button" selector="#tax_cart_display-head"/> + <element name="ShoppingCartDisplaySettingsTabExpand" type="button" selector="#tax_cart_display-head:not(.open)"/> + <element name="ParameterizedShoppingCartDisplayCheckbox" type="checkbox" selector="//input[@name='groups[cart_display][fields][{{arg}}][inherit]']" parameterized="true"/> + <element name="ParameterizedShoppingCartDisplayDropdown" type="select" selector="//input[@name='groups[cart_display][fields][{{arg}}][inherit]']/../..//select" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php index 157d740d524c1..a0158a6b473df 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php @@ -69,16 +69,6 @@ protected function setUp(): void $this->checker = new SettingChecker($this->configMock, $placeholderFactoryMock, $this->scopeCodeResolverMock); } - public function testGetEnvValue(): void - { - $_ENV = array_merge($this->env, ['SOME_PLACEHOLDER' => 0, 'another_placeholder' => 1, 'some_placeholder' => 1]); - $this->placeholderMock->expects($this->any()) - ->method('isApplicable') - ->willReturn(true); - $this->assertSame($this->checker->getEnvValue('SOME_PLACEHOLDER'), 1); - $this->assertSame($this->checker->getEnvValue('another_placeholder'), 1); - } - /** * @param string $path * @param string $scope diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php b/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php index 88b5c3e48ea19..50421c6967b36 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php @@ -200,7 +200,10 @@ protected function fillSimpleProductData( continue; } - $product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode())); + $product->setData( + $attribute->getAttributeCode(), + $parentProduct->getData($attribute->getAttributeCode()) ?? $attribute->getDefaultValue() + ); } $keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id']; diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Section/AdminProductFormConfigurationsSection/AdminProductFormConfigurationsSection.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Section/AdminProductFormConfigurationsSection/AdminProductFormConfigurationsSection.xml index 22cb822dbe762..1ceb33a231c99 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Section/AdminProductFormConfigurationsSection/AdminProductFormConfigurationsSection.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Section/AdminProductFormConfigurationsSection/AdminProductFormConfigurationsSection.xml @@ -53,5 +53,12 @@ <element name="fileUploaderInput" type="file" selector="//input[@type='file' and @class='file-uploader-input']"/> <element name="variationImageSource" type="text" selector="[data-index='configurable-matrix'] [data-index='thumbnail_image_container'] img[src*='{{imageName}}']" parameterized="true"/> <element name="variationProductLinkByName" type="text" selector="//div[@data-index='configurable-matrix']//*[@data-index='name_container']//a[contains(text(), '{{productName}}')]" parameterized="true"/> + <element name="unAssignSource" type="button" selector="//span[text()='{{source_name}}']/../../..//button[@class='action-delete']//span[text()='Unassign']" parameterized="true"/> + <element name="btnAssignSources" type="button" selector="//button//span[text()='Assign Sources']/.."/> + <element name="chkSourceToAssign" type="checkbox" selector="//input[@id='idscheck{{source_id}}']/.." parameterized="true"/> + <element name="btnDoneAssignedSources" type="button" selector="//aside[@class='modal-slide product_form_product_form_sources_assign_sources_modal _show']//button[@class='action-primary']//span[text()='Done']/.." /> + <element name="searchBySource" type="input" selector="//div[contains(@data-bind,'inventory_source_listing.inventory_source_listing')]/div[2]//input[@placeholder='Search by keyword']"/> + <element name="clickSearch" type="button" selector="//div[contains(@data-bind,'inventory_source_listing.inventory_source_listing')]/div[2]//button[@aria-label='Search']"/> + <element name="btnDoneAdvancedInventory" type="button" selector="//aside[@class='modal-slide product_form_product_form_advanced_inventory_modal _show']//button[@class='action-primary']//span[text()='Done']/.." /> </section> </sections> diff --git a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCheckResultsOfColorAndOtherFiltersTest.xml b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCheckResultsOfColorAndOtherFiltersTest.xml index 852cc97b0f040..bc56c333ac4fb 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCheckResultsOfColorAndOtherFiltersTest.xml +++ b/app/code/Magento/ConfigurableProduct/Test/Mftf/Test/AdminCheckResultsOfColorAndOtherFiltersTest.xml @@ -201,5 +201,6 @@ <waitForPageLoad stepKey="waitForNewSimpleProductPage"/> <seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessageThird"/> <magentoCron stepKey="runCronIndex" groups="index"/> + <waitForPageLoad stepKey="waitForPageLoadAfterReindex"/> </test> </tests> diff --git a/app/code/Magento/Customer/Api/AccountManagementInterface.php b/app/code/Magento/Customer/Api/AccountManagementInterface.php index 9c607be9f217c..165233cc6a880 100644 --- a/app/code/Magento/Customer/Api/AccountManagementInterface.php +++ b/app/code/Magento/Customer/Api/AccountManagementInterface.php @@ -8,6 +8,7 @@ namespace Magento\Customer\Api; use Magento\Framework\Exception\InputException; +use Magento\Framework\Exception\LocalizedException; /** * Interface for managing customers accounts. @@ -194,7 +195,7 @@ public function resendConfirmation($email, $websiteId, $redirectUrl = ''); * Check if given email is associated with a customer account in given website. * * @param string $customerEmail - * @param int $websiteId If not set, will use the current websiteId + * @param int|null $websiteId If not set, will use the current websiteId * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 3719cb61cede7..29f1ebc0e531b 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -20,6 +20,7 @@ use Magento\Customer\Model\Customer as CustomerModel; use Magento\Customer\Model\Customer\CredentialsValidator; use Magento\Customer\Model\ForgotPasswordToken\GetCustomerByToken; +use Magento\Customer\Model\Logger as CustomerLogger; use Magento\Customer\Model\Metadata\Validator; use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory; use Magento\Directory\Model\AllowedCountries; @@ -57,7 +58,6 @@ use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Psr\Log\LoggerInterface as PsrLogger; -use Magento\Customer\Model\Logger as CustomerLogger; /** * Handle various customer account actions @@ -69,6 +69,11 @@ */ class AccountManagement implements AccountManagementInterface { + /** + * System Configuration Path for Enable/Disable Login at Guest Checkout + */ + public const GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG = 'checkout/options/enable_guest_checkout_login'; + /** * Configuration paths for create account email template * @@ -719,7 +724,7 @@ private function handleUnknownTemplate($template) throw new InputException( __( 'Invalid value of "%value" provided for the %fieldName field. ' - . 'Possible values: %template1 or %template2.', + . 'Possible values: %template1 or %template2.', [ 'value' => $template, 'fieldName' => 'template', @@ -1120,7 +1125,7 @@ public function validate(CustomerInterface $customer) $result = $this->eavValidator->isValid($customerModel); if ($result === false && is_array($this->eavValidator->getMessages())) { return $validationResults->setIsValid(false)->setMessages( - // phpcs:ignore Magento2.Functions.DiscouragedFunction + // phpcs:ignore Magento2.Functions.DiscouragedFunction call_user_func_array( 'array_merge', array_values($this->eavValidator->getMessages()) @@ -1132,9 +1137,24 @@ public function validate(CustomerInterface $customer) /** * @inheritdoc + * + * @param string $customerEmail + * @param int|null $websiteId + * @return bool + * @throws LocalizedException */ public function isEmailAvailable($customerEmail, $websiteId = null) { + $guestLoginConfig = $this->scopeConfig->getValue( + self::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + $websiteId + ); + + if (!$guestLoginConfig) { + return true; + } + try { if ($websiteId === null) { $websiteId = $this->storeManager->getStore()->getWebsiteId(); diff --git a/app/code/Magento/Customer/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPlugin.php b/app/code/Magento/Customer/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPlugin.php deleted file mode 100644 index 53e170f6026f8..0000000000000 --- a/app/code/Magento/Customer/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPlugin.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Customer\Model\App\FrontController; - -use Magento\Framework\App\Response\Http as ResponseHttp; -use Magento\Customer\Model\Session; - -/** - * Plugin for delete the cookie when the customer is not exist. - * - * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) - */ -class DeleteCookieWhenCustomerNotExistPlugin -{ - /** - * @var ResponseHttp - */ - private $responseHttp; - - /** - * @var Session - */ - private $session; - - /** - * Constructor - * - * @param ResponseHttp $responseHttp - * @param Session $session - */ - public function __construct( - ResponseHttp $responseHttp, - Session $session - ) { - $this->responseHttp = $responseHttp; - $this->session = $session; - } - - /** - * Delete the cookie when the customer is not exist before dispatch the front controller. - * - * @return void - */ - public function beforeDispatch(): void - { - if (!$this->session->getCustomerId()) { - $this->responseHttp->sendVary(); - } - } -} diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php index c7b44288bc85f..ffb5f41a40687 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php @@ -94,6 +94,15 @@ public function __construct( ); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_idFieldName = 'entity_id'; + } + /** * @inheritdoc */ diff --git a/app/code/Magento/Customer/Model/Session.php b/app/code/Magento/Customer/Model/Session.php index f5a7cc0d124b3..ec47afe8e065a 100644 --- a/app/code/Magento/Customer/Model/Session.php +++ b/app/code/Magento/Customer/Model/Session.php @@ -399,7 +399,11 @@ public function getCustomerGroupId() public function _resetState(): void { $this->_customer = null; - parent::_resetState(); // TODO: Change the autogenerated stub + $this->_customerModel = null; + $this->setCustomerId(null); + $this->setCustomerGroupId($this->groupManagement->getNotLoggedInGroup()->getId()); + $this->_isCustomerIdChecked = null; + parent::_resetState(); } /** diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/EnterAddressDetailsActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/EnterAddressDetailsActionGroup.xml new file mode 100644 index 0000000000000..074b93d860f19 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/EnterAddressDetailsActionGroup.xml @@ -0,0 +1,18 @@ +<!-- + /** + * 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="EnterAddressDetailsActionGroup" extends="EnterCustomerAddressInfoActionGroup"> + <annotations> + <description>Removed specific page. Fills in the required details </description> + </annotations> + + <remove keyForRemoval="goToAddressPage"/> + <remove keyForRemoval="saveAddress"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/FillNewCustomerAddressFieldsActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/FillNewCustomerAddressFieldsActionGroup.xml new file mode 100644 index 0000000000000..d31bacf807ec3 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/FillNewCustomerAddressFieldsActionGroup.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="FillNewCustomerAddressFieldsActionGroup" extends="FillNewCustomerAddressRequiredFieldsActionGroup"> + <annotations> + <description>Select country before select state </description> + </annotations> + <arguments> + <argument name="address" type="entity"/> + </arguments> + + <remove keyForRemoval="selectCountry"/> + <selectOption selector="{{StorefrontCustomerAddressFormSection.country}}" userInput="{{address.country}}" stepKey="selectCountryField" after="fillStreetAddress"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontDeleteStoredPaymentMethodActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontDeleteStoredPaymentMethodActionGroup.xml new file mode 100644 index 0000000000000..567122c45317e --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontDeleteStoredPaymentMethodActionGroup.xml @@ -0,0 +1,26 @@ +<?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="StorefrontDeleteStoredPaymentMethodActionGroup"> + <annotations> + <description>Goes to the Stored Payment Method and delete the 2nd card</description> + </annotations> + <arguments> + <argument name="card" type="entity" defaultValue="StoredPaymentMethods"/> + </arguments> + + <click selector="{{StorefrontCustomerStoredPaymentMethodsSection.deleteBtn(card.cardExpire)}}" stepKey="clickOnDelete"/> + <waitForElementVisible selector="{{StorefrontCustomerStoredPaymentMethodsSection.deleteMessage}}" stepKey="waitForMessageToVisible"/> + <seeElement selector="{{StorefrontCustomerStoredPaymentMethodsSection.deleteMessage}}" stepKey="seeDeleteConfirmationMessage1"/> + <click selector="{{StorefrontCustomerStoredPaymentMethodsSection.delete}}" stepKey="clickOnDeleteInAlert"/> + <waitForPageLoad stepKey="waitForCustomersGridIsLoaded"/> + <see selector="{{StorefrontCustomerStoredPaymentMethodsSection.successMessage}}" userInput="Stored Payment Method was successfully removed" stepKey="seeSuccessMessage"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontFillCustomerCreateAnAccountActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontFillCustomerCreateAnAccountActionGroup.xml new file mode 100644 index 0000000000000..f08a2422e0230 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/StorefrontFillCustomerCreateAnAccountActionGroup.xml @@ -0,0 +1,19 @@ +<?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="StorefrontFillCustomerCreateAnAccountActionGroup" extends="StorefrontFillCustomerAccountCreationFormActionGroup"> + <annotations> + <description>Fills in the provided Customer details on the Storefront Customer creation page.</description> + </annotations> + + <remove keyForRemoval="fillFirstName"/> + <remove keyForRemoval="fillLastName"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml index f6587a757ff3e..b1eeeec6de62e 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerSignInFormSection/StorefrontCustomerSignInPopupFormSection.xml @@ -13,6 +13,6 @@ <element name="password" type="input" selector="#pass"/> <element name="signIn" type="button" selector="(//button[@id='send2'][contains(@class, 'login')])[1]" timeout="30"/> <element name="forgotYourPassword" type="button" selector="//a[@class='action']//span[contains(text(),'Forgot Your Password?')]" timeout="30"/> - <element name="createAnAccount" type="button" selector="//div[contains(@class,'actions-toolbar')]//a[contains(.,'Create an Account')]" timeout="30"/> + <element name="createAnAccount" type="button" selector="(//div[contains(@class,'actions-toolbar')]//a[contains(.,'Create an Account')])[last()]" timeout="30"/> </section> </sections> diff --git a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerStoredPaymentMethodsSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerStoredPaymentMethodsSection.xml index d6b586e42f28c..ba8159948701d 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerStoredPaymentMethodsSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerStoredPaymentMethodsSection.xml @@ -11,5 +11,9 @@ <section name="StorefrontCustomerStoredPaymentMethodsSection"> <element name="cardNumber" type="text" selector="td.card-number"/> <element name="expirationDate" type="text" selector="td.card-expire"/> + <element name="deleteBtn" type="button" selector=".//*[contains(text(),'{{var1}}')]/../td[@class='col actions']//button" parameterized="true"/> + <element name="delete" type="button" selector="(//*[@class='action primary']/span)[2]"/> + <element name="deleteMessage" type="text" selector="//div[@class='modal-content']//div[text()='Are you sure you want to delete this card: 0002?']"/> + <element name="successMessage" type="text" selector=".//*[@class='message-success success message']/div"/> </section> </sections> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/EndToEndB2CLoggedInUserTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/EndToEndB2CLoggedInUserTest.xml index 6e7fe4e259d7a..cee34fb258aa3 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/EndToEndB2CLoggedInUserTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/EndToEndB2CLoggedInUserTest.xml @@ -23,6 +23,7 @@ </skip> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <resetCookie userInput="PHPSESSID" stepKey="resetCookieForCart"/> <actionGroup ref="AdminLoginActionGroup" after="resetCookieForCart" stepKey="loginAsAdmin"/> </before> @@ -32,6 +33,7 @@ <actionGroup ref="DeleteCustomerFromAdminActionGroup" stepKey="deleteCustomerFromAdmin"/> <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearProductsGridFilters"/> <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <!-- Step 0: User signs up an account --> <comment userInput="Start of signing up user account" stepKey="startOfSigningUpUserAccount" /> diff --git a/app/code/Magento/Customer/Test/Unit/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPluginTest.php b/app/code/Magento/Customer/Test/Unit/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPluginTest.php deleted file mode 100644 index fd06dbf6b8004..0000000000000 --- a/app/code/Magento/Customer/Test/Unit/Model/App/FrontController/DeleteCookieWhenCustomerNotExistPluginTest.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Customer\Test\Unit\Model\App\FrontController; - -use Magento\Customer\Model\App\FrontController\DeleteCookieWhenCustomerNotExistPlugin; -use Magento\Framework\App\Response\Http as ResponseHttp; -use Magento\Customer\Model\Session; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; - -/** - * Tests \Magento\Customer\Model\App\FrontController\DeleteCookieWhenCustomerNotExistPluginTest. - */ -class DeleteCookieWhenCustomerNotExistPluginTest extends TestCase -{ - /** - * @var DeleteCookieWhenCustomerNotExistPlugin - */ - protected DeleteCookieWhenCustomerNotExistPlugin $plugin; - - /** - * @var ResponseHttp|MockObject - */ - protected ResponseHttp|MockObject $responseHttpMock; - - /** - * @var Session|MockObject - */ - protected MockObject|Session $customerSessionMock; - - /** - * Set up - */ - protected function setUp(): void - { - $this->customerSessionMock = $this->createMock(Session::class); - $this->responseHttpMock = $this->createMock(ResponseHttp::class); - $this->plugin = new DeleteCookieWhenCustomerNotExistPlugin( - $this->responseHttpMock, - $this->customerSessionMock - ); - } - - public function testBeforeDispatch() - { - $this->customerSessionMock->expects($this->once()) - ->method('getCustomerId') - ->willReturn(0); - $this->plugin->beforeDispatch(); - } -} diff --git a/app/code/Magento/Customer/ViewModel/Customer/Data.php b/app/code/Magento/Customer/ViewModel/Customer/Data.php deleted file mode 100644 index 8c285b368c961..0000000000000 --- a/app/code/Magento/Customer/ViewModel/Customer/Data.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Customer\ViewModel\Customer; - -use Magento\Customer\Model\Context; -use Magento\Framework\App\Http\Context as HttpContext; -use Magento\Framework\Serialize\Serializer\Json as Json; -use Magento\Framework\View\Element\Block\ArgumentInterface; - -/** - * Customer's data view model - */ -class Data implements ArgumentInterface -{ - /** - * @var Json - */ - private $jsonEncoder; - - /** - * - * @var HttpContext - */ - private $httpContext; - - /** - * @param HttpContext $httpContext - * @param Json $jsonEncoder - */ - public function __construct( - HttpContext $httpContext, - Json $jsonEncoder - ) { - $this->httpContext = $httpContext; - $this->jsonEncoder = $jsonEncoder; - } - - /** - * Check is user login - * - * @return bool - */ - public function isLoggedIn() - { - return $this->httpContext->getValue(Context::CONTEXT_AUTH); - } - - /** - * Encode the mixed $valueToEncode into the JSON format - * - * @param mixed $valueToEncode - * @return string - */ - public function jsonEncode($valueToEncode) - { - return $this->jsonEncoder->serialize($valueToEncode); - } -} diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index e29f7cc1cf1ea..827a153e94674 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -130,7 +130,4 @@ <type name="Magento\Customer\Model\Session"> <plugin name="afterLogout" type="Magento\Customer\Model\Plugin\ClearSessionsAfterLogoutPlugin"/> </type> - <type name="Magento\Framework\App\FrontControllerInterface"> - <plugin name="delete-cookie-when-customer-not-exist" type="Magento\Customer\Model\App\FrontController\DeleteCookieWhenCustomerNotExistPlugin"/> - </type> </config> diff --git a/app/code/Magento/Customer/view/frontend/layout/default.xml b/app/code/Magento/Customer/view/frontend/layout/default.xml index eba504a12a1e5..b431373ca4125 100644 --- a/app/code/Magento/Customer/view/frontend/layout/default.xml +++ b/app/code/Magento/Customer/view/frontend/layout/default.xml @@ -48,11 +48,7 @@ </arguments> </block> <block name="customer.customer.data" class="Magento\Customer\Block\CustomerData" - template="Magento_Customer::js/customer-data.phtml"> - <arguments> - <argument name="view_model" xsi:type="object">Magento\Customer\ViewModel\Customer\Data</argument> - </arguments> - </block> + template="Magento_Customer::js/customer-data.phtml"/> <block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData" template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/> </referenceContainer> diff --git a/app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml b/app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml index 7031778a8d473..de5d0004a288b 100644 --- a/app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml @@ -3,16 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -use Magento\Customer\ViewModel\Customer\Data; -use Magento\Framework\App\ObjectManager; /** @var \Magento\Customer\Block\CustomerData $block */ +/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */ +$expirableSectionNames = $block->getExpirableSectionNames(); // phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper -/** @var Data $viewModel */ -$viewModel = $block->getViewModel() ?? ObjectManager::getInstance()->get(Data::class); -$customerDataUrl = $block->getCustomerDataUrl('customer/account/updateSession'); -$expirableSectionNames = $block->getExpirableSectionNames(); +// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis +$jsonHelper = $this->helper(\Magento\Framework\Json\Helper\Data::class); ?> <script type="text/x-magento-init"> { @@ -20,10 +18,13 @@ $expirableSectionNames = $block->getExpirableSectionNames(); "Magento_Customer/js/customer-data": { "sectionLoadUrl": "<?= $block->escapeJs($block->getCustomerDataUrl('customer/section/load')) ?>", "expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>, - "expirableSectionNames": <?= /* @noEscape */ $viewModel->jsonEncode($expirableSectionNames) ?>, + "expirableSectionNames": <?= /* @noEscape */ $jsonHelper->jsonEncode( + $block->getExpirableSectionNames() + ) ?>, "cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>", - "updateSessionUrl": "<?= $block->escapeJs($customerDataUrl) ?>", - "isLoggedIn": "<?= /* @noEscape */ $viewModel->isLoggedIn() ?>" + "updateSessionUrl": "<?= $block->escapeJs( + $block->getCustomerDataUrl('customer/account/updateSession') + ) ?>" } } } diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index 5ff83bbb9b14d..11ddc0386d86d 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -47,20 +47,10 @@ define([ * Invalidate Cache By Close Cookie Session */ invalidateCacheByCloseCookieSession = function () { - var isLoggedIn = parseInt(options.isLoggedIn, 10) || 0; - if (!$.cookieStorage.isSet('mage-cache-sessid')) { storage.removeAll(); } - if (!$.localStorage.isSet('mage-customer-login')) { - $.localStorage.set('mage-customer-login', isLoggedIn); - } - if ($.localStorage.get('mage-customer-login') !== isLoggedIn) { - $.localStorage.set('mage-customer-login', isLoggedIn); - storage.removeAll(); - } - $.cookieStorage.set('mage-cache-sessid', true); }; diff --git a/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoDeveloperModeOnlyTestSuite.xml b/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoDeveloperModeOnlyTestSuite.xml index 3a7d3663c8875..8c3e0f750debd 100644 --- a/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoDeveloperModeOnlyTestSuite.xml +++ b/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoDeveloperModeOnlyTestSuite.xml @@ -14,9 +14,7 @@ <group name="developer_mode_only"/> </include> <after> - <!-- Command should be uncommented once MQE-1711 is resolved --> - <comment userInput="Command should be uncommented once MQE-1711 is resolved" stepKey="comment" /> - <!-- <magentoCLI command="deploy:mode:set production" stepKey="enableProductionMode"/> --> + <magentoCLI command="deploy:mode:set production" stepKey="enableProductionMode"/> </after> </suite> </suites> diff --git a/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoProductionModeOnlyTestSuite.xml b/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoProductionModeOnlyTestSuite.xml index bf7014cdbb49d..82ba4102736f7 100644 --- a/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoProductionModeOnlyTestSuite.xml +++ b/app/code/Magento/Deploy/Test/Mftf/Suite/MagentoProductionModeOnlyTestSuite.xml @@ -7,16 +7,8 @@ --> <suites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Suite/etc/suiteSchema.xsd"> <suite name="MagentoProductionModeOnlyTestSuite"> - <before> - <!-- Command should be uncommented once MQE-1711 is resolved --> - <comment userInput="Command should be uncommented once MQE-1711 is resolved" stepKey="comment" /> - <!-- <magentoCLI command="deploy:mode:set production" stepKey="enableProductionMode"/> --> - </before> <include> <group name="production_mode_only"/> </include> - <after> - <comment userInput="Command should be uncommented once MQE-1711 is resolved" stepKey="comment" /> - </after> </suite> </suites> diff --git a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php index abd817940956f..1bc2ca7f63dfa 100644 --- a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php +++ b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php @@ -19,6 +19,7 @@ * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.ExcessivePublicCount) * @since 100.0.2 */ abstract class AbstractCollection extends AbstractDb implements SourceProviderInterface @@ -180,6 +181,23 @@ protected function _construct() { } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_itemsById = []; + $this->_staticFields = []; + $this->_entity = null; + $this->_selectEntityTypes = []; + $this->_selectAttributes = []; + $this->_filterAttributes = []; + $this->_joinEntities = []; + $this->_joinAttributes = []; + $this->_joinFields = []; + } + /** * Retrieve table name * @@ -1597,14 +1615,12 @@ protected function _afterLoad() protected function _reset() { parent::_reset(); - $this->_selectEntityTypes = []; $this->_selectAttributes = []; $this->_filterAttributes = []; $this->_joinEntities = []; $this->_joinAttributes = []; $this->_joinFields = []; - return $this; } diff --git a/app/code/Magento/Eav/Model/ResourceModel/Attribute/Collection.php b/app/code/Magento/Eav/Model/ResourceModel/Attribute/Collection.php index 7abb54e780f5f..897640f852cc7 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Attribute/Collection.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Attribute/Collection.php @@ -10,6 +10,7 @@ /** * EAV additional attribute resource collection (Using Forms) * + * phpcs:disable Magento2.Classes.AbstractApi.AbstractApi * @api * @since 100.0.2 */ @@ -18,7 +19,7 @@ abstract class Collection extends \Magento\Eav\Model\ResourceModel\Entity\Attrib /** * code of password hash in customer's EAV tables */ - const EAV_CODE_PASSWORD_HASH = 'password_hash'; + public const EAV_CODE_PASSWORD_HASH = 'password_hash'; /** * Current website scope instance @@ -64,6 +65,15 @@ public function __construct( parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $connection, $resource); } + /** + * @inheritDoc + */ + public function _resetState(): void //phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedFunction + { + /* Note: because Eav attribute loading takes significant performance, + we are not resetting it like other collections. */ + } + /** * Default attribute entity type code * @@ -212,6 +222,7 @@ protected function _initSelect() /** * Specify attribute entity type filter. + * * Entity type is defined. * * @param int $type diff --git a/app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php b/app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php index 9438178e56085..063b6041782d7 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php @@ -96,6 +96,16 @@ protected function _construct() } } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_store = null; + $this->_entityType = null; + } + /** * Get EAV website table * @@ -193,6 +203,7 @@ public function setSortOrder($direction = self::SORT_ORDER_ASC) */ protected function _beforeLoad() { + $store = $this->getStore(); $select = $this->getSelect(); $connection = $this->getConnection(); $entityType = $this->getEntityType(); @@ -254,7 +265,6 @@ protected function _beforeLoad() } } - $store = $this->getStore(); $joinWebsiteExpression = $connection->quoteInto( 'sa.attribute_id = main_table.attribute_id AND sa.website_id = ?', (int)$store->getWebsiteId() diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Data.php b/app/code/Magento/Eav/Model/Validator/Attribute/Data.php index 7b29b9dde6790..4175608db5f08 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Data.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Data.php @@ -8,6 +8,7 @@ use Magento\Eav\Model\Attribute; use Magento\Eav\Model\AttributeDataFactory; +use Magento\Eav\Model\Config; use Magento\Framework\DataObject; /** @@ -47,18 +48,39 @@ class Data extends \Magento\Framework\Validator\AbstractValidator */ private $ignoredAttributesByTypesList; + /** + * @var \Magento\Eav\Model\Config + */ + private $eavConfig; + /** * @param AttributeDataFactory $attrDataFactory + * @param Config|null $eavConfig * @param array $ignoredAttributesByTypesList */ public function __construct( AttributeDataFactory $attrDataFactory, + Config $eavConfig = null, array $ignoredAttributesByTypesList = [] ) { + $this->eavConfig = $eavConfig ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(Config::class); $this->_attrDataFactory = $attrDataFactory; $this->ignoredAttributesByTypesList = $ignoredAttributesByTypesList; } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_attributes = []; + $this->allowedAttributesList = []; + $this->deniedAttributesList = []; + $this->_data = []; + } + /** * Set list of attributes for validation in isValid method. * @@ -166,8 +188,9 @@ protected function _getAttributes($entity) } elseif ($entity instanceof \Magento\Framework\Model\AbstractModel && $entity->getResource() instanceof \Magento\Eav\Model\Entity\AbstractEntity ) { // $entity is EAV-model + $type = $entity->getEntityType()->getEntityTypeCode(); /** @var \Magento\Eav\Model\Entity\Type $entityType */ - $entityType = $entity->getEntityType(); + $entityType = $this->eavConfig->getEntityType($type); $attributes = $entityType->getAttributeCollection()->getItems(); $ignoredTypeAttributes = $this->ignoredAttributesByTypesList[$entityType->getEntityTypeCode()] ?? []; diff --git a/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/DataTest.php b/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/DataTest.php index 88daf1a8a6f52..e1aab7f44b48a 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/DataTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Validator/Attribute/DataTest.php @@ -13,6 +13,7 @@ use Magento\Eav\Model\AttributeDataFactory; use Magento\Eav\Model\Entity\AbstractEntity; use Magento\Eav\Model\Validator\Attribute\Data; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; use Magento\Framework\Model\AbstractModel; use Magento\Framework\ObjectManagerInterface; @@ -35,6 +36,11 @@ class DataTest extends TestCase */ private $model; + /** + * @var \Magento\Eav\Model\Config|MockObject + */ + private $eavConfigMock; + /** * @inheritdoc */ @@ -49,7 +55,12 @@ protected function setUp(): void ] ) ->getMock(); - + $this->createMock(ObjectManagerInterface::class); + ObjectManager::setInstance($this->createMock(ObjectManagerInterface::class)); + $this->eavConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Config::class) + ->onlyMethods(['getEntityType']) + ->disableOriginalConstructor() + ->getMock(); $this->model = new Data($this->attrDataFactory); } @@ -205,13 +216,17 @@ public function testIsValidAttributesFromCollection(): void 'is_visible' => true, ] ); + $entityTypeCode = 'entity_type_code'; $collection = $this->getMockBuilder(DataObject::class) ->addMethods(['getItems'])->getMock(); $collection->expects($this->once())->method('getItems')->willReturn([$attribute]); $entityType = $this->getMockBuilder(DataObject::class) - ->addMethods(['getAttributeCollection']) + ->addMethods(['getAttributeCollection','getEntityTypeCode']) ->getMock(); + $entityType->expects($this->atMost(2))->method('getEntityTypeCode')->willReturn($entityTypeCode); $entityType->expects($this->once())->method('getAttributeCollection')->willReturn($collection); + $this->eavConfigMock->expects($this->once())->method('getEntityType') + ->with($entityTypeCode)->willReturn($entityType); $entity = $this->_getEntityMock(); $entity->expects($this->once())->method('getResource')->willReturn($resource); $entity->expects($this->once())->method('getEntityType')->willReturn($entityType); @@ -235,7 +250,7 @@ public function testIsValidAttributesFromCollection(): void )->willReturn( $dataModel ); - $validator = new Data($attrDataFactory); + $validator = new Data($attrDataFactory, $this->eavConfigMock); $validator->setData(['attribute' => 'new_test_data']); $this->assertTrue($validator->isValid($entity)); diff --git a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php index 1db0bad36e243..87712641c05d4 100644 --- a/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php +++ b/app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicField.php @@ -18,6 +18,7 @@ use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Catalog\Model\ResourceModel\Category\Collection; +use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\Framework\App\ObjectManager; use Magento\Store\Model\StoreManagerInterface; @@ -29,9 +30,9 @@ class DynamicField implements FieldProviderInterface /** * Category collection. * - * @var Collection + * @var CollectionFactory */ - private $categoryCollection; + private $categoryCollectionFactory; /** * Customer group repository. @@ -41,8 +42,6 @@ class DynamicField implements FieldProviderInterface private $groupRepository; /** - * Search criteria builder. - * * @var SearchCriteriaBuilder */ private $searchCriteriaBuilder; @@ -79,8 +78,10 @@ class DynamicField implements FieldProviderInterface * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param FieldNameResolver $fieldNameResolver * @param AttributeProvider $attributeAdapterProvider - * @param Collection $categoryCollection + * @param Collection $categoryCollection @deprecated @see $categoryCollectionFactory * @param StoreManagerInterface|null $storeManager + * @param CollectionFactory|null $categoryCollectionFactory + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( FieldTypeConverterInterface $fieldTypeConverter, @@ -90,7 +91,8 @@ public function __construct( FieldNameResolver $fieldNameResolver, AttributeProvider $attributeAdapterProvider, Collection $categoryCollection, - ?StoreManagerInterface $storeManager = null + ?StoreManagerInterface $storeManager = null, + ?CollectionFactory $categoryCollectionFactory = null ) { $this->groupRepository = $groupRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; @@ -98,7 +100,8 @@ public function __construct( $this->indexTypeConverter = $indexTypeConverter; $this->fieldNameResolver = $fieldNameResolver; $this->attributeAdapterProvider = $attributeAdapterProvider; - $this->categoryCollection = $categoryCollection; + $this->categoryCollectionFactory = $categoryCollectionFactory + ?: ObjectManager::getInstance()->get(CollectionFactory::class); $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class); } @@ -108,7 +111,7 @@ public function __construct( public function getFields(array $context = []): array { $allAttributes = []; - $categoryIds = $this->categoryCollection->getAllIds(); + $categoryIds = $this->categoryCollectionFactory->create()->getAllIds(); $positionAttribute = $this->attributeAdapterProvider->getByAttributeCode('position'); $categoryNameAttribute = $this->attributeAdapterProvider->getByAttributeCode('category_name'); foreach ($categoryIds as $categoryId) { diff --git a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php index 2cf8c9f6a3fa9..6b0e3961a8fc3 100644 --- a/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php +++ b/app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/DynamicFieldTest.php @@ -8,6 +8,7 @@ namespace Magento\Elasticsearch\Test\Unit\Model\Adapter\FieldMapper\Product\FieldProvider; use Magento\Catalog\Model\ResourceModel\Category\Collection; +use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Api\Data\GroupSearchResultsInterface; use Magento\Customer\Api\GroupRepositoryInterface; @@ -111,8 +112,13 @@ protected function setUp(): void ->disableOriginalConstructor() ->onlyMethods(['getAllIds']) ->getMock(); + $categoryCollection = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->onlyMethods(['create']) + ->getMock(); + $categoryCollection->method('create') + ->willReturn($this->categoryCollection); $this->storeManager = $this->createMock(StoreManagerInterface::class); - $this->provider = new DynamicField( $this->fieldTypeConverter, $this->indexTypeConverter, @@ -121,7 +127,8 @@ protected function setUp(): void $this->fieldNameResolver, $this->attributeAdapterProvider, $this->categoryCollection, - $this->storeManager + $this->storeManager, + $categoryCollection ); } diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php index dfdfa7b138481..c4f6784aaa79e 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -81,6 +81,11 @@ class Filter extends Template */ protected $_modifiers = ['nl2br' => '']; + /** + * @var string + */ + private const CACHE_KEY_PREFIX = "EMAIL_FILTER_"; + /** * @var bool */ @@ -284,7 +289,7 @@ public function setUseAbsoluteLinks($flag) * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @deprecated SID query parameter is not used in URLs anymore. - * @see setUseSessionInUrl + * @see SessionId's in URL */ public function setUseSessionInUrl($flag) { @@ -408,6 +413,11 @@ public function blockDirective($construction) { $skipParams = ['class', 'id', 'output']; $blockParameters = $this->getParameters($construction[2]); + + if (isset($blockParameters['cache_key'])) { + $blockParameters['cache_key'] = self::CACHE_KEY_PREFIX . $blockParameters['cache_key']; + } + $block = null; if (isset($blockParameters['class'])) { @@ -694,7 +704,7 @@ public function varDirective($construction) * @param string $default assumed modifier if none present * @return array * @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces - * @see explodeModifiers + * @see Directive Processor Interfaces */ protected function explodeModifiers($value, $default = null) { @@ -714,7 +724,7 @@ protected function explodeModifiers($value, $default = null) * @param string $modifiers * @return string * @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces - * @see applyModifiers + * @see Directive Processor Interfaces */ protected function applyModifiers($value, $modifiers) { @@ -744,7 +754,7 @@ protected function applyModifiers($value, $modifiers) * @param string $type * @return string * @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces - * @see modifierEscape + * @see Directive Processor Interfacees */ public function modifierEscape($value, $type = 'html') { diff --git a/app/code/Magento/Fedex/Model/Config/Backend/FedexUrl.php b/app/code/Magento/Fedex/Model/Config/Backend/FedexUrl.php new file mode 100644 index 0000000000000..33cd6f64de9cf --- /dev/null +++ b/app/code/Magento/Fedex/Model/Config/Backend/FedexUrl.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Fedex\Model\Config\Backend; + +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Framework\Validator\Url; + +/** + * Represents a config URL that may point to a Fedex endpoint + */ +class FedexUrl extends Value +{ + /** + * @var Url + */ + private Url $url; + /** + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection + * @param Url $url + * @param array $data + */ + public function __construct( + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + Url $url, + array $data = [] + ) { + parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); + $this->url = $url; + } + + /** + * @inheritDoc + * + * @return AbstractModel + * @throws ValidatorException + */ + public function beforeSave(): AbstractModel + { + $isValid = $this->url->isValid($this->getValue(), ['http', 'https']); + + if ($isValid) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $host = parse_url((string)$this->getValue(), \PHP_URL_HOST); + + if (!empty($host) && !preg_match('/(?:.+\.|^)fedex\.com$/i', $host)) { + throw new ValidatorException(__('Fedex API endpoint URL\'s must use fedex.com')); + } + } + + return parent::beforeSave(); + } +} diff --git a/app/code/Magento/Fedex/Test/Unit/Model/Config/Backend/FedexUrlTest.php b/app/code/Magento/Fedex/Test/Unit/Model/Config/Backend/FedexUrlTest.php new file mode 100644 index 0000000000000..56626222312bf --- /dev/null +++ b/app/code/Magento/Fedex/Test/Unit/Model/Config/Backend/FedexUrlTest.php @@ -0,0 +1,131 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Fedex\Test\Unit\Model\Config\Backend; + +use Magento\Fedex\Model\Config\Backend\FedexUrl; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Model\Context; +use Magento\Framework\Registry; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\Validator\Url; +use Magento\Rule\Model\ResourceModel\AbstractResource; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +/** + * Verify behavior of FedexUrl backend type + */ +class FedexUrlTest extends TestCase +{ + + /** + * @var FedexUrl + */ + private $urlConfig; + + /** + * @var Url + */ + private $url; + + /** + * @var Context|MockObject + */ + private $contextMock; + + protected function setUp(): void + { + $objectManager = new ObjectManager($this); + $this->contextMock = $this->createMock(Context::class); + $registry = $this->createMock(Registry::class); + $config = $this->createMock(ScopeConfigInterface::class); + $cacheTypeList = $this->createMock(TypeListInterface::class); + $this->url = $this->createMock(Url::class); + $resource = $this->createMock(AbstractResource::class); + $resourceCollection = $this->createMock(AbstractDb::class); + $eventManagerMock = $this->getMockForAbstractClass(ManagerInterface::class); + $eventManagerMock->expects($this->any())->method('dispatch'); + $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock); + + $this->urlConfig = $objectManager->getObject( + FedexUrl::class, + [ + 'url' => $this->url, + 'context' => $this->contextMock, + 'registry' => $registry, + 'config' => $config, + 'cacheTypeList' => $cacheTypeList, + 'resource' => $resource, + 'resourceCollection' => $resourceCollection, + ] + ); + } + + /** + * @dataProvider validDataProvider + * @param string|null $data The valid data + * @throws ValidatorException + */ + public function testBeforeSave(string $data = null): void + { + $this->url->expects($this->any())->method('isValid')->willReturn(true); + $this->urlConfig->setValue($data); + $this->urlConfig->beforeSave(); + $this->assertTrue($this->url->isValid($data)); + } + + /** + * @dataProvider invalidDataProvider + * @param string $data The invalid data + */ + public function testBeforeSaveErrors(string $data): void + { + $this->url->expects($this->any())->method('isValid')->willReturn(true); + $this->expectException('Magento\Framework\Exception\ValidatorException'); + $this->expectExceptionMessage('Fedex API endpoint URL\'s must use fedex.com'); + $this->urlConfig->setValue($data); + $this->urlConfig->beforeSave(); + } + + /** + * Validator Data Provider + * + * @return array + */ + public function validDataProvider(): array + { + return [ + [], + [null], + [''], + ['http://fedex.com'], + ['https://foo.fedex.com'], + ['http://foo.fedex.com/foo/bar?baz=bash&fizz=buzz'], + ]; + } + + /** + * @return \string[][] + */ + public function invalidDataProvider(): array + { + return [ + ['http://fedexfoo.com'], + ['https://foofedex.com'], + ['https://fedex.com.fake.com'], + ['https://fedex.info'], + ['http://fedex.com.foo.com/foo/bar?baz=bash&fizz=buzz'], + ['http://foofedex.com/foo/bar?baz=bash&fizz=buzz'], + ]; + } +} diff --git a/app/code/Magento/Fedex/etc/adminhtml/system.xml b/app/code/Magento/Fedex/etc/adminhtml/system.xml index f164a8e21e0ae..a200b5bda7199 100644 --- a/app/code/Magento/Fedex/etc/adminhtml/system.xml +++ b/app/code/Magento/Fedex/etc/adminhtml/system.xml @@ -40,12 +40,14 @@ </field> <field id="production_webservices_url" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" canRestore="1"> <label>Web-Services URL (Production)</label> + <backend_model>Magento\Fedex\Model\Config\Backend\FedexUrl</backend_model> <depends> <field id="sandbox_mode">0</field> </depends> </field> <field id="sandbox_webservices_url" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" canRestore="1"> <label>Web-Services URL (Sandbox)</label> + <backend_model>Magento\Fedex\Model\Config\Backend\FedexUrl</backend_model> <depends> <field id="sandbox_mode">1</field> </depends> diff --git a/app/code/Magento/Fedex/i18n/en_US.csv b/app/code/Magento/Fedex/i18n/en_US.csv index d1509d42730bc..2911ebe793f23 100644 --- a/app/code/Magento/Fedex/i18n/en_US.csv +++ b/app/code/Magento/Fedex/i18n/en_US.csv @@ -78,3 +78,4 @@ Debug,Debug "Show Method if Not Applicable","Show Method if Not Applicable" "Sort Order","Sort Order" "Can't convert a shipping cost from ""%1-%2"" for FedEx carrier.","Can't convert a shipping cost from ""%1-%2"" for FedEx carrier." +"Fedex API endpoint URL\'s must use fedex.com","Fedex API endpoint URL\'s must use fedex.com" diff --git a/app/code/Magento/GraphQl/Model/Backpressure/BackpressureFieldValidator.php b/app/code/Magento/GraphQl/Model/Backpressure/BackpressureFieldValidator.php index 5edbf4e207c91..c9f1c943a71e3 100644 --- a/app/code/Magento/GraphQl/Model/Backpressure/BackpressureFieldValidator.php +++ b/app/code/Magento/GraphQl/Model/Backpressure/BackpressureFieldValidator.php @@ -43,6 +43,7 @@ public function __construct( /** * Validate resolver args * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param Field $field * @param array $args * @return void diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php b/app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php index 9dcb2fdafb74f..6fd229f26a1a6 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\ImportExport\Model\Import; /** * Download history controller @@ -47,6 +48,7 @@ public function __construct( */ public function execute() { + // phpcs:ignore Magento2.Functions.DiscouragedFunction $fileName = basename($this->getRequest()->getParam('filename')); /** @var \Magento\ImportExport\Helper\Report $reportHelper */ @@ -59,17 +61,12 @@ public function execute() return $resultRedirect; } - $this->fileFactory->create( + return $this->fileFactory->create( $fileName, - null, + ['type' => 'filename', 'value' => Import::IMPORT_HISTORY_DIR . $fileName], DirectoryList::VAR_IMPORT_EXPORT, 'application/octet-stream', $reportHelper->getReportSize($fileName) ); - - /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ - $resultRaw = $this->resultRawFactory->create(); - $resultRaw->setContents($reportHelper->getReportOutput($fileName)); - return $resultRaw; } } diff --git a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php index ebf88e6c68e23..b74f48685feed 100644 --- a/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php +++ b/app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php @@ -106,18 +106,13 @@ public function execute() $fileSize = $this->sampleFileProvider->getSize($entityName); $fileName = $entityName . '.csv'; - $this->fileFactory->create( + return $this->fileFactory->create( $fileName, - null, + $fileContents, DirectoryList::VAR_IMPORT_EXPORT, 'application/octet-stream', $fileSize ); - - $resultRaw = $this->resultRawFactory->create(); - $resultRaw->setContents($fileContents); - - return $resultRaw; } /** diff --git a/app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php b/app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php index 57e33a1dd51a3..7c8e06d3f681d 100644 --- a/app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php +++ b/app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php @@ -9,14 +9,17 @@ use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\Redirect; +use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Request\Http; use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Raw; use Magento\Framework\Controller\Result\RawFactory; use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\ImportExport\Controller\Adminhtml\History\Download; use Magento\ImportExport\Helper\Report; +use Magento\ImportExport\Model\Import; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -155,8 +158,20 @@ public function testExecute($requestFilename, $processedFilename) $this->reportHelper->method('importFileExists') ->with($processedFilename) ->willReturn(true); - $this->resultRaw->expects($this->once())->method('setContents'); - $this->downloadController->execute(); + + $responseMock = $this->getMockBuilder(ResponseInterface::class) + ->getMock(); + $this->fileFactory->expects($this->once()) + ->method('create') + ->with( + $processedFilename, + ['type' => 'filename', 'value' =>Import::IMPORT_HISTORY_DIR . $processedFilename], + DirectoryList::VAR_IMPORT_EXPORT, + 'application/octet-stream', + 1 + ) + ->willReturn($responseMock); + $this->assertSame($responseMock, $this->downloadController->execute()); } /** diff --git a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml index ac39d72388e6c..fc58db1bed373 100644 --- a/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml +++ b/app/code/Magento/Marketplace/view/adminhtml/templates/index.phtml @@ -32,8 +32,8 @@ <h2 class="page-sub-title"><?= $block->escapeHtml(__('Partner search')) ?></h2> <p> <?= $block->escapeHtml(__( - 'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver ' . - 'the best possible customer experiences. They are recognized as experts in eCommerce, ' . + 'Magento has a thriving ecosystem of technology partners to help merchants and brands deliver ' + . 'the best possible customer experiences. They are recognized as experts in eCommerce, ' . 'search, email marketing, payments, tax, fraud, optimization and analytics, fulfillment, ' . 'and more. Visit the Magento Partner Directory to see all of our trusted partners.' )); ?> @@ -61,7 +61,7 @@ )); ?> </p> <a class="action-secondary" target="_blank" - href="https://marketplace.magento.com/"> + href="https://commercemarketplace.adobe.com/"> <?= $block->escapeHtml(__('Visit Magento Marketplaces')) ?> </a> </div> diff --git a/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/AssertStorefrontMultishippingAddressAndItemUKGEActionGroup.xml b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/AssertStorefrontMultishippingAddressAndItemUKGEActionGroup.xml new file mode 100644 index 0000000000000..a31fc9a0e02fb --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/AssertStorefrontMultishippingAddressAndItemUKGEActionGroup.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="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" extends="AssertStorefrontMultishippingAddressAndItemActionGroup"> + <annotations> + <description>Verify item information on Ship to Multiple Addresses page for UK and Germany.</description> + </annotations> + <arguments> + <argument name="addressQtySequenceNumber" type="string" defaultValue="1"/> + </arguments> + <remove keyForRemoval="verifyAddress"/> + <seeInField selector="{{MultishippingSection.shippingAddressSelector(addressQtySequenceNumber)}}" userInput="{{firstName}} {{lastName}}, {{addressStreetLine1}}, {{city}}, {{postCode}}, {{country}}" stepKey="verifyAddressDetails"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup.xml b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup.xml new file mode 100644 index 0000000000000..012648deae5e9 --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup.xml @@ -0,0 +1,33 @@ +<?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="StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup"> + <annotations> + <description>Goes to the provided Storefront URL. Selects the provided Product Option under the Product Attribute. Fills in the provided Quantity. Clicks Add to Cart. Validates that the Success Message is present.</description> + </annotations> + <arguments> + <argument name="urlKey" type="string"/> + <argument name="color" type="string"/> + <argument name="qty" type="string"/> + </arguments> + + <amOnPage url="{{urlKey}}.html" stepKey="goToStorefrontPage"/> + <waitForPageLoad stepKey="waitForProductFrontPageToLoad"/> + <waitForElementVisible selector="{{StorefrontProductInfoMainSection.productOptionSelectByColor}}" stepKey="waitForOptions"/> + <selectOption selector="{{StorefrontProductInfoMainSection.productOptionSelectByColor}}" userInput="{{color}}" stepKey="selectOption1"/> + <fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{qty}}" stepKey="fillProductQuantity"/> + <waitForElementNotVisible selector="{{StorefrontProductActionSection.addToCartDisabled}}" stepKey="waitForAddToCartButtonToRemoveDisabledState"/> + <waitForElementClickable selector="{{StorefrontProductActionSection.addToCart}}" stepKey="waitForAddToCartButton"/> + <click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="clickOnAddToCartButton"/> + <waitForPageLoad stepKey="waitForProductToAddInCart"/> + <waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/> + <seeElement selector="{{StorefrontProductPageSection.successMsg}}" stepKey="seeSuccessSaveMessage"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAssertBillingAddressInBillingInfoStepGEActionGroup.xml b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAssertBillingAddressInBillingInfoStepGEActionGroup.xml new file mode 100644 index 0000000000000..c401098a07943 --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Mftf/ActionGroup/StorefrontAssertBillingAddressInBillingInfoStepGEActionGroup.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="StorefrontAssertBillingAddressInBillingInfoStepGEActionGroup" extends="StorefrontAssertBillingAddressInBillingInfoStepActionGroup"> + <annotations> + <description>Assert that Billing Address block contains provided Address data for Germany.</description> + </annotations> + <remove keyForRemoval="seeState"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Section/MultishippingSection/MultishippingSection.xml b/app/code/Magento/Multishipping/Test/Mftf/Section/MultishippingSection/MultishippingSection.xml index 304f0a9c7a12a..5273a56bb9edf 100644 --- a/app/code/Magento/Multishipping/Test/Mftf/Section/MultishippingSection/MultishippingSection.xml +++ b/app/code/Magento/Multishipping/Test/Mftf/Section/MultishippingSection/MultishippingSection.xml @@ -18,5 +18,8 @@ <element name="productLink" type="button" selector="(//form[@id='checkout_multishipping_form']//a[contains(text(),'{{productName}}')])[{{sequenceNumber}}]" parameterized="true"/> <element name="removeItemButton" type="button" selector="//a[contains(@title, 'Remove Item')][{{var}}]" parameterized="true"/> <element name="back" type="button" selector=".action.back"/> + <element name="addressSection" type="text" selector="//div[@class='block-title']/strong[text()='Address {{var}} ']" parameterized="true"/> + <element name="flatRateCharge" type="text" selector="//span[@class='price' and text()='${{price}}']/../../label[contains(text(),'Fixed')]" parameterized="true"/> + <element name="enterNewAddress" type="button" selector=".action.add"/> </section> </sections> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Section/ShippingMethodSection.xml b/app/code/Magento/Multishipping/Test/Mftf/Section/ShippingMethodSection.xml index f8fff9dc77797..af62a0fc28337 100644 --- a/app/code/Magento/Multishipping/Test/Mftf/Section/ShippingMethodSection.xml +++ b/app/code/Magento/Multishipping/Test/Mftf/Section/ShippingMethodSection.xml @@ -13,5 +13,6 @@ <element name="selectShippingMethod" type="radio" selector="//div[@class='block block-shipping'][position()={{shippingBlockPosition}}]//dd[position()={{shippingMethodPosition}}]//input[@class='radio']" parameterized="true" timeout="5"/> <element name="shippingMethod" type="radio" selector="//div[@class='block block-shipping'][position()={{shippingBlockPosition}}]//dd[position()={{shippingMethodPosition}}]" parameterized="true" timeout="5"/> <element name="goToBillingInfo" type="button" selector=".action.primary.continue"/> + <element name="productDetails" type="text" selector="//a[text()='{{var1}}']/../../..//td[@class='col qty' and text()='{{var2}}']" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutAddressesToolbarSection.xml b/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutAddressesToolbarSection.xml index cf6bd10b0e8df..279967c2a3be0 100644 --- a/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutAddressesToolbarSection.xml +++ b/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutAddressesToolbarSection.xml @@ -17,6 +17,7 @@ <element name="checkmoneyorderonOverViewPage" type="text" selector="//dt[contains(text() , 'Check / Money order')]"/> <element name="othershippingitems" type="text" selector="//div[@class='block block-other']//div/strong[contains(text(),'Other items in your order')]/../..//div[2]//td/strong/a[contains(text(),'{{var}}')]" parameterized="true" /> <element name="shippingaddresstext" type="text" selector="//div[@class='box box-order-shipping-address']//span[contains(text(),'Shipping Address')]" /> + <element name="grandTotalAmount" type="text" selector="//div[@id='checkout-review-submit']/div[@class='grand totals']"/> </section> </sections> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutBillingToolbarSection.xml b/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutBillingToolbarSection.xml index 6cfc09c1653fd..c2ae07b987976 100644 --- a/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutBillingToolbarSection.xml +++ b/app/code/Magento/Multishipping/Test/Mftf/Section/StorefrontMultishippingCheckoutBillingToolbarSection.xml @@ -10,5 +10,7 @@ xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> <section name="StorefrontMultishippingCheckoutBillingToolbarSection"> <element name="goToReviewOrder" type="button" selector="button.action.primary.continue"/> + <element name="changeBillingAddress" type="button" selector="//span[text()='Change']"/> + <element name="selectBillingAddress" type="button" selector="//a[text()='333-33-333-33']/../../..//span[text()='Select Address']"/> </section> </sections> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Test/MultishipmentCheckoutWithDifferentProductTest.xml b/app/code/Magento/Multishipping/Test/Mftf/Test/MultishipmentCheckoutWithDifferentProductTest.xml new file mode 100644 index 0000000000000..cb09866438a79 --- /dev/null +++ b/app/code/Magento/Multishipping/Test/Mftf/Test/MultishipmentCheckoutWithDifferentProductTest.xml @@ -0,0 +1,395 @@ +<?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="MultishipmentCheckoutWithDifferentProductTest"> + <annotations> + <features value="Multishipment"/> + <stories value="Multishipping checkout with different product's types"/> + <title value="Multishipping checkout with different product's types"/> + <description value="Multishipping checkout with different product's types"/> + <severity value="MAJOR"/> + <testCaseId value="AC-4267"/> + <group value="Multishipment"/> + </annotations> + + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <createData entity="Customer_US_UK_DE" stepKey="createCustomer"/> + <!-- Create category and 2 simple product --> + <createData entity="ApiCategory" stepKey="createCategory"/> + <createData entity="ApiSimpleProduct" stepKey="firstSimpleProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="price">10</field> + </createData> + <createData entity="ApiSimpleProduct" stepKey="secondSimpleProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="price">15</field> + </createData> + <!-- Create group product with created above simple products --> + <createData entity="ApiGroupedProduct2" stepKey="createGroupedProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="OneSimpleProductLink" stepKey="addFirstProduct"> + <requiredEntity createDataKey="createGroupedProduct"/> + <requiredEntity createDataKey="firstSimpleProduct"/> + </createData> + <updateData entity="OneMoreSimpleProductLink" createDataKey="addFirstProduct" stepKey="addSecondProduct"> + <requiredEntity createDataKey="createGroupedProduct"/> + <requiredEntity createDataKey="secondSimpleProduct"/> + </updateData> + <!--edit default quantity of each simple product under grouped product.--> + <amOnPage url="{{AdminProductEditPage.url($$createGroupedProduct.id$$)}}" stepKey="openGroupedProductEditPage"/> + <actionGroup ref="FillDefaultQuantityForLinkedToGroupProductInGridActionGroup" stepKey="fillDefaultQtyForVirtualProduct"> + <argument name="productName" value="$$firstSimpleProduct.name$$"/> + <argument name="qty" value="1"/> + </actionGroup> + <actionGroup ref="FillDefaultQuantityForLinkedToGroupProductInGridActionGroup" stepKey="fillDefaultQtyForSecondProduct"> + <argument name="productName" value="$$secondSimpleProduct.name$$"/> + <argument name="qty" value="2"/> + </actionGroup> + <actionGroup ref="AdminFormSaveAndCloseActionGroup" stepKey="saveAndCloseCreatedGroupedProduct"/> + <!-- Create Configurable Product --> + <createData entity="ApiConfigurableProduct" stepKey="createConfigurableProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <!-- Search for the Created Configurable Product --> + <actionGroup ref="FilterAndSelectProductActionGroup" stepKey="openConfigurableProductForEdit"> + <argument name="productSku" value="$$createConfigurableProduct.sku$$"/> + </actionGroup> + <!--Update the Created Configurable Product --> + <actionGroup ref="AdminCreateThreeConfigurationsForConfigurableProductActionGroup" stepKey="editConfigurableProduct"> + <argument name="product" value="{{createConfigurableProduct}}"/> + <argument name="redColor" value="{{colorProductAttribute2.name}}"/> + <argument name="blueColor" value="{{colorProductAttribute3.name}}"/> + <argument name="whiteColor" value="{{colorProductAttribute1.name}}"/> + </actionGroup> + <!--Create bundle product with dynamic price with two simple products --> + <createData entity="ApiBundleProduct" stepKey="createDynamicBundleProduct"/> + <createData entity="DropDownBundleOption" stepKey="createFirstBundleOption"> + <requiredEntity createDataKey="createDynamicBundleProduct"/> + </createData> + <createData entity="ApiBundleLink" stepKey="firstLinkOptionToDynamicProduct"> + <requiredEntity createDataKey="createDynamicBundleProduct"/> + <requiredEntity createDataKey="createFirstBundleOption"/> + <requiredEntity createDataKey="firstSimpleProduct"/> + </createData> + <createData entity="ApiBundleLink" stepKey="secondLinkOptionToDynamicProduct"> + <requiredEntity createDataKey="createDynamicBundleProduct"/> + <requiredEntity createDataKey="createFirstBundleOption"/> + <requiredEntity createDataKey="secondSimpleProduct"/> + </createData> + <!--Assign bundle product to category--> + <amOnPage url="{{AdminProductEditPage.url($$createDynamicBundleProduct.id$$)}}" stepKey="openBundleProductEditPage"/> + <actionGroup ref="AdminAssignCategoryToProductAndSaveActionGroup" stepKey="assignCategoryToProduct"> + <argument name="categoryName" value="$createCategory.name$"/> + </actionGroup> + </before> + <after> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearGridFilters"/> + <actionGroup ref="AdminDeleteAllProductsFromGridActionGroup" stepKey="deleteAllProducts"/> + + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <!-- Delete the Created Color attribute--> + <actionGroup ref="AdminDeleteCreatedColorSpecificAttributeActionGroup" stepKey="deleteWhiteColorAttribute"> + <argument name="Color" value="{{colorProductAttribute1.name}}"/> + </actionGroup> + <actionGroup ref="AdminDeleteCreatedColorSpecificAttributeActionGroup" stepKey="deleteRedColorAttribute"> + <argument name="Color" value="{{colorProductAttribute2.name}}"/> + </actionGroup> + <actionGroup ref="AdminDeleteCreatedColorSpecificAttributeActionGroup" stepKey="deleteBlueColorAttribute"> + <argument name="Color" value="{{colorProductAttribute3.name}}"/> + </actionGroup> + <!-- Admin logout --> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addFirstSimpleProductToCart"> + <argument name="product" value="$$firstSimpleProduct$$"/> + </actionGroup> + <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addSecondSimpleProductToCart"> + <argument name="product" value="$$secondSimpleProduct$$"/> + </actionGroup> + <!-- Add grouped product to shopping cart --> + <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addGroupedProductToCart"> + <argument name="product" value="$$createGroupedProduct$$"/> + </actionGroup> + <!-- goto Bundle Product Page--> + <amOnPage url="{{StorefrontProductPage.url($createDynamicBundleProduct.custom_attributes[url_key]$)}}" stepKey="navigateToBundleProduct"/> + <!-- Add Bundle first Product to Cart --> + <actionGroup ref="StorefrontAddBundleProductToTheCartActionGroup" stepKey="addFirstBundleProductToCart"> + <argument name="productName" value="$firstSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + </actionGroup> + <!-- Add Bundle second Product to Cart --> + <actionGroup ref="StorefrontAddBundleProductToTheCartActionGroup" stepKey="addSecondBundleProductToCart"> + <argument name="productName" value="$secondSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + </actionGroup> + <!--Add different configurable product to cart.--> + <actionGroup ref="StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup" stepKey="addRedConfigurableProductToCart"> + <argument name="urlKey" value="$createConfigurableProduct.custom_attributes[url_key]$" /> + <argument name="color" value="Red"/> + <argument name="qty" value="1"/> + </actionGroup> + <actionGroup ref="StorefrontAddConfigurableProductOfSpecificColorToTheCartActionGroup" stepKey="addBlueConfigurableProductToCart"> + <argument name="urlKey" value="$createConfigurableProduct.custom_attributes[url_key]$" /> + <argument name="color" value="Blue"/> + <argument name="qty" value="3"/> + </actionGroup> + <!--verify total product quantity in minicart.--> + <seeElement selector="{{StorefrontMinicartSection.quantity(11)}}" stepKey="seeAddedProductQuantityInMiniCart"/> + <!-- Go to Shopping Cart page --> + <actionGroup ref="clickViewAndEditCartFromMiniCartActionGroup" stepKey="goToShoppingCartFromMinicart"/> + <!-- Link "Check Out with Multiple Addresses" is shown --> + <seeLink userInput="Check Out with Multiple Addresses" stepKey="seeLinkIsPresent"/> + <!-- Click Check Out with Multiple Addresses --> + <actionGroup ref="StorefrontCheckoutWithMultipleAddressesActionGroup" stepKey="checkoutWithMultipleAddresses"/> + <!-- Check Ship to Multiple Address Page is opened--> + <waitForPageLoad stepKey="waitForAddressPage"/> + <seeInCurrentUrl url="{{MultishippingCheckoutAddressesPage.url}}" stepKey="seeShipToMultipleAddressesPageIsOpened"/> + <!--select different address To Ship for different products--> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectFirstAddressFromThreeOption"> + <argument name="sequenceNumber" value="1"/> + <argument name="option" value="John Doe, 368 Broadway St. 113, New York, New York 10001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectSecondAddressFromThreeOption"> + <argument name="sequenceNumber" value="2"/> + <argument name="option" value="Jane Doe, 172, Westminster Bridge Rd, London, SE1 7RW, United Kingdom"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectThirdAddressFromThreeOption"> + <argument name="sequenceNumber" value="3"/> + <argument name="option" value="John Doe, 368 Broadway St. 113, New York, New York 10001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectFourthAddressFromThreeOption"> + <argument name="sequenceNumber" value="4"/> + <argument name="option" value="Jane Doe, 172, Westminster Bridge Rd, London, SE1 7RW, United Kingdom"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectFifthAddressFromThreeOption"> + <argument name="sequenceNumber" value="5"/> + <argument name="option" value="Jane Doe, 172, Westminster Bridge Rd, London, SE1 7RW, United Kingdom"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectSixthAddressFromThreeOption"> + <argument name="sequenceNumber" value="6"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectSeventhAddressFromThreeOption"> + <argument name="sequenceNumber" value="7"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectEighthAddressFromThreeOption"> + <argument name="sequenceNumber" value="8"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectNinthAddressFromThreeOption"> + <argument name="sequenceNumber" value="9"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectTenthAddressFromThreeOption"> + <argument name="sequenceNumber" value="10"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectEleventhAddressFromThree"> + <argument name="sequenceNumber" value="11"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/> + </actionGroup> + <click selector="{{SingleShippingSection.updateAddress}}" stepKey="clickOnUpdateAddress"/> + <waitForPageLoad time="30" stepKey="waitForShippingInformationAfterUpdated"/> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemActionGroup" stepKey="verifyFirstLineAllDetails"> + <argument name="sequenceNumber" value="1"/> + <argument name="productName" value="$firstSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="{{US_Address_NY.firstname}}"/> + <argument name="lastName" value="{{US_Address_NY.lastname}}"/> + <argument name="city" value="{{US_Address_NY.city}}"/> + <argument name="state" value="{{US_Address_NY.state}}"/> + <argument name="postCode" value="{{US_Address_NY.postcode}}"/> + <argument name="country" value="{{US_Address_NY.country}}"/> + <argument name="addressStreetLine1" value="{{US_Address_NY.street[0]}}"/> + <argument name="addressStreetLine2" value="{{US_Address_NY.street[1]}}"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemActionGroup" stepKey="verifySecondLineQtyAllDetails"> + <argument name="sequenceNumber" value="2"/> + <argument name="productName" value="$firstSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="{{US_Address_NY.firstname}}"/> + <argument name="lastName" value="{{US_Address_NY.lastname}}"/> + <argument name="city" value="{{US_Address_NY.city}}"/> + <argument name="state" value="{{US_Address_NY.state}}"/> + <argument name="postCode" value="{{US_Address_NY.postcode}}"/> + <argument name="country" value="{{US_Address_NY.country}}"/> + <argument name="addressStreetLine1" value="{{US_Address_NY.street[0]}}"/> + <argument name="addressStreetLine2" value="{{US_Address_NY.street[1]}}"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyThirdLineAllDetails"> + <argument name="productSequenceNumber" value="1"/> + <argument name="addressQtySequenceNumber" value="3"/> + <argument name="productName" value="$secondSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="Jane"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="London"/> + <argument name="postCode" value="SE1 7RW"/> + <argument name="country" value="United Kingdom"/> + <argument name="addressStreetLine1" value="172, Westminster Bridge Rd"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyFourthLineAllDetails"> + <argument name="productSequenceNumber" value="2"/> + <argument name="addressQtySequenceNumber" value="4"/> + <argument name="productName" value="$secondSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="Jane"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="London"/> + <argument name="postCode" value="SE1 7RW"/> + <argument name="country" value="United Kingdom"/> + <argument name="addressStreetLine1" value="172, Westminster Bridge Rd"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyFifthLineAllDetails"> + <argument name="productSequenceNumber" value="3"/> + <argument name="addressQtySequenceNumber" value="5"/> + <argument name="productName" value="$secondSimpleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="Jane"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="London"/> + <argument name="postCode" value="SE1 7RW"/> + <argument name="country" value="United Kingdom"/> + <argument name="addressStreetLine1" value="172, Westminster Bridge Rd"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifySixthLineAllDetails"> + <argument name="productSequenceNumber" value="1"/> + <argument name="addressQtySequenceNumber" value="6"/> + <argument name="productName" value="$createDynamicBundleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="Berlin"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifySeventhLineAllDetails"> + <argument name="productSequenceNumber" value="2"/> + <argument name="addressQtySequenceNumber" value="7"/> + <argument name="productName" value="$createDynamicBundleProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="Berlin"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyEighthLineAllDetails"> + <argument name="productSequenceNumber" value="1"/> + <argument name="addressQtySequenceNumber" value="8"/> + <argument name="productName" value="$createConfigurableProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="Berlin"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyNinthLineAllDetails"> + <argument name="productSequenceNumber" value="2"/> + <argument name="addressQtySequenceNumber" value="9"/> + <argument name="productName" value="$createConfigurableProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="Berlin"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyTenthLineAllDetails"> + <argument name="productSequenceNumber" value="3"/> + <argument name="addressQtySequenceNumber" value="10"/> + <argument name="productName" value="$createConfigurableProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="Berlin"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="AssertStorefrontMultishippingAddressAndItemUKGEActionGroup" stepKey="verifyEleventhLineAllDetails"> + <argument name="productSequenceNumber" value="4"/> + <argument name="addressQtySequenceNumber" value="11"/> + <argument name="productName" value="$createConfigurableProduct.name$"/> + <argument name="quantity" value="1"/> + <argument name="firstName" value="John"/> + <argument name="lastName" value="Doe"/> + <argument name="city" value="{{DE_Address_Berlin_Not_Default_Address.city}}"/> + <argument name="postCode" value="10789"/> + <argument name="country" value="Germany"/> + <argument name="addressStreetLine1" value="Augsburger Strabe 41"/> + </actionGroup> + <actionGroup ref="StorefrontSaveAddressActionGroup" stepKey="saveAddresses"/> + <!--verify multishipment all three section--> + <seeElement selector="{{MultishippingSection.addressSection('1')}}" stepKey="firstAddressSection"/> + <seeElement selector="{{MultishippingSection.addressSection('2')}}" stepKey="secondAddressSection"/> + <seeElement selector="{{MultishippingSection.addressSection('3')}}" stepKey="thirdAddressSection"/> + <!--verify flat rate charge for all three section--> + <seeElement selector="{{MultishippingSection.flatRateCharge('10.00')}}" stepKey="verifyFirstFlatRateAmount"/> + <seeElement selector="{{MultishippingSection.flatRateCharge('15.00')}}" stepKey="verifySecondFlatRateAmount"/> + <seeElement selector="{{MultishippingSection.flatRateCharge('30.00')}}" stepKey="verifyThirdFlatRateAmount"/> + <!-- Click On Continue to Billing--> + <click selector="{{StorefrontMultishippingCheckoutShippingToolbarSection.continueToBilling}}" stepKey="clickContinueToBilling"/> + <waitForPageLoad stepKey="waitForCheckoutShippingToolbarPageLoad"/> + <!-- See Billing Information Page is opened--> + <seeInCurrentUrl url="{{MultishippingCheckoutBillingPage.url}}" stepKey="seeBillingPageIsOpened"/> + <!-- click on change billing address button --> + <click selector="{{StorefrontMultishippingCheckoutBillingToolbarSection.changeBillingAddress}}" stepKey="clickChangeBillingAddressButton"/> + <!-- select new billing address--> + <click selector="{{StorefrontMultishippingCheckoutBillingToolbarSection.selectBillingAddress}}" stepKey="selectBillingAddress"/> + <wait stepKey="waitForPaymentPageToLoad" time="10"/> + <!-- Page contains Payment Method --> + <seeElement selector="{{StorefrontMultishippingCheckoutAddressesToolbarSection.checkmoneyorder}}" stepKey="CheckMoney"/> + <!-- Select Payment method "Check / Money Order --> + <conditionalClick selector="{{StorefrontMultishippingCheckoutAddressesToolbarSection.checkmoneyorder}}" dependentSelector="{{StorefrontMultishippingCheckoutAddressesToolbarSection.checkmoneyorder}}" visible="true" stepKey="selectCheckmoPaymentMethod"/> + <!-- Select Payment method e.g. "Check / Money Order" and click Go to Review Your Order --> + <waitForElement selector="{{StorefrontMultishippingCheckoutBillingToolbarSection.goToReviewOrder}}" stepKey="waitForElementgoToReviewOrder"/> + <click selector="{{StorefrontMultishippingCheckoutBillingToolbarSection.goToReviewOrder}}" stepKey="clickGoToReviewOrder"/> + <!-- See Order review Page is opened--> + <seeInCurrentUrl url="{{MultishippingCheckoutOverviewPage.url}}" stepKey="seeMultishipingCheckoutOverviewPageIsOpened"/> + <!-- Check Page contains customer's billing address on OverViewPage--> + <actionGroup ref="StorefrontAssertBillingAddressInBillingInfoStepGEActionGroup" stepKey="assertCustomerBillingInformationOverViewPage"> + <argument name="address" value="DE_Address_Berlin_Not_Default_Address"/> + </actionGroup> + <!-- Check Payment Method on OverViewPage--> + <seeElement selector="{{StorefrontMultishippingCheckoutAddressesToolbarSection.checkmoneyorderonOverViewPage}}" stepKey="seeCheckMoneyorderonOverViewPage"/> + <!--Check total amount --> + <see selector="{{StorefrontMultishippingCheckoutAddressesToolbarSection.grandTotalAmount}}" userInput="Grand Total: $215.00" stepKey="seeGrandTotalAmount"/> + <!-- Click 'Place Order' --> + <actionGroup ref="PlaceOrderActionGroup" stepKey="placeOrder"/> + <!--Check Thank you for your purchase!" page is opened --> + <see selector="{{StorefrontMultipleShippingMethodSection.successMessage}}" userInput="Successfully ordered" stepKey="seeSuccessMessage"/> + <!--Grab Order ID of placed all 3 order --> + <grabTextFrom selector="{{StorefrontMultipleShippingMethodSection.orderId('1')}}" stepKey="grabFirstOrderId"/> + <grabTextFrom selector="{{StorefrontMultipleShippingMethodSection.orderId('2')}}" stepKey="grabSecondOrderId"/> + <grabTextFrom selector="{{StorefrontMultipleShippingMethodSection.orderId('3')}}" stepKey="grabThirdOrderId"/> + <!-- Go to My Account > My Orders and verify orderId--> + <amOnPage url="{{StorefrontCustomerOrdersHistoryPage.url}}" stepKey="goToMyOrdersPage"/> + <waitForPageLoad stepKey="waitForMyOrdersPageLoad"/> + <seeElement selector="{{StorefrontCustomerOrdersGridSection.orderView({$grabFirstOrderId})}}" stepKey="seeFirstOrder"/> + <seeElement selector="{{StorefrontCustomerOrdersGridSection.orderView({$grabSecondOrderId})}}" stepKey="seeSecondOrder"/> + <seeElement selector="{{StorefrontCustomerOrdersGridSection.orderView({$grabThirdOrderId})}}" stepKey="seeThirdOrder"/> + <!-- Logout customer --> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> + </test> +</tests> diff --git a/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml b/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml index 82563e5055c2a..07b2834fa04d4 100644 --- a/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml +++ b/app/code/Magento/Multishipping/Test/Mftf/Test/StoreFrontGuestCheckingWithMultishipmentTest.xml @@ -44,6 +44,7 @@ </actionGroup> <actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openCart"/> <click selector="{{MultishippingSection.checkoutWithMultipleAddresses}}" stepKey="proceedMultishipping"/> + <waitForElementClickable selector="{{StorefrontCustomerSignInPopupFormSection.createAnAccount}}" stepKey="waitForCreateAccount"/> <click selector="{{StorefrontCustomerSignInPopupFormSection.createAnAccount}}" stepKey="clickCreateAccount"/> <seeElement selector="{{CheckoutShippingSection.region}}" stepKey="seeRegionSelector"/> </test> diff --git a/app/code/Magento/Newsletter/Model/ResourceModel/Queue/Collection.php b/app/code/Magento/Newsletter/Model/ResourceModel/Queue/Collection.php index f4e72c61953f0..bd7c62e82e630 100644 --- a/app/code/Magento/Newsletter/Model/ResourceModel/Queue/Collection.php +++ b/app/code/Magento/Newsletter/Model/ResourceModel/Queue/Collection.php @@ -30,8 +30,6 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab protected $_isStoreFilter = false; /** - * Date - * * @var \Magento\Framework\Stdlib\DateTime\DateTime */ protected $_date; diff --git a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php index 64f6c066f01b6..d59bf28310778 100644 --- a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php +++ b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php @@ -32,7 +32,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab protected $_storeTable; /** - * Queue joined flag + * Flag for joined queue * * @var boolean */ @@ -82,8 +82,7 @@ public function __construct( } /** - * Constructor - * Configures collection + * Constructor configures collection * * @return void */ diff --git a/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php b/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php index 5340f5204e21e..061cc801d5d1e 100644 --- a/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php +++ b/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php @@ -5,6 +5,7 @@ */ namespace Magento\PageCache\Model\App\FrontController; +use Magento\Framework\App\PageCache\NotCacheableInterface; use Magento\Framework\App\Response\Http as ResponseHttp; /** @@ -73,7 +74,7 @@ public function aroundDispatch( $result = $this->kernel->load(); if ($result === false) { $result = $proceed($request); - if ($result instanceof ResponseHttp) { + if ($result instanceof ResponseHttp && !$result instanceof NotCacheableInterface) { $this->addDebugHeaders($result); $this->kernel->process($result); } diff --git a/app/code/Magento/PageCache/Test/Mftf/Test/FlushStaticFilesCacheButtonVisibilityTest.xml b/app/code/Magento/PageCache/Test/Mftf/Test/FlushStaticFilesCacheButtonVisibilityTest.xml index a7cf367ff3030..4d1a174632661 100644 --- a/app/code/Magento/PageCache/Test/Mftf/Test/FlushStaticFilesCacheButtonVisibilityTest.xml +++ b/app/code/Magento/PageCache/Test/Mftf/Test/FlushStaticFilesCacheButtonVisibilityTest.xml @@ -31,6 +31,7 @@ <waitForPageLoad stepKey="waitForPageCacheManagementLoad"/> <!-- Check 'Flush Static Files Cache' not visible in production mode. --> - <dontSee selector="{{AdminCacheManagementSection.additionalCacheButton('Flush Static Files Cache')}}" stepKey="dontSeeFlushStaticFilesButton" /> + <scrollTo selector="{{AdminCacheManagementSection.additionalCacheButton('Flush Catalog Images Cache')}}" stepKey="scrollToAdditionalCacheButtons"/> + <dontSeeElement selector="{{AdminCacheManagementSection.additionalCacheButton('Flush Static Files Cache')}}" stepKey="dontSeeFlushStaticFilesButton"/> </test> </tests> diff --git a/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php b/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php index 0827f84a21192..30e0e6a0276ad 100644 --- a/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php +++ b/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php @@ -11,6 +11,7 @@ use Laminas\Http\Header\GenericHeader; use Magento\Framework\App\FrontControllerInterface; use Magento\Framework\App\PageCache\Kernel; +use Magento\Framework\App\PageCache\NotCacheableInterface; use Magento\Framework\App\PageCache\Version; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\Http; @@ -243,6 +244,41 @@ public function testAroundDispatchDisabled($state): void ); } + /** + * @return void + */ + public function testAroundNotCacheableResponse(): void + { + $this->configMock + ->expects($this->once()) + ->method('getType') + ->willReturn(Config::BUILT_IN); + $this->configMock->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + $this->versionMock + ->expects($this->once()) + ->method('process'); + $this->kernelMock->expects($this->once()) + ->method('load') + ->willReturn(false); + $this->stateMock->expects($this->never()) + ->method('getMode'); + $this->kernelMock->expects($this->never()) + ->method('process'); + $this->responseMock->expects($this->never()) + ->method('setHeader'); + $notCacheableResponse = $this->createMock(NotCacheableInterface::class); + $this->assertSame( + $notCacheableResponse, + $this->plugin->aroundDispatch( + $this->frontControllerMock, + fn () => $notCacheableResponse, + $this->requestMock + ) + ); + } + /** * @return array */ diff --git a/app/code/Magento/Paypal/Test/Mftf/ActionGroup/AdminPayPalPayflowProWithValutActionGroup.xml b/app/code/Magento/Paypal/Test/Mftf/ActionGroup/AdminPayPalPayflowProWithValutActionGroup.xml new file mode 100644 index 0000000000000..c97e580a2c93a --- /dev/null +++ b/app/code/Magento/Paypal/Test/Mftf/ActionGroup/AdminPayPalPayflowProWithValutActionGroup.xml @@ -0,0 +1,36 @@ +<?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="AdminPayPalPayflowProWithValutActionGroup"> + <annotations> + <description>Goes to the 'Configuration' page for 'Payment Methods'. Fills in the provided Sample PayPal Payflow pro credentials and other details. Clicks on Save.</description> + </annotations> + <arguments> + <argument name="credentials" defaultValue="SamplePaypalPaymentsProConfig"/> + <argument name="countryCode" type="string" defaultValue="us"/> + </arguments> + <amOnPage url="{{AdminConfigPaymentMethodsPage.url}}" stepKey="navigateToPaymentConfigurationPage"/> + <waitForPageLoad stepKey="waitForConfigPageLoad"/> + <click selector ="{{OtherPayPalPaymentsConfigSection.expandTab(countryCode)}}" stepKey="expandOtherPaypalConfigButton"/> + <scrollTo selector="{{PayPalPayflowProConfigSection.paymentGateway(countryCode)}}" stepKey="scrollToConfigure"/> + <click selector ="{{PayPalPayflowProConfigSection.configureBtn(countryCode)}}" stepKey="clickPayPalPaymentsProConfigureBtn"/> + <scrollTo selector="{{PayPalPayflowProConfigSection.partner(countryCode)}}" stepKey="scrollToBottom"/> + <fillField selector ="{{PayPalPayflowProConfigSection.partner(countryCode)}}" userInput="{{credentials.paypal_paymentspro_parner}}" stepKey="inputPartner"/> + <fillField selector ="{{PayPalPayflowProConfigSection.user(countryCode)}}" userInput="{{credentials.paypal_paymentspro_user}}" stepKey="inputUser"/> + <fillField selector ="{{PayPalPayflowProConfigSection.vendor(countryCode)}}" userInput="{{credentials.paypal_paymentspro_vendor}}" stepKey="inputVendor"/> + <fillField selector ="{{PayPalPayflowProConfigSection.password(countryCode)}}" userInput="{{credentials.paypal_paymentspro_password}}" stepKey="inputPassword"/> + <selectOption selector="{{PayPalPayflowProConfigSection.testmode(countryCode)}}" userInput="Yes" stepKey="enableTestMode"/> + <selectOption selector ="{{PayPalPayflowProConfigSection.enableSolution(countryCode)}}" userInput="Yes" stepKey="enableSolution"/> + <selectOption selector ="{{PayPalPayflowProConfigSection.enableVault(countryCode)}}" userInput="Yes" stepKey="enableSolutionValut"/> + <click selector="{{AdminConfigSection.saveButton}}" stepKey="saveConfig"/> + <waitForPageLoad stepKey="waitForSaving"/> + <see selector="{{AdminMessagesSection.success}}" userInput="You saved the configuration." stepKey="seeSuccess"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Paypal/Test/Mftf/ActionGroup/StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup.xml b/app/code/Magento/Paypal/Test/Mftf/ActionGroup/StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup.xml index a2c7b7d82a349..0a1077e0c18eb 100644 --- a/app/code/Magento/Paypal/Test/Mftf/ActionGroup/StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup.xml +++ b/app/code/Magento/Paypal/Test/Mftf/ActionGroup/StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup.xml @@ -19,11 +19,11 @@ <conditionalClick selector="{{PayPalPaymentSection.existingAccountLoginBtn}}" dependentSelector="{{PayPalPaymentSection.existingAccountLoginBtn}}" visible="true" stepKey="skipAccountCreationAndLogin"/> <waitForPageLoad stepKey="waitForLoginPageLoad"/> <waitForElement selector="{{PayPalPaymentSection.email}}" stepKey="waitForLoginForm" /> - <fillField selector="{{PayPalPaymentSection.email}}" userInput="{{credentials.magento/paypal_sandbox_login_email}}" stepKey="fillEmail"/> + <fillField selector="{{PayPalPaymentSection.email}}" userInput="{{credentials.magento/PAYPAL_LOGIN}}" stepKey="fillEmail"/> <click selector="{{PayPalPaymentSection.nextButton}}" stepKey="clickNext"/> <waitForElementVisible selector="{{PayPalPaymentSection.password}}" stepKey="waitForPasswordField"/> <click selector="{{PayPalPaymentSection.password}}" stepKey="focusOnPasswordField"/> - <fillField selector="{{PayPalPaymentSection.password}}" userInput="{{credentials.magento/paypal_sandbox_login_password}}" stepKey="fillPassword"/> + <fillField selector="{{PayPalPaymentSection.password}}" userInput="{{credentials.magento/PAYPAL_PWD}}" stepKey="fillPassword"/> <click selector="{{PayPalPaymentSection.loginBtn}}" stepKey="login"/> <waitForPageLoad stepKey="wait"/> </actionGroup> diff --git a/app/code/Magento/Paypal/Test/Mftf/Data/PaypalData.xml b/app/code/Magento/Paypal/Test/Mftf/Data/PaypalData.xml index 95e69cf6e93cf..4e88bbe73e2e6 100644 --- a/app/code/Magento/Paypal/Test/Mftf/Data/PaypalData.xml +++ b/app/code/Magento/Paypal/Test/Mftf/Data/PaypalData.xml @@ -214,7 +214,7 @@ </entity> <entity name="VisaDefaultCardInfo"> <data key="cardNumberEnding">1111</data> - <data key="cardExpire">01/2030</data> + <data key="cardExpire">1/2030</data> </entity> <entity name="SamplePaypalExpressConfig2" type="paypal_express_config"> <data key="paypal_express_email">rlus_1349181941_biz@ebay.com</data> @@ -223,4 +223,10 @@ <data key="paypal_express_api_signature">AFcWxV21C7fd0v3bYYYRCpSSRl31AqoP3QLd.JUUpDPuPpQIgT0-m401</data> <data key="paypal_express_merchantID">54Z2EE6T7PRB4</data> </entity> + <entity name="SamplePaypalPaymentsProConfig" type="paypal_paymentspro_config"> + <data key="paypal_paymentspro_parner">PayPal</data> + <data key="paypal_paymentspro_user">MksGLTest</data> + <data key="paypal_paymentspro_vendor">MksGLTest</data> + <data key="paypal_paymentspro_password">Abcd@123</data> + </entity> </entities> diff --git a/app/code/Magento/Paypal/Test/Mftf/Section/OtherPayPalPaymentsConfigSection/PayPalPayflowProConfigSection.xml b/app/code/Magento/Paypal/Test/Mftf/Section/OtherPayPalPaymentsConfigSection/PayPalPayflowProConfigSection.xml new file mode 100644 index 0000000000000..9f4b2a6a47f19 --- /dev/null +++ b/app/code/Magento/Paypal/Test/Mftf/Section/OtherPayPalPaymentsConfigSection/PayPalPayflowProConfigSection.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> + <section name="PayPalPayflowProConfigSection"> + <element name="configureBtn" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout-head" parameterized="true"/> + <element name="partner" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_partner" parameterized="true"/> + <element name="user" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_user" parameterized="true"/> + <element name="vendor" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_vendor" parameterized="true"/> + <element name="password" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_pwd" parameterized="true"/> + <element name="testmode" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_paypal_payflow_api_settings_sandbox_flag" parameterized="true"/> + <element name="enableSolution" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_enable_paypal_payflow" parameterized="true"/> + <element name="enableVault" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways_paypal_payflowpro_with_express_checkout_paypal_payflow_required_payflowpro_cc_vault_active" parameterized="true"/> + <element name="paymentGateway" type="button" selector="#payment_{{countryCode}}_paypal_payment_gateways-head" parameterized="true"/> + </section> +</sections> diff --git a/app/code/Magento/Paypal/Test/Mftf/Test/DeleteSavedWithPayflowProCreditCardFromCustomerAccountTest.xml b/app/code/Magento/Paypal/Test/Mftf/Test/DeleteSavedWithPayflowProCreditCardFromCustomerAccountTest.xml new file mode 100644 index 0000000000000..5fc0469a1b096 --- /dev/null +++ b/app/code/Magento/Paypal/Test/Mftf/Test/DeleteSavedWithPayflowProCreditCardFromCustomerAccountTest.xml @@ -0,0 +1,105 @@ +<?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="DeleteSavedWithPayflowProCreditCardFromCustomerAccountTest"> + <annotations> + <stories value="Stored Payment Method"/> + <title value="Delete saved with Payflow Pro credit card from customer account"/> + <description value="Delete saved with Payflow Pro credit card from customer account"/> + <severity value="MAJOR"/> + <testCaseId value="AC-4838"/> + <group value="paypal"/> + </annotations> + <before> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + <createData entity="SimpleProduct" stepKey="createSimpleProduct1"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <actionGroup ref="AdminPayPalPayflowProWithValutActionGroup" stepKey="ConfigPayPalExpress"> + <argument name="credentials" value="SamplePaypalPaymentsProConfig"/> + </actionGroup> + </before> + <after> + <createData entity="RollbackPaypalPayflowPro" stepKey="rollbackPaypalPayflowProConfig"/> + <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!-- Login as Customer --> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct1.custom_attributes[url_key]$$)}}" stepKey="goToStorefront"/> + <!-- Add product 1 to cart --> + <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage"> + <argument name="productName" value="$createSimpleProduct1.name$"/> + </actionGroup> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/> + <!-- Select shipping --> + <actionGroup ref="StorefrontSetShippingMethodActionGroup" stepKey="selectFlatrate"> + <argument name="shippingMethodName" value="Flat Rate"/> + </actionGroup> + <!-- Go to Order review --> + <actionGroup ref="StorefrontCheckoutClickNextOnShippingStepActionGroup" stepKey="goToCheckoutPaymentPage"/> + <!-- Checkout select Credit Card (Payflow Pro) and place order--> + <waitForPageLoad stepKey="waitForLoadingMask"/> + <waitForPageLoad stepKey="waitForPaymentPageLoad"/> + <conditionalClick selector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Credit Card (Payflow Pro)')}}" dependentSelector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Check / Money order')}}" visible="true" stepKey="selectCheckmoPaymentMethod"/> + <waitForPageLoad stepKey="waitForLoadingMaskAfterPaymentMethodSelection"/> + <!--Fill Card Data --> + <actionGroup ref="StorefrontPaypalFillCardDataActionGroup" stepKey="fillCardDataPaypal"> + <argument name="cardData" value="VisaDefaultCard"/> + </actionGroup> + <waitForPageLoad stepKey="waitForFillCardData"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder"/> + <!-- 2nd time order--> + <amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct1.custom_attributes[url_key]$$)}}" stepKey="goToStorefront2"/> + <!-- Add product 1 to cart --> + <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage2"> + <argument name="productName" value="$createSimpleProduct1.name$"/> + </actionGroup> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart2"/> + <!-- Select shipping --> + <actionGroup ref="StorefrontSetShippingMethodActionGroup" stepKey="selectFlatrate2"> + <argument name="shippingMethodName" value="Flat Rate"/> + </actionGroup> + <!-- Go to Order review --> + <actionGroup ref="StorefrontCheckoutClickNextOnShippingStepActionGroup" stepKey="goToCheckoutPaymentPage2"/> + <!-- Checkout select Credit Card (Payflow Pro) and place order--> + <waitForPageLoad stepKey="waitForLoadingMask2ndTime"/> + <waitForPageLoad stepKey="waitForPaymentPageLoad2ndTime"/> + <conditionalClick selector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Credit Card (Payflow Pro)')}}" dependentSelector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Check / Money order')}}" visible="true" stepKey="selectCheckmoPaymentMethod2"/> + <waitForPageLoad stepKey="waitForLoadingMaskAfterPaymentMethodSelection2"/> + <!--Fill Card Data --> + <actionGroup ref="StorefrontPaypalFillCardDataActionGroup" stepKey="fillCardDataPaypal2"> + <argument name="cardData" value="Visa3DSecureCard"/> + </actionGroup> + <waitForPageLoad stepKey="waitForFillCardData2ndTime"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder2"/> + <!-- Go to My Account --> + <!-- Open My Account > Stored Payment Methods --> + <amOnPage stepKey="goToMyAccountPage" url="{{StorefrontCustomerDashboardPage.url}}"/> + <waitForPageLoad stepKey="waitForSideBarPageLoad2ndTime"/> + <actionGroup ref="StorefrontCustomerGoToSidebarMenu" stepKey="goToSidebarMenu2"> + <argument name="menu" value="Stored Payment Methods"/> + </actionGroup> + <!-- Assert Card number that ends with 1111 and exp Date--> + <actionGroup ref="AssertStorefrontCustomerSavedCardActionGroup" stepKey="assertCustomerPaymentMethod"> + <argument name="card" value="VisaDefaultCardInfo"/> + </actionGroup> + <!-- Assert Card number that ends with 0002 and exp Date--> + <actionGroup ref="AssertStorefrontCustomerSavedCardActionGroup" stepKey="assertCustomerPaymentMethod2"> + <argument name="card" value="Visa3DSecureCardInfo"/> + </actionGroup> + <!-- Delete second card--> + <actionGroup ref="StorefrontDeleteStoredPaymentMethodActionGroup" stepKey="deleteStoredCard"> + <argument name="card" value="Visa3DSecureCardInfo"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Paypal/Test/Mftf/Test/EditOrderFromAdminWithSavedWithinPayPalPayflowProCreditCardForRegisteredCustomerTest.xml b/app/code/Magento/Paypal/Test/Mftf/Test/EditOrderFromAdminWithSavedWithinPayPalPayflowProCreditCardForRegisteredCustomerTest.xml new file mode 100644 index 0000000000000..f16c1df71a129 --- /dev/null +++ b/app/code/Magento/Paypal/Test/Mftf/Test/EditOrderFromAdminWithSavedWithinPayPalPayflowProCreditCardForRegisteredCustomerTest.xml @@ -0,0 +1,93 @@ +<?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="EditOrderFromAdminWithSavedWithinPayPalPayflowProCreditCardForRegisteredCustomerTest"> + <annotations> + <features value="PayPal"/> + <stories value="Payment methods"/> + <title value="Edit Order from Admin with saved within PayPal Payflow Pro credit card for Registered Customer"/> + <description value="Edit Order from Admin with saved within PayPal Payflow Pro credit card for Registered Customer"/> + <severity value="MAJOR"/> + <testCaseId value="AC-5107"/> + <group value="paypal"/> + <group value="payflowpro"/> + </annotations> + <before> + <!--Create a customer--> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + <!-- Create simple product--> + <createData entity="SimpleProduct" stepKey="createSimpleProduct1"/> + <!-- Login to admin--> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <!-- Configure Paypal payflowpro--> + <actionGroup ref="AdminPayPalPayflowProWithValutActionGroup" stepKey="ConfigPayPalExpress"> + <argument name="credentials" value="SamplePaypalPaymentsProConfig"/> + </actionGroup> + </before> + <after> + <!-- Disable payflowpro--> + <createData entity="RollbackPaypalPayflowPro" stepKey="rollbackPaypalPayflowProConfig"/> + <!-- Delete product and customer--> + <deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <!-- Logout--> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!-- Login as Customer --> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct1.custom_attributes[url_key]$$)}}" stepKey="goToStorefront"/> + <!-- Add product 1 to cart --> + <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage"> + <argument name="productName" value="$createSimpleProduct1.name$"/> + </actionGroup> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/> + <!-- Select shipping --> + <actionGroup ref="StorefrontSetShippingMethodActionGroup" stepKey="selectFlatrate"> + <argument name="shippingMethodName" value="Flat Rate"/> + </actionGroup> + <!-- Go to Order review --> + <actionGroup ref="StorefrontCheckoutClickNextOnShippingStepActionGroup" stepKey="goToCheckoutPaymentPage"/> + <!-- Checkout select Credit Card (Payflow Pro) and place order--> + <waitForPageLoad stepKey="waitForLoadingMask"/> + <waitForPageLoad stepKey="waitForPaymentPageLoad"/> + <conditionalClick selector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Credit Card (Payflow Pro)')}}" dependentSelector="{{StorefrontCheckoutPaymentMethodSection.checkPaymentMethodByName('Check / Money order')}}" visible="true" stepKey="selectCheckmoPaymentMethod"/> + <waitForPageLoad stepKey="waitForLoadingMaskAfterPaymentMethodSelection"/> + <!--Fill Card Data and place an order--> + <actionGroup ref="StorefrontPaypalFillCardDataActionGroup" stepKey="fillCardDataPaypal"> + <argument name="cardData" value="VisaDefaultCard"/> + </actionGroup> + <waitForPageLoad stepKey="waitForFillCardData"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickOnPlaceOrder"/> + <!-- Grab order number--> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/> + <!--Navigate to admin order grid and filter the order--> + <actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrderById"> + <argument name="orderId" value="$grabOrderNumber"/> + </actionGroup> + <actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="clickOrderRow"/> + <!-- Click on edit--> + <actionGroup ref="AdminEditOrderActionGroup" stepKey="openOrderForEdit"> + <argument name="orderId" value="$grabOrderNumber"/> + </actionGroup> + <!-- Select stored card and submit order--> + <conditionalClick selector="{{AdminOrderFormPaymentSection.storedCard}}" dependentSelector="{{AdminOrderFormPaymentSection.checkMoneyOption}}" visible="true" stepKey="checkCheckMoneyOption"/> + <click selector="{{OrdersGridSection.submitOrder}}" stepKey="submitOrder"/> + <see stepKey="seeSuccessMessageForOrder" userInput="You created the order."/> + <!-- Filter order--> + <actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrderByIdAgain"> + <argument name="orderId" value="$grabOrderNumber"/> + </actionGroup> + <!--verify order status is canceled--> + <click selector="{{AdminOrdersGridSection.secondRow}}" stepKey="clickSecondOrderRow"/> + <waitForPageLoad stepKey="waitForOrderPageLoad"/> + <see userInput="Canceled" selector="{{AdminOrderDetailsInformationSection.orderStatus}}" stepKey="seeOrderStatus"/> + </test> +</tests> diff --git a/app/code/Magento/Paypal/Test/Mftf/Test/EnablePaypalExpressCheckoutAndSubmitAnOrderUsingPaypalExpressCheckoutTest.xml b/app/code/Magento/Paypal/Test/Mftf/Test/EnablePaypalExpressCheckoutAndSubmitAnOrderUsingPaypalExpressCheckoutTest.xml new file mode 100644 index 0000000000000..42606464c4a9d --- /dev/null +++ b/app/code/Magento/Paypal/Test/Mftf/Test/EnablePaypalExpressCheckoutAndSubmitAnOrderUsingPaypalExpressCheckoutTest.xml @@ -0,0 +1,76 @@ +<?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="EnablePaypalExpressCheckoutAndSubmitAnOrderUsingPaypalExpressCheckoutTest"> + <annotations> + <features value="PayPal"/> + <stories value="Enable paypal express checkout and validate the customer checkout payment works with paypal express"/> + <title value="Enable paypal express checkout and validate the customer checkout payment works with paypal express"/> + <description value="Enable paypal express checkout and validate the customer checkout payment works with paypal express"/> + <severity value="MAJOR"/> + <testCaseId value="AC-6951"/> + </annotations> + <before> + <!--Enable free shipping method --> + <magentoCLI command="config:set {{EnableFreeShippingConfigData.path}} {{EnableFreeShippingConfigData.value}}" stepKey="enableFreeShipping"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <!-- New Customer --> + <createData entity="Simple_US_Customer" stepKey="createCustomer"> + <field key="firstname">John1</field> + <field key="lastname">Doe1</field> + </createData> + <createData entity="SimpleProduct2" stepKey="simpleProduct"> + <field key="price">1</field> + </createData> + <actionGroup ref="AdminPayPalExpressCheckoutEnableActionGroup" stepKey="ConfigPayPalExpress"> + <argument name="credentials" value="SamplePaypalExpressConfig2"/> + </actionGroup> + </before> + <after> + <magentoCLI command="config:set {{DisableFreeShippingConfigData.path}} {{DisableFreeShippingConfigData.value}}" stepKey="disableFreeShipping"/> + <magentoCLI command="config:set paypal/general/merchant_country US" stepKey="setMerchantCountry"/> + <magentoCLI command="config:set payment/paypal_express/active 0" stepKey="disablePayPalExpress"/> + <magentoCLI command="config:set payment/wps_express/active 0" stepKey="disableWPSExpress"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="signUpNewUser"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addSimpleProductToCart"> + <argument name="product" value="$simpleProduct$"/> + </actionGroup> + <!--Go to cart page--> + <actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="gotoCart"/> + <!-- Click on Paypal paypal button--> + <actionGroup ref="SwitchToPayPalGroupBtnActionGroup" stepKey="clickPayPalBtn"> + <argument name="elementNumber" value="1"/> + </actionGroup> + <!--Login to Paypal in-context--> + <actionGroup ref="StorefrontLoginToPayPalPaymentAccountTwoStepActionGroup" stepKey="LoginToPayPal"/> + <!--Transfer Cart Line and Shipping Method assertion--> + <actionGroup ref="PayPalAssertTransferLineAndShippingMethodNotExistActionGroup" stepKey="assertPayPalSettings"/> + <!--Click PayPal button and go back to Magento site--> + <actionGroup ref="StorefrontPaypalSwitchBackToMagentoFromCheckoutPageActionGroup" stepKey="goBackToMagentoSite"/> + <actionGroup ref="StorefrontSelectShippingMethodOnOrderReviewPageActionGroup" stepKey="selectShippingMethod"> + <argument name="shippingMethod" value="Free - $0.00"/> + </actionGroup> + <actionGroup ref="StorefrontPlaceOrderOnOrderReviewPageActionGroup" stepKey="clickPlaceOrderBtn"/> + <!-- I see order successful Page instead of Order Review Page --> + <actionGroup ref="AssertStorefrontCheckoutSuccessActionGroup" stepKey="assertCheckoutSuccess"/> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/> + <!--Go to Admin and check order information--> + <actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrderGrid"> + <argument name="orderId" value="$grabOrderNumber"/> + </actionGroup> + <actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="clickOrderRow"/> + <actionGroup ref="CancelPendingOrderActionGroup" stepKey="cancelOrder"/> + </test> +</tests> diff --git a/app/code/Magento/Quote/Model/BillingAddressManagement.php b/app/code/Magento/Quote/Model/BillingAddressManagement.php index 6f8a44dff464c..9ed4f5ecd516b 100644 --- a/app/code/Magento/Quote/Model/BillingAddressManagement.php +++ b/app/code/Magento/Quote/Model/BillingAddressManagement.php @@ -3,14 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Quote\Model; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\InputException; -use Magento\Quote\Model\Quote\Address\BillingAddressPersister; -use Psr\Log\LoggerInterface as Logger; use Magento\Quote\Api\BillingAddressManagementInterface; -use Magento\Framework\App\ObjectManager; +use Magento\Quote\Api\Data\AddressInterface; +use Psr\Log\LoggerInterface as Logger; /** * Quote billing address write service object. @@ -25,14 +26,14 @@ class BillingAddressManagement implements BillingAddressManagementInterface protected $addressValidator; /** - * Logger. + * Logger object. * * @var Logger */ protected $logger; /** - * Quote repository. + * Quote repository object. * * @var \Magento\Quote\Api\CartRepositoryInterface */ @@ -72,10 +73,14 @@ public function __construct( * @inheritdoc * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false) + public function assign($cartId, AddressInterface $address, $useForShipping = false) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); + + // validate the address + $this->addressValidator->validateWithExistingAddress($quote, $address); + $address->setCustomerId($quote->getCustomerId()); $quote->removeAddress($quote->getBillingAddress()->getId()); $quote->setBillingAddress($address); @@ -104,6 +109,7 @@ public function get($cartId) * * @return \Magento\Quote\Model\ShippingAddressAssignment * @deprecated 101.0.0 + * @see \Magento\Quote\Model\ShippingAddressAssignment */ private function getShippingAddressAssignment() { diff --git a/app/code/Magento/Quote/Model/QuoteAddressValidator.php b/app/code/Magento/Quote/Model/QuoteAddressValidator.php index f0bc12f7b3a36..f8e7141b3bb00 100644 --- a/app/code/Magento/Quote/Model/QuoteAddressValidator.php +++ b/app/code/Magento/Quote/Model/QuoteAddressValidator.php @@ -3,8 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Quote\Model; +use Magento\Customer\Api\AddressRepositoryInterface; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\Session; +use Magento\Framework\Exception\InputException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\CartInterface; @@ -17,35 +24,33 @@ class QuoteAddressValidator { /** - * Address factory. - * - * @var \Magento\Customer\Api\AddressRepositoryInterface + * @var AddressRepositoryInterface */ - protected $addressRepository; + protected AddressRepositoryInterface $addressRepository; /** - * Customer repository. - * - * @var \Magento\Customer\Api\CustomerRepositoryInterface + * @var CustomerRepositoryInterface */ - protected $customerRepository; + protected CustomerRepositoryInterface $customerRepository; /** + * @var Session * @deprecated 101.1.1 This class is not a part of HTML presentation layer and should not use sessions. + * @see Session */ - protected $customerSession; + protected Session $customerSession; /** * Constructs a quote shipping address validator service object. * - * @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository - * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository Customer repository. - * @param \Magento\Customer\Model\Session $customerSession + * @param AddressRepositoryInterface $addressRepository + * @param CustomerRepositoryInterface $customerRepository Customer repository. + * @param Session $customerSession */ public function __construct( - \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, - \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, - \Magento\Customer\Model\Session $customerSession + AddressRepositoryInterface $addressRepository, + CustomerRepositoryInterface $customerRepository, + Session $customerSession ) { $this->addressRepository = $addressRepository; $this->customerRepository = $customerRepository; @@ -56,10 +61,10 @@ public function __construct( * Validate address. * * @param AddressInterface $address - * @param int|null $customerId Cart belongs to + * @param int|null $customerId * @return void - * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid. + * @throws LocalizedException The specified customer ID or address ID is not valid. + * @throws NoSuchEntityException The specified customer ID or address ID is not valid. */ private function doValidate(AddressInterface $address, ?int $customerId): void { @@ -67,7 +72,7 @@ private function doValidate(AddressInterface $address, ?int $customerId): void if ($customerId) { $customer = $this->customerRepository->getById($customerId); if (!$customer->getId()) { - throw new \Magento\Framework\Exception\NoSuchEntityException( + throw new NoSuchEntityException( __('Invalid customer id %1', $customerId) ); } @@ -76,7 +81,7 @@ private function doValidate(AddressInterface $address, ?int $customerId): void if ($address->getCustomerAddressId()) { //Existing address cannot belong to a guest if (!$customerId) { - throw new \Magento\Framework\Exception\NoSuchEntityException( + throw new NoSuchEntityException( __('Invalid customer address id %1', $address->getCustomerAddressId()) ); } @@ -84,7 +89,7 @@ private function doValidate(AddressInterface $address, ?int $customerId): void try { $this->addressRepository->getById($address->getCustomerAddressId()); } catch (NoSuchEntityException $e) { - throw new \Magento\Framework\Exception\NoSuchEntityException( + throw new NoSuchEntityException( __('Invalid address id %1', $address->getId()) ); } @@ -94,7 +99,7 @@ private function doValidate(AddressInterface $address, ?int $customerId): void return $address->getId(); }, $this->customerRepository->getById($customerId)->getAddresses()); if (!in_array($address->getCustomerAddressId(), $applicableAddressIds)) { - throw new \Magento\Framework\Exception\NoSuchEntityException( + throw new NoSuchEntityException( __('Invalid customer address id %1', $address->getCustomerAddressId()) ); } @@ -104,29 +109,74 @@ private function doValidate(AddressInterface $address, ?int $customerId): void /** * Validates the fields in a specified address data object. * - * @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object. + * @param AddressInterface $addressData The address data object. * @return bool - * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid. + * @throws InputException The specified address belongs to another customer. + * @throws NoSuchEntityException|LocalizedException The specified customer ID or address ID is not valid. */ - public function validate(AddressInterface $addressData) + public function validate(AddressInterface $addressData): bool { $this->doValidate($addressData, $addressData->getCustomerId()); return true; } + /** + * Validate Quest Address for guest user + * + * @param AddressInterface $address + * @param CartInterface $cart + * @return void + * @throws NoSuchEntityException + */ + private function doValidateForGuestQuoteAddress(AddressInterface $address, CartInterface $cart): void + { + //validate guest cart address + if ($address->getId() !== null) { + $old = $cart->getAddressById($address->getId()); + if ($old === false) { + throw new NoSuchEntityException( + __('Invalid quote address id %1', $address->getId()) + ); + } + } + } + /** * Validate address to be used for cart. * * @param CartInterface $cart * @param AddressInterface $address * @return void - * @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer. - * @throws \Magento\Framework\Exception\NoSuchEntityException The specified customer ID or address ID is not valid. + * @throws InputException The specified address belongs to another customer. + * @throws NoSuchEntityException|LocalizedException The specified customer ID or address ID is not valid. */ public function validateForCart(CartInterface $cart, AddressInterface $address): void { - $this->doValidate($address, $cart->getCustomerIsGuest() ? null : $cart->getCustomer()->getId()); + if ($cart->getCustomerIsGuest()) { + $this->doValidateForGuestQuoteAddress($address, $cart); + } + $this->doValidate($address, $cart->getCustomerIsGuest() ? null : (int) $cart->getCustomer()->getId()); + } + + /** + * Validate address id to be used for cart. + * + * @param CartInterface $cart + * @param AddressInterface $address + * @return void + * @throws NoSuchEntityException The specified customer ID or address ID is not valid. + */ + public function validateWithExistingAddress(CartInterface $cart, AddressInterface $address): void + { + // check if address belongs to quote. + if ($address->getId() !== null) { + $old = $cart->getAddressesCollection()->getItemById($address->getId()); + if ($old === null) { + throw new NoSuchEntityException( + __('Invalid quote address id %1', $address->getId()) + ); + } + } } } diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index b59737bff988b..6e27625283bec 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -127,6 +127,16 @@ protected function _construct() $this->_init(QuoteItem::class, ResourceQuoteItem::class); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_productIds = []; + $this->_quote = null; + } + /** * Retrieve store Id (From Quote) * diff --git a/app/code/Magento/Quote/i18n/en_US.csv b/app/code/Magento/Quote/i18n/en_US.csv index 54b7edbd7fd15..483b29a9fdbce 100644 --- a/app/code/Magento/Quote/i18n/en_US.csv +++ b/app/code/Magento/Quote/i18n/en_US.csv @@ -69,6 +69,7 @@ Carts,Carts "Validated Country Code","Validated Country Code" "Validated Vat Number","Validated Vat Number" "Invalid Quote Item id %1","Invalid Quote Item id %1" +"Invalid quote address id %1","Invalid quote address id %1" "Number above 0 is required for the limit","Number above 0 is required for the limit" "Please select a valid rate limit period in seconds: %1.","Please select a valid rate limit period in seconds: %1." "Identity type not found","Identity type not found" diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php index abd5ceca881f4..307087391b89d 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php @@ -87,7 +87,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); /** Check if the current user is allowed to perform actions with the cart */ - $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); + $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); try { $this->cartItemRepository->deleteById($cartId, $itemId); @@ -97,7 +97,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__($e->getMessage()), $e); } - $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); return [ 'cart' => [ 'model' => $cart, diff --git a/app/code/Magento/Review/Model/ResourceModel/Review/Product/Collection.php b/app/code/Magento/Review/Model/ResourceModel/Review/Product/Collection.php index 1fb7e7df2461f..900cdc1f330d4 100644 --- a/app/code/Magento/Review/Model/ResourceModel/Review/Product/Collection.php +++ b/app/code/Magento/Review/Model/ResourceModel/Review/Product/Collection.php @@ -21,22 +21,16 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection { /** - * Entities alias - * * @var array */ protected $_entitiesAlias = []; /** - * Review store table - * * @var string */ protected $_reviewStoreTable; /** - * Add store data flag - * * @var bool */ protected $_addStoreDataFlag = false; @@ -159,6 +153,17 @@ protected function _construct() $this->_initTables(); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_entitiesAlias = []; + $this->_addStoreDataFlag = false; + $this->_storesIds = []; + } + /** * Initialize select * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php index 65ccb43879ac6..643ed5445231f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php @@ -3,18 +3,26 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Sales\Controller\Adminhtml\Order\Create; -use Magento\Framework\App\Action\HttpGetActionInterface; -use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\ForwardFactory; -use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Controller\Result\RawFactory; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\RegexValidator; +use Magento\Framework\View\Result\PageFactory; use Magento\Sales\Controller\Adminhtml\Order\Create as CreateAction; use Magento\Store\Model\StoreManagerInterface; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class LoadBlock extends CreateAction implements HttpPostActionInterface, HttpGetActionInterface { /** @@ -28,13 +36,19 @@ class LoadBlock extends CreateAction implements HttpPostActionInterface, HttpGet private $storeManager; /** - * @param Action\Context $context - * @param \Magento\Catalog\Helper\Product $productHelper - * @param \Magento\Framework\Escaper $escaper + * @var RegexValidator + */ + private RegexValidator $regexValidator; + + /** + * @param Context $context + * @param Product $productHelper + * @param Escaper $escaper * @param PageFactory $resultPageFactory * @param ForwardFactory $resultForwardFactory * @param RawFactory $resultRawFactory * @param StoreManagerInterface|null $storeManager + * @param RegexValidator|null $regexValidator */ public function __construct( Action\Context $context, @@ -43,7 +57,8 @@ public function __construct( PageFactory $resultPageFactory, ForwardFactory $resultForwardFactory, RawFactory $resultRawFactory, - StoreManagerInterface $storeManager = null + StoreManagerInterface $storeManager = null, + RegexValidator $regexValidator = null ) { $this->resultRawFactory = $resultRawFactory; parent::__construct( @@ -55,6 +70,8 @@ public function __construct( ); $this->storeManager = $storeManager ?: ObjectManager::getInstance() ->get(StoreManagerInterface::class); + $this->regexValidator = $regexValidator + ?: ObjectManager::getInstance()->get(RegexValidator::class); } /** @@ -64,6 +81,7 @@ public function __construct( * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) + * @throws LocalizedException */ public function execute() { @@ -84,6 +102,12 @@ public function execute() $asJson = $request->getParam('json'); $block = $request->getParam('block'); + if ($block && !$this->regexValidator->validateParamRegex($block)) { + throw new LocalizedException( + __('The url has invalid characters. Please correct and try again.') + ); + } + /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); if ($asJson) { diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index a2aaed18cb56e..15d853cabfbee 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -29,6 +29,8 @@ class DownloadCustomOption extends \Magento\Framework\App\Action\Action implemen /** * @var \Magento\Framework\Unserialize\Unserialize * @deprecated 101.0.0 + * @deprecated No longer used + * @see $serializer */ protected $unserialize; @@ -106,7 +108,7 @@ public function execute() if ($this->getRequest()->getParam('key') != $info['secret_key']) { return $resultForward->forward('noroute'); } - $this->download->downloadFile($info); + return $this->download->createResponse($info); } catch (\Exception $e) { return $resultForward->forward('noroute'); } diff --git a/app/code/Magento/Sales/Model/Download.php b/app/code/Magento/Sales/Model/Download.php index e4a0a0ba93e7b..8f7b991f3ce4c 100644 --- a/app/code/Magento/Sales/Model/Download.php +++ b/app/code/Magento/Sales/Model/Download.php @@ -67,8 +67,22 @@ public function __construct( * @param array $info * @return void * @throws \Exception + * @deprecated No longer recommended + * @see createResponse() */ public function downloadFile($info) + { + $this->createResponse($info); + } + + /** + * Returns a file response + * + * @param array $info + * @return \Magento\Framework\App\ResponseInterface + * @throws \Exception + */ + public function createResponse($info) { $relativePath = $info['order_path']; if (!$this->_isCanProcessed($relativePath)) { @@ -80,7 +94,7 @@ public function downloadFile($info) ); } } - $this->_fileFactory->create( + return $this->_fileFactory->create( $info['title'], ['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'], $this->rootDirBasePath, diff --git a/app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormPaymentSection.xml b/app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormPaymentSection.xml index 447e6fcad7b49..499f067a3e1c8 100644 --- a/app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormPaymentSection.xml +++ b/app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormPaymentSection.xml @@ -31,5 +31,6 @@ <element name="freePaymentLabel" type="text" selector="#order-billing_method_form label[for='p_method_free']"/> <element name="paymentLabelWithRadioButton" type="text" selector="#order-billing_method_form .admin__field-option input[title='{{paymentMethodName}}'] + label" parameterized="true"/> <element name="checkoutPaymentMethod" type="radio" selector="//div[@class='payment-method _active']/div/input[@id= '{{methodName}}']" parameterized="true"/> + <element name="storedCard" type="radio" selector="#p_method_payflowpro_cc_vault" timeout="30"/> </section> </sections> diff --git a/app/code/Magento/Sales/Test/Mftf/Section/AdminOrdersGridSection.xml b/app/code/Magento/Sales/Test/Mftf/Section/AdminOrdersGridSection.xml index e2172a903397f..efa2cec38a961 100644 --- a/app/code/Magento/Sales/Test/Mftf/Section/AdminOrdersGridSection.xml +++ b/app/code/Magento/Sales/Test/Mftf/Section/AdminOrdersGridSection.xml @@ -47,5 +47,11 @@ <element name="exactOrderId" type="text" selector="//table[contains(@class, 'data-grid')]//div[text()='{{orderId}}']" parameterized="true"/> <element name="orderIdByIncrementId" type="text" selector="//input[@class='admin__control-checkbox' and @value={{incrId}}]/parent::label/parent::td/following-sibling::td" parameterized="true"/> <element name="orderSubtotal" type="input" selector="//tbody//tr[@class='col-0']//td[@class='label' and contains(text(),'Subtotal')]/..//td//span[@class='price']"/> + <element name="orderPageSearchProductBySKU" type="input" selector="#sales_order_create_search_grid_filter_sku"/> + <element name="searchProductButtonOrderPage" type="button" selector="//div[@class='order-details order-details-existing-customer']//button[@title='Search']" timeout="60"/> + <element name="selectGiftsWrappingDesign" type="select" selector="//label[@class='admin__field-label' and text()='Gift Wrapping Design']/..//select"/> + <element name="giftsWrappingForOrderExclTaxPrice" type="text" selector="//td[contains(text(),'Gift Wrapping for Order (Excl. Tax)')]/..//span[@class='price' and text()='${{price}}']" parameterized="true"/> + <element name="giftsWrappingForOrderInclTaxPrice" type="text" selector="//td[contains(text(),'Gift Wrapping for Order (Incl. Tax)')]/..//span[@class='price' and text()='${{price}}']" parameterized="true"/> + <element name="secondRow" type="button" selector="tr.data-row:nth-of-type(2)"/> </section> </sections> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/OrderDataGridDisplaysPurchaseDateTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/OrderDataGridDisplaysPurchaseDateTest.xml new file mode 100644 index 0000000000000..1ac8b58b115b1 --- /dev/null +++ b/app/code/Magento/Sales/Test/Mftf/Test/OrderDataGridDisplaysPurchaseDateTest.xml @@ -0,0 +1,192 @@ +<?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="OrderDataGridDisplaysPurchaseDateTest"> + <annotations> + <stories value="verify purchase date format"/> + <title value="Order Data Grid displays Purchase Date in correct format"/> + <description value="Order Data Grid displays Purchase Date in correct format"/> + <testCaseId value="AC-4455"/> + <severity value="MAJOR"/> + </annotations> + <before> + <!-- Set Store Code To Urls --> + <magentoCLI command="config:set {{StorefrontEnableAddStoreCodeToUrls.path}} {{StorefrontEnableAddStoreCodeToUrls.value}}" stepKey="setAddStoreCodeToUrlsToYes"/> + <!-- Login as Admin --> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <!--Create website--> + <actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createSecondWebsite"> + <argument name="newWebsiteName" value="{{secondCustomWebsite.name}}"/> + <argument name="websiteCode" value="{{secondCustomWebsite.code}}"/> + </actionGroup> + <!-- Create second store --> + <actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createSecondStoreGroup"> + <argument name="website" value="{{secondCustomWebsite.name}}"/> + <argument name="storeGroupName" value="{{SecondStoreGroupUnique.name}}"/> + <argument name="storeGroupCode" value="{{SecondStoreGroupUnique.code}}"/> + </actionGroup> + <!-- Create second store view --> + <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondStoreView"> + <argument name="StoreGroup" value="SecondStoreGroupUnique"/> + <argument name="customStore" value="SecondStoreUnique"/> + </actionGroup> + <magentoCron groups="index" stepKey="reindexAllIndexes"/> + <!-- Change time zone for second website--> + <actionGroup ref="AdminChangeTimeZoneForDifferentWebsiteActionGroup" stepKey="openConfigPage"> + <argument name="websiteName" value="{{secondCustomWebsite.name}}"/> + <argument name="timeZoneName" value="Hawaii-Aleutian Standard Time (America/Adak)"/> + </actionGroup> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfiguration"/> + <!-- Change time zone for Main website--> + <actionGroup ref="AdminChangeTimeZoneForDifferentWebsiteActionGroup" stepKey="openConfigPageSecondTime"> + <argument name="websiteName" value="Main Website"/> + <argument name="timeZoneName" value="Taipei Standard Time (Asia/Taipei)"/> + </actionGroup> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfigurationSecondTime"/> + <!-- Create category and simple product --> + <createData entity="ApiCategory" stepKey="createCategory"/> + <createData entity="ApiSimpleProduct" stepKey="createSimpleProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="price">10</field> + </createData> + <!-- Open product page and assign grouped project to second website --> + <actionGroup ref="FilterAndSelectProductActionGroup" stepKey="openAdminProductPage"> + <argument name="productSku" value="$$createSimpleProduct.sku$$"/> + </actionGroup> + <actionGroup ref="AdminAssignProductInWebsiteActionGroup" stepKey="assignProductToSecondWebsite"> + <argument name="website" value="{{secondCustomWebsite.name}}"/> + </actionGroup> + <actionGroup ref="SaveProductFormActionGroup" stepKey="saveSimpleProduct"/> + <createData entity="Simple_US_Customer" stepKey="createCustomer"/> + <!--Go to Storefront as Customer--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin"> + <argument name="Customer" value="$$createCustomer$$" /> + </actionGroup> + </before> + <after> + <!-- Disabled Store URLs --> + <magentoCLI command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}" stepKey="setAddStoreCodeToUrlsToNo"/> + <!-- Delete Category --> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <!-- Delete simple product --> + <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> + <!-- Delete first customer --> + <deleteData createDataKey="createCustomer" stepKey="deleteFirstCustomer"/> + <!-- Delete second customer --> + <deleteData createDataKey="createSecondCustomer" stepKey="deleteSecondCustomer"/> + <amOnPage url="{{AdminDashboardPage.url}}" stepKey="gotoOnDashboardPage"/> + <waitForPageLoad stepKey="waitForDashboardPageToLoad"/> + <!-- Reset time zone for Main website--> + <actionGroup ref="AdminChangeTimeZoneForDifferentWebsiteActionGroup" stepKey="openConfigPageSecondTime"> + <argument name="websiteName" value="Main Website"/> + <argument name="timeZoneName" value="Central Standard Time (America/Chicago)"/> + </actionGroup> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfigurationSecondTime"/> + <!--set main website as default--> + <actionGroup ref="AdminSetDefaultWebsiteActionGroup" stepKey="setMainWebsiteAsDefault"> + <argument name="websiteName" value="Main Website"/> + </actionGroup> + <!-- Delete second website --> + <actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteWebsite"> + <argument name="websiteName" value="{{secondCustomWebsite.name}}"/> + </actionGroup> + <magentoCron groups="index" stepKey="reindex"/> + <!--reset prouct grid filter--> + <actionGroup ref="NavigateToAndResetProductGridToDefaultViewActionGroup" stepKey="resetProductGridFilter"/> + <!-- Admin logout --> + <actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/> + </after> + <!-- Go to product page --> + <amOnPage url="$$createSimpleProduct.custom_attributes[url_key]$$.html" stepKey="navigateToSimpleProductPage"/> + <waitForPageLoad stepKey="waitForCatalogPageLoad"/> + <!-- Add Product to Shopping Cart --> + <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage"> + <argument name="productName" value="$$createSimpleProduct.name$$"/> + </actionGroup> + <!-- Go to Checkout --> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMiniCart"/> + <actionGroup ref="StorefrontSelectFirstShippingMethodActionGroup" stepKey="selectFlatRateShippingMethod"/> + <comment userInput="Adding the comment to replace waitForLoadingMask2 action for preserving Backward Compatibility" stepKey="waitForLoadingMask2"/> + <actionGroup ref="StorefrontCheckoutClickNextButtonActionGroup" stepKey="clickNext"/> + <!-- Checkout select Check/Money Order payment --> + <actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPayment"/> + <!-- Click Place Order button --> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickPlaceOrder"/> + <!-- capture date at time of Placing Order --> + <generateDate date="+2 hour" format="M j, Y" stepKey="generateDateAtFirstOrderTime"/> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabFirstOrderNumber"/> + <amOnPage url="{{AdminDashboardPage.url}}" stepKey="amOnDashboardPage"/> + <waitForPageLoad stepKey="waitForDashboardPageLoad"/> + <!--set second website as default--> + <actionGroup ref="AdminSetDefaultWebsiteActionGroup" stepKey="setSecondWebsiteAsDefault"> + <argument name="websiteName" value="{{secondCustomWebsite.name}}"/> + </actionGroup> + <!-- create second Customer--> + <createData entity="Simple_US_Customer_CA" stepKey="createSecondCustomer"/> + <!--Go to Storefront as Customer--> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="secondCustomerLogin"> + <argument name="Customer" value="$$createSecondCustomer$$" /> + </actionGroup> + <!-- Go to product page --> + <amOnPage url="$$createSimpleProduct.custom_attributes[url_key]$$.html" stepKey="navigateToSimpleProductPageSecondTime"/> + <waitForPageLoad stepKey="waitForCatalogPageLoadSecondTime"/> + <!-- Add Product to Shopping Cart --> + <actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPageSecondTime"> + <argument name="productName" value="$$createSimpleProduct.name$$"/> + </actionGroup> + <!-- Go to Checkout --> + <actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMiniCartSecondTime"/> + <actionGroup ref="StorefrontSelectFirstShippingMethodActionGroup" stepKey="selectFlatRateShippingMethodSecondTime"/> + <actionGroup ref="StorefrontCheckoutClickNextButtonActionGroup" stepKey="clickNextSecondTime"/> + <!-- Checkout select Check/Money Order payment --> + <actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyPaymentSecondTime"/> + <!-- Click Place Order button --> + <wait time="75" stepKey="waitBeforePlaceOrder"/> + <actionGroup ref="ClickPlaceOrderActionGroup" stepKey="clickPlaceOrderSecondTime"/> + <!-- capture date at time of Placing Order --> + <generateDate date="+2 hour" format="M j, Y" stepKey="generateDateAtSecondOrderTime"/> + <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabSecondOrderNumber"/> + <!-- Go to admin and check order status --> + <actionGroup ref="AdminOrdersPageOpenActionGroup" stepKey="navigateToSalesOrderPage"/> + <actionGroup ref="SearchAdminDataGridByKeywordActionGroup" stepKey="searchForFirstOrder"> + <argument name="keyword" value="{$grabFirstOrderNumber}"/> + </actionGroup> + <!--Get date from "Purchase Date" column --> + <grabTextFrom selector="{{AdminOrdersGridSection.gridCell('1','Purchase Date')}}" stepKey="grabPurchaseDateForFirstOrderInDefaultLocale"/> + <!--Get date and time in default locale (US)--> + <executeJS function="return (new Date('{$grabPurchaseDateForFirstOrderInDefaultLocale}').toLocaleDateString('en-US',{month: 'short', day: 'numeric', year: 'numeric'} ))" stepKey="getDateMonthYearNameForFirstOrderInUS"/> + <!--Checking oder placing Date with default "Interface Locale"--> + <assertStringContainsString stepKey="checkingFirstOrderDateWithPurchaseDate"> + <expectedResult type="variable">getDateMonthYearNameForFirstOrderInUS</expectedResult> + <actualResult type="variable">grabPurchaseDateForFirstOrderInDefaultLocale</actualResult> + </assertStringContainsString> + <!--compare date of order with date of purchase--> + <assertStringContainsString stepKey="checkingFirstOrderDateWithDefaultInterfaceLocale1"> + <expectedResult type="variable">generateDateAtFirstOrderTime</expectedResult> + <actualResult type="variable">grabPurchaseDateForFirstOrderInDefaultLocale</actualResult> + </assertStringContainsString> + <actionGroup ref="SearchAdminDataGridByKeywordActionGroup" stepKey="searchForSecondOrder"> + <argument name="keyword" value="{$grabSecondOrderNumber}"/> + </actionGroup> + <!--Get date from "Purchase Date" column--> + <grabTextFrom selector="{{AdminOrdersGridSection.gridCell('1','Purchase Date')}}" stepKey="grabPurchaseDateForSecondOrderInDefaultLocale"/> + <!--Get date and time in default locale (US)--> + <executeJS function="return (new Date('{$grabPurchaseDateForSecondOrderInDefaultLocale}').toLocaleDateString('en-US',{month: 'short', day: 'numeric', year: 'numeric'} ))" stepKey="getDateMonthYearNameForSecondOrderInUS"/> + <!--Checking Purchase Date with default "Interface Locale"--> + <assertStringContainsString stepKey="checkingSecondOrderDateWithDefaultInterfaceLocale"> + <expectedResult type="variable">getDateMonthYearNameForSecondOrderInUS</expectedResult> + <actualResult type="variable">grabPurchaseDateForSecondOrderInDefaultLocale</actualResult> + </assertStringContainsString> + <!--compare date of order with date of purchase--> + <assertStringContainsString stepKey="checkingSecondOrderDateWithPurchaseDate"> + <expectedResult type="variable">generateDateAtSecondOrderTime</expectedResult> + <actualResult type="variable">grabPurchaseDateForFirstOrderInDefaultLocale</actualResult> + </assertStringContainsString> + </test> +</tests> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/PlaceAnOrderAndCreditMemoItValidateTheOrderStatusIsClosedTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/PlaceAnOrderAndCreditMemoItValidateTheOrderStatusIsClosedTest.xml index 6d13738271781..37df878652166 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/PlaceAnOrderAndCreditMemoItValidateTheOrderStatusIsClosedTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/PlaceAnOrderAndCreditMemoItValidateTheOrderStatusIsClosedTest.xml @@ -15,6 +15,7 @@ <testCaseId value="AC-1577"/> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <!-- Add downloadable domains --> <magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add example.com static.magento.com"/> @@ -82,6 +83,7 @@ <!-- Logout User and Admin --> <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="navigateToProductPage"> diff --git a/app/code/Magento/Sales/Test/Mftf/Test/StorefrontCreateOrderWithDifferentAddressesTest.xml b/app/code/Magento/Sales/Test/Mftf/Test/StorefrontCreateOrderWithDifferentAddressesTest.xml index 66994a33d182c..e95326cd979ca 100644 --- a/app/code/Magento/Sales/Test/Mftf/Test/StorefrontCreateOrderWithDifferentAddressesTest.xml +++ b/app/code/Magento/Sales/Test/Mftf/Test/StorefrontCreateOrderWithDifferentAddressesTest.xml @@ -16,15 +16,16 @@ <group value="cloud"/> </annotations> <before> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 1" stepKey="EnablingGuestCheckoutLogin"/> <createData entity="SimpleProduct2" stepKey="createSimpleProduct"/> <createData entity="Customer_UK_US" stepKey="createCustomer"/> </before> <after> <deleteData createDataKey="createCustomer" stepKey="deleteCreateCustomer"/> <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> - <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> + <magentoCLI command="config:set checkout/options/enable_guest_checkout_login 0" stepKey="DisablingGuestCheckoutLogin"/> </after> <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="navigateToProductPage"> diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php index c870051b93554..93bdb1f189270 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php @@ -9,6 +9,7 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\App\Request\Http; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Forward; use Magento\Framework\Controller\Result\ForwardFactory; use Magento\Framework\Serialize\Serializer\Json; @@ -24,32 +25,32 @@ class DownloadCustomOptionTest extends TestCase /** * Option ID Test Value */ - const OPTION_ID = '123456'; + public const OPTION_ID = '123456'; /** * Option Code Test Value */ - const OPTION_CODE = 'option_123456'; + public const OPTION_CODE = 'option_123456'; /** * Option Product ID Value */ - const OPTION_PRODUCT_ID = 'option_test_product_id'; + public const OPTION_PRODUCT_ID = 'option_test_product_id'; /** * Option Type Value */ - const OPTION_TYPE = 'file'; + public const OPTION_TYPE = 'file'; /** * Option Value Test Value */ - const OPTION_VALUE = 'option_test_value'; + public const OPTION_VALUE = 'option_test_value'; /** * Option Value Test Value */ - const SECRET_KEY = 'secret_key'; + public const SECRET_KEY = 'secret_key'; /** * @var \Magento\Quote\Model\Quote\Item\Option|MockObject @@ -95,7 +96,7 @@ protected function setUp(): void $this->downloadMock = $this->getMockBuilder(Download::class) ->disableOriginalConstructor() - ->setMethods(['downloadFile']) + ->setMethods(['createResponse']) ->getMock(); $this->serializerMock = $this->getMockBuilder(Json::class) @@ -199,7 +200,8 @@ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOcc ->willReturn($productOptionValues[self::OPTION_TYPE]); } if ($noRouteOccurs) { - $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true); + $result = $this->resultForwardMock; + $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); } else { $unserializeResult = [self::SECRET_KEY => self::SECRET_KEY]; @@ -208,14 +210,15 @@ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOcc ->with($itemOptionValues[self::OPTION_VALUE]) ->willReturn($unserializeResult); + $result = $this->getMockBuilder(ResponseInterface::class) + ->getMock(); $this->downloadMock->expects($this->once()) - ->method('downloadFile') + ->method('createResponse') ->with($unserializeResult) - ->willReturn(true); + ->willReturn($result); - $this->objectMock->expects($this->once())->method('endExecute')->willReturn(true); } - $this->objectMock->execute(); + $this->assertSame($result, $this->objectMock->execute()); } /** diff --git a/app/code/Magento/SalesRule/Model/Validator.php b/app/code/Magento/SalesRule/Model/Validator.php index abf34172c7296..14cc17690ef8e 100644 --- a/app/code/Magento/SalesRule/Model/Validator.php +++ b/app/code/Magento/SalesRule/Model/Validator.php @@ -8,6 +8,7 @@ use Laminas\Validator\ValidatorInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Address; use Magento\Quote\Model\Quote\Item\AbstractItem; @@ -28,7 +29,7 @@ * @method Validator setCustomerGroupId($id) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Validator extends \Magento\Framework\Model\AbstractModel +class Validator extends \Magento\Framework\Model\AbstractModel implements ResetAfterRequestInterface { /** * Rule source collection @@ -151,6 +152,18 @@ public function __construct( parent::__construct($context, $registry, $resource, $resourceCollection, $data); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->counter = 0; + $this->_skipActionsValidation = false; + $this->_rulesItemTotals = []; + $this->_isFirstTimeResetRun = true; + $this->_rules = null; + } + /** * Init validator * Init process load collection of rules for specific website, diff --git a/app/code/Magento/Shipping/Test/Mftf/Test/MultiShippingWithCreationNewCustomerAndAddressesDuringCheckoutTest.xml b/app/code/Magento/Shipping/Test/Mftf/Test/MultiShippingWithCreationNewCustomerAndAddressesDuringCheckoutTest.xml new file mode 100644 index 0000000000000..f973b8f700b4c --- /dev/null +++ b/app/code/Magento/Shipping/Test/Mftf/Test/MultiShippingWithCreationNewCustomerAndAddressesDuringCheckoutTest.xml @@ -0,0 +1,160 @@ +<?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="MultiShippingWithCreationNewCustomerAndAddressesDuringCheckoutTest"> + <annotations> + <stories value="Multi shipping with creation new customer and addresses during checkout"/> + <title value="Verify Multi shipping with creation new customer and addresses during checkout"/> + <description value="Verify Multi shipping with creation new customer and addresses during checkout"/> + <severity value="MAJOR"/> + <testCaseId value="AC-4685" /> + </annotations> + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminArea"/> + <!-- remove the Filter From the page--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFilterFromProductIndex"/> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createSimpleProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="name">simple product</field> + </createData> + <!-- Create configurable product --> + <createData entity="ApiConfigurableProduct" stepKey="createConfigProduct"> + <requiredEntity createDataKey="createCategory"/> + <field key="name">config product</field> + </createData> + <!-- Search for the Created Configurable Product --> + <actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="openConfigurableProductEditPage"> + <argument name="productId" value="$createConfigProduct.id$"/> + </actionGroup> + <click selector="{{AdminProductFormConfigurationsSection.createConfigurations}}" stepKey="clickOnCreateConfigurations"/> + <waitForPageLoad stepKey="waitForSelectAttributesPage"/> + <actionGroup ref="CreateOptionsForAttributeActionGroup" stepKey="createOptions"> + <argument name="attributeName" value="Color"/> + <argument name="firstOptionName" value="Red"/> + <argument name="secondOptionName" value="Green"/> + </actionGroup> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton"/> + <click selector="{{AdminCreateProductConfigurationsPanel.applySinglePriceToAllSkus}}" stepKey="clickOnApplySinglePriceToAllSkus"/> + <fillField selector="{{AdminCreateProductConfigurationsPanel.singlePrice}}" userInput="10" stepKey="enterAttributePrice"/> + <click selector="{{AdminCreateProductConfigurationsPanel.applySingleQuantityToEachSkus}}" stepKey="clickOnApplySingleQuantityToEachSku"/> + <fillField selector="{{AdminCreateProductConfigurationsPanel.quantity}}" userInput="100" stepKey="enterAttributeQuantity"/> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextStep"/> + <waitForElementVisible selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="waitForNextPageOpened"/> + <click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="generateProducts"/> + <waitForElementVisible selector="{{AdminProductFormActionSection.saveButton}}" stepKey="waitForSaveButtonVisible"/> + <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="saveProduct"/> + <conditionalClick selector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" dependentSelector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" visible="true" stepKey="clickOnConfirmInPopup"/> + <seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/> + </before> + <after> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearGridFilters"/> + <actionGroup ref="AdminDeleteAllProductsFromGridActionGroup" stepKey="deleteAllProducts"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <!-- Delete customer --> + <actionGroup ref="DeleteCustomerByEmailActionGroup" stepKey="deleteCustomer"> + <argument name="email" value="{{CustomerEntityOne.email}}"/> + </actionGroup> + <actionGroup ref="AdminDeleteCreatedColorAttributeActionGroup" stepKey="deleteRedColorAttribute"> + <argument name="Color" value="Red"/> + </actionGroup> + <actionGroup ref="AdminDeleteCreatedColorAttributeActionGroup" stepKey="deleteBlueColorAttribute"> + <argument name="Color" value="Green"/> + </actionGroup> + <!-- reindex and flush cache --> + <magentoCron groups="index" stepKey="reindex"/> + <actionGroup ref="CliCacheCleanActionGroup" stepKey="flushCache"> + <argument name="tags" value="full_page"/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> + </after> + <actionGroup ref="StorefrontNavigateToCategoryUrlActionGroup" stepKey="openCategoryPage"> + <argument name="categoryUrl" value="$$createCategory.custom_attributes[url_key]$$"/> + </actionGroup> + <waitForPageLoad stepKey="waitForProductPage"/> + <actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addSimpleProductToCart"> + <argument name="product" value="$createSimpleProduct$"/> + </actionGroup> + <!-- Add configurable product to the cart --> + <actionGroup ref="StorefrontAddConfigurableProductToTheCartActionGroup" stepKey="addConfigurableProductToCart1"> + <argument name="urlKey" value="$$createConfigProduct.custom_attributes[url_key]$$" /> + <argument name="productAttribute" value="Color"/> + <argument name="productOption" value="Red"/> + <argument name="qty" value="1"/> + </actionGroup> + <actionGroup ref="StorefrontAddConfigurableProductToTheCartActionGroup" stepKey="addConfigurableProductToCart2"> + <argument name="urlKey" value="$$createConfigProduct.custom_attributes[url_key]$$" /> + <argument name="productAttribute" value="Color"/> + <argument name="productOption" value="Green"/> + <argument name="qty" value="1"/> + </actionGroup> + <!-- Check Out with Multiple Addresses --> + <actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openCart"/> + <waitForElementVisible selector="{{MultishippingSection.shippingMultipleCheckout}}" stepKey="waitMultipleAddressShippingButton"/> + <click selector="{{MultishippingSection.shippingMultipleCheckout}}" stepKey="clickToMultipleAddressShippingButton"/> + <!--Create an account--> + <waitForElementVisible selector="{{AdminCreateUserSection.createAnAccountButtonForCustomer}}" stepKey="waitCreateAnAccountButton"/> + <click selector="{{AdminCreateUserSection.createAnAccountButtonForCustomer}}" stepKey="clickOnCreateAnAccountButton"/> + <waitForPageLoad stepKey="waitForCreateAccountPageToLoad"/> + <actionGroup ref="EnterAddressDetailsActionGroup" stepKey="enterAddressInfo"> + <argument name="Address" value="US_Address_CA"/> + </actionGroup> + <actionGroup ref="StorefrontFillCustomerCreateAnAccountActionGroup" stepKey="fillDetails"> + <argument name="customer" value="CustomerEntityOne"/> + </actionGroup> + <actionGroup ref="StorefrontClickCreateAnAccountCustomerAccountCreationFormActionGroup" stepKey="submitCreateAccountForm"/> + <click selector="{{MultishippingSection.enterNewAddress}}" stepKey="clickOnAddress"/> + <waitForPageLoad stepKey="waitForAddressFieldsPageOpen"/> + <actionGroup ref="FillNewCustomerAddressFieldsActionGroup" stepKey="editAddressFields"> + <argument name="address" value="DE_Address_Berlin_Not_Default_Address"/> + <argument name="address" value="DE_Address_Berlin_Not_Default_Address"/> + </actionGroup> + <actionGroup ref="StorefrontSaveCustomerAddressActionGroup" stepKey="saveAddress"/> + <waitForPageLoad stepKey="waitForShippingPageToOpen"/> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectCAAddress"> + <argument name="sequenceNumber" value="1"/> + <argument name="option" value="John Doe, 7700 West Parmer Lane 113, Los Angeles, California 90001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectCAAddressForSecondProduct"> + <argument name="sequenceNumber" value="2"/> + <argument name="option" value="John Doe, 7700 West Parmer Lane 113, Los Angeles, California 90001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectGEAddress"> + <argument name="sequenceNumber" value="3"/> + <argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, Berlin 10789, Germany"/> + </actionGroup> + <actionGroup ref="StorefrontChangeMultishippingItemQtyActionGroup" stepKey="setProductQuantity"> + <argument name="sequenceNumber" value="3"/> + <argument name="quantity" value="10"/> + </actionGroup> + <actionGroup ref="StorefrontSaveAddressActionGroup" stepKey="saveAddresses"/> + <waitForPageLoad stepKey="waitForPageToLoadProperly"/> + <seeElement selector="{{ShippingMethodSection.productDetails('simple product','1')}}" stepKey="assertSimpleProductDetails"/> + <seeElement selector="{{ShippingMethodSection.productDetails('config product','1')}}" stepKey="assertConfigProductRedDetails"/> + <seeElement selector="{{ShippingMethodSection.productDetails('config product','10')}}" stepKey="assertConfigProductGreenDetails"/> + <!-- Click 'Continue to Billing Information' --> + <actionGroup ref="StorefrontLeaveDefaultShippingMethodsAndGoToBillingInfoActionGroup" stepKey="useDefaultShippingMethod"/> + <!-- Click 'Go to Review Your Order' --> + <actionGroup ref="SelectBillingInfoActionGroup" stepKey="useDefaultBillingMethod"/> + <!-- Click 'Place Order' --> + <actionGroup ref="PlaceOrderActionGroup" stepKey="placeOrder"/> + <waitForPageLoad stepKey="waitForOrderPlace"/> + <grabTextFrom selector="{{StorefrontMultipleShippingMethodSection.orderId('1')}}" stepKey="grabFirstOrderId"/> + <grabTextFrom selector="{{StorefrontMultipleShippingMethodSection.orderId('2')}}" stepKey="grabSecondOrderId"/> + <!-- Go to My Account > My Orders and verify orderId--> + <amOnPage url="{{StorefrontCustomerOrdersHistoryPage.url}}" stepKey="goToMyOrdersPage"/> + <waitForPageLoad stepKey="waitForMyOrdersPageLoad"/> + <seeElement selector="{{StorefrontCustomerOrdersGridSection.orderView({$grabFirstOrderId})}}" stepKey="seeFirstOrder"/> + <seeElement selector="{{StorefrontCustomerOrdersGridSection.orderView({$grabSecondOrderId})}}" stepKey="seeSecondOrder"/> + <!-- Logout customer --> + <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer"/> + </test> +</tests> diff --git a/app/code/Magento/Shipping/Test/Mftf/Test/MultipleAddressCheckoutWithTwoDifferentRatesTest.xml b/app/code/Magento/Shipping/Test/Mftf/Test/MultipleAddressCheckoutWithTwoDifferentRatesTest.xml new file mode 100644 index 0000000000000..8ff3f81e13ff5 --- /dev/null +++ b/app/code/Magento/Shipping/Test/Mftf/Test/MultipleAddressCheckoutWithTwoDifferentRatesTest.xml @@ -0,0 +1,92 @@ +<?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="MultipleAddressCheckoutWithTwoDifferentRatesTest"> + <annotations> + <stories value="Multiple Address Checkout with Table Rates (Use Two Different Rates)"/> + <title value="Verify Multiple Address Checkout with Table Rates (Use Two Different Rates)"/> + <description value="Verify Multiple Address Checkout with Table Rates (Use Two Different Rates)"/> + <severity value="MAJOR"/> + <testCaseId value="AC-4499" /> + </annotations> + <before> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <createData entity="SimpleProduct" stepKey="createProduct"> + <requiredEntity createDataKey="createCategory"/> + </createData> + <createData entity="Simple_US_Customer_CA_NY_Addresses" stepKey="createCustomer"/> + <actionGroup ref="AdminLoginActionGroup" stepKey="login"/> + <!-- remove the Filter From the page--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/> + <actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFilterFromProductIndex"/> + </before> + <after> + <!-- Delete created data --> + <!-- disable table rate meth0d --> + <actionGroup ref="AdminOpenShippingMethodsConfigPageActionGroup" stepKey="openShippingMethodConfigPage"/> + <!-- Switch to Website scope --> + <actionGroup ref="AdminSwitchWebsiteActionGroup" stepKey="AdminSwitchStoreView"> + <argument name="website" value="_defaultWebsite"/> + </actionGroup> + <actionGroup ref="AdminChangeTableRatesShippingMethodStatusActionGroup" stepKey="disableTableRatesShippingMethod"> + <argument name="status" value="0"/> + </actionGroup> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfig"/> + <deleteData createDataKey="createProduct" stepKey="deleteProduct"/> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> + <magentoCron groups="index" stepKey="reindex"/> + <actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache"> + <argument name="tags" value=""/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!-- Go to Stores > Configuration > Sales > Shipping Methods --> + <actionGroup ref="AdminOpenShippingMethodsConfigPageActionGroup" stepKey="openShippingMethodConfigPage"/> + <!-- Switch to Website scope --> + <actionGroup ref="AdminSwitchWebsiteActionGroup" stepKey="AdminSwitchStoreView"> + <argument name="website" value="_defaultWebsite"/> + </actionGroup> + <!-- Enable Table Rate method and save config --> + <actionGroup ref="AdminChangeTableRatesShippingMethodStatusActionGroup" stepKey="enableTableRatesShippingMethod"/> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfig"/> + <!-- Make sure you have Condition Weight vs. Destination --> + <see selector="{{AdminShippingMethodTableRatesSection.condition}}" userInput="{{TableRatesWeightVSDestination.condition}}" stepKey="seeDefaultCondition"/> + <!-- Import file and save config --> + <conditionalClick selector="{{AdminShippingMethodTableRatesSection.carriersTableRateTab}}" dependentSelector="{{AdminShippingMethodTableRatesSection.carriersTableRateActive}}" visible="false" stepKey="expandTab"/> + <attachFile selector="{{AdminShippingMethodTableRatesSection.importFile}}" userInput="table_rate_30895.csv" stepKey="attachFileForImport"/> + <actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfigs"/> + <!-- Login as customer --> + <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer"> + <argument name="Customer" value="$$createCustomer$$"/> + </actionGroup> + <!-- Add product to the shopping cart --> + <actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage"> + <argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/> + </actionGroup> + <actionGroup ref="StorefrontEnterProductQuantityAndAddToTheCartActionGroup" stepKey="enterProductQuantityAndAddToTheCartAgain"> + <argument name="quantity" value="2"/> + </actionGroup> + <!-- Open the shopping cart page --> + <actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openShoppingCart"/> + <click selector="{{MultishippingSection.checkoutWithMultipleAddresses}}" stepKey="proceedMultishipping"/> + <!-- Select different addresses and click 'Go to Shipping Information' --> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectCAAddress"> + <argument name="sequenceNumber" value="1"/> + <argument name="option" value="John Doe, 7700 West Parmer Lane 113, Los Angeles, California 90001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectNYAddress"> + <argument name="sequenceNumber" value="2"/> + <argument name="option" value="John Doe, 368 Broadway St. Apt. 113, New York, New York 10001, United States"/> + </actionGroup> + <actionGroup ref="StorefrontSaveAddressActionGroup" stepKey="saveAddresses"/> + <see selector="{{ShippingMethodSection.shippingMethod('1','2')}}" userInput="Table Rate $5.00" stepKey="assertTableRateForLA"/> + <see selector="{{ShippingMethodSection.shippingMethod('2','2')}}" userInput="Table Rate $10.00" stepKey="assertTableRateForNY"/> + </test> +</tests> diff --git a/app/code/Magento/Store/App/Config/Source/RuntimeConfigSource.php b/app/code/Magento/Store/App/Config/Source/RuntimeConfigSource.php index 80aaa31b184fe..b8b0ede43c70d 100644 --- a/app/code/Magento/Store/App/Config/Source/RuntimeConfigSource.php +++ b/app/code/Magento/Store/App/Config/Source/RuntimeConfigSource.php @@ -102,7 +102,7 @@ private function getEntities($table, $keyField) ); foreach ($entities as $entity) { - $data[strtolower($entity[$keyField])] = $entity; + $data[$entity[$keyField]] = $entity; } return $data; diff --git a/app/code/Magento/Store/App/Config/Type/Scopes.php b/app/code/Magento/Store/App/Config/Type/Scopes.php index 6bfed343f4c04..ea1f86a2239ff 100644 --- a/app/code/Magento/Store/App/Config/Type/Scopes.php +++ b/app/code/Magento/Store/App/Config/Type/Scopes.php @@ -72,7 +72,7 @@ public function get($path = '') $path = $this->convertIdPathToCodePath($patchChunks); } - return $this->data->getData(strtolower($path)); + return $this->data->getData($path); } /** diff --git a/app/code/Magento/Store/Model/Config/Processor/Fallback.php b/app/code/Magento/Store/Model/Config/Processor/Fallback.php index 1b1afaae6c009..537802d312eed 100644 --- a/app/code/Magento/Store/Model/Config/Processor/Fallback.php +++ b/app/code/Magento/Store/Model/Config/Processor/Fallback.php @@ -11,7 +11,10 @@ use Magento\Framework\DB\Adapter\TableNotFoundException; use Magento\Store\App\Config\Type\Scopes; use Magento\Store\Model\ResourceModel\Store; +use Magento\Store\Model\ResourceModel\Store\AllStoresCollectionFactory; use Magento\Store\Model\ResourceModel\Website; +use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollection; +use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollectionFactory; /** * Fallback through different scopes and merge them @@ -111,13 +114,6 @@ private function prepareWebsitesConfig( array $websitesConfig ) { $result = []; - - foreach ($websitesConfig as $websiteCode => $webConfiguration) { - if (!isset($websitesConfig[strtolower($websiteCode)])) { - $websitesConfig[strtolower($websiteCode)] = $webConfiguration; - unset($websitesConfig[$websiteCode]); - } - } foreach ((array)$this->websiteData as $website) { $code = $website['code']; $id = $website['website_id']; @@ -143,12 +139,6 @@ private function prepareStoresConfig( ) { $result = []; - foreach ($storesConfig as $storeCode => $storeConfiguration) { - if (!isset($storesConfig[strtolower($storeCode)])) { - $storesConfig[strtolower($storeCode)] = $storeConfiguration; - unset($storesConfig[$storeCode]); - } - } foreach ((array)$this->storeData as $store) { $code = $store['code']; $id = $store['store_id']; @@ -201,18 +191,5 @@ private function loadScopes(): void $this->storeData = []; $this->websiteData = []; } - $this->normalizeStoreData(); - } - - /** - * Sets stores code to lower case - * - * @return void - */ - private function normalizeStoreData(): void - { - foreach ($this->storeData as $key => $store) { - $this->storeData[$key]['code'] = strtolower($store['code']); - } } } diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 34cbd76d24dc2..2c1ad47693870 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -17,6 +17,7 @@ use Magento\Framework\DataObject\IdentityInterface; use Magento\Framework\Filesystem; use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Magento\Framework\Url\ModifierInterface; use Magento\Framework\Url\ScopeInterface as UrlScopeInterface; use Magento\Framework\UrlInterface; @@ -43,7 +44,8 @@ class Store extends AbstractExtensibleModel implements AppScopeInterface, UrlScopeInterface, IdentityInterface, - StoreInterface + StoreInterface, + ResetAfterRequestInterface { /** * Store Id key name @@ -466,7 +468,6 @@ protected function _construct() protected function _getSession() { if (!$this->_session->isSessionExists()) { - $this->_session->setName('store_' . $this->getCode()); $this->_session->start(); } return $this->_session; @@ -1421,4 +1422,17 @@ public function __debugInfo() { return []; } + + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->_baseUrlCache = []; + $this->_configCache = null; + $this->_configCacheBaseNodes = []; + $this->_dirCache = []; + $this->_urlCache = []; + $this->_baseUrlCache = []; + } } diff --git a/app/code/Magento/Store/Model/StoreManager.php b/app/code/Magento/Store/Model/StoreManager.php index a28efb40d3d74..f6e7ebbc8d2fe 100644 --- a/app/code/Magento/Store/Model/StoreManager.php +++ b/app/code/Magento/Store/Model/StoreManager.php @@ -335,6 +335,6 @@ public function __debugInfo() */ public function _resetState(): void { - $this->reinitStores(); + $this->currentStoreId = null; } } diff --git a/app/code/Magento/Store/Test/Mftf/Section/AdminNewWebsiteActionsSection.xml b/app/code/Magento/Store/Test/Mftf/Section/AdminNewWebsiteActionsSection.xml index c0927884bdd2b..7376976b12a50 100644 --- a/app/code/Magento/Store/Test/Mftf/Section/AdminNewWebsiteActionsSection.xml +++ b/app/code/Magento/Store/Test/Mftf/Section/AdminNewWebsiteActionsSection.xml @@ -8,5 +8,6 @@ <sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> <section name="AdminNewWebsiteActionsSection"> <element name="saveWebsite" type="button" selector="#save" timeout="120"/> + <element name="setAsDefault" type="checkbox" selector=".//*[@name='website[is_default]']" timeout="120"/> </section> </sections> diff --git a/app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php b/app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php index 96990f72d6de1..9645aa2d6b808 100644 --- a/app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php @@ -68,73 +68,12 @@ public function testGet() ->getMock(); $selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->connection->expects($this->any())->method('select')->willReturn($selectMock); - $this->connection->expects($this->exactly(3))->method('fetchAll') - ->willReturnOnConsecutiveCalls( - [ - 'WebsiteCode' => [ - 'website_id' => '3', - 'code' => 'WebsiteCode', - 'name' => 'website', - 'sort_order' => '0', - 'default_group_id' => '4', - 'is_default' => '0' - ] - ], - [ - 0 => [ - 'group_id' => '4', - 'website_id' => '3', - 'name' => 'store', - 'root_category_id' => '2', - 'default_store_id' => '11', - 'code' => 'second_website' - ] - ], - [ - 'SecondWebsite' => [ - 'store_id' => '11', - 'code' => 'SECOND_WEBSITE', - 'website_id' => '3', - 'group_id' => '4', - 'name' => 'second', - 'sort_order' => '0', - 'is_active' => '1' - ] - ] - ); + $this->connection->expects($this->any())->method('fetchAll')->willReturn([]); $this->assertEquals( [ - 'websites' => [ - 'websitecode' => [ - 'website_id' => '3', - 'code' => 'WebsiteCode', - 'name' => 'website', - 'sort_order' => '0', - 'default_group_id' => '4', - 'is_default' => '0' - ] - ], - 'groups' => [ - 4 => [ - 'group_id' => '4', - 'website_id' => '3', - 'name' => 'store', - 'root_category_id' => '2', - 'default_store_id' => '11', - 'code' => 'second_website' - ] - ], - 'stores' => [ - 'second_website' => [ - 'store_id' => '11', - 'code' => 'SECOND_WEBSITE', - 'website_id' => '3', - 'group_id' => '4', - 'name' => 'second', - 'sort_order' => '0', - 'is_active' => '1' - ] - ], + 'websites' => [], + 'groups' => [], + 'stores' => [], ], $this->configSource->get() ); diff --git a/app/code/Magento/Store/Test/Unit/Model/Config/Processor/FallbackTest.php b/app/code/Magento/Store/Test/Unit/Model/Config/Processor/FallbackTest.php deleted file mode 100644 index 7846186f42970..0000000000000 --- a/app/code/Magento/Store/Test/Unit/Model/Config/Processor/FallbackTest.php +++ /dev/null @@ -1,154 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -declare(strict_types=1); - -namespace Magento\Store\Test\Unit\Model\Config\Processor; - -use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\ResourceConnection; -use Magento\Store\App\Config\Type\Scopes; -use Magento\Store\Model\Config\Processor\Fallback; -use Magento\Store\Model\ResourceModel\Store; -use Magento\Store\Model\ResourceModel\Website; -use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; - -class FallbackTest extends TestCase -{ - /** - * @var Scopes|Scopes&MockObject|MockObject - */ - private Scopes $scopes; - /** - * @var ResourceConnection|ResourceConnection&MockObject|MockObject - */ - private ResourceConnection $resourceConnection; - /** - * @var Store|Store&MockObject|MockObject - */ - private Store $storeResource; - /** - * @var Website|Website&MockObject|MockObject - */ - private Website $websiteResource; - /** - * @var DeploymentConfig|DeploymentConfig&MockObject|MockObject - */ - private DeploymentConfig $deploymentConfig; - /** - * @var Fallback - */ - private Fallback $fallback; - - /** - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->scopes = $this->createMock(Scopes::class); - $this->resourceConnection = $this->createMock(ResourceConnection::class); - $this->storeResource = $this->createMock(Store::class); - $this->websiteResource = $this->createMock(Website::class); - $this->deploymentConfig = $this->createMock(DeploymentConfig::class); - $this->fallback = new Fallback( - $this->scopes, - $this->resourceConnection, - $this->storeResource, - $this->websiteResource, - $this->deploymentConfig - ); - } - - /** - * @return void - */ - public function testProcessWithStoreCodeCapitalLetters() - { - $storesData = $this->getStoresData(); - $websiteData = $this->getWebsitesData(); - $this->deploymentConfig->expects($this->once())->method('isDbAvailable')->willReturn(true); - $this->storeResource->expects($this->once())->method('readAllStores')->willReturn($storesData); - $this->websiteResource->expects($this->once())->method('readAllWebsites')->willReturn($websiteData); - - $result = $this->fallback->process( - [ - 'stores' => [ - 'TWO' => [ - 'checkout' => [ - 'options' => ['guest_checkout' => 0] - ] - ] - ], - 'websites' => [ - ['admin' => ['web' => ['routers' => ['frontend' => ['disabled' => true]]]]] - ] - ] - ); - $this->assertTrue(in_array('two', array_keys($result['stores']))); - } - - /** - * Sample stores data - * - * @return array[] - */ - private function getStoresData(): array - { - return [ - [ - 'store_id' => 0, - 'code' => 'admin', - 'website_id' => 0, - 'group_id' => 0, - 'name' => 'Admin', - 'sort_order' => 0, - 'is_active' => 1 - ], - [ - 'store_id' => 1, - 'code' => 'default', - 'website_id' => 1, - 'group_id' => 1, - 'name' => 'Default Store View', - 'sort_order' => 0, - 'is_active' => 1 - ], - [ - 'store_id' => 2, - 'code' => 'TWO', - 'website_id' => 1, - 'group_id' => 1, - 'name' => 'TWO', - 'sort_order' => 0, - 'is_active' => 1 - ] - ]; - } - - private function getWebsitesData(): array - { - return [ - [ - 'website_id' => 0, - 'code' => 'admin', - 'name' => 'Admin', - 'sort_order' => 0, - 'default_group_id' => 0, - 'is_default' => 0 - ], - [ - 'website_id' => 1, - 'code' => 'base', - 'name' => 'Main Website', - 'sort_order' => 0, - 'default_group_id' => 1, - 'is_default' => 1 - ] - ]; - } -} diff --git a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductWithTwoOptionsActionGroup.xml b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductWithTwoOptionsActionGroup.xml new file mode 100644 index 0000000000000..97d905e0b3b44 --- /dev/null +++ b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddTextSwatchToProductWithTwoOptionsActionGroup.xml @@ -0,0 +1,46 @@ +<?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="AddTextSwatchToProductWithTwoOptionsActionGroup"> + <annotations> + <description>Add text swatch property attribute.</description> + </annotations> + <arguments> + <argument name="attributeName" defaultValue="{{textSwatchAttribute.default_label}}" type="string"/> + <argument name="attributeCode" defaultValue="{{textSwatchAttribute.attribute_code}}" type="string"/> + <argument name="option1" defaultValue="textSwatchOption1" type="string"/> + <argument name="option2" defaultValue="textSwatchOption2" type="string"/> + <argument name="usedInProductListing" defaultValue="No" type="string"/> + </arguments> + <!--Begin creating text swatch attribute--> + <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> + <waitForPageLoad stepKey="waitForNewProductAttributePage"/> + <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{attributeName}}" stepKey="fillDefaultLabel"/> + <selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="{{textSwatchAttribute.input_type}}" stepKey="selectInputType"/> + <click selector="{{AdminManageSwatchSection.addSwatchText}}" stepKey="clickAddSwatch1"/> + <fillField selector="{{AdminManageSwatchSection.swatchTextByIndex('0')}}" userInput="{{option1}}" stepKey="fillSwatch1"/> + <fillField selector="{{AdminManageSwatchSection.swatchAdminDescriptionByIndex('0')}}" userInput="{{option1}}" stepKey="fillSwatch1Description"/> + <click selector="{{AdminManageSwatchSection.addSwatchText}}" stepKey="clickAddSwatch2"/> + <fillField selector="{{AdminManageSwatchSection.swatchTextByIndex('1')}}" userInput="{{option2}}" stepKey="fillSwatch2"/> + <fillField selector="{{AdminManageSwatchSection.swatchAdminDescriptionByIndex('1')}}" userInput="{{option2}}" stepKey="fillSwatch2Description"/> + <click selector="{{AttributePropertiesSection.AdvancedProperties}}" stepKey="expandAdvancedProperties"/> + <selectOption selector="{{AttributePropertiesSection.Scope}}" userInput="1" stepKey="selectGlobalScope"/> + <fillField selector="{{AdvancedAttributePropertiesSection.AttributeCode}}" userInput="{{attributeCode}}" stepKey="fillAttributeCodeField"/> + <scrollToTopOfPage stepKey="scrollToTabs"/> + <click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/> + <waitForElementVisible selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" stepKey="waitForTabSwitch"/> + <!-- Set Use In Layered Navigation --> + <scrollToTopOfPage stepKey="scrollToTopOfPage"/> + <click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="goToStorefrontProperties"/> + <selectOption selector="{{AttributePropertiesSection.useInLayeredNavigation}}" userInput="1" stepKey="selectUseInLayeredNavigation"/> + <selectOption selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" userInput="{{usedInProductListing}}" stepKey="useInProductListing"/> + <click selector="{{AttributePropertiesSection.SaveAndEdit}}" stepKey="clickSave"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddVisualSwatchActionGroup.xml b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddVisualSwatchActionGroup.xml new file mode 100644 index 0000000000000..3533d8c343965 --- /dev/null +++ b/app/code/Magento/Swatches/Test/Mftf/ActionGroup/AddVisualSwatchActionGroup.xml @@ -0,0 +1,58 @@ +<?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="AddVisualSwatchActionGroup"> + <annotations> + <description>Add visual image swatch property attribute.</description> + </annotations> + + <!-- Begin creating a new product attribute of type "Image Swatch" --> + <amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/> + <waitForPageLoad stepKey="waitForAttributePageLoad"/> + <fillField selector="{{AttributePropertiesSection.DefaultLabel}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="fillDefaultLabel"/> + <!-- Select visual swatch --> + <selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="swatch_visual" stepKey="selectInputType"/> + <!-- This hack is because the same <input type="file"> is re-purposed used for all uploads. --> + <executeJS function="HTMLInputElement.prototype.click = function() { if(this.type !== 'file') HTMLElement.prototype.click.call(this); };" stepKey="disableClick"/> + <!-- Set swatch image #1 --> + <click selector="{{AdminManageSwatchSection.addSwatch}}" stepKey="clickAddSwatch1"/> + <executeJS function="jQuery('#swatch_window_option_option_0').click()" stepKey="clickSwatch1"/> + <click selector="{{AdminManageSwatchSection.nthUploadFile('1')}}" stepKey="clickUploadFile1"/> + <attachFile selector="input[name='datafile']" userInput="adobe-thumb.jpg" stepKey="attachFile1"/> + <waitForElementNotVisible selector="{{AdminManageSwatchSection.swatchWindowUnavailable('0')}}" stepKey="waitForImageUploaded1"/> + <fillField selector="{{AdminManageSwatchSection.adminInputByIndex('0')}}" userInput="visualSwatchOption1" stepKey="fillAdmin1"/> + <fillField selector="{{AdminManageSwatchSection.visualSwatchDefaultStoreViewBox('0')}}" userInput="visualSwatchOption1" stepKey="fillSwatchDefaultStoreViewBox1"/> + <click selector="{{AdminManageSwatchSection.visualSwatchDefaultStoreViewBox('0')}}" stepKey="clickOutsideToDisableDropDown"/> + <!-- Set swatch image #2 --> + <click selector="{{AdminManageSwatchSection.addSwatch}}" stepKey="clickAddSwatch2"/> + <executeJS function="jQuery('#swatch_window_option_option_1').click()" stepKey="clickSwatch2"/> + <click selector="{{AdminManageSwatchSection.nthUploadFile('2')}}" stepKey="clickUploadFile2"/> + <attachFile selector="input[name='datafile']" userInput="adobe-small.jpg" stepKey="attachFile2"/> + <waitForElementNotVisible selector="{{AdminManageSwatchSection.swatchWindowUnavailable('1')}}" stepKey="waitForImageUploaded2"/> + <fillField selector="{{AdminManageSwatchSection.adminInputByIndex('1')}}" userInput="visualSwatchOption2" stepKey="fillAdmin2"/> + <fillField selector="{{AdminManageSwatchSection.visualSwatchDefaultStoreViewBox('1')}}" userInput="visualSwatchOption2" stepKey="fillSwatchDefaultStoreViewBox2"/> + <click selector="{{AdminManageSwatchSection.swatchWindow('1')}}" stepKey="clicksWatchWindow2"/> + <!-- Set scope --> + <click selector="{{AttributePropertiesSection.AdvancedProperties}}" stepKey="expandAdvancedProperties"/> + <selectOption selector="{{AttributePropertiesSection.Scope}}" userInput="1" stepKey="selectGlobalScope"/> + <scrollToTopOfPage stepKey="scrollToTabs"/> + <click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/> + <waitForElementVisible selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" stepKey="waitForTabSwitch"/> + <selectOption selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" userInput="Yes" stepKey="useInProductListing"/> + <!-- Set Use In Layered Navigation --> + <scrollToTopOfPage stepKey="scrollToTop2"/> + <click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="goToStorefrontProperties"/> + <selectOption selector="{{AttributePropertiesSection.useInLayeredNavigation}}" userInput="1" stepKey="selectUseInLayeredNavigation"/> + <!-- Save the new product attribute --> + <click selector="{{AttributePropertiesSection.Save}}" stepKey="clickSaveAndEdit"/> + <wait stepKey="waitToLoad" time="3"/> + <waitForElementVisible selector="{{AdminProductMessagesSection.successMessage}}" stepKey="waitForSuccess"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml b/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml index 6ff7be38e1290..1c45331b83f8f 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml @@ -37,5 +37,6 @@ <element name="updateSwatchTextValues" type="input" selector="//tbody[@data-role='swatch-visual-options-container']//tr[{{row}}]//td[{{col}}]//input" parameterized="true"/> <element name="nthSwatchWindowEdit" type="button" selector="//tbody[@data-role='swatch-visual-options-container']//tr[{{row}}]//div[@class='swatch_window'][{{col}}]/.." parameterized="true"/> <element name="defaultLabelField" type="input" selector="//input[@id='attribute_label']"/> + <element name="visualSwatchDefaultStoreViewBox" type="input" selector="input[name='optionvisual[value][option_{{index}}][1]']" parameterized="true"/> </section> </sections> diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminSimpleProductwithTextandVisualSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminSimpleProductwithTextandVisualSwatchTest.xml new file mode 100644 index 0000000000000..f5ada80de18a5 --- /dev/null +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminSimpleProductwithTextandVisualSwatchTest.xml @@ -0,0 +1,146 @@ +<?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="AdminSimpleProductwithTextandVisualSwatchTest"> + <annotations> + <features value="Swatches"/> + <stories value="Create simple product and configure visual and text swatches"/> + <title value="Admin can create simple product with text and visual swatches"/> + <description value="Admin can create simple product with text and visual swatches"/> + <severity value="CRITICAL"/> + <testCaseId value="AC-5727"/> + </annotations> + <before> + <!-- Login as Admin --> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <!--Create text and visual swatch attribute--> + <actionGroup ref="AddTextSwatchToProductWithTwoOptionsActionGroup" stepKey="createTextSwatch"/> + <actionGroup ref="AddVisualSwatchActionGroup" stepKey="createVisualSwatch"/> + <!--Assign text swatch attribute to the Default set--> + <actionGroup ref="AdminOpenAttributeSetGridPageActionGroup" stepKey="openAttributeSetPage"/> + <actionGroup ref="AdminOpenAttributeSetByNameActionGroup" stepKey="openDefaultAttributeSet"/> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup"> + <argument name="group" value="Product Details"/> + <argument name="attribute" value="{{textSwatchAttribute.attribute_code}}"/> + </actionGroup> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="saveAttributeSet"/> + <!--Assign visual swatch attribute to the Default set--> + <actionGroup ref="AdminOpenAttributeSetGridPageActionGroup" stepKey="openAttributeSetPage1"/> + <actionGroup ref="AdminOpenAttributeSetByNameActionGroup" stepKey="openDefaultAttributeSet1"/> + <actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup1"> + <argument name="group" value="Product Details"/> + <argument name="attribute" value="{{ProductAttributeFrontendLabel.label}}"/> + </actionGroup> + <actionGroup ref="SaveAttributeSetActionGroup" stepKey="saveAttributeSet1"/> + <!--Create category --> + <createData entity="SimpleSubCategory" stepKey="createCategory"/> + <!--Create product and fill new text swatch attribute field--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/> + <waitForPageLoad stepKey="waitForProductIndexPage"/> + <actionGroup ref="GoToCreateProductPageActionGroup" stepKey="goToCreateProduct"> + <argument name="product" value="SimpleProduct"/> + </actionGroup> + <actionGroup ref="FillMainProductFormNoWeightActionGroup" stepKey="fillProductForm"> + <argument name="product" value="SimpleProduct"/> + </actionGroup> + <!-- Add text swatch product to category --> + <searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[$$createCategory.name$$]" stepKey="fillCategory"/> + <click selector="{{AdminProductFormSection.saveCategory}}" stepKey="saveCategory"/> + <scrollToTopOfPage stepKey="scrollToTop0"/> + <selectOption selector="{{AdminProductFormSection.attributeRequiredInputField(textSwatchAttribute.attribute_code)}}" userInput="textSwatchOption1" stepKey="fillTheAttributeRequiredInputField"/> + <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSaveButton"/> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex"> + <argument name="indices" value=""/> + </actionGroup> + <!-- Create product and fill new visual swatch attribute field--> + <amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex1"/> + <waitForPageLoad stepKey="waitForProductIndexPage1"/> + <actionGroup ref="GoToCreateProductPageActionGroup" stepKey="goToCreateProduct1"> + <argument name="product" value="SimpleProduct"/> + </actionGroup> + <actionGroup ref="FillMainProductFormNoWeightActionGroup" stepKey="fillProductForm1"> + <argument name="product" value="DownloadableProduct"/> + </actionGroup> + <!-- Add visual swatch product to category --> + <searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[$$createCategory.name$$]" stepKey="fillCategory1"/> + <click selector="{{AdminProductFormSection.saveCategory}}" stepKey="saveCategory1"/> + <scrollToTopOfPage stepKey="scrollToTop1"/> + <selectOption selector="{{AdminProductFormSection.attributeRequiredInputField(ProductAttributeFrontendLabel.label)}}" userInput="visualSwatchOption2" stepKey="fillTheAttributeRequiredInputField1"/> + <actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSaveButton1"/> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex1"> + <argument name="indices" value=""/> + </actionGroup> + </before> + <after> + <!-- Delete text and visual swatch attributes --> + <actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="openProductAttributeFromSearchResultInGrid0"> + <argument name="productAttributeCode" value="{{textSwatchAttribute.attribute_code}}"/> + </actionGroup> + <actionGroup ref="DeleteProductAttributeByAttributeCodeActionGroup" stepKey="deleteProductAttributeByAttributeCode0"> + <argument name="productAttributeCode" value="{{textSwatchAttribute.attribute_code}}"/> + </actionGroup> + <actionGroup ref="AssertProductAttributeRemovedSuccessfullyActionGroup" stepKey="deleteProductAttributeSuccess0"/> + <actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="openProductAttributeFromSearchResultInGrid1"> + <argument name="productAttributeCode" value="{{ProductAttributeFrontendLabel.label}}"/> + </actionGroup> + <actionGroup ref="DeleteProductAttributeByAttributeCodeActionGroup" stepKey="deleteProductAttributeByAttributeCode1"> + <argument name="productAttributeCode" value="{{ProductAttributeFrontendLabel.label}}"/> + </actionGroup> + <actionGroup ref="AssertProductAttributeRemovedSuccessfullyActionGroup" stepKey="deleteProductAttributeSuccess1"/> + <actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="navigateToProductAttributeGrid"/> + <click selector="{{AdminProductAttributeGridSection.ResetFilter}}" stepKey="resetFiltersOnGrid"/> + <!-- Delete category --> + <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> + <!-- Delete product --> + <actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="goToProductCatalog"/> + <actionGroup ref="DeleteProductsIfTheyExistActionGroup" stepKey="deleteProduct"/> + <actionGroup ref="ResetProductGridToDefaultViewActionGroup" stepKey="resetFiltersIfExist"/> + <actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex2"> + <argument name="indices" value=""/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!--Assert that attribute values present in layered navigation --> + <amOnPage url="$$createCategory.custom_attributes[url_key]$$.html" stepKey="amOnCategoryPage"/> + <waitForPageLoad stepKey="waitForCategoryPageLoad"/> + <click selector="{{StorefrontCategorySidebarSection.seeLayeredNavigationCategoryTextSwatch}}" stepKey="clickTextSwatch"/> + <click selector="{{StorefrontCategorySidebarSection.seeTextSwatchOption}}" stepKey="seeTextSwatch"/> + <see userInput="{{SimpleProduct.name}}" stepKey="assertTextSwatchProduct"/> + <!--Assert that attribute values present in layered navigation --> + <amOnPage url="$$createCategory.custom_attributes[url_key]$$.html" stepKey="amOnCategoryPage1"/> + <waitForPageLoad stepKey="waitForCategoryPageLoad1"/> + <click selector="{{StorefrontCategorySidebarSection.seeLayeredNavigationCategoryVisualSwatch}}" stepKey="clickVisualSwatch"/> + <click selector="{{StorefrontCategorySidebarSection.seeVisualSwatchOption}}" stepKey="seeVisualSwatch"/> + <see userInput="{{DownloadableProduct.name}}" stepKey="assertVisualSwatchProduct"/> + <!--Verfiy the text swatch attribute product appears in search option with option one --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPage"/> + <actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchForOptionOne"> + <argument name="phrase" value="textSwatchOption1"/> + </actionGroup> + <see selector="{{StorefrontCategoryMainSection.productName}}" userInput="{{SimpleProduct.name}}" stepKey="seeTextSwatchAttributeProductName"/> + <!--Verfiy the text swatch attribute product does not appears in search option with option two --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPage1"/> + <actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchForOptionTwo"> + <argument name="phrase" value="textSwatchOption2"/> + </actionGroup> + <dontSee selector="{{StorefrontCatalogSearchMainSection.searchResults}}" userInput="{{SimpleProduct.name}}" stepKey="doNotSeeProduct"/> + <!--Verfiy the visual swatch attribute product appears in search option with option two --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPage2"/> + <actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchForOptionTwo1"> + <argument name="phrase" value="visualSwatchOption2"/> + </actionGroup> + <see selector="{{StorefrontCategoryMainSection.productName}}" userInput="{{DownloadableProduct.name}}" stepKey="seeVisualSwatchAttributeProductName"/> + <!--Verfiy the visual swatch attribute product does not appears in search option with option one --> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPage3"/> + <actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchForOptionOne1"> + <argument name="phrase" value="visualSwatchOption1"/> + </actionGroup> + <dontSee selector="{{StorefrontCatalogSearchMainSection.searchResults}}" userInput="{{DownloadableProduct.name}}" stepKey="doNotSeeProduct1"/> + </test> +</tests> diff --git a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php index 9e7e62e0a077f..7f58641d4d227 100644 --- a/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php @@ -23,8 +23,11 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Request\Http; use Magento\Framework\App\RequestInterface; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Json\EncoderInterface; use Magento\Framework\Model\AbstractModel; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Pricing\PriceInfo\Base; use Magento\Framework\Stdlib\ArrayUtils; @@ -95,8 +98,23 @@ class ConfigurableTest extends TestCase */ private $request; + /** + * @var ObjectManagerInterface|MockObject + */ + private $objectManagerMock; + + /** + * @var DeploymentConfig|MockObject + */ + private $deploymentConfig; + protected function setUp(): void { + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->onlyMethods(['get']) + ->getMockForAbstractClass(); + \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock); $this->arrayUtils = $this->createMock(ArrayUtils::class); $this->jsonEncoder = $this->getMockForAbstractClass(EncoderInterface::class); $this->helper = $this->createMock(Data::class); @@ -127,6 +145,16 @@ protected function setUp(): void $context = $this->getContextMock(); $context->method('getRequest')->willReturn($this->request); + $this->deploymentConfig = $this->createPartialMock( + DeploymentConfig::class, + ['get'] + ); + + $this->deploymentConfig->expects($this->any()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY) + ->willReturn('448198e08af35844a42d3c93c1ef4e03'); + $objectManagerHelper = new ObjectManager($this); $this->configurable = $objectManagerHelper->getObject( ConfigurableRenderer::class, @@ -146,7 +174,7 @@ protected function setUp(): void 'configurableAttributeData' => $this->configurableAttributeData, 'data' => [], 'variationPrices' => $this->variationPricesMock, - 'customerSession' => $customerSession, + 'customerSession' => $customerSession ] ); } @@ -308,6 +336,10 @@ public function testGetCacheKey() ->willReturn($configurableAttributes); $this->request->method('toArray')->willReturn($requestParams); + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with(DeploymentConfig::class) + ->willReturn($this->deploymentConfig); $this->assertStringContainsString( sha1(json_encode(['color' => 59, 'size' => 1])), $this->configurable->getCacheKey() diff --git a/app/code/Magento/Tax/Test/Mftf/Data/TaxRateData.xml b/app/code/Magento/Tax/Test/Mftf/Data/TaxRateData.xml index bc6099790431f..4bc1c068570f4 100644 --- a/app/code/Magento/Tax/Test/Mftf/Data/TaxRateData.xml +++ b/app/code/Magento/Tax/Test/Mftf/Data/TaxRateData.xml @@ -147,4 +147,7 @@ <entity name="SecondTaxRateTexas" extends="TaxRateTexas"> <data key="rate">0.125</data> </entity> + <entity name="ThirdTaxRateTexas" extends="TaxRateTexas"> + <data key="rate">20</data> + </entity> </entities> diff --git a/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml b/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml index 3692e82072afc..404fcb52c91e9 100644 --- a/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml +++ b/app/code/Magento/UrlRewrite/Test/Mftf/Data/UrlRewriteData.xml @@ -28,7 +28,7 @@ </entity> <entity name="customPermanentUrlRewrite" type="urlRewrite"> <data key="request_path" unique="prefix">wishlist</data> - <data key="target_path">https://marketplace.magento.com/</data> + <data key="target_path">https://commercemarketplace.adobe.com/</data> <data key="redirect_type">301</data> <data key="redirect_type_label">Permanent (301)</data> <data key="store_id">1</data> @@ -37,7 +37,7 @@ </entity> <entity name="customTemporaryUrlRewrite" type="urlRewrite"> <data key="request_path" unique="prefix">wishlist</data> - <data key="target_path">https://marketplace.magento.com/</data> + <data key="target_path">https://commercemarketplace.adobe.com/</data> <data key="redirect_type">302</data> <data key="redirect_type_label">Temporary (302)</data> <data key="store_id">1</data> diff --git a/app/code/Magento/Usps/Model/Config/Backend/UspsUrl.php b/app/code/Magento/Usps/Model/Config/Backend/UspsUrl.php new file mode 100644 index 0000000000000..17cdcc83961bd --- /dev/null +++ b/app/code/Magento/Usps/Model/Config/Backend/UspsUrl.php @@ -0,0 +1,76 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Usps\Model\Config\Backend; + +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Framework\Validator\Url; + +/** + * Represents a config URL that may point to a USPS endpoint + * + * @SuppressWarnings(PHPMD.Superglobals) + */ +class UspsUrl extends Value +{ + /** + * @var Url + */ + private Url $url; + + /** + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param Url $url + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection + * @param array $data + */ + public function __construct( + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + Url $url, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] + ) { + $this->url = $url; + parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); + } + + /** + * @inheritdoc + * + * @throws ValidatorException + */ + public function beforeSave() + { + $isValid = $this->url->isValid($this->getValue()); + if ($isValid) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $host = parse_url((string)$this->getValue(), \PHP_URL_HOST); + + if (!empty($host) && !preg_match("/(?:.+\.|^)usps|shippingapis\.com$/i", $host)) { + throw new ValidatorException(__('USPS API endpoint URL\'s must use usps.com or shippingapis.com')); + } + } + + return parent::beforeSave(); + } +} diff --git a/app/code/Magento/Usps/Test/Unit/Model/Config/Backend/UspsUrlTest.php b/app/code/Magento/Usps/Test/Unit/Model/Config/Backend/UspsUrlTest.php new file mode 100644 index 0000000000000..da18923366c55 --- /dev/null +++ b/app/code/Magento/Usps/Test/Unit/Model/Config/Backend/UspsUrlTest.php @@ -0,0 +1,124 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Usps\Test\Unit\Model\Config\Backend; + +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\Validator\Url; +use Magento\Usps\Model\Config\Backend\UspsUrl; +use PHPUnit\Framework\TestCase; + +/** + * Verify behavior of UspsUrl backend type + * + * @SuppressWarnings(PHPMD.Superglobals) + */ +class UspsUrlTest extends TestCase +{ + /** + * @var UspsUrl + */ + private $urlConfig; + + /** + * @var Url + */ + private $url; + + /** + * @var Context + */ + private $contextMock; + + protected function setUp(): void + { + $objectManager = new ObjectManager($this); + + $this->contextMock = $this->createMock(Context::class); + $registry = $this->createMock(Registry::class); + $config = $this->createMock(ScopeConfigInterface::class); + $cacheTypeList = $this->createMock(TypeListInterface::class); + $this->url = $this->createMock(Url::class); + $resource = $this->createMock(AbstractResource::class); + $resourceCollection = $this->createMock(AbstractDb::class); + $eventManagerMock = $this->getMockForAbstractClass(ManagerInterface::class); + + $eventManagerMock->expects($this->any())->method('dispatch'); + $this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($eventManagerMock); + + $this->urlConfig = $objectManager->getObject( + UspsUrl::class, + [ + 'url' => $this->url, + 'context' => $this->contextMock, + 'registry' => $registry, + 'config' => $config, + 'cacheTypeList' => $cacheTypeList, + 'resource' => $resource, + 'resourceCollection' => $resourceCollection, + ] + ); + } + + /** + * @dataProvider validDataProvider + * @param string $data The valid data + * @throws ValidatorException + */ + public function testBeforeSave(string $data = ""): void + { + $this->url->expects($this->any())->method('isValid')->willReturn(true); + $this->urlConfig->setValue($data); + $this->urlConfig->beforeSave(); + $this->assertTrue($this->url->isValid($data)); + } + + /** + * @dataProvider invalidDataProvider + * @param string $data The invalid data + */ + public function testBeforeSaveErrors(string $data): void + { + $this->url->expects($this->any())->method('isValid')->willReturn(true); + $this->expectException('Magento\Framework\Exception\ValidatorException'); + $this->expectExceptionMessage('USPS API endpoint URL\'s must use usps.com or shippingapis.com'); + $this->urlConfig->setValue($data); + $this->urlConfig->beforeSave(); + } + + public function validDataProvider(): array + { + return [ + [], + [''], + ['http://usps.com'], + ['https://foo.usps.com'], + ['http://foo.usps.com/foo/bar?baz=bash&fizz=buzz'], + ]; + } + + /** + * @return string[][] + */ + public function invalidDataProvider(): array + { + return [ + ['https://shippingapis.com.fake.com'], + ['https://shippingapis.info'], + ['http://shippingapis.com.foo.com/foo/bar?baz=bash&fizz=buzz'], + ]; + } +} diff --git a/app/code/Magento/Usps/etc/adminhtml/system.xml b/app/code/Magento/Usps/etc/adminhtml/system.xml index b01f7be9a19f9..00c9632b99367 100644 --- a/app/code/Magento/Usps/etc/adminhtml/system.xml +++ b/app/code/Magento/Usps/etc/adminhtml/system.xml @@ -16,9 +16,11 @@ </field> <field id="gateway_url" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" canRestore="1"> <label>Gateway URL</label> + <backend_model>Magento\Usps\Model\Config\Backend\UspsUrl</backend_model> </field> <field id="gateway_secure_url" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" canRestore="1"> <label>Secure Gateway URL</label> + <backend_model>Magento\Usps\Model\Config\Backend\UspsUrl</backend_model> </field> <field id="title" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Title</label> diff --git a/app/code/Magento/Usps/i18n/en_US.csv b/app/code/Magento/Usps/i18n/en_US.csv index ab1a11155fe04..65837cfb4dc77 100644 --- a/app/code/Magento/Usps/i18n/en_US.csv +++ b/app/code/Magento/Usps/i18n/en_US.csv @@ -137,3 +137,4 @@ Machinable,Machinable Debug,Debug "Show Method if Not Applicable","Show Method if Not Applicable" "Sort Order","Sort Order" +"USPS API endpoint URL\'s must use usps.com or shippingapis.com","USPS API endpoint URL\'s must use usps.com or shippingapis.com" diff --git a/app/code/Magento/Widget/Test/Mftf/Test/CheckDisplayingOfApostrophesInTheTextFieldBoxWhileCreatingPageWidgetTest.xml b/app/code/Magento/Widget/Test/Mftf/Test/CheckDisplayingOfApostrophesInTheTextFieldBoxWhileCreatingPageWidgetTest.xml new file mode 100644 index 0000000000000..82b43a0756e17 --- /dev/null +++ b/app/code/Magento/Widget/Test/Mftf/Test/CheckDisplayingOfApostrophesInTheTextFieldBoxWhileCreatingPageWidgetTest.xml @@ -0,0 +1,83 @@ +<?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="CheckDisplayingOfApostrophesInTheTextFieldBoxWhileCreatingPageWidgetTest"> + <annotations> + <features value="Widget"/> + <stories value="Checking displaying of apostrophes (') in the text field box while creating page widget"/> + <title value="Checking displaying of apostrophes (') in the text field box while creating page widget"/> + <description value="Checking displaying of apostrophes (') in the text field box while creating page widget"/> + <severity value="MAJOR"/> + <testCaseId value="AC-4389"/> + <group value="widget"/> + <group value="pagebuilder_disabled"/> + </annotations> + <before> + <!-- Pre-condition 1- Login as Admin --> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <!-- Pre-condition 3- Verify page in grid--> + <actionGroup ref="AdminOpenCMSPagesGridActionGroup" stepKey="openCMSPagesGridActionGroup"/> + <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilters"/> + <actionGroup ref="SortByIdDescendingActionGroup" stepKey="sortGridByIdDescending"/> + <click selector="{{CmsPagesPageActionsSection.select('home')}}" stepKey="clickSelectCMSPage" /> + <!-- Pre-condition 4- Update the page in grid--> + <click selector="{{CmsPagesPageActionsSection.edit('home')}}" stepKey="OpenThePageToBeEdited"/> + <waitForPageLoad stepKey="waitForPageLoadPostSelectingHomePage"/> + <waitForElementVisible selector="{{CmsNewPagePageContentSection.header}}" stepKey="waitForContentTabForPageToBeVisible"/> + <!-- Pre-condition 5- Expand the Content section > Insert Widget --> + <click selector="{{CmsNewPagePageContentSection.header}}" stepKey="clickExpandContentTabForPage"/> + <conditionalClick selector="{{CmsNewPagePageActionsSection.showHideEditor}}" dependentSelector="{{CmsNewPagePageActionsSection.showHideEditor}}" visible="true" stepKey="clickOnShowHideEditorLinkIfVisibleForInsertingWidget"/> + <waitForElementVisible selector="{{CmsNewPagePageActionsSection.insertWidget}}" stepKey="waitForTheInsertWidgetButtonToDisplay"/> + <actionGroup ref="AdminInsertWidgetToCmsPageContentActionGroup" stepKey="selectCMSPageLinkFromDropdown"/> + <waitForPageLoad stepKey="waitForPageLoadPostSelectingFromDropDown"/> + <!-- Pre-condition 6 - 11 - Update the Anchor Custom Text --> + <fillField selector="{{WidgetSection.InputAnchorCustomText}}" userInput="Custom texts' for tests" stepKey="InputValuesWithApostrophe"/> + <click selector="{{WidgetSection.SelectPageButton}}" stepKey="clickOnSelectPageButton"/> + <waitForElementVisible selector="{{WidgetSection.URLKeySelectPage}}" stepKey="waitForSelectPageDialogToPopulate"/> + <fillField selector="{{WidgetSection.URLKeySelectPage}}" userInput="home" stepKey="EnterThePageURL"/> + <click selector="{{WidgetSection.SearchButtonSelectPage}}" stepKey="clickOnSearchButton"/> + <waitForPageLoad stepKey="waitForResultsToBeDisplayed"/> + <click selector="{{WidgetSection.SearchResultSelectPage('home')}}" stepKey="clickOnDisplayedResult"/> + <click selector="{{WidgetSection.InsertWidget}}" stepKey="clickOnInsertWidget"/> + <waitForElementVisible selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="waitForInsertWidgetDialogToDisappear" time="5"/> + <click selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="clickSavePage"/> + <waitForElementVisible selector="{{CmsPagesPageActionsSection.savePageSuccessMessage}}" stepKey="waitForSuccessMessageLoggedOut" time="5"/> + <see userInput="You saved the page." stepKey="seeSuccessMessage"/> + </before> + <after> + <actionGroup ref="AdminOpenCMSPagesGridActionGroup" stepKey="openCMSPagesGridActionGroupToReset"/> + <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFiltersToReset"/> + <actionGroup ref="SortByIdDescendingActionGroup" stepKey="sortGridByIdDescendingToReset"/> + <click selector="{{CmsPagesPageActionsSection.select('home')}}" stepKey="clickSelectCMSPageToReset" /> + <!-- Pre-condition 4- Update the page in grid To Reset--> + <click selector="{{CmsPagesPageActionsSection.edit('home')}}" stepKey="OpenThePageToBeEditedToReset"/> + <waitForPageLoad stepKey="waitForPageLoadPostSelectingHomePageToReset"/> + <waitForElementVisible selector="{{CmsNewPagePageContentSection.header}}" stepKey="waitForContentTabForPageToBeVisibleToReset"/> + <!-- Pre-condition 5- Expand the Content section > Insert Widget To Reset --> + <click selector="{{CmsNewPagePageContentSection.header}}" stepKey="clickExpandContentTabForPageToReset"/> + <conditionalClick selector="{{CmsNewPagePageActionsSection.showHideEditor}}" dependentSelector="{{CmsNewPagePageActionsSection.showHideEditor}}" visible="true" stepKey="clickOnShowHideEditorLinkIfVisibleForInsertingWidgetToOriginal"/> + <waitForElementVisible selector="{{CmsNewPagePageActionsSection.insertWidget}}" stepKey="waitForTheInsertWidgetButtonToDisplayToReset"/> + <clearField selector="{{CmsNewPagePageContentSection.content}}" stepKey="clearWidgetTextFieldToReset"/> + <fillField selector="{{CmsNewPagePageContentSection.content}}" userInput="<p>CMS homepage content goes here.</p>" stepKey="InputDefaultValuesInWidgetTextFieldToReset"/> + <waitForElementVisible selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="waitForInsertWidgetDialogToDisappearToReset" time="5"/> + <click selector="{{CmsNewPagePageActionsSection.saveAndContinueEdit}}" stepKey="clickSavePageToReset"/> + <waitForElementVisible selector="{{CmsPagesPageActionsSection.savePageSuccessMessage}}" stepKey="waitForSuccessMessageLoggedOutToReset" time="5"/> + <see userInput="You saved the page." stepKey="seeSuccessMessageToReset"/> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="navigateToHomePage"/> + <waitForPageLoad stepKey="waitToLoadHomePage"/> + <grabTextFrom selector="{{StorefrontCMSPageSection.widgetContentApostrophe('Custom texts')}}" stepKey="grabContentFromWidget"/> + <assertEquals message="Asserts the widget contains apostrophe On storefront" stepKey="assertApostropheOnWidgetText"> + <expectedResult type="string">Custom texts' for tests</expectedResult> + <actualResult type="string">{$grabContentFromWidget}</actualResult> + </assertEquals> + </test> +</tests> diff --git a/app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php b/app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php index 3a2d9061e7f36..f194bab868ec9 100644 --- a/app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php +++ b/app/code/Magento/Wishlist/Controller/Index/DownloadCustomOption.php @@ -97,7 +97,7 @@ public function execute() $secretKey = $this->getRequest()->getParam('key'); if ($secretKey == $info['secret_key']) { - $this->_fileResponseFactory->create( + return $this->_fileResponseFactory->create( $info['title'], ['value' => $info['quote_path'], 'type' => 'filename'], DirectoryList::MEDIA, diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php index 4cbaadf0773ae..a2e7fcb95a430 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php @@ -111,20 +111,21 @@ public function get(string $query, array $variables = [], string $operationName */ private function processResponse(string $response, array $responseHeaders = [], array $responseCookies = []) { - $responseArray = $this->json->jsonDecode($response); - + $responseArray = null; + try { + $responseArray = $this->json->jsonDecode($response); + } catch (\Exception $exception) { + // Note: We don't care about this exception because we have error checking bellow if it fails to decode. + } if (!is_array($responseArray)) { //phpcs:ignore Magento2.Exceptions.DirectThrow throw new \Exception('Unknown GraphQL response body: ' . $response); } - $this->processErrors($responseArray, $responseHeaders, $responseCookies); - if (!isset($responseArray['data'])) { //phpcs:ignore Magento2.Exceptions.DirectThrow throw new \Exception('Unknown GraphQL response body: ' . $response); } - return $responseArray['data']; } @@ -225,7 +226,7 @@ private function processErrors($responseBodyArray, array $responseHeaders = [], } throw new ResponseContainsErrorsException( - 'GraphQL response contains errors: ' . $errorMessage, + 'GraphQL response contains errors: ' . $errorMessage . "\n" . var_export($responseBodyArray, true), $responseBodyArray, null, 0, diff --git a/dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php b/dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php index 63f6814897863..0bac15256d355 100644 --- a/dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php @@ -8,10 +8,13 @@ use Magento\Customer\Api\Data\CustomerInterface as Customer; use Magento\Customer\Model\AccountManagement; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\InputException; use Magento\Framework\Webapi\Exception as HTTPExceptionCodes; use Magento\Newsletter\Model\Subscriber; use Magento\Security\Model\Config; +use Magento\Store\Model\ScopeInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Helper\Customer as CustomerHelper; use Magento\TestFramework\TestCase\WebapiAbstract; @@ -23,15 +26,20 @@ */ class AccountManagementTest extends WebapiAbstract { - const SERVICE_VERSION = 'V1'; - const SERVICE_NAME = 'customerAccountManagementV1'; - const RESOURCE_PATH = '/V1/customers'; + public const SERVICE_VERSION = 'V1'; + public const SERVICE_NAME = 'customerAccountManagementV1'; + public const RESOURCE_PATH = '/V1/customers'; /** * Sample values for testing */ - const ATTRIBUTE_CODE = 'attribute_code'; - const ATTRIBUTE_VALUE = 'attribute_value'; + public const ATTRIBUTE_CODE = 'attribute_code'; + public const ATTRIBUTE_VALUE = 'attribute_value'; + + /** + * @var ObjectManager + */ + private $objectManager; /** * @var AccountManagementInterface @@ -86,6 +94,8 @@ class AccountManagementTest extends WebapiAbstract */ protected function setUp(): void { + $this->objectManager = Bootstrap::getObjectManager(); + $this->accountManagement = Bootstrap::getObjectManager()->get( \Magento\Customer\Api\AccountManagementInterface::class ); @@ -645,6 +655,7 @@ public function testIsReadonly() public function testEmailAvailable() { + $config = $this->objectManager->get(ScopeConfigInterface::class); $customerData = $this->_createCustomer(); $serviceInfo = [ @@ -662,7 +673,18 @@ public function testEmailAvailable() 'customerEmail' => $customerData[Customer::EMAIL], 'websiteId' => $customerData[Customer::WEBSITE_ID], ]; - $this->assertFalse($this->_webApiCall($serviceInfo, $requestData)); + + $emailSetting = $config->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + $customerData[Customer::WEBSITE_ID] + ); + + if (!$emailSetting) { + $this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); + } else { + $this->assertFalse($this->_webApiCall($serviceInfo, $requestData)); + } } public function testEmailAvailableInvalidEmail() diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductFragmentTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductFragmentTest.php index 32a2f8f763572..ff932026c5ce2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductFragmentTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductFragmentTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Catalog; +use Exception; use Magento\TestFramework\TestCase\GraphQlAbstract; /** @@ -16,8 +17,9 @@ class ProductFragmentTest extends GraphQlAbstract { /** * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @throws Exception */ - public function testSimpleProductFragment() + public function testSimpleProductNamedFragment(): void { $sku = 'simple'; $name = 'Simple Product'; @@ -36,9 +38,9 @@ public function testSimpleProductFragment() fragment BasicProductInformation on ProductInterface { sku name - price { - regularPrice { - amount { + price_range{ + minimum_price{ + final_price{ value } } @@ -49,6 +51,42 @@ public function testSimpleProductFragment() $actualProductData = $result['products']['items'][0]; $this->assertNotEmpty($actualProductData); $this->assertEquals($name, $actualProductData['name']); - $this->assertEquals($price, $actualProductData['price']['regularPrice']['amount']['value']); + $this->assertEquals($price, $actualProductData['price_range']['minimum_price']['final_price']['value']); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php + * @throws Exception + */ + public function testSimpleProductInlineFragment(): void + { + $sku = 'simple'; + $name = 'Simple Product'; + $price = 10; + + $query = <<<QUERY +query GetProduct { + products(filter: { sku: { eq: "$sku" } }) { + items { + sku + ... on ProductInterface { + name + price_range{ + minimum_price{ + final_price{ + value + } + } + } + } + } + } +} +QUERY; + $result = $this->graphQlQuery($query); + $actualProductData = $result['products']['items'][0]; + $this->assertNotEmpty($actualProductData); + $this->assertEquals($name, $actualProductData['name']); + $this->assertEquals($price, $actualProductData['price_range']['minimum_price']['final_price']['value']); } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCms/CategoryBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCms/CategoryBlockTest.php index 8e9a76a3a0cfd..091c0e419ee51 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCms/CategoryBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogCms/CategoryBlockTest.php @@ -19,6 +19,7 @@ class CategoryBlockTest extends GraphQlAbstract { /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoApiDataFixture Magento/Catalog/_files/category_tree.php * @magentoApiDataFixture Magento/Cms/_files/block.php */ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl/PriceAttributeOptionsLabelTranslateTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl/PriceAttributeOptionsLabelTranslateTest.php index 425643a37f308..643d2131bb995 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl/PriceAttributeOptionsLabelTranslateTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogGraphQl/PriceAttributeOptionsLabelTranslateTest.php @@ -201,6 +201,6 @@ public function testValidateAggregateAttributeOptionsInLabelLocaleTranslationFor } } - $this->assertEquals($priceAttributeOptionLabel, 'Preisansicht'); + $this->assertEquals('Preisansicht', $priceAttributeOptionLabel); } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php index 07de3e1641b60..fa9a2f21c8530 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Cms/CmsBlockTest.php @@ -38,6 +38,7 @@ protected function setUp(): void /** * Verify the fields of CMS Block selected by identifiers * + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoApiDataFixture Magento/Cms/_files/blocks.php */ public function testGetCmsBlock() @@ -71,6 +72,7 @@ public function testGetCmsBlock() /** * Verify the fields of CMS Block selected by block_id * + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoApiDataFixture Magento/Cms/_files/blocks.php */ public function testGetCmsBlockByBlockId() diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php index 65d2e2b784689..3756eddd1cd31 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CmsGraphQl/Model/Resolver/BlockTest.php @@ -18,6 +18,9 @@ use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; use Magento\Widget\Model\Template\FilterEmulate; +/** + * Test for cms block resolver cache + */ class BlockTest extends ResolverCacheAbstract { /** @@ -52,6 +55,7 @@ protected function setUp(): void } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoDataFixture Magento/Cms/_files/blocks.php */ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest() @@ -90,6 +94,7 @@ public function testCmsSingleBlockResolverCacheAndInvalidationAsGuest() } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoDataFixture Magento/Cms/_files/block.php * @magentoDataFixture Magento/Cms/_files/blocks.php */ @@ -134,6 +139,7 @@ public function testCmsMultipleBlockResolverCacheAndInvalidationAsGuest() } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoDataFixture Magento/Cms/_files/block.php */ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted() @@ -171,6 +177,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDeleted() } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoDataFixture Magento/Cms/_files/blocks.php */ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled() @@ -209,6 +216,7 @@ public function testCmsBlockResolverCacheInvalidatesWhenBlockGetsDisabled() } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoDataFixture Magento/Cms/_files/block.php * @magentoDataFixture Magento/Store/_files/second_store.php */ diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/IsEmailAvailableTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/IsEmailAvailableTest.php index f0bd7dc1e854a..b683b4bd521d6 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/IsEmailAvailableTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/IsEmailAvailableTest.php @@ -7,6 +7,11 @@ namespace Magento\GraphQl\Customer; +use Magento\Customer\Model\AccountManagement; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Api\StoreResolverInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; /** @@ -14,6 +19,25 @@ */ class IsEmailAvailableTest extends GraphQlAbstract { + /** + * @var ScopeConfigInterface|null + */ + private ?ScopeConfigInterface $scopeConfig; + + /** + * @var string|null + */ + private ?string $storeId; + + public function setUp(): void + { + $objectManager = Bootstrap::getObjectManager(); + $this->scopeConfig = $objectManager->get(ScopeConfigInterface::class); + /* @var StoreResolverInterface $storeResolver */ + $storeResolver = $objectManager->get(StoreResolverInterface::class); + $this->storeId = $storeResolver->getCurrentStoreId(); + } + /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ @@ -31,7 +55,16 @@ public function testEmailNotAvailable() self::assertArrayHasKey('isEmailAvailable', $response); self::assertArrayHasKey('is_email_available', $response['isEmailAvailable']); - self::assertFalse($response['isEmailAvailable']['is_email_available']); + $emailConfig = $this->scopeConfig->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_STORE, + $this->storeId + ); + if (!$emailConfig) { + self::assertTrue($response['isEmailAvailable']['is_email_available']); + } else { + self::assertFalse($response['isEmailAvailable']['is_email_available']); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Newsletter/Customer/SubscribeEmailToNewsletterTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Newsletter/Customer/SubscribeEmailToNewsletterTest.php index ec0e49cc55153..17c18521f2a2c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Newsletter/Customer/SubscribeEmailToNewsletterTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Newsletter/Customer/SubscribeEmailToNewsletterTest.php @@ -8,11 +8,14 @@ namespace Magento\GraphQl\Newsletter\Customer; use Exception; +use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\CustomerAuthUpdate; use Magento\Customer\Model\CustomerRegistry; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\AuthenticationException; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Newsletter\Model\ResourceModel\Subscriber as SubscriberResourceModel; +use Magento\Store\Model\ScopeInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -40,6 +43,10 @@ class SubscribeEmailToNewsletterTest extends GraphQlAbstract * @var SubscriberResourceModel */ private $subscriberResource; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; /** * @inheritDoc @@ -47,6 +54,7 @@ class SubscribeEmailToNewsletterTest extends GraphQlAbstract protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); + $this->scopeConfig = $objectManager->get(ScopeConfigInterface::class); $this->customerAuthUpdate = Bootstrap::getObjectManager()->get(CustomerAuthUpdate::class); $this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class); $this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); @@ -146,10 +154,17 @@ public function testNewsletterSubscriptionWithAnotherCustomerEmail() { $query = $this->getQuery('customer2@search.example.com'); - $this->expectException(Exception::class); - $this->expectExceptionMessage('Cannot create a newsletter subscription.' . "\n"); - - $this->graphQlMutation($query, [], '', $this->getHeaderMap('customer@search.example.com')); + $guestLoginConfig = $this->scopeConfig->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + 1 + ); + + if ($guestLoginConfig) { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Cannot create a newsletter subscription.' . "\n"); + $this->graphQlMutation($query, [], '', $this->getHeaderMap('customer@search.example.com')); + } } /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/PaymentGraphQl/StoreConfigTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/PaymentGraphQl/StoreConfigTest.php index 884e2e87a9c57..f47efa6d2ecb8 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/PaymentGraphQl/StoreConfigTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/PaymentGraphQl/StoreConfigTest.php @@ -12,11 +12,10 @@ /** * Test coverage for zero subtotal and check/money order payment methods in the store config * - * @magentoDbIsolation enabled */ class StoreConfigTest extends GraphQlAbstract { - const STORE_CONFIG_QUERY = <<<QUERY + public const STORE_CONFIG_QUERY = <<<QUERY { storeConfig { zero_subtotal_enabled diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php index 870da96ad25f4..b1978964d0d4d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php @@ -7,11 +7,11 @@ namespace Magento\GraphQl\Quote\Customer; -use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException; use Magento\TestFramework\TestCase\GraphQlAbstract; /** diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php index e17cafa9a43df..b2aa977bbb59f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php @@ -47,24 +47,14 @@ protected function setUp(): void } /** - * @magentoApiDataFixture Magento/Store/_files/store.php - * @magentoApiDataFixture Magento/Store/_files/inactive_store.php + * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ + * @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php */ - public function testDefaultWebsiteAvailableStoreConfigs(): void + public function testNonDefaultWebsiteAvailableStoreConfigs(): void { - $storeConfigs = $this->storeConfigManager->getStoreConfigs(); - - $expectedAvailableStores = []; - $expectedAvailableStoreCodes = [ - 'default', - 'test' - ]; - - foreach ($storeConfigs as $storeConfig) { - if (in_array($storeConfig->getCode(), $expectedAvailableStoreCodes)) { - $expectedAvailableStores[] = $storeConfig; - } - } + $storeConfigs = $this->storeConfigManager->getStoreConfigs(['fixture_second_store', 'fixture_third_store']); $query = <<<QUERY @@ -100,20 +90,37 @@ public function testDefaultWebsiteAvailableStoreConfigs(): void } } QUERY; - $response = $this->graphQlQuery($query); + $headerMap = ['Store' => 'fixture_second_store']; + $response = $this->graphQlQuery($query, [], '', $headerMap); $this->assertArrayHasKey('availableStores', $response); - foreach ($expectedAvailableStores as $key => $storeConfig) { + foreach ($storeConfigs as $key => $storeConfig) { $this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); } } /** - * @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php + * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ + * @magentoApiDataFixture Magento/Store/_files/store.php + * @magentoApiDataFixture Magento/Store/_files/inactive_store.php */ - public function testNonDefaultWebsiteAvailableStoreConfigs(): void + public function testDefaultWebsiteAvailableStoreConfigs(): void { - $storeConfigs = $this->storeConfigManager->getStoreConfigs(['fixture_second_store', 'fixture_third_store']); + $storeConfigs = $this->storeConfigManager->getStoreConfigs(); + + $expectedAvailableStores = []; + $expectedAvailableStoreCodes = [ + 'default', + 'test' + ]; + + foreach ($storeConfigs as $storeConfig) { + if (in_array($storeConfig->getCode(), $expectedAvailableStoreCodes)) { + $expectedAvailableStores[] = $storeConfig; + } + } $query = <<<QUERY @@ -149,11 +156,10 @@ public function testNonDefaultWebsiteAvailableStoreConfigs(): void } } QUERY; - $headerMap = ['Store' => 'fixture_second_store']; - $response = $this->graphQlQuery($query, [], '', $headerMap); + $response = $this->graphQlQuery($query); $this->assertArrayHasKey('availableStores', $response); - foreach ($storeConfigs as $key => $storeConfig) { + foreach ($expectedAvailableStores as $key => $storeConfig) { $this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); } } @@ -206,6 +212,9 @@ private function validateStoreConfig(StoreConfigInterface $storeConfig, array $r } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ * @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php * @magentoConfigFixture web/url/use_store 1 */ @@ -266,6 +275,9 @@ public function testAllStoreConfigsWithCodeInUrlEnabled(): void } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ * @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php */ public function testCurrentGroupStoreConfigs(): void diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php index c79bbf0e0a300..80f55d83a40e2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/StoreConfigResolverTest.php @@ -35,6 +35,7 @@ protected function setUp(): void } /** + * @magentoConfigFixture default_store web/seo/use_rewrites 1 * @magentoApiDataFixture Magento/Store/_files/store.php * @throws NoSuchEntityException */ diff --git a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php index 2add2ed48fb98..419cbde64d9b7 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php @@ -87,6 +87,7 @@ protected function _processTransactionRequests($eventName, \PHPUnit\Framework\Te * * @param \PHPUnit\Framework\TestCase $test * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function _startTransaction(\PHPUnit\Framework\TestCase $test) { @@ -110,6 +111,7 @@ function ($errNo, $errStr, $errFile, $errLine) use ($test) { $this->_eventManager->fireEvent('startTransaction', [$test]); restore_error_handler(); } catch (\Exception $e) { + $this->_isTransactionActive = false; $test->getTestResultObject()->addFailure( $test, new \PHPUnit\Framework\AssertionFailedError((string)$e), @@ -125,8 +127,8 @@ function ($errNo, $errStr, $errFile, $errLine) use ($test) { protected function _rollbackTransaction() { if ($this->_isTransactionActive) { - $this->_getConnection()->rollbackTransparentTransaction(); $this->_isTransactionActive = false; + $this->_getConnection()->rollbackTransparentTransaction(); $this->_eventManager->fireEvent('rollbackTransaction'); $this->_getConnection()->closeConnection(); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/StockTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/StockTest.php index 24d5b668ac09c..e5cc7082b65da 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/StockTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/StockTest.php @@ -54,7 +54,7 @@ protected function setUp(): void public function testValidate(): void { $this->expectException(LocalizedException::class); - $this->expectErrorMessage((string)__('Please enter a valid number in this field.')); + $this->expectExceptionMessage((string)__('Please enter a valid number in this field.')); $product = $this->productFactory->create(); $product->setQuantityAndStockStatus(['qty' => 'string']); $this->model->validate($product); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/AuthorizationTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/AuthorizationTest.php index 9d388dfac3a9e..5d1fff9f62feb 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/AuthorizationTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/AuthorizationTest.php @@ -136,7 +136,7 @@ public function postRequestData(): array public function testAuthorizedSavingOfWithException(array $data): void { $this->expectException(AuthorizationException::class); - $this->expectErrorMessage('Not allowed to edit the product\'s design attributes'); + $this->expectExceptionMessage('Not allowed to edit the product\'s design attributes'); $this->request->setPost(new Parameters($data)); /** @var Product $product */ diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductWebsiteLinkRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductWebsiteLinkRepositoryTest.php index 9ae327036971b..f94b9c6db54a3 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductWebsiteLinkRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductWebsiteLinkRepositoryTest.php @@ -65,7 +65,7 @@ public function testSaveWithoutWebsiteId(): void $productWebsiteLink = $this->productWebsiteLinkFactory->create(); $productWebsiteLink->setSku('unique-simple-azaza'); $this->expectException(InputException::class); - $this->expectErrorMessage((string)__('There are not websites for assign to product')); + $this->expectExceptionMessage((string)__('There are not websites for assign to product')); $this->productWebsiteLinkRepository->save($productWebsiteLink); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/SuffixTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/SuffixTest.php index 9979e8cd6ea68..8c32cb192ad32 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/SuffixTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/SuffixTest.php @@ -32,6 +32,7 @@ * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class SuffixTest extends TestCase { @@ -83,7 +84,7 @@ protected function setUp(): void public function testSaveWithError(): void { $this->expectException(LocalizedException::class); - $this->expectErrorMessage((string)__('Anchor symbol (#) is not supported in url rewrite suffix.')); + $this->expectExceptionMessage((string)__('Anchor symbol (#) is not supported in url rewrite suffix.')); $this->model->setValue('.html#'); $this->model->beforeSave(); } diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 4b6fac496df0d..438ba1ed75e87 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -656,7 +656,7 @@ protected function getUsedProducts() */ public function testAddCustomOptionToConfigurableChildProduct(): void { - $this->expectErrorMessage( + $this->expectExceptionMessage( 'Required custom options cannot be added to a simple product that is a part of a composite product.' ); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php index beab52c142402..958f6da93e071 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/VariationHandlerTest.php @@ -109,6 +109,20 @@ public function testGenerateSimpleProductsWithPartialData(array $productsData): } } + /** + * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php + * @dataProvider generateSimpleProductsWithPartialDataDataProvider + * @param array $productsData + * @return void + */ + public function testGeneratedSimpleProductInheritTaxClassFromParent(array $productsData): void + { + $this->product->setTaxClassId(2); + $generatedProduct = $this->variationHandler->generateSimpleProducts($this->product, $productsData); + $product = $this->productRepository->getById(reset($generatedProduct)); + $this->assertEquals(2, $product->getTaxClassId()); + } + /** * @return array */ diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php index f671cf1e69b63..c9196a581f542 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php @@ -9,6 +9,7 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\AddressRepositoryInterface; use Magento\Customer\Api\Data\AddressInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\InputException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\State\ExpiredException; @@ -16,6 +17,7 @@ use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\Stdlib\DateTime; use Magento\Framework\Url as UrlBuilder; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; @@ -604,7 +606,18 @@ public function testResendConfirmationNotNeeded() */ public function testIsEmailAvailable() { - $this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com', 1)); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $guestLoginConfig = $scopeConfig->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + 1 + ); + + if (!$guestLoginConfig) { + $this->assertTrue($this->accountManagement->isEmailAvailable('customer@example.com', 1)); + } else { + $this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com', 1)); + } } /** @@ -612,7 +625,18 @@ public function testIsEmailAvailable() */ public function testIsEmailAvailableNoWebsiteSpecified() { - $this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com')); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $guestLoginConfig = $scopeConfig->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + 1 + ); + + if (!$guestLoginConfig) { + $this->assertTrue($this->accountManagement->isEmailAvailable('customer@example.com')); + } else { + $this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com')); + } } /** diff --git a/dev/tests/integration/testsuite/Magento/Framework/App/ResourceConnection/ConnectionFactoryTest.php b/dev/tests/integration/testsuite/Magento/Framework/App/ResourceConnection/ConnectionFactoryTest.php index 93ed3d84c8452..72ba459997c32 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/App/ResourceConnection/ConnectionFactoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/App/ResourceConnection/ConnectionFactoryTest.php @@ -36,7 +36,8 @@ public function testCreate() ]; $connection = $this->model->create($dbConfig); $this->assertInstanceOf(\Magento\Framework\DB\Adapter\AdapterInterface::class, $connection); - $this->assertClassHasAttribute('logger', get_class($connection)); + $this->assertIsObject($connection); + $this->assertTrue(property_exists($connection, 'logger')); $object = new ReflectionClass(get_class($connection)); $attribute = $object->getProperty('logger'); $attribute->setAccessible(true); diff --git a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/ObjectManagerTest.php b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/ObjectManagerTest.php index 9b5ea2f361ba9..03de1a5ac09ab 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/ObjectManagerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/ObjectManager/ObjectManagerTest.php @@ -12,25 +12,27 @@ class ObjectManagerTest extends \PHPUnit\Framework\TestCase /**#@+ * Test class with type error */ - const TEST_CLASS_WITH_TYPE_ERROR = \Magento\Framework\ObjectManager\TestAsset\ConstructorWithTypeError::class; + public const TEST_CLASS_WITH_TYPE_ERROR = + \Magento\Framework\ObjectManager\TestAsset\ConstructorWithTypeError::class; /**#@+ * Test classes for basic instantiation */ - const TEST_CLASS = \Magento\Framework\ObjectManager\TestAsset\Basic::class; + public const TEST_CLASS = \Magento\Framework\ObjectManager\TestAsset\Basic::class; - const TEST_CLASS_INJECTION = \Magento\Framework\ObjectManager\TestAsset\BasicInjection::class; + public const TEST_CLASS_INJECTION = \Magento\Framework\ObjectManager\TestAsset\BasicInjection::class; /**#@-*/ /**#@+ * Test classes and interface to test preferences */ - const TEST_INTERFACE = \Magento\Framework\ObjectManager\TestAsset\TestAssetInterface::class; + public const TEST_INTERFACE = \Magento\Framework\ObjectManager\TestAsset\TestAssetInterface::class; - const TEST_INTERFACE_IMPLEMENTATION = \Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation::class; + public const TEST_INTERFACE_IMPLEMENTATION = + \Magento\Framework\ObjectManager\TestAsset\InterfaceImplementation::class; - const TEST_CLASS_WITH_INTERFACE = \Magento\Framework\ObjectManager\TestAsset\InterfaceInjection::class; + public const TEST_CLASS_WITH_INTERFACE = \Magento\Framework\ObjectManager\TestAsset\InterfaceInjection::class; /**#@-*/ @@ -141,7 +143,8 @@ public function testNewInstance($actualClassName, array $properties = [], $expec $object = new ReflectionClass($actualClassName); if ($properties) { foreach ($properties as $propertyName => $propertyClass) { - $this->assertClassHasAttribute($propertyName, $actualClassName); + $this->assertIsObject($testObject); + $this->assertTrue(property_exists($testObject, $propertyName)); $attribute = $object->getProperty($propertyName); $attribute->setAccessible(true); $propertyObject = $attribute->getValue($testObject); diff --git a/dev/tests/integration/testsuite/Magento/Framework/ProfilerTest.php b/dev/tests/integration/testsuite/Magento/Framework/ProfilerTest.php index 4a6c542a110bf..df400561e2ffa 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/ProfilerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/ProfilerTest.php @@ -1,7 +1,5 @@ <?php /** - * Test case for \Magento\Framework\Profiler - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -25,7 +23,8 @@ public function testApplyConfigWithDrivers(array $config, array $expectedDrivers { $profiler = new \Magento\Framework\Profiler(); $profiler::applyConfig($config, ''); - $this->assertClassHasAttribute('_drivers', \Magento\Framework\Profiler::class); + $this->assertIsObject($profiler); + $this->assertTrue(property_exists($profiler, '_drivers')); $object = new ReflectionClass(\Magento\Framework\Profiler::class); $attribute = $object->getProperty('_drivers'); $attribute->setAccessible(true); diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/_files/state-skip-list.php b/dev/tests/integration/testsuite/Magento/GraphQl/_files/state-skip-list.php index 3225a27f41365..7033ed2436c6c 100644 --- a/dev/tests/integration/testsuite/Magento/GraphQl/_files/state-skip-list.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/_files/state-skip-list.php @@ -37,6 +37,7 @@ 'customRemoteFilesystem' => null, Magento\Store\App\Config\Type\Scopes::class => null, Magento\Framework\Module\Dir\Reader::class => null, + Magento\Framework\Module\PackageInfo::class => null, Magento\Framework\App\Language\Dictionary::class => null, Magento\Framework\ObjectManager\ConfigInterface::class => null, Magento\Framework\App\Cache\Type\Config::class => null, diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Model/ExportTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Model/ExportTest.php index 50972ef0325a6..73aa382baafb3 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Model/ExportTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Model/ExportTest.php @@ -35,7 +35,8 @@ public function testGetEntityAdapterWithValidEntity($entity, $expectedEntityType { $this->_model->setData(['entity' => $entity]); $this->_model->getEntityAttributeCollection(); - $this->assertClassHasAttribute('_entityAdapter', get_class($this->_model)); + $this->assertIsObject($this->_model); + $this->assertTrue(property_exists($this->_model, '_entityAdapter')); $object = new ReflectionClass(get_class($this->_model)); $attribute = $object->getProperty('_entityAdapter'); $attribute->setAccessible(true); diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Subscriber/NewActionTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Subscriber/NewActionTest.php index 63670e9cb458d..f0c5ce25911f4 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Subscriber/NewActionTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Controller/Subscriber/NewActionTest.php @@ -8,12 +8,15 @@ namespace Magento\Newsletter\Controller\Subscriber; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Newsletter\Model\ResourceModel\Subscriber as SubscriberResource; use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory; use Magento\Newsletter\Model\ResourceModel\Subscriber\Grid\Collection as GridCollection; +use Magento\Store\Model\ScopeInterface; use Magento\TestFramework\TestCase\AbstractController; use Laminas\Stdlib\Parameters; @@ -222,8 +225,18 @@ public function testWithEmailAssignedToAnotherCustomer(): void $this->session->loginById(1); $this->prepareRequest('customer2@search.example.com'); $this->dispatch('newsletter/subscriber/new'); + $scopeConfig = $this->_objectManager->get(ScopeConfigInterface::class); + $guestLoginConfig = $scopeConfig->getValue( + AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG, + ScopeInterface::SCOPE_WEBSITE, + 1 + ); - $this->performAsserts('This email address is already assigned to another user.'); + if ($guestLoginConfig) { + $this->performAsserts('This email address is already assigned to another user.'); + } else { + $this->performAsserts('This email address is already subscribed.'); + } } /** diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php index 719d78b07ca3c..34df1deb4ff35 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php @@ -6,8 +6,11 @@ namespace Magento\Newsletter\Model\Plugin; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Mail\Template\TransportBuilderMock; /** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * phpcs:disable Magento2.Security.Superglobal * @magentoAppIsolation enabled */ class PluginTest extends \PHPUnit\Framework\TestCase @@ -24,6 +27,11 @@ class PluginTest extends \PHPUnit\Framework\TestCase */ protected $customerRepository; + /** + * @var TransportBuilderMock + */ + protected $transportBuilderMock; + protected function setUp(): void { $this->accountManagement = Bootstrap::getObjectManager()->get( @@ -32,6 +40,9 @@ protected function setUp(): void $this->customerRepository = Bootstrap::getObjectManager()->get( \Magento\Customer\Api\CustomerRepositoryInterface::class ); + $this->transportBuilderMock = Bootstrap::getObjectManager()->get( + TransportBuilderMock::class + ); } protected function tearDown(): void @@ -223,4 +234,67 @@ public function testCustomerWithTwoNewsLetterSubscriptions() $extensionAttributes = $customer->getExtensionAttributes(); $this->assertTrue($extensionAttributes->getIsSubscribed()); } + + /** + * @magentoAppArea adminhtml + * @magentoDbIsolation enabled + * @magentoConfigFixture current_store newsletter/general/active 1 + * @magentoDataFixture Magento/Customer/_files/customer_welcome_email_template.php + * + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function testCreateAccountWithNewsLetterSubscription(): void + { + $objectManager = Bootstrap::getObjectManager(); + /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */ + $customerFactory = $objectManager->get(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class); + $customerDataObject = $customerFactory->create() + ->setFirstname('John') + ->setLastname('Doe') + ->setEmail('customer@example.com'); + $extensionAttributes = $customerDataObject->getExtensionAttributes(); + $extensionAttributes->setIsSubscribed(true); + $customerDataObject->setExtensionAttributes($extensionAttributes); + $this->accountManagement->createAccount($customerDataObject, '123123qW'); + $message = $this->transportBuilderMock->getSentMessage(); + + $this->assertNotNull($message); + $this->assertEquals('Welcome to Main Website Store', $message->getSubject()); + $this->assertStringContainsString( + 'John', + $message->getBody()->getParts()[0]->getRawContent() + ); + $this->assertStringContainsString( + 'customer@example.com', + $message->getBody()->getParts()[0]->getRawContent() + ); + + /** @var \Magento\Newsletter\Model\Subscriber $subscriber */ + $subscriber = $objectManager->create(\Magento\Newsletter\Model\Subscriber::class); + $subscriber->loadByEmail('customer@example.com'); + $this->assertTrue($subscriber->isSubscribed()); + + $this->transportBuilderMock->setTemplateIdentifier( + 'newsletter_subscription_confirm_email_template' + )->setTemplateVars([ + 'subscriber_data' => [ + 'confirmation_link' => $subscriber->getConfirmationLink(), + ], + ])->setTemplateOptions([ + 'area' => \Magento\Framework\App\Area::AREA_FRONTEND, + 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID + ]) + ->addTo('customer@example.com') + ->getTransport(); + + $message = $this->transportBuilderMock->getSentMessage(); + + $this->assertNotNull($message); + $this->assertStringContainsString( + $subscriber->getConfirmationLink(), + $message->getBody()->getParts()[0]->getRawContent() + ); + $this->assertEquals('Newsletter subscription confirmation', $message->getSubject()); + } } diff --git a/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php new file mode 100644 index 0000000000000..1c19a80e7f35f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Store/Model/MultiStoreTest.php @@ -0,0 +1,150 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Store\Model; + +use Magento\Customer\Test\Fixture\Customer; +use Magento\Framework\App\Area; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\ObjectManagerInterface; +use Magento\Newsletter\Model\Subscriber; +use Magento\Store\Test\Fixture\Group as StoreGroupFixture; +use Magento\Store\Test\Fixture\Store as StoreFixture; +use Magento\Store\Test\Fixture\Website as WebsiteFixture; +use Magento\TestFramework\Fixture\Config as ConfigFixture; +use Magento\TestFramework\Fixture\DataFixture; +use Magento\TestFramework\Fixture\DataFixtureStorage; +use Magento\TestFramework\Fixture\DataFixtureStorageManager; +use Magento\TestFramework\Fixture\DbIsolation; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Mail\Template\TransportBuilderMock; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * phpcs:disable Magento2.Security.Superglobal + */ +class MultiStoreTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var DataFixtureStorage + */ + private $fixtures; + + /** + * @inheridoc + * @throws LocalizedException + */ + protected function setUp(): void + { + parent::setUp(); + + $this->objectManager = Bootstrap::getObjectManager(); + $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage(); + } + + /** + * @return void + * @throws LocalizedException + * @throws \Magento\Framework\Exception\MailException + */ + #[ + DbIsolation(false), + ConfigFixture('system/smtp/transport', 'smtp', 'store'), + DataFixture(WebsiteFixture::class, as: 'website2'), + DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'store_group2'), + DataFixture(StoreFixture::class, ['store_group_id' => '$store_group2.id$'], 'store2'), + DataFixture( + Customer::class, + [ + 'store_id' => '$store2.id$', + 'website_id' => '$website2.id$', + 'addresses' => [[]] + ], + as: 'customer1' + ), + DataFixture(WebsiteFixture::class, as: 'website3'), + DataFixture(StoreGroupFixture::class, ['website_id' => '$website3.id$'], 'store_group3'), + DataFixture(StoreFixture::class, ['store_group_id' => '$store_group3.id$'], 'store3'), + DataFixture( + Customer::class, + [ + 'store_id' => '$store3.id$', + 'website_id' => '$website3.id$', + 'addresses' => [[]] + ], + as: 'customer2' + ), + ] + public function testStoreSpecificEmailInFromHeader() :void + { + $customerOne = $this->fixtures->get('customer1'); + $storeOne = $this->fixtures->get('store2'); + $customerOneData = [ + 'email' => $customerOne->getDataByKey('email'), + 'storeId' => $storeOne->getData('store_id'), + 'storeEmail' => 'store_one@example.com' + ]; + + $this->subscribeNewsLetterAndAssertFromHeader($customerOneData); + + $customerTwo = $this->fixtures->get('customer2'); + $storeTwo = $this->fixtures->get('store3'); + $customerTwoData = [ + 'email' => $customerTwo->getDataByKey('email'), + 'storeId' => $storeTwo->getData('store_id'), + 'storeEmail' => 'store_two@example.com' + ]; + + $this->subscribeNewsLetterAndAssertFromHeader($customerTwoData); + } + + /** + * @param $customerData + * @return void + * @throws LocalizedException + * @throws \Magento\Framework\Exception\MailException + */ + private function subscribeNewsLetterAndAssertFromHeader( + $customerData + ) :void { + /** @var Subscriber $subscriber */ + $subscriber = $this->objectManager->create(Subscriber::class); + $subscriber->subscribe($customerData['email']); + + /** @var TransportBuilderMock $transportBuilderMock */ + $transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class); + $transportBuilderMock->setTemplateIdentifier( + 'customer_password_reset_password_template' + )->setTemplateVars([ + 'subscriber_data' => [ + 'confirmation_link' => $subscriber->getConfirmationLink(), + ], + ])->setTemplateOptions([ + 'area' => Area::AREA_FRONTEND, + 'store' => (int) $customerData['storeId'] + ]) + ->setFromByScope( + [ + 'email' => $customerData['storeEmail'], + 'name' => 'Store Email Name' + ], + (int) $customerData['storeId'] + ) + ->addTo($customerData['email']) + ->getTransport(); + + $headers = $transportBuilderMock->getSentMessage()->getHeaders(); + + $this->assertNotNull($transportBuilderMock->getSentMessage()); + $this->assertStringContainsString($customerData['storeEmail'], $headers['From']); + } +} diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php index c1b19ca77beb4..f5d4dd5638d28 100644 --- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php +++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserResetPasswordEmailTest.php @@ -7,21 +7,28 @@ namespace Magento\User\Controller\Adminhtml; +use Magento\Framework\App\Area; +use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Mail\EmailMessage; +use Magento\Framework\Message\MessageInterface; use Magento\Store\Model\Store; use Magento\TestFramework\Fixture\Config as Config; use Magento\TestFramework\Fixture\DataFixture; use Magento\TestFramework\Fixture\DataFixtureStorage; use Magento\TestFramework\Fixture\DataFixtureStorageManager; +use Magento\TestFramework\Fixture\DbIsolation; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Mail\Template\TransportBuilderMock; use Magento\TestFramework\TestCase\AbstractBackendController; use Magento\User\Model\User as UserModel; +use Magento\User\Model\UserFactory; use Magento\User\Test\Fixture\User as UserDataFixture; /** * Test class for user reset password email * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @magentoAppArea adminhtml */ class UserResetPasswordEmailTest extends AbstractBackendController @@ -36,6 +43,26 @@ class UserResetPasswordEmailTest extends AbstractBackendController */ protected $userModel; + /** + * @var UserFactory + */ + private $userFactory; + + /** + * @var \Magento\Framework\Mail\MessageInterfaceFactory + */ + private $messageFactory; + + /** + * @var \Magento\Framework\Mail\TransportInterfaceFactory + */ + private $transportFactory; + + /** + * @var WriterInterface + */ + private $configWriter; + /** * @throws LocalizedException */ @@ -44,6 +71,10 @@ protected function setUp(): void parent::setUp(); $this->fixtures = DataFixtureStorageManager::getStorage(); $this->userModel = $this->_objectManager->create(UserModel::class); + $this->messageFactory = $this->_objectManager->get(\Magento\Framework\Mail\MessageInterfaceFactory::class); + $this->transportFactory = $this->_objectManager->get(\Magento\Framework\Mail\TransportInterfaceFactory::class); + $this->userFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(UserFactory::class); + $this->configWriter = $this->_objectManager->get(WriterInterface::class); } #[ @@ -74,4 +105,121 @@ private function getResetPasswordUri(EmailMessage $message): string $urlString = trim($match[0][0], $store->getBaseUrl('web')); return substr($urlString, 0, strpos($urlString, "/key")); } + + /** + * Test admin email notification after password change + * + * @throws LocalizedException + * @return void + */ + #[ + DataFixture(UserDataFixture::class, ['role_id' => 1], 'user') + ] + public function testAdminEmailNotificationAfterPasswordChange(): void + { + // Load admin user + $user = $this->fixtures->get('user'); + $username = $user->getDataByKey('username'); + $adminEmail = $user->getDataByKey('email'); + + // login with old credentials + $adminUser = $this->userFactory->create(); + $adminUser->login($username, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); + + // Change password + $adminUser->setPassword('newPassword123'); + $adminUser->save(); + + /** @var TransportBuilderMock $transportBuilderMock */ + $transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class); + $transportBuilderMock->setTemplateIdentifier( + 'customer_password_reset_password_template' + )->setTemplateVars([ + 'customer' => [ + 'name' => $user->getDataByKey('firstname') . ' ' . $user->getDataByKey('lastname') + ] + ])->setTemplateOptions([ + 'area' => Area::AREA_FRONTEND, + 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID + ]) + ->addTo($adminEmail) + ->getTransport(); + + $message = $transportBuilderMock->getSentMessage(); + + // Verify an email was dispatched to the correct user + $this->assertNotNull($transportBuilderMock->getSentMessage()); + $this->assertEquals($adminEmail, $message->getTo()[0]->getEmail()); + } + + /** + * @return void + * @throws LocalizedException + */ + #[ + DbIsolation(false), + Config( + 'admin/security/min_time_between_password_reset_requests', + '0', + 'store' + ), + DataFixture(UserDataFixture::class, ['role_id' => 1], 'user') + ] + public function testEnablePasswordChangeFrequencyLimit(): void + { + // Load admin user + $user = $this->fixtures->get('user'); + $username = $user->getDataByKey('username'); + $adminEmail = $user->getDataByKey('email'); + + // login admin + $adminUser = $this->userFactory->create(); + $adminUser->login($username, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); + + // Resetting password multiple times + for ($i = 0; $i < 5; $i++) { + $this->getRequest()->setPostValue('email', $adminEmail); + $this->dispatch('backend/admin/auth/forgotpassword'); + } + + /** @var TransportBuilderMock $transportMock */ + $transportMock = Bootstrap::getObjectManager()->get( + TransportBuilderMock::class + ); + $sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent(); + + $this->assertStringContainsString( + 'There was recently a request to change the password for your account', + $sendMessage + ); + + // Setting the limit to greater than 0 + $this->configWriter->save('admin/security/min_time_between_password_reset_requests', 2); + + // Resetting password multiple times + for ($i = 0; $i < 5; $i++) { + $this->getRequest()->setPostValue('email', $adminEmail); + $this->dispatch('backend/admin/auth/forgotpassword'); + } + + $this->assertSessionMessages( + $this->equalTo( + ['We received too many requests for password resets.' + . ' Please wait and try again later or contact hello@example.com.'] + ), + MessageInterface::TYPE_ERROR + ); + + // Wait for 2 minutes before resetting password + sleep(120); + + $this->getRequest()->setPostValue('email', $adminEmail); + $this->dispatch('backend/admin/auth/forgotpassword'); + + $sendMessage = $transportMock->getSentMessage()->getBody()->getParts()[0]->getRawContent(); + $this->assertStringContainsString( + 'There was recently a request to change the password for your account', + $sendMessage + ); + } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ObserverImplementationTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ObserverImplementationTest.php index 360483b69eaef..45852174d4e35 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ObserverImplementationTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ObserverImplementationTest.php @@ -57,13 +57,19 @@ public function testObserverHasNoExtraPublicMethods() $errors = []; foreach (self::$observerClasses as $observerClass) { $reflection = (new \ReflectionClass($observerClass)); + $publicMethodsCount = 0; $maxCountMethod = $reflection->getConstructor() ? 2 : 1; + $publicMethods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC); + foreach ($publicMethods as $publicMethod) { + if (!str_starts_with($publicMethod->getName(), '_')) { + $publicMethodsCount++; + } + } - if (count($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) > $maxCountMethod) { + if ($publicMethodsCount > $maxCountMethod) { $errors[] = $observerClass; } } - $errors = array_diff($errors, [GetPriceConfigurationObserver::class]); if ($errors) { $errors = array_unique($errors); diff --git a/lib/internal/Magento/Framework/Api/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Api/SearchCriteriaBuilder.php index 1ec40a7d39b6b..e5cf9d7c54886 100644 --- a/lib/internal/Magento/Framework/Api/SearchCriteriaBuilder.php +++ b/lib/internal/Magento/Framework/Api/SearchCriteriaBuilder.php @@ -9,14 +9,13 @@ namespace Magento\Framework\Api; use Magento\Framework\Api\Search\FilterGroupBuilder; -use Magento\Framework\ObjectManager\ResetAfterRequestInterface; /** * Builder for SearchCriteria Service Data Object * * @api */ -class SearchCriteriaBuilder extends AbstractSimpleObjectBuilder implements ResetAfterRequestInterface +class SearchCriteriaBuilder extends AbstractSimpleObjectBuilder { /** * @var FilterGroupBuilder @@ -148,12 +147,4 @@ public function setCurrentPage($currentPage) { return $this->_set(SearchCriteria::CURRENT_PAGE, $currentPage); } - - /** - * @inheritDoc - */ - public function _resetState(): void - { - $this->data = []; - } } diff --git a/lib/internal/Magento/Framework/App/Area.php b/lib/internal/Magento/Framework/App/Area.php index dcda864197f88..58a690a230b59 100644 --- a/lib/internal/Magento/Framework/App/Area.php +++ b/lib/internal/Magento/Framework/App/Area.php @@ -9,7 +9,6 @@ namespace Magento\Framework\App; use Magento\Framework\ObjectManager\ConfigLoaderInterface; -use Magento\Framework\ObjectManager\ResetAfterRequestInterface; /** * Application area model @@ -17,7 +16,7 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @api */ -class Area implements \Magento\Framework\App\AreaInterface, ResetAfterRequestInterface +class Area implements \Magento\Framework\App\AreaInterface { public const AREA_GLOBAL = 'global'; public const AREA_FRONTEND = 'frontend'; @@ -261,12 +260,4 @@ protected function _initDesign() $this->_getDesign()->setArea($this->_code)->setDefaultDesignTheme(); return $this; } - - /** - * @inheritDoc - */ - public function _resetState(): void - { - $this->_loadedParts = []; - } } diff --git a/lib/internal/Magento/Framework/App/AreaList.php b/lib/internal/Magento/Framework/App/AreaList.php index 8c3cc1d551916..c69bf42bdc06a 100644 --- a/lib/internal/Magento/Framework/App/AreaList.php +++ b/lib/internal/Magento/Framework/App/AreaList.php @@ -5,12 +5,14 @@ */ namespace Magento\Framework\App; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; + /** * Lists router area codes & processes resolves FrontEndNames to area codes * * @api */ -class AreaList +class AreaList implements ResetAfterRequestInterface { /** * @var array @@ -127,4 +129,12 @@ public function getArea($code) } return $this->_areaInstances[$code]; } + + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->_areaInstances = []; + } } diff --git a/lib/internal/Magento/Framework/App/Config.php b/lib/internal/Magento/Framework/App/Config.php index e5d5101d8f96a..32a1cd4948d66 100644 --- a/lib/internal/Magento/Framework/App/Config.php +++ b/lib/internal/Magento/Framework/App/Config.php @@ -1,5 +1,6 @@ <?php /** + * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ @@ -125,7 +126,6 @@ public function clean() */ public function get($configType, $path = '', $default = null) { - $path = strtolower($path); $result = null; if (isset($this->types[$configType])) { $result = $this->types[$configType]->get($path); diff --git a/lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php b/lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php index fced047ed42d0..681af35944695 100644 --- a/lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php +++ b/lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php @@ -59,10 +59,9 @@ public function resolve($scopeType, $scopeCode) $scopeCode = $resolverScopeCode; } - $this->resolvedScopeCodes[$scopeType][$scopeCode] = - is_null($resolverScopeCode) ? null : strtolower($resolverScopeCode); + $this->resolvedScopeCodes[$scopeType][$scopeCode] = $resolverScopeCode; - return $this->resolvedScopeCodes[$scopeType][$scopeCode]; + return $resolverScopeCode; } /** diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index ce8bb38795b5c..a14354b4fdb9a 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -51,6 +51,16 @@ class DeploymentConfig */ private $overrideData; + /** + * @var array + */ + private $envOverrides = []; + + /** + * @var array + */ + private $readerLoad = []; + /** * Constructor * @@ -84,7 +94,9 @@ public function get($key = null, $defaultValue = null) } $result = $this->getByKey($key); if ($result === null) { - $this->reloadData(); + if (empty($this->flatData) || count($this->getAllEnvOverrides())) { + $this->reloadData(); + } $result = $this->getByKey($key); } return $result ?? $defaultValue; @@ -114,13 +126,13 @@ public function getConfigData($key = null) { if ($key === null) { if (empty($this->data)) { - $this->reloadData(); + $this->reloadInitialData(); } return $this->data; } $result = $this->getConfigDataByKey($key); if ($result === null) { - $this->reloadData(); + $this->reloadInitialData(); $result = $this->getConfigDataByKey($key); } return $result; @@ -170,28 +182,55 @@ private function getEnvOverride() : array * @throws FileSystemException * @throws RuntimeException */ - private function reloadData(): void + private function reloadInitialData(): void { + if (empty($this->readerLoad) || empty($this->data) || empty($this->flatData)) { + $this->readerLoad = $this->reader->load(); + } $this->data = array_replace( - $this->reader->load(), + $this->readerLoad, $this->overrideData ?? [], $this->getEnvOverride() ); + } + + /** + * Loads the configuration data + * + * @return void + * @throws FileSystemException + * @throws RuntimeException + */ + private function reloadData(): void + { + $this->reloadInitialData(); // flatten data for config retrieval using get() $this->flatData = $this->flattenParams($this->data); + $this->flatData = $this->getAllEnvOverrides() + $this->flatData; + } - // allow reading values from env variables by convention - // MAGENTO_DC_{path}, like db/connection/default/host => - // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST - foreach (getenv() as $key => $value) { - if (false !== \strpos($key, self::MAGENTO_ENV_PREFIX) - && $key !== self::OVERRIDE_KEY - ) { - // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host - $flatKey = strtolower(str_replace([self::MAGENTO_ENV_PREFIX, '__'], ['', '/'], $key)); - $this->flatData[$flatKey] = $value; + /** + * Load all getenv() configs once + * + * @return array + */ + private function getAllEnvOverrides(): array + { + if (empty($this->envOverrides)) { + // allow reading values from env variables by convention + // MAGENTO_DC_{path}, like db/connection/default/host => + // can be overwritten by MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST + foreach (getenv() as $key => $value) { + if (false !== \strpos($key, self::MAGENTO_ENV_PREFIX) + && $key !== self::OVERRIDE_KEY + ) { + // convert MAGENTO_DC_DB__CONNECTION__DEFAULT__HOST into db/connection/default/host + $flatKey = strtolower(str_replace([self::MAGENTO_ENV_PREFIX, '__'], ['', '/'], $key)); + $this->envOverrides[$flatKey] = $value; + } } } + return $this->envOverrides; } /** diff --git a/lib/internal/Magento/Framework/App/Http/Context.php b/lib/internal/Magento/Framework/App/Http/Context.php index aedc50bccc475..6c4648be087ff 100644 --- a/lib/internal/Magento/Framework/App/Http/Context.php +++ b/lib/internal/Magento/Framework/App/Http/Context.php @@ -142,5 +142,6 @@ public function toArray() public function _resetState(): void { $this->data = []; + $this->default = []; } } diff --git a/lib/internal/Magento/Framework/App/PageCache/Kernel.php b/lib/internal/Magento/Framework/App/PageCache/Kernel.php index 47b9798e47ec6..bcf4b36666e9e 100644 --- a/lib/internal/Magento/Framework/App/PageCache/Kernel.php +++ b/lib/internal/Magento/Framework/App/PageCache/Kernel.php @@ -10,6 +10,8 @@ /** * Builtin cache processor + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Kernel { @@ -140,6 +142,7 @@ public function process(\Magento\Framework\App\Response\Http $response) $maxAge = $matches[1]; $response->setNoCacheHeaders(); if (($response->getHttpResponseCode() == 200 || $response->getHttpResponseCode() == 404) + && !$response instanceof NotCacheableInterface && ($this->request->isGet() || $this->request->isHead()) ) { $tagsHeader = $response->getHeader('X-Magento-Tags'); diff --git a/lib/internal/Magento/Framework/App/Request/Http.php b/lib/internal/Magento/Framework/App/Request/Http.php index 4ecc40f0e3ceb..2535b499f8a6f 100644 --- a/lib/internal/Magento/Framework/App/Request/Http.php +++ b/lib/internal/Magento/Framework/App/Request/Http.php @@ -458,5 +458,6 @@ public function _resetState(): void $this->headers = null; $this->metadata = []; $this->content = ''; + $this->distroBaseUrl = null; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Config/ScopeCodeResolverTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Config/ScopeCodeResolverTest.php index 6da8ed2f039da..592ae69419723 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Config/ScopeCodeResolverTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Config/ScopeCodeResolverTest.php @@ -67,6 +67,6 @@ public function testResolve() $this->scope->expects($this->once()) ->method('getCode') ->willReturn($scopeCode); - $this->assertEquals(strtolower($scopeCode), $this->scopeCodeResolver->resolve($scopeType, $scopeId)); + $this->assertEquals($scopeCode, $this->scopeCodeResolver->resolve($scopeType, $scopeId)); } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ConfigTest.php index 73e171fdc4859..90d3aadcc84b3 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ConfigTest.php @@ -71,7 +71,7 @@ public function testGetValue($scope, $scopeCode = null) } $this->configType->expects($this->once()) ->method('get') - ->with($scope =='store' ? 'stores/path' : 'websites/mywebsite/path') + ->with($scope =='store' ? 'stores/path' : 'websites/myWebsite/path') ->willReturn(true); $this->assertTrue($this->appConfig->getValue($path, $scope, $scopeCode ?: $this->scope)); @@ -84,7 +84,7 @@ public function getValueDataProvider() { return [ ['store', 1], - ['website'] + ['website'], ]; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php index 42b4d7866c23b..78e9d27c7ab21 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php @@ -50,6 +50,14 @@ class DeploymentConfigTest extends TestCase 'test_override' => 'overridden', ]; + /** + * @var array + */ + private static $flattenedFixtureSecond + = [ + 'test_override' => 'overridden2' + ]; + /** * @var array */ @@ -112,6 +120,25 @@ public function testGetters(): void $this->assertSame('overridden', $this->deploymentConfig->get('test_override')); } + /** + * @return void + * @throws FileSystemException + * @throws RuntimeException + */ + public function testGettersReloadConfig(): void + { + $this->readerMock->expects($this->any())->method('load')->willReturn(self::$flattenedFixtureSecond); + $this->deploymentConfig = new DeploymentConfig( + $this->readerMock, + ['test_override' => 'overridden2'] + ); + $this->assertNull($this->deploymentConfig->get('invalid_key')); + $this->assertNull($this->deploymentConfig->getConfigData('invalid_key')); + putenv('MAGENTO_DC_A=abc'); + $this->assertSame('abc', $this->deploymentConfig->get('a')); + $this->assertSame('overridden2', $this->deploymentConfig->get('test_override')); + } + /** * @return void * @throws FileSystemException @@ -149,7 +176,7 @@ public function testNotAvailable(): void */ public function testNotAvailableThenAvailable(): void { - $this->readerMock->expects($this->exactly(2))->method('load')->willReturn(['Test']); + $this->readerMock->expects($this->exactly(1))->method('load')->willReturn(['Test']); $object = new DeploymentConfig($this->readerMock); $this->assertFalse($object->isAvailable()); $this->assertFalse($object->isAvailable()); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php b/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php index 164286728f3b7..ea6b4cbf9b199 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/PageCache/KernelTest.php @@ -14,6 +14,7 @@ use Magento\Framework\App\PageCache\Cache; use Magento\Framework\App\PageCache\Identifier; use Magento\Framework\App\PageCache\Kernel; +use Magento\Framework\App\PageCache\NotCacheableInterface; use Magento\Framework\App\Request\Http; use Magento\Framework\App\Response\HttpFactory; use Magento\Framework\Serialize\SerializerInterface; @@ -328,4 +329,28 @@ public function processNotSaveCacheProvider(): array ['public, max-age=100, s-maxage=100', 200, false, true] ]; } + + public function testProcessNotSaveCacheForNotCacheableResponse(): void + { + $header = CacheControl::fromString("Cache-Control: public, max-age=100, s-maxage=100"); + $notCacheableResponse = $this->getMockBuilder(\Magento\Framework\App\Response\File::class) + ->disableOriginalConstructor() + ->getMock(); + + $notCacheableResponse->expects($this->once()) + ->method('getHeader') + ->with('Cache-Control') + ->willReturn($header); + $notCacheableResponse->expects($this->any()) + ->method('getHttpResponseCode') + ->willReturn(200); + $notCacheableResponse->expects($this->once()) + ->method('setNoCacheHeaders'); + $this->requestMock + ->expects($this->any())->method('isGet') + ->willReturn(true); + $this->fullPageCacheMock->expects($this->never()) + ->method('save'); + $this->kernel->process($notCacheableResponse); + } } diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index 8bda62709897b..9432a9db9db4f 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -933,5 +933,12 @@ public function __wakeup() public function _resetState(): void { $this->clear(); + // TODO: Is it safe to move the following into clear() ? + $this->_orders = []; + $this->_filters = []; + $this->_isFiltersRendered = false; + $this->_curPage = 1; + $this->_pageSize = false; + $this->_flags = []; } } diff --git a/lib/internal/Magento/Framework/Data/Collection/AbstractDb.php b/lib/internal/Magento/Framework/Data/Collection/AbstractDb.php index b829f063ac2de..b6e53bdfde555 100644 --- a/lib/internal/Magento/Framework/Data/Collection/AbstractDb.php +++ b/lib/internal/Magento/Framework/Data/Collection/AbstractDb.php @@ -19,6 +19,7 @@ * phpcs:disable Magento2.Classes.AbstractApi * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @since 100.0.2 */ abstract class AbstractDb extends \Magento\Framework\Data\Collection @@ -119,6 +120,22 @@ public function __construct( $this->_logger = $logger; } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->setConnection($this->_conn); + // Note: not resetting _idFieldName because some subclasses define it class property + $this->_bindParams = []; + $this->_data = null; + // Note: not resetting _map because some subclasses define it class property but not _construct method. + $this->_fetchStmt = null; + $this->_isOrdersRendered = false; + $this->extensionAttributesJoinProcessor = null; + } + /** * Get resource instance. * diff --git a/lib/internal/Magento/Framework/HTTP/LaminasClient.php b/lib/internal/Magento/Framework/HTTP/LaminasClient.php index 10bb4dd18c5ce..082b0b1ceb89b 100644 --- a/lib/internal/Magento/Framework/HTTP/LaminasClient.php +++ b/lib/internal/Magento/Framework/HTTP/LaminasClient.php @@ -12,9 +12,10 @@ use Laminas\Http\Client; use Magento\Framework\HTTP\Adapter\Curl; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Traversable; -class LaminasClient extends Client +class LaminasClient extends Client implements ResetAfterRequestInterface { /** * Internal flag to allow decoding of request body @@ -37,6 +38,14 @@ public function __construct($uri = null, $options = null) parent::__construct($uri, $options); } + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->reset(); + } + /** * Change value of internal flag to disable/enable custom prepare functionality * diff --git a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php index f04bea1030ade..1d0417ad23aca 100644 --- a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php +++ b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php @@ -92,7 +92,7 @@ protected function _getClassMethods() protected function isInterceptedMethod(\ReflectionMethod $method) { return !($method->isConstructor() || $method->isFinal() || $method->isStatic() || $method->isDestructor()) && - !in_array($method->getName(), ['__sleep', '__wakeup', '__clone']); + !in_array($method->getName(), ['__sleep', '__wakeup', '__clone', '_resetState']); } /** diff --git a/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php b/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php index 5fcfaa6fb635c..c5ea050fc60c7 100644 --- a/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractExtensibleModel.php @@ -127,7 +127,7 @@ protected function filterCustomAttributes($data) if (isset($data[self::CUSTOM_ATTRIBUTES][0])) { $data[self::CUSTOM_ATTRIBUTES] = $this->flattenCustomAttributesArrayToMap($data[self::CUSTOM_ATTRIBUTES]); } - $customAttributesCodes = $this->getCustomAttributesCodes(); + $customAttributesCodes = $this->getCustomAttributesCodes(); $data[self::CUSTOM_ATTRIBUTES] = array_intersect_key( (array) $data[self::CUSTOM_ATTRIBUTES], array_flip($customAttributesCodes) diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php b/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php index 4b8c651dfaa1c..4e335e62d8f1a 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php @@ -145,6 +145,27 @@ protected function _construct() //phpcs:ignore Magento2.CodeAnalysis.EmptyBlock { } + /** + * @inheritDoc + */ + public function _resetState(): void + { + parent::_resetState(); + $this->_model = null; + $this->_resourceModel = null; + $this->_fieldsToSelect = null; + $this->expressionFieldsToSelect = []; + $this->_initialFieldsToSelect = null; + $this->_fieldsToSelectChanged = false; + $this->_joinedTables = []; + $this->_mainTable = null; + $this->_resetItemsDataChanged = false; + $this->_eventPrefix = ''; + $this->_eventObject = ''; + $this->_construct(); + $this->_initSelect(); + } + /** * Retrieve main table * diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index 757411465304a..b458b60b9caba 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -140,8 +140,11 @@ public function isModuleInfoAvailable() */ private function loadConfigData() { - if (null === $this->configData && null !== $this->config->get(ConfigOptionsListConstants::KEY_MODULES)) { - $this->configData = $this->config->get(ConfigOptionsListConstants::KEY_MODULES); + if (null === $this->configData) { + $config = $this->config->get(ConfigOptionsListConstants::KEY_MODULES); + if (null !== $config) { + $this->configData = $config; + } } } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php index 07d35c77026eb..c532af8580ca6 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php @@ -129,7 +129,7 @@ public function testIsModuleInfoAvailableNoConfig(): void { $this->config ->method('get') - ->willReturnOnConsecutiveCalls(['modules' => 'testModule'], null); + ->willReturnOnConsecutiveCalls(null); $this->assertFalse($this->model->isModuleInfoAvailable()); } @@ -144,7 +144,7 @@ public function testIsModuleInfoAvailableNoConfig(): void private function setLoadConfigExpectation($isExpected = true): void { if ($isExpected) { - $this->config->expects($this->exactly(2))->method('get')->willReturn(self::$enabledFixture); + $this->config->expects($this->once())->method('get')->willReturn(self::$enabledFixture); } else { $this->config->expects($this->never())->method('get'); } diff --git a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php index 2ed3859de4012..8bb78ba303e94 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php +++ b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php @@ -135,11 +135,21 @@ protected function _getClassMethods() ) && !in_array( $method->getName(), - ['__sleep', '__wakeup', '__clone', '__debugInfo'] + ['__sleep', '__wakeup', '__clone', '__debugInfo', '_resetState'] ) ) { $methods[] = $this->_getMethodInfo($method); } + if ($method->getName() === '_resetState') { + $methods[] = [ + 'name' => '_resetState', + 'returnType' => 'void', + 'body' => "if (\$this->_subject) {\n" . + " \$this->_subject->_resetState(); \n" . + "}\n", + 'docblock' => ['shortDescription' => 'Reset state of proxied instance'], + ]; + } } return $methods; diff --git a/lib/internal/Magento/Framework/RegexValidator.php b/lib/internal/Magento/Framework/RegexValidator.php new file mode 100644 index 0000000000000..77274f0f52247 --- /dev/null +++ b/lib/internal/Magento/Framework/RegexValidator.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Framework; + +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Validator\RegexFactory; + +class RegexValidator extends RegexFactory +{ + + /** + * @var RegexFactory + */ + private RegexFactory $regexValidatorFactory; + + /** + * Validation pattern for handles array + */ + private const VALIDATION_RULE_PATTERN = '/^[a-z0-9,.]+[a-z0-9_,.]*$/i'; + + /** + * @param RegexFactory|null $regexValidatorFactory + */ + public function __construct( + ?RegexFactory $regexValidatorFactory = null + ) { + $this->regexValidatorFactory = $regexValidatorFactory + ?: ObjectManager::getInstance()->get(RegexFactory::class); + } + + /** + * Validates parameter regex + * + * @param string $params + * @param string $pattern + * @return bool + */ + public function validateParamRegex(string $params, string $pattern = self::VALIDATION_RULE_PATTERN): bool + { + $validator = $this->regexValidatorFactory->create(['pattern' => $pattern]); + + if ($params && !$validator->isValid($params)) { + return false; + } + + return true; + } +} diff --git a/lib/internal/Magento/Framework/Session/SessionManager.php b/lib/internal/Magento/Framework/Session/SessionManager.php index 6c008995bfe3f..f79f0900c2c28 100644 --- a/lib/internal/Magento/Framework/Session/SessionManager.php +++ b/lib/internal/Magento/Framework/Session/SessionManager.php @@ -638,6 +638,13 @@ private function initIniOptions() */ public function _resetState(): void { - session_write_close(); + if (session_status() === PHP_SESSION_ACTIVE) { + session_write_close(); + session_id(''); + } + session_name('PHPSESSID'); + session_unset(); + static::$urlHostCache = []; + $_SESSION = []; } } diff --git a/lib/internal/Magento/Framework/Translate.php b/lib/internal/Magento/Framework/Translate.php index 3b8069c8ef2f1..7dc7622c2eed2 100644 --- a/lib/internal/Magento/Framework/Translate.php +++ b/lib/internal/Magento/Framework/Translate.php @@ -609,5 +609,6 @@ public function _resetState(): void { $this->_config = []; $this->_data = []; + $this->_localeCode = null; } } diff --git a/lib/internal/Magento/Framework/Validator/AbstractValidator.php b/lib/internal/Magento/Framework/Validator/AbstractValidator.php index c90092f64d95c..7b5c895685a3f 100644 --- a/lib/internal/Magento/Framework/Validator/AbstractValidator.php +++ b/lib/internal/Magento/Framework/Validator/AbstractValidator.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Validator; use Laminas\Validator\Translator\TranslatorInterface; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; /** * Abstract validator class. @@ -14,7 +15,7 @@ * @api * @since 100.0.2 */ -abstract class AbstractValidator implements ValidatorInterface +abstract class AbstractValidator implements ValidatorInterface, ResetAfterRequestInterface { /** * @var TranslatorInterface|null @@ -31,6 +32,15 @@ abstract class AbstractValidator implements ValidatorInterface */ protected $_messages = []; + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->_translator = null; + $this->_messages = []; + } + /** * Set default translator instance * diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index 7c02dc0675206..e40f6f64e463b 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -7,7 +7,10 @@ namespace Magento\Framework\View\Element; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Cache\LockGuardedCacheLoader; +use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\DataObject\IdentityInterface; /** @@ -51,6 +54,7 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl /** * @var \Magento\Framework\Session\SidResolverInterface * @deprecated 102.0.5 Not used anymore. + * @see Session Id's In URL */ protected $_sidResolver; @@ -166,6 +170,11 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl */ protected $_cache; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * @var LockGuardedCacheLoader */ @@ -199,6 +208,7 @@ public function __construct( $this->_localeDate = $context->getLocaleDate(); $this->inlineTranslation = $context->getInlineTranslation(); $this->lockQuery = $context->getLockGuardedCacheLoader(); + if (isset($data['jsLayout'])) { $this->jsLayout = $data['jsLayout']; unset($data['jsLayout']); @@ -880,6 +890,7 @@ public static function extractModuleName($className) * @param array|null $allowedTags * @return string * @deprecated 103.0.0 Use $escaper directly in templates and in blocks. + * @see Escaper Usage */ public function escapeHtml($data, $allowedTags = null) { @@ -893,6 +904,7 @@ public function escapeHtml($data, $allowedTags = null) * @return string * @since 101.0.0 * @deprecated 103.0.0 Use $escaper directly in templates and in blocks. + * @see Escaper Usage */ public function escapeJs($string) { @@ -907,6 +919,7 @@ public function escapeJs($string) * @return string * @since 101.0.0 * @deprecated 103.0.0 Use $escaper directly in templates and in blocks. + * @see Escaper Usage */ public function escapeHtmlAttr($string, $escapeSingleQuote = true) { @@ -920,6 +933,7 @@ public function escapeHtmlAttr($string, $escapeSingleQuote = true) * @return string * @since 101.0.0 * @deprecated 103.0.0 Use $escaper directly in templates and in blocks. + * @see Escaper Usage */ public function escapeCss($string) { @@ -947,6 +961,7 @@ public function stripTags($data, $allowableTags = null, $allowHtmlEntities = fal * @param string $string * @return string * @deprecated 103.0.0 Use $escaper directly in templates and in blocks. + * @see Escaper Usage */ public function escapeUrl($string) { @@ -959,6 +974,7 @@ public function escapeUrl($string) * @param string $data * @return string * @deprecated 101.0.0 + * @see Escaper Usage */ public function escapeXssInUrl($data) { @@ -974,6 +990,7 @@ public function escapeXssInUrl($data) * @param bool $addSlashes * @return string * @deprecated 101.0.0 + * @see Escaper Usage */ public function escapeQuote($data, $addSlashes = false) { @@ -988,6 +1005,7 @@ public function escapeQuote($data, $addSlashes = false) * * @return string|array * @deprecated 101.0.0 + * @see Escaper Usage */ public function escapeJsQuote($data, $quote = '\'') { @@ -1035,8 +1053,12 @@ public function getCacheKey() $key = array_values($key); // ignore array keys + $key[] = (string)$this->getDeploymentConfig()->get( + ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY + ); + $key = implode('|', $key); - $key = sha1($key); // use hashing to hide potentially private data + $key = hash('sha256', $key); // use hashing to hide potentially private data return static::CACHE_KEY_PREFIX . $key; } @@ -1175,10 +1197,25 @@ public function getVar($name, $module = null) * * @return bool * @deprecated + * @see https://developer.adobe.com/commerce/php/development/cache/page/private-content * @since 103.0.1 */ public function isScopePrivate() { return $this->_isScopePrivate; } + + /** + * Get DeploymentConfig + * + * @return DeploymentConfig + */ + private function getDeploymentConfig() : DeploymentConfig + { + if ($this->deploymentConfig === null) { + $this->deploymentConfig = ObjectManager::getInstance() + ->get(DeploymentConfig::class); + } + return $this->deploymentConfig; + } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php index fa425b413560b..55c84f9b5ca3a 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php @@ -9,10 +9,13 @@ use Magento\Framework\App\Cache\StateInterface as CacheStateInterface; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Cache\LockGuardedCacheLoader; +use Magento\Framework\Config\ConfigOptionsListConstants; use Magento\Framework\Config\View; use Magento\Framework\Escaper; use Magento\Framework\Event\ManagerInterface as EventManagerInterface; +use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\Session\SidResolverInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; @@ -69,11 +72,26 @@ class AbstractBlockTest extends TestCase */ private $lockQuery; + /** + * @var DeploymentConfig|MockObject + */ + private $deploymentConfig; + + /** + * @var ObjectManagerInterface|MockObject + */ + private $objectManagerMock; + /** * @return void */ protected function setUp(): void { + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->onlyMethods(['create']) + ->getMockForAbstractClass(); + \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock); $this->eventManagerMock = $this->getMockForAbstractClass(EventManagerInterface::class); $this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); $this->cacheStateMock = $this->getMockForAbstractClass(CacheStateInterface::class); @@ -108,13 +126,18 @@ protected function setUp(): void $contextMock->expects($this->once()) ->method('getLockGuardedCacheLoader') ->willReturn($this->lockQuery); + $this->block = $this->getMockForAbstractClass( AbstractBlock::class, [ 'context' => $contextMock, - 'data' => [], + 'data' => [] ] ); + $this->deploymentConfig = $this->createPartialMock( + DeploymentConfig::class, + ['get'] + ); } /** @@ -224,9 +247,20 @@ public function testGetCacheKey() */ public function testGetCacheKeyByName() { + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with(DeploymentConfig::class) + ->willReturn($this->deploymentConfig); + + $this->deploymentConfig->expects($this->any()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY) + ->willReturn('448198e08af35844a42d3c93c1ef4e03'); + $nameInLayout = 'testBlock'; $this->block->setNameInLayout($nameInLayout); - $cacheKey = sha1($nameInLayout); + $encryptionKey = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY); + $cacheKey = hash('sha256', $nameInLayout . '|' . $encryptionKey); $this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey()); }