Skip to content

Commit ddc7bcf

Browse files
authored
Merge branch '2.4-develop' into PB-500
2 parents 2866fd8 + 302f6c5 commit ddc7bcf

File tree

218 files changed

+6739
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+6739
-855
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Analytics\Plugin;
10+
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Integration\Model\Integration;
13+
use Magento\Integration\Model\Validator\BearerTokenValidator;
14+
15+
/**
16+
* Overrides authorization config to always allow analytics token to be used as bearer
17+
*/
18+
class BearerTokenValidatorPlugin
19+
{
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private ScopeConfigInterface $config;
24+
25+
/**
26+
* @param ScopeConfigInterface $config
27+
*/
28+
public function __construct(ScopeConfigInterface $config)
29+
{
30+
$this->config = $config;
31+
}
32+
33+
/***
34+
* Always allow access token for analytics to be used as bearer
35+
*
36+
* @param BearerTokenValidator $subject
37+
* @param bool $result
38+
* @param Integration $integration
39+
* @return bool
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function afterIsIntegrationAllowedAsBearerToken(
43+
BearerTokenValidator $subject,
44+
bool $result,
45+
Integration $integration
46+
): bool {
47+
return $result || $integration->getName() === $this->config->getValue('analytics/integration_name');
48+
}
49+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Analytics\Test\Unit\Plugin;
10+
11+
use Magento\Analytics\Plugin\BearerTokenValidatorPlugin;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Integration\Model\Integration;
14+
use Magento\Integration\Model\Validator\BearerTokenValidator;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class BearerTokenValidatorPluginTest extends TestCase
19+
{
20+
/**
21+
* @var BearerTokenValidatorPlugin
22+
*/
23+
private BearerTokenValidatorPlugin $plugin;
24+
25+
/**
26+
* @var BearerTokenValidator|MockObject
27+
*/
28+
private $validator;
29+
30+
public function setUp(): void
31+
{
32+
$config = $this->createMock(ScopeConfigInterface::class);
33+
$config->method('getValue')
34+
->with('analytics/integration_name')
35+
->willReturn('abc');
36+
$this->plugin = new BearerTokenValidatorPlugin($config);
37+
$this->validator = $this->createMock(BearerTokenValidator::class);
38+
}
39+
40+
public function testTrueIsPassedThrough()
41+
{
42+
$integration = $this->createMock(Integration::class);
43+
$integration->method('__call')
44+
->with('getName')
45+
->willReturn('invalid');
46+
47+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
48+
self::assertTrue($result);
49+
}
50+
51+
public function testFalseWhenIntegrationDoesntMatch()
52+
{
53+
$integration = $this->createMock(Integration::class);
54+
$integration->method('__call')
55+
->with('getName')
56+
->willReturn('invalid');
57+
58+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, false, $integration);
59+
self::assertFalse($result);
60+
}
61+
62+
public function testTrueWhenIntegrationMatches()
63+
{
64+
$integration = $this->createMock(Integration::class);
65+
$integration->method('__call')
66+
->with('getName')
67+
->willReturn('abc');
68+
69+
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration);
70+
self::assertTrue($result);
71+
}
72+
}

app/code/Magento/Analytics/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,7 @@
271271
<argument name="connectionFactory" xsi:type="object">Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory</argument>
272272
</arguments>
273273
</type>
274+
<type name="Magento\Integration\Model\Validator\BearerTokenValidator">
275+
<plugin name="allow_bearer_token" type="Magento\Analytics\Plugin\BearerTokenValidatorPlugin"/>
276+
</type>
274277
</config>

app/code/Magento/Backend/Test/Mftf/ActionGroup/AssertAdminDashboardDisplayedWithNoErrorsActionGroup.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<description>Checks if Dashboard is displayed properly</description>
1414
</annotations>
1515

16-
<seeElement selector="{{AdminDashboardSection.dashboardDiagramOrderContentTab}}" stepKey="seeOrderContentTab"/>
17-
<seeElement selector="{{AdminDashboardSection.dashboardDiagramContent}}" stepKey="seeDiagramContent"/>
16+
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramOrderContentTab}}" stepKey="seeOrderContentTab"/>
17+
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramContent}}" stepKey="seeDiagramContent"/>
1818
<click selector="{{AdminDashboardSection.dashboardDiagramAmounts}}" stepKey="clickDashboardAmount"/>
19-
<waitForLoadingMaskToDisappear stepKey="waitForDashboardAmountLoading"/>
20-
<seeElement selector="{{AdminDashboardSection.dashboardDiagramAmountsContentTab}}" stepKey="seeDiagramAmountContent"/>
21-
<seeElement selector="{{AdminDashboardSection.dashboardDiagramTotals}}" stepKey="seeAmountTotals"/>
19+
<waitForPageLoad stepKey="waitForDashboardAmountLoading"/>
20+
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramAmountsContentTab}}" stepKey="seeDiagramAmountContent"/>
21+
<waitForElementVisible selector="{{AdminDashboardSection.dashboardDiagramTotals}}" stepKey="seeAmountTotals"/>
2222
<dontSeeJsError stepKey="dontSeeJsError"/>
2323
</actionGroup>
2424
</actionGroups>

app/code/Magento/Backend/Test/Mftf/Test/AdminCheckDashboardWithChartsTest.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88

9-
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1111
<test name="AdminCheckDashboardWithChartsTest">
1212
<annotations>
@@ -22,6 +22,9 @@
2222
</annotations>
2323
<before>
2424
<magentoCLI command="config:set admin/dashboard/enable_charts 1" stepKey="setEnableCharts"/>
25+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCaches">
26+
<argument name="tags" value="config full_page"/>
27+
</actionGroup>
2528
<createData entity="SimpleProduct2" stepKey="createProduct">
2629
<field key="price">150</field>
2730
</createData>
@@ -43,11 +46,15 @@
4346
</before>
4447
<after>
4548
<magentoCLI command="config:set admin/dashboard/enable_charts 0" stepKey="setDisableChartsAsDefault"/>
49+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanInvalidatedCaches">
50+
<argument name="tags" value="config full_page"/>
51+
</actionGroup>
4652
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
4753
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
4854
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
4955
</after>
5056

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

5360
<updateData createDataKey="createCustomerCart" entity="CustomerOrderPaymentMethod" stepKey="sendCustomerPaymentInformation">
@@ -60,8 +67,9 @@
6067
<requiredEntity createDataKey="createCustomerCart"/>
6168
</createData>
6269

63-
<reloadPage stepKey="refreshPage"/>
70+
<actionGroup ref="ReloadPageActionGroup" stepKey="refreshPage"/>
6471
<actionGroup ref="AssertAdminDashboardDisplayedWithNoErrorsActionGroup" stepKey="assertAdminDashboardNotBroken"/>
72+
<waitForElementVisible selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="waitForQuantityAfter"/>
6573
<grabTextFrom selector="{{AdminDashboardSection.dashboardTotals('Quantity')}}" stepKey="grabQuantityAfter"/>
6674
<assertGreaterThan stepKey="checkQuantityWasChanged">
6775
<actualResult type="const">$grabQuantityAfter</actualResult>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
12+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class Link implements DataFixtureInterface
16+
{
17+
public const DEFAULT_DATA = [
18+
'id' => null,
19+
'sku' => null,
20+
'option_id' => null,
21+
'qty' => 1,
22+
'position' => 1,
23+
'is_default' => false,
24+
'price' => null,
25+
'price_type' => null,
26+
'can_change_quantity' => 0
27+
];
28+
29+
/**
30+
* @var ProcessorInterface
31+
*/
32+
private $dataProcessor;
33+
34+
/**
35+
* @var DataObjectFactory
36+
*/
37+
private $dataObjectFactory;
38+
39+
/**
40+
* @param ProcessorInterface $dataProcessor
41+
* @param DataObjectFactory $dataObjectFactory
42+
*/
43+
public function __construct(
44+
ProcessorInterface $dataProcessor,
45+
DataObjectFactory $dataObjectFactory
46+
) {
47+
$this->dataProcessor = $dataProcessor;
48+
$this->dataObjectFactory = $dataObjectFactory;
49+
}
50+
51+
/**
52+
* {@inheritdoc}
53+
* @param array $data Parameters. Same format as Link::DEFAULT_DATA.
54+
*/
55+
public function apply(array $data = []): ?DataObject
56+
{
57+
return $this->dataObjectFactory->create(['data' => $this->prepareData($data)]);
58+
}
59+
60+
/**
61+
* Prepare link data
62+
*
63+
* @param array $data
64+
* @return array
65+
*/
66+
private function prepareData(array $data): array
67+
{
68+
$data = array_merge(self::DEFAULT_DATA, $data);
69+
70+
return $this->dataProcessor->process($this, $data);
71+
}
72+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Fixture;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\DataObjectFactory;
14+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
15+
use Magento\TestFramework\Fixture\DataFixtureInterface;
16+
17+
class Option implements DataFixtureInterface
18+
{
19+
private const DEFAULT_DATA = [
20+
'option_id' => null,
21+
'title' => 'option%uniqid%',
22+
'required' => true,
23+
'type' => 'select',
24+
'position' => 1,
25+
'sku' => null,
26+
'product_links' => []
27+
];
28+
29+
/**
30+
* @var ProcessorInterface
31+
*/
32+
private $dataProcessor;
33+
34+
/**
35+
* @var DataObjectFactory
36+
*/
37+
private $dataObjectFactory;
38+
39+
/**
40+
* @var ProductRepositoryInterface
41+
*/
42+
private $productRepository;
43+
44+
/**
45+
* @param ProcessorInterface $dataProcessor
46+
* @param DataObjectFactory $dataObjectFactory
47+
*/
48+
public function __construct(
49+
ProcessorInterface $dataProcessor,
50+
DataObjectFactory $dataObjectFactory,
51+
ProductRepositoryInterface $productRepository
52+
) {
53+
$this->dataProcessor = $dataProcessor;
54+
$this->dataObjectFactory = $dataObjectFactory;
55+
$this->productRepository = $productRepository;
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
* @param array $data Parameters. Same format as Option::DEFAULT_DATA.
61+
* - $data['product_links']: An array of product IDs, SKUs or instances. For advanced configuration use an array
62+
* like Link::DEFAULT_DATA.
63+
*/
64+
public function apply(array $data = []): ?DataObject
65+
{
66+
return $this->dataObjectFactory->create(['data' => $this->prepareData($data)]);
67+
}
68+
69+
/**
70+
* Prepare option data
71+
*
72+
* @param array $data
73+
* @return array
74+
*/
75+
private function prepareData(array $data): array
76+
{
77+
$data = array_merge(self::DEFAULT_DATA, $data);
78+
$data['product_links'] = $this->prepareLinksData($data);
79+
80+
return $this->dataProcessor->process($this, $data);
81+
}
82+
83+
/**
84+
* Prepare links data
85+
*
86+
* @param array $data
87+
* @return array
88+
*/
89+
private function prepareLinksData(array $data): array
90+
{
91+
$links = [];
92+
93+
foreach ($data['product_links'] as $link) {
94+
$linkData = [];
95+
if (is_numeric($link)) {
96+
$product = $this->productRepository->getById($link);
97+
$linkData['sku'] = $product->getSku();
98+
} elseif (is_string($link)) {
99+
$linkData['sku'] = $link;
100+
} elseif ($link instanceof ProductInterface) {
101+
$product = $this->productRepository->get($link->getSku());
102+
$linkData['sku'] = $product->getSku();
103+
} else {
104+
$linkData = $link instanceof DataObject ? $link->toArray() : $link;
105+
}
106+
107+
$linkData += Link::DEFAULT_DATA;
108+
$links[] = $linkData;
109+
}
110+
111+
return $links;
112+
}
113+
}

0 commit comments

Comments
 (0)