Skip to content

Commit 86d434f

Browse files
merge magento/2.3-develop into magento-tsg/2.3-develop-com-pr10
2 parents d1597df + 382582e commit 86d434f

File tree

28 files changed

+755
-432
lines changed

28 files changed

+755
-432
lines changed

app/code/Magento/Catalog/Model/Product/Image/ParamsBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ private function getWatermark(string $type, int $scopeId = null): array
132132
if ($file) {
133133
$size = explode(
134134
'x',
135-
$this->scopeConfig->getValue(
135+
(string) $this->scopeConfig->getValue(
136136
"design/watermark/{$type}_size",
137-
ScopeInterface::SCOPE_STORE
137+
ScopeInterface::SCOPE_STORE,
138+
$scopeId
138139
)
139140
);
140141
$opacity = $this->scopeConfig->getValue(

app/code/Magento/Catalog/Test/Unit/Model/Product/Image/ParamsBuilderTest.php

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Test\Unit\Model\Product\Image;
89

@@ -11,10 +12,15 @@
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\Framework\Config\View;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1416
use Magento\Framework\View\ConfigInterface;
1517
use Magento\Store\Model\ScopeInterface;
18+
use PHPUnit\Framework\TestCase;
1619

17-
class ParamsBuilderTest extends \PHPUnit\Framework\TestCase
20+
/**
21+
* Test product image params builder
22+
*/
23+
class ParamsBuilderTest extends TestCase
1824
{
1925
/**
2026
* @var ScopeConfigInterface
@@ -30,10 +36,17 @@ class ParamsBuilderTest extends \PHPUnit\Framework\TestCase
3036
* @var ParamsBuilder
3137
*/
3238
private $model;
39+
/**
40+
* @var array
41+
*/
42+
private $scopeConfigData = [];
3343

44+
/**
45+
* @inheritDoc
46+
*/
3447
protected function setUp()
3548
{
36-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
49+
$objectManager = new ObjectManager($this);
3750
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
3851
$this->viewConfig = $this->createMock(ConfigInterface::class);
3952
$this->model = $objectManager->getObject(
@@ -43,28 +56,37 @@ protected function setUp()
4356
'viewConfig' => $this->viewConfig,
4457
]
4558
);
59+
$this->scopeConfigData = [];
60+
$this->scopeConfig->method('getValue')
61+
->willReturnCallback(
62+
function ($path, $scopeType, $scopeCode) {
63+
return $this->scopeConfigData[$path][$scopeType][$scopeCode] ?? null;
64+
}
65+
);
4666
}
4767

4868
/**
49-
* Test watermark location.
69+
* Test build() with different parameters and config values
70+
*
71+
* @param int $scopeId
72+
* @param array $config
73+
* @param array $imageArguments
74+
* @param array $expected
75+
* @dataProvider buildDataProvider
5076
*/
51-
public function testWatermarkLocation()
77+
public function testBuild(int $scopeId, array $config, array $imageArguments, array $expected)
5278
{
53-
$imageArguments = [
54-
'type' => 'type',
55-
'height' => 'image_height',
56-
'width' => 'image_width',
57-
'angle' => 'angle',
58-
'background' => [1, 2, 3]
79+
$this->scopeConfigData[Image::XML_PATH_JPEG_QUALITY][ScopeConfigInterface::SCOPE_TYPE_DEFAULT][null] = 80;
80+
foreach ($config as $path => $value) {
81+
$this->scopeConfigData[$path][ScopeInterface::SCOPE_STORE][$scopeId] = $value;
82+
}
83+
$imageArguments += [
84+
'type' => 'image',
85+
'height' => '600',
86+
'width' => '400',
87+
'angle' => '45',
88+
'background' => [110, 64, 224]
5989
];
60-
$scopeId = 1;
61-
$quality = 100;
62-
$file = 'file';
63-
$width = 'width';
64-
$height = 'height';
65-
$size = "{$width}x{$height}";
66-
$opacity = 'opacity';
67-
$position = 'position';
6890

6991
$viewMock = $this->createMock(View::class);
7092
$viewMock->expects($this->once())
@@ -77,51 +99,16 @@ public function testWatermarkLocation()
7799
->with(['area' => Area::AREA_FRONTEND])
78100
->willReturn($viewMock);
79101

80-
$this->scopeConfig->expects($this->exactly(5))->method('getValue')->withConsecutive(
81-
[
82-
Image::XML_PATH_JPEG_QUALITY
83-
],
84-
[
85-
"design/watermark/{$imageArguments['type']}_image",
86-
ScopeInterface::SCOPE_STORE,
87-
$scopeId,
88-
],
89-
[
90-
"design/watermark/{$imageArguments['type']}_size",
91-
ScopeInterface::SCOPE_STORE],
92-
[
93-
"design/watermark/{$imageArguments['type']}_imageOpacity",
94-
ScopeInterface::SCOPE_STORE,
95-
$scopeId
96-
],
97-
[
98-
"design/watermark/{$imageArguments['type']}_position",
99-
ScopeInterface::SCOPE_STORE,
100-
$scopeId
101-
]
102-
)->willReturnOnConsecutiveCalls(
103-
$quality,
104-
$file,
105-
$size,
106-
$opacity,
107-
$position
108-
);
109-
110102
$actual = $this->model->build($imageArguments, $scopeId);
111-
$expected = [
103+
$expected += [
112104
'image_type' => $imageArguments['type'],
113105
'background' => $imageArguments['background'],
114106
'angle' => $imageArguments['angle'],
115-
'quality' => $quality,
107+
'quality' => 80,
116108
'keep_aspect_ratio' => true,
117109
'keep_frame' => true,
118110
'keep_transparency' => true,
119111
'constrain_only' => true,
120-
'watermark_file' => $file,
121-
'watermark_image_opacity' => $opacity,
122-
'watermark_position' => $position,
123-
'watermark_width' => $width,
124-
'watermark_height' => $height,
125112
'image_height' => $imageArguments['height'],
126113
'image_width' => $imageArguments['width'],
127114
];
@@ -131,4 +118,50 @@ public function testWatermarkLocation()
131118
$actual
132119
);
133120
}
121+
122+
/**
123+
* Provides test scenarios for
124+
*
125+
* @return array
126+
*/
127+
public function buildDataProvider()
128+
{
129+
return [
130+
'watermark config' => [
131+
1,
132+
[
133+
'design/watermark/small_image_image' => 'stores/1/magento-logo.png',
134+
'design/watermark/small_image_size' => '60x40',
135+
'design/watermark/small_image_imageOpacity' => '50',
136+
'design/watermark/small_image_position' => 'bottom-right',
137+
],
138+
[
139+
'type' => 'small_image'
140+
],
141+
[
142+
'watermark_file' => 'stores/1/magento-logo.png',
143+
'watermark_image_opacity' => '50',
144+
'watermark_position' => 'bottom-right',
145+
'watermark_width' => '60',
146+
'watermark_height' => '40',
147+
]
148+
],
149+
'watermark config empty' => [
150+
1,
151+
[
152+
'design/watermark/small_image_image' => 'stores/1/magento-logo.png',
153+
],
154+
[
155+
'type' => 'small_image'
156+
],
157+
[
158+
'watermark_file' => 'stores/1/magento-logo.png',
159+
'watermark_image_opacity' => null,
160+
'watermark_position' => null,
161+
'watermark_width' => null,
162+
'watermark_height' => null,
163+
]
164+
]
165+
];
166+
}
134167
}

app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function addVisibilityFilter(SearchCriteriaInterface $searchCriteria, bo
129129
? $this->visibility->getVisibleInSearchIds()
130130
: $this->visibility->getVisibleInCatalogIds();
131131

132-
$this->addFilter($searchCriteria, 'visibility', $visibilityIds);
132+
$this->addFilter($searchCriteria, 'visibility', $visibilityIds, 'in');
133133
}
134134

135135
/**
@@ -155,13 +155,20 @@ private function preparePriceAggregation(SearchCriteriaInterface $searchCriteria
155155
* @param SearchCriteriaInterface $searchCriteria
156156
* @param string $field
157157
* @param mixed $value
158+
* @param string|null $condition
158159
*/
159-
private function addFilter(SearchCriteriaInterface $searchCriteria, string $field, $value): void
160-
{
160+
private function addFilter(
161+
SearchCriteriaInterface $searchCriteria,
162+
string $field,
163+
$value,
164+
?string $condition = null
165+
): void {
161166
$filter = $this->filterBuilder
162167
->setField($field)
163168
->setValue($value)
169+
->setConditionType($condition)
164170
->create();
171+
165172
$this->filterGroupBuilder->addFilter($filter);
166173
$filterGroups = $searchCriteria->getFilterGroups();
167174
$filterGroups[] = $this->filterGroupBuilder->create();

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,20 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Category;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
12-
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search;
13-
use Magento\Framework\App\ObjectManager;
1411
use Magento\Framework\GraphQl\Config\Element\Field;
1512
use Magento\Framework\GraphQl\Query\ResolverInterface;
1613
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder;
18-
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Filter;
1914
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
15+
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\ProductQueryInterface;
2016

2117
/**
2218
* Category products resolver, used by GraphQL endpoints to retrieve products assigned to a category
2319
*/
2420
class Products implements ResolverInterface
2521
{
2622
/**
27-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
28-
*/
29-
private $productRepository;
30-
31-
/**
32-
* @var Builder
33-
* @deprecated
34-
*/
35-
private $searchCriteriaBuilder;
36-
37-
/**
38-
* @var Filter
39-
* @deprecated
40-
*/
41-
private $filterQuery;
42-
43-
/**
44-
* @var Search
23+
* @var ProductQueryInterface
4524
*/
4625
private $searchQuery;
4726

@@ -51,25 +30,15 @@ class Products implements ResolverInterface
5130
private $searchApiCriteriaBuilder;
5231

5332
/**
54-
* @param ProductRepositoryInterface $productRepository
55-
* @param Builder $searchCriteriaBuilder
56-
* @param Filter $filterQuery
57-
* @param Search $searchQuery
33+
* @param ProductQueryInterface $searchQuery
5834
* @param SearchCriteriaBuilder $searchApiCriteriaBuilder
5935
*/
6036
public function __construct(
61-
ProductRepositoryInterface $productRepository,
62-
Builder $searchCriteriaBuilder,
63-
Filter $filterQuery,
64-
Search $searchQuery = null,
65-
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
37+
ProductQueryInterface $searchQuery,
38+
SearchCriteriaBuilder $searchApiCriteriaBuilder
6639
) {
67-
$this->productRepository = $productRepository;
68-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
69-
$this->filterQuery = $filterQuery;
70-
$this->searchQuery = $searchQuery ?? ObjectManager::getInstance()->get(Search::class);
71-
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
72-
ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
40+
$this->searchQuery = $searchQuery;
41+
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder;
7342
}
7443

7544
/**
@@ -94,18 +63,17 @@ public function resolve(
9463
'eq' => $value['id']
9564
]
9665
];
97-
$searchCriteria = $this->searchApiCriteriaBuilder->build($args, false);
98-
$searchResult = $this->searchQuery->getResult($searchCriteria, $info);
66+
$searchResult = $this->searchQuery->getResult($args, $info);
9967

10068
//possible division by 0
101-
if ($searchCriteria->getPageSize()) {
102-
$maxPages = ceil($searchResult->getTotalCount() / $searchCriteria->getPageSize());
69+
if ($searchResult->getPageSize()) {
70+
$maxPages = ceil($searchResult->getTotalCount() / $searchResult->getPageSize());
10371
} else {
10472
$maxPages = 0;
10573
}
10674

107-
$currentPage = $searchCriteria->getCurrentPage();
108-
if ($searchCriteria->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
75+
$currentPage = $searchResult->getCurrentPage();
76+
if ($searchResult->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
10977
$currentPage = new GraphQlInputException(
11078
__(
11179
'currentPage value %1 specified is greater than the number of pages available.',
@@ -118,7 +86,7 @@ public function resolve(
11886
'total_count' => $searchResult->getTotalCount(),
11987
'items' => $searchResult->getProductsSearchResult(),
12088
'page_info' => [
121-
'page_size' => $searchCriteria->getPageSize(),
89+
'page_size' => $searchResult->getPageSize(),
12290
'current_page' => $currentPage,
12391
'total_pages' => $maxPages
12492
]

0 commit comments

Comments
 (0)