Skip to content

Commit 37c9902

Browse files
authored
Merge branch 'magento-commerce:2.4-develop' into B2B-1967
2 parents 6c34dc2 + 548ac72 commit 37c9902

File tree

9 files changed

+314
-75
lines changed

9 files changed

+314
-75
lines changed

app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Query/Builder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function initQuery(RequestInterface $request)
9191
'body' => [
9292
'from' => min(self::ELASTIC_INT_MAX, $request->getFrom()),
9393
'size' => $request->getSize(),
94-
'stored_fields' => ['_id', '_score'],
94+
'stored_fields' => '_none_',
95+
'docvalue_fields' => ['_id', '_score'],
9596
'sort' => $this->sortBuilder->getSort($request),
9697
'query' => [],
9798
],

app/code/Magento/Elasticsearch/SearchAdapter/Aggregation/Builder/Dynamic.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ private function getEntityStorage(array $queryResult)
5959
{
6060
$ids = [];
6161
foreach ($queryResult['hits']['hits'] as $document) {
62+
if (!array_key_exists('_id', $document) && isset($document['fields']['_id'][0])) {
63+
$document['_id'] = $document['fields']['_id'][0];
64+
unset($document['fields']);
65+
}
6266
$ids[] = $document['_id'];
6367
}
6468

app/code/Magento/Elasticsearch/SearchAdapter/ResponseFactory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Framework\ObjectManagerInterface;
99

1010
/**
11-
* Response Factory
11+
* Query Response Factory
1212
* @api
1313
* @since 100.1.0
1414
*/
@@ -23,15 +23,15 @@ class ResponseFactory
2323
protected $objectManager;
2424

2525
/**
26-
* Document Factory
26+
* Document Factory to create Search Document instance
2727
*
2828
* @var DocumentFactory
2929
* @since 100.1.0
3030
*/
3131
protected $documentFactory;
3232

3333
/**
34-
* Aggregation Factory
34+
* Aggregation Factory to create Aggregation instance
3535
*
3636
* @var AggregationFactory
3737
* @since 100.1.0
@@ -64,6 +64,10 @@ public function create($response)
6464
{
6565
$documents = [];
6666
foreach ($response['documents'] as $rawDocument) {
67+
if (!array_key_exists('_id', $rawDocument) && isset($rawDocument['fields']['_id'][0])) {
68+
$rawDocument['_id'] = $rawDocument['fields']['_id'][0];
69+
unset($rawDocument['fields']);
70+
}
6771
/** @var \Magento\Framework\Api\Search\Document[] $documents */
6872
$documents[] = $this->documentFactory->create(
6973
$rawDocument

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/ResponseFactoryTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,32 @@ protected function setUp(): void
7272
public function testCreate(): void
7373
{
7474
$documents = [
75-
['title' => 'oneTitle', 'description' => 'oneDescription'],
76-
['title' => 'twoTitle', 'description' => 'twoDescription']
75+
[
76+
'title' => 'oneTitle',
77+
'description' => 'oneDescription',
78+
'fields' => [
79+
'_id' => ['1']
80+
]
81+
],
82+
[
83+
'title' => 'twoTitle',
84+
'description' => 'twoDescription',
85+
'fields' => [
86+
'_id' => ['2']
87+
]
88+
]
89+
];
90+
$modifiedDocuments = [
91+
[
92+
'title' => 'oneTitle',
93+
'description' => 'oneDescription',
94+
'_id' => '1'
95+
],
96+
[
97+
'title' => 'twoTitle',
98+
'description' => 'twoDescription',
99+
'_id' => '2'
100+
]
77101
];
78102
$aggregations = [
79103
'aggregation1' => [
@@ -113,7 +137,7 @@ public function testCreate(): void
113137

114138
$this->documentFactory
115139
->method('create')
116-
->withConsecutive([$documents[0]], [$documents[1]])
140+
->withConsecutive([$modifiedDocuments[0]], [$modifiedDocuments[1]])
117141
->willReturnOnConsecutiveCalls('document1', 'document2');
118142

119143
$this->aggregationFactory

app/code/Magento/Theme/Plugin/Data/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Collection
2323
*/
2424
public function afterGetCurPage(DataCollection $subject, int $result): int
2525
{
26-
if ($result > $subject->getLastPageNumber()) {
26+
if ($result > 1 && $result > $subject->getLastPageNumber()) {
2727
$result = 1;
2828
}
2929

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Theme\Test\Unit\Plugin;
9+
10+
use Magento\Framework\Data\Collection;
11+
use Magento\Theme\Plugin\Data\Collection as CollectionPlugin;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* This Unit Test covers a Plugin (not Collection), overriding the `curPage` (current page)
17+
*
18+
* @see \Magento\Framework\Data\Collection
19+
*/
20+
class CollectionTest extends TestCase
21+
{
22+
/**
23+
* @var Collection|MockObject
24+
*/
25+
private $dataCollectionMock;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
$this->dataCollectionMock = $this->getMockBuilder(Collection::class)
33+
->disableOriginalConstructor()
34+
->onlyMethods(['getLastPageNumber'])
35+
->getMock();
36+
}
37+
38+
/**
39+
* Test covers use-case for the first page of results. We don't expect calculation of the last page to be executed.
40+
*
41+
* @return void
42+
*/
43+
public function testCurrentPageIsNotOverriddenIfFirstPage(): void
44+
{
45+
// Given
46+
$currentPagePlugin = new CollectionPlugin();
47+
48+
// Expects
49+
$this->dataCollectionMock->expects($this->never())
50+
->method('getLastPageNumber');
51+
52+
// When
53+
$currentPagePlugin->afterGetCurPage($this->dataCollectionMock, 1);
54+
}
55+
56+
/**
57+
* Test covers use-case for non-first page of results. We expect calculation of the last page to be executed.
58+
*
59+
* @return void
60+
*/
61+
public function testCurrentPageIsOverriddenIfNotAFirstPage(): void
62+
{
63+
// Given
64+
$currentPagePlugin = new CollectionPlugin();
65+
66+
// Expects
67+
$this->dataCollectionMock->expects($this->once())
68+
->method('getLastPageNumber');
69+
70+
// When
71+
$currentPagePlugin->afterGetCurPage($this->dataCollectionMock, 2);
72+
}
73+
}

dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,17 @@ class SampleRepositoryTest extends WebapiAbstract
3636
*/
3737
protected $deleteServiceInfo;
3838

39+
/**
40+
* @var DomainManagerInterface
41+
*/
42+
private $domainManager;
43+
3944
protected function setUp(): void
4045
{
46+
$objectManager = Bootstrap::getObjectManager();
47+
$this->domainManager = $objectManager->get(DomainManagerInterface::class);
48+
$this->domainManager->addDomains(['example.com']);
49+
4150
$this->createServiceInfo = [
4251
'rest' => [
4352
'resourcePath' => '/V1/products/downloadable-product/downloadable-links/samples',
@@ -75,6 +84,15 @@ protected function setUp(): void
7584
$this->testImagePath = __DIR__ . str_replace('/', DIRECTORY_SEPARATOR, '/_files/test_image.jpg');
7685
}
7786

87+
/**
88+
* Remove example domain from whitelist and call parent restore configuration
89+
*/
90+
protected function tearDown(): void
91+
{
92+
parent::tearDown();
93+
$this->domainManager->removeDomains(['example.com']);
94+
}
95+
7896
/**
7997
* Retrieve product that was updated by test
8098
*
@@ -155,58 +173,6 @@ public function testCreateUploadsProvidedFileContent()
155173
$this->assertNull($sample->getSampleUrl());
156174
}
157175

158-
/**
159-
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
160-
*/
161-
public function testCreateSavesTitleInStoreViewScope()
162-
{
163-
$requestData = [
164-
'isGlobalScopeContent' => false,
165-
'sku' => 'downloadable-product',
166-
'sample' => [
167-
'title' => 'Store View Title',
168-
'sort_order' => 1,
169-
'sample_url' => 'http://www.sample.example.com/',
170-
'sample_type' => 'url',
171-
],
172-
];
173-
174-
$newSampleId = $this->_webApiCall($this->createServiceInfo, $requestData);
175-
$sample = $this->getTargetSample($this->getTargetProduct(), $newSampleId);
176-
$globalScopeSample = $this->getTargetSample($this->getTargetProduct(true), $newSampleId);
177-
$this->assertNotNull($sample);
178-
$this->assertEquals($requestData['sample']['title'], $sample->getTitle());
179-
$this->assertEquals($requestData['sample']['sort_order'], $sample->getSortOrder());
180-
$this->assertEquals($requestData['sample']['sample_url'], $sample->getSampleUrl());
181-
$this->assertEquals($requestData['sample']['sample_type'], $sample->getSampleType());
182-
$this->assertEmpty($globalScopeSample->getTitle());
183-
}
184-
185-
/**
186-
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
187-
*/
188-
public function testCreateSavesProvidedUrls()
189-
{
190-
$requestData = [
191-
'isGlobalScopeContent' => false,
192-
'sku' => 'downloadable-product',
193-
'sample' => [
194-
'title' => 'Sample with URL resource',
195-
'sort_order' => 1,
196-
'sample_url' => 'http://www.sample.example.com/',
197-
'sample_type' => 'url',
198-
],
199-
];
200-
201-
$newSampleId = $this->_webApiCall($this->createServiceInfo, $requestData);
202-
$sample = $this->getTargetSample($this->getTargetProduct(), $newSampleId);
203-
$this->assertNotNull($sample);
204-
$this->assertEquals($requestData['sample']['title'], $sample->getTitle());
205-
$this->assertEquals($requestData['sample']['sort_order'], $sample->getSortOrder());
206-
$this->assertEquals($requestData['sample']['sample_type'], $sample->getSampleType());
207-
$this->assertEquals($requestData['sample']['sample_url'], $sample->getSampleUrl());
208-
}
209-
210176
/**
211177
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
212178
*/

0 commit comments

Comments
 (0)