Skip to content

Commit

Permalink
Merge pull request #7371 from magento-cia/2.4.4-develop-2.4-develop-s…
Browse files Browse the repository at this point in the history
…ync-122321

Final sync of 2.4.4-develop with 2.4-develop
  • Loading branch information
dvoskoboinikov authored Dec 24, 2021
2 parents 61fe1d1 + 043092b commit 59dfc49
Show file tree
Hide file tree
Showing 149 changed files with 2,589 additions and 439 deletions.
49 changes: 49 additions & 0 deletions app/code/Magento/Analytics/Plugin/BearerTokenValidatorPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Analytics\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Integration\Model\Integration;
use Magento\Integration\Model\Validator\BearerTokenValidator;

/**
* Overrides authorization config to always allow analytics token to be used as bearer
*/
class BearerTokenValidatorPlugin
{
/**
* @var ScopeConfigInterface
*/
private ScopeConfigInterface $config;

/**
* @param ScopeConfigInterface $config
*/
public function __construct(ScopeConfigInterface $config)
{
$this->config = $config;
}

/***
* Always allow access token for analytics to be used as bearer
*
* @param BearerTokenValidator $subject
* @param bool $result
* @param Integration $integration
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterIsIntegrationAllowedAsBearerToken(
BearerTokenValidator $subject,
bool $result,
Integration $integration
): bool {
return $result || $integration->getName() === $this->config->getValue('analytics/integration_name');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Analytics\Test\Unit\Plugin;

use Magento\Analytics\Plugin\BearerTokenValidatorPlugin;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Integration\Model\Integration;
use Magento\Integration\Model\Validator\BearerTokenValidator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class BearerTokenValidatorPluginTest extends TestCase
{
/**
* @var BearerTokenValidatorPlugin
*/
private BearerTokenValidatorPlugin $plugin;

/**
* @var BearerTokenValidator|MockObject
*/
private $validator;

public function setUp(): void
{
$config = $this->createMock(ScopeConfigInterface::class);
$config->method('getValue')
->with('analytics/integration_name')
->willReturn('abc');
$this->plugin = new BearerTokenValidatorPlugin($config);
$this->validator = $this->createMock(BearerTokenValidator::class);
}

public function testTrueIsPassedThrough()
{
$integration = $this->createMock(Integration::class);
$integration->method('__call')
->with('getName')
->willReturn('invalid');

$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
self::assertTrue($result);
}

public function testFalseWhenIntegrationDoesntMatch()
{
$integration = $this->createMock(Integration::class);
$integration->method('__call')
->with('getName')
->willReturn('invalid');

$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, false, $integration);
self::assertFalse($result);
}

public function testTrueWhenIntegrationMatches()
{
$integration = $this->createMock(Integration::class);
$integration->method('__call')
->with('getName')
->willReturn('abc');

$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
self::assertTrue($result);
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Analytics/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,7 @@
<argument name="connectionFactory" xsi:type="object">Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory</argument>
</arguments>
</type>
<type name="Magento\Integration\Model\Validator\BearerTokenValidator">
<plugin name="allow_bearer_token" type="Magento\Analytics\Plugin\BearerTokenValidatorPlugin"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<description>Checks if Dashboard is displayed properly</description>
</annotations>

<seeElement selector="{{AdminDashboardSection.dashboardDiagramOrderContentTab}}" stepKey="seeOrderContentTab"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramContent}}" stepKey="seeDiagramContent"/>
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramOrderContentTab}}" stepKey="seeOrderContentTab"/>
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramContent}}" stepKey="seeDiagramContent"/>
<click selector="{{AdminDashboardSection.dashboardDiagramAmounts}}" stepKey="clickDashboardAmount"/>
<waitForLoadingMaskToDisappear stepKey="waitForDashboardAmountLoading"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramAmountsContentTab}}" stepKey="seeDiagramAmountContent"/>
<seeElement selector="{{AdminDashboardSection.dashboardDiagramTotals}}" stepKey="seeAmountTotals"/>
<waitForPageLoad stepKey="waitForDashboardAmountLoading"/>
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramAmountsContentTab}}" stepKey="seeDiagramAmountContent"/>
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramTotals}}" stepKey="seeAmountTotals"/>
<dontSeeJsError stepKey="dontSeeJsError"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCheckDashboardWithChartsTest">
<annotations>
Expand All @@ -22,6 +22,9 @@
</annotations>
<before>
<magentoCLI command="config:set admin/dashboard/enable_charts 1" stepKey="setEnableCharts"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCaches">
<argument name="tags" value="config full_page"/>
</actionGroup>
<createData entity="SimpleProduct2" stepKey="createProduct">
<field key="price">150</field>
</createData>
Expand All @@ -43,11 +46,15 @@
</before>
<after>
<magentoCLI command="config:set admin/dashboard/enable_charts 0" stepKey="setDisableChartsAsDefault"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCaches">
<argument name="tags" value="config full_page"/>
</actionGroup>
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<waitForElementVisible selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="waitForQuantityBefore"/>
<grabTextFrom selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="grabQuantityBefore"/>

<updateData createDataKey="createCustomerCart" entity="CustomerOrderPaymentMethod" stepKey="sendCustomerPaymentInformation">
Expand All @@ -60,8 +67,9 @@
<requiredEntity createDataKey="createCustomerCart"/>
</createData>

<reloadPage stepKey="refreshPage"/>
<actionGroup ref="ReloadPageActionGroup" stepKey="refreshPage"/>
<actionGroup ref="AssertAdminDashboardDisplayedWithNoErrorsActionGroup" stepKey="assertAdminDashboardNotBroken"/>
<waitForElementVisible selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="waitForQuantityAfter"/>
<grabTextFrom selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="grabQuantityAfter"/>
<assertGreaterThan stepKey="checkQuantityWasChanged">
<actualResult type="const">$grabQuantityAfter</actualResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
<argument name="image" defaultValue="ProductImage"/>
</arguments>

<waitForElementVisible selector="{{AdminProductImagesSection.productImagesToggle}}" stepKey="waitForImagesSection"/>
<conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductImagesSection"/>
<waitForPageLoad time="30" stepKey="waitForPageRefresh"/>
<waitForPageLoad stepKey="waitForPageRefresh"/>
<waitForElementVisible selector="{{AdminProductImagesSection.imageUploadButton}}" stepKey="seeImageSectionIsReady"/>
<attachFile selector="{{AdminProductImagesSection.imageFileUpload}}" userInput="{{image.file}}" stepKey="uploadFile"/>
<waitForPageLoad stepKey="waitForImageUpload"/>
<waitForElementNotVisible selector="{{AdminProductImagesSection.uploadProgressBar}}" stepKey="waitForUpload"/>
<waitForElementVisible selector="{{AdminProductImagesSection.imageFile(image.fileName)}}" stepKey="waitForThumbnail"/>
</actionGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<arguments>
<argument name="image" defaultValue="{{MagentoLogo.filename}}" type="string"/>
</arguments>
<waitForElementVisible selector="{{AdminProductImagesSection.productImagesToggle}}" stepKey="waitForProductImagesSection"/>
<conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageUploadButton}}" visible="false" stepKey="openProductImagesSection"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<waitForElementVisible selector="{{AdminProductImagesSection.imageFile(image)}}" stepKey="seeImage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
<argument name="image" defaultValue="ProductImage"/>
<argument name="altText" defaultValue="{{ProductImage.title}}" type="string"/>
</arguments>
<waitForElementVisible selector="{{AdminProductImagesSection.productImagesToggle}}" stepKey="waitForImagesSection"/>
<conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageFile(image.fileName)}}" visible="false" stepKey="expandImages"/>
<waitForPageLoad stepKey="waitForImages"/>
<waitForElementVisible selector="{{AdminProductImagesSection.imageFile(image.fileName)}}" stepKey="seeProductImageName"/>
<click selector="{{AdminProductImagesSection.imageFile(image.fileName)}}" stepKey="clickProductImage"/>
<waitForPageLoad stepKey="waitForImageDetails"/>
<waitForElementVisible selector="{{AdminProductImagesSection.altText}}" stepKey="seeAltTextSection"/>
<grabValueFrom selector="{{AdminProductImagesSection.altText}}" stepKey="actualAltText"/>
<assertEquals stepKey="assertAltText">
<expectedResult type="string">{{altText}}</expectedResult>
<actualResult type="variable">actualAltText</actualResult>
</assertEquals>
<click selector="{{AdminSlideOutDialogSection.closeButton}}" stepKey="clickCloseButton"/>
<waitForPageLoad stepKey="waitForClose"/>
<waitForElementNotVisible selector="{{AdminProductImagesSection.altText}}" stepKey="waitForDetailsGone"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
<argument name="image" defaultValue="ProductImage"/>
<argument name="altText" defaultValue="{{ProductImage.title}}" type="string"/>
</arguments>
<waitForElementVisible selector="{{AdminProductImagesSection.productImagesToggle}}" stepKey="waitForImagesSection"/>
<conditionalClick selector="{{AdminProductImagesSection.productImagesToggle}}" dependentSelector="{{AdminProductImagesSection.imageFile(image.fileName)}}" visible="false" stepKey="expandImages"/>
<waitForPageLoad stepKey="waitForImages"/>
<waitForElementVisible selector="{{AdminProductImagesSection.imageFile(image.fileName)}}" stepKey="seeProductImageName"/>
<click selector="{{AdminProductImagesSection.imageFile(image.fileName)}}" stepKey="clickProductImage"/>
<waitForPageLoad stepKey="waitForImageDetails"/>
<waitForElementVisible selector="{{AdminProductImagesSection.altText}}" stepKey="seeAltTextSection"/>
<fillField selector="{{AdminProductImagesSection.altText}}" userInput="{{altText}}" stepKey="fillAltTextSection"/>
<click selector="{{AdminSlideOutDialogSection.closeButton}}" stepKey="clickCloseButton"/>
<waitForPageLoad stepKey="waitForClose"/>
<waitForElementNotVisible selector="{{AdminProductImagesSection.altText}}" stepKey="waitForDetailsGone"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<actionGroup ref="AdminDeleteProductAttributeByLabelActionGroup" stepKey="deleteCreatedAttribute">
<argument name="productAttributeLabel" value="{{ProductAttributeFrontendLabel.label}}"/>
</actionGroup>
<!-- Reindex after deleting product attribute -->
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdminPanel"/>
</after>
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="navigateToProductPage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<actionGroup ref="AdminDeleteProductAttributeByLabelActionGroup" stepKey="deleteCreatedAttribute">
<argument name="productAttributeLabel" value="{{ProductAttributeFrontendLabel.label}}"/>
</actionGroup>
<!-- Reindex after deleting product attribute -->
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdminPanel"/>
</after>
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="navigateToProductPage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<actionGroup ref="AdminDeleteProductAttributeByLabelActionGroup" stepKey="deleteAttribute">
<argument name="productAttributeLabel" value="{{colorProductAttribute.default_label}}" />
</actionGroup>
<!-- Reindex after deleting product attribute -->
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
</after>

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/etc/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<resource id="Magento_Catalog::catalog" title="Catalog" translate="title" sortOrder="30">
<resource id="Magento_Catalog::catalog_inventory" title="Inventory" translate="title" sortOrder="10">
<resource id="Magento_Catalog::products" title="Products" translate="title" sortOrder="10">
<resource id="Magento_Catalog::update_attributes" title="Update Attributes" translate="title" sortOrder="10" />
<resource id="Magento_Catalog::update_attributes" title="Mass Update Attributes" translate="title" sortOrder="10" />
<resource id="Magento_Catalog::edit_product_design" title="Edit Product Design" translate="title" sortOrder="20" />
</resource>
<resource id="Magento_Catalog::categories" title="Categories" translate="title" sortOrder="20">
Expand All @@ -27,7 +27,7 @@
</resource>
</resource>
<resource id="Magento_Backend::stores_attributes">
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30" />
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30"/>
<resource id="Magento_Catalog::sets" title="Attribute Set" translate="title" sortOrder="40"/>
</resource>
</resource>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Quantity,Quantity
Edit,Edit
"Are you sure?","Are you sure?"
"Change Status","Change Status"
"Update Attributes","Update Attributes"
"Mass Update Attributes","Mass Update Attributes"
"start typing to search category","start typing to search category"
"New Category","New Category"
"Images (.gif, .jpg, .png)","Images (.gif, .jpg, .png)"
Expand Down
8 changes: 6 additions & 2 deletions app/code/Magento/CatalogInventory/Model/StockManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\CatalogInventory\Model\ResourceModel\Stock as ResourceStock;
use Magento\Framework\Exception\LocalizedException;

/**
* Implements a few interfaces for backward compatibility
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class StockManagement implements StockManagementInterface, RegisterProductSaleInterface, RevertProductSaleInterface
{
Expand Down Expand Up @@ -91,7 +94,8 @@ public function __construct(
* @param string[] $items
* @param int $websiteId
* @return StockItemInterface[]
* @throws \Magento\Framework\Exception\LocalizedException
* @throws StockStateException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function registerProductsSale($items, $websiteId = null)
Expand All @@ -118,7 +122,7 @@ public function registerProductsSale($items, $websiteId = null)
&& !$this->stockState->checkQty($productId, $orderedQty, $stockItem->getWebsiteId())
) {
$this->getResource()->commit();
throw new \Magento\Framework\Exception\LocalizedException(
throw new StockStateException(
__('Some of the products are out of stock.')
);
}
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/CatalogInventory/Model/StockStateException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogInventory\Model;

use Magento\Framework\Exception\LocalizedException;

/**
* Exception class reflecting when an operation cannot be completed due to the current stock status of an inventory item
*
* @api
*/
class StockStateException extends LocalizedException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function testRegisterProductsSale(
*/
public function testRegisterProductsSaleException(array $items, array $lockedItems)
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$this->expectException('Magento\CatalogInventory\Model\StockStateException');
$this->expectExceptionMessage('Some of the products are out of stock.');
$this->stockResourceMock
->expects($this->once())
Expand Down
Loading

0 comments on commit 59dfc49

Please sign in to comment.