Skip to content

Commit 4fad67d

Browse files
authored
MDEE-942: Fix integration SimpleProductsTest (#466)
1 parent b61d6e0 commit 4fad67d

File tree

5 files changed

+45
-66
lines changed

5 files changed

+45
-66
lines changed

CatalogDataExporter/Model/Provider/Product/Attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function get(array $values): array
100100
$output[$key]['storeViewCode'] = $storeViewCode;
101101
$output[$key]['attributes'] = [
102102
'attributeCode' => $row['attribute_code'],
103-
'value' => ($row['value'] != null) ?
103+
'value' => ($row['value'] !== null) ?
104104
$this->attributeMetadata->getAttributeValue(
105105
$row['attribute_code'],
106106
$storeViewCode,

CatalogDataExporter/Model/Query/Eav/EavAttributeQueryBuilder.php

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,22 @@
2929
*/
3030
class EavAttributeQueryBuilder implements EavAttributeQueryBuilderInterface
3131
{
32-
/**
33-
* @var ResourceConnection
34-
*/
35-
private $resourceConnection;
36-
37-
/**
38-
* @var MetadataPool
39-
*/
40-
private $metadataPool;
41-
42-
/**
43-
* @var string
44-
*/
45-
private $entityType;
46-
4732
/**
4833
* List of attributes that need to be added/removed to fetch
49-
*
50-
* @var array
51-
*/
52-
private $linkedAttributes;
53-
54-
/**
55-
* @var array
5634
*/
35+
private array $linkedAttributes;
5736
private const SUPPORTED_BACKEND_TYPES = [
5837
'int',
5938
'decimal',
6039
'text',
6140
'varchar',
6241
'datetime',
6342
];
64-
65-
/**
66-
* @var int[]
67-
*/
68-
private $entityTypeIdMap;
69-
70-
/**
71-
* @var Config
72-
*/
73-
private $eavConfig;
74-
75-
/**
76-
* @var array
77-
*/
43+
private ResourceConnection $resourceConnection;
44+
private MetadataPool $metadataPool;
45+
private string $entityType;
46+
private array $entityTypeIdMap;
47+
private Config $eavConfig;
7848
private array $attributesMetadata = [];
7949
private array $storeCodeToStoreIdMap = [];
8050

@@ -138,7 +108,6 @@ public function build(array $entityIds, array $attributes, string $storeCode): S
138108
* Form and return query to get entity $entityTableAttributes for given $entityIds
139109
*
140110
* @param AdapterInterface $connection
141-
* @param array $entityTableAttributes
142111
* @param int[] $entityIds
143112
* @param string $entityTableName
144113
* @return Select
@@ -206,7 +175,6 @@ private function getAttributesMetaData(
206175
*
207176
* @param AdapterInterface $connection
208177
* @param EntityMetadataInterface $metadata
209-
* @param array $entityTableAttributes
210178
* @param int[] $entityIds
211179
* @param array $eavAttributesMetaData
212180
* @param string $entityTableName
@@ -243,7 +211,8 @@ private function getEavAttributes(
243211
),
244212
['store_id']
245213
)
246-
->join(['a' => $this->resourceConnection->getTableName('eav_attribute')],
214+
->join(
215+
['a' => $this->resourceConnection->getTableName('eav_attribute')],
247216
'eav.attribute_id = a.attribute_id',
248217
['attribute_code']
249218
)
@@ -259,6 +228,8 @@ private function getEavAttributes(
259228
}
260229

261230
/**
231+
* Get store id by store code
232+
*
262233
* @param string $storeCode
263234
* @return int
264235
*/
@@ -283,10 +254,9 @@ private function getStoreId(string $storeCode): int
283254
* Add linked attributes to output
284255
*
285256
* @param array $attributes
286-
* @param array $entityTableAttributes
287257
* @return array
288258
*/
289-
private function getEavAttributeCodes($attributes): array
259+
private function getEavAttributeCodes(array $attributes): array
290260
{
291261
$unusedAttributeList = [];
292262
$newAttributes = [];

CatalogDataExporter/Test/Integration/AbstractProductTestHelper.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace Magento\CatalogDataExporter\Test\Integration;
1818

19+
use JsonException;
1920
use Magento\Catalog\Api\CategoryRepositoryInterface;
2021
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
2122
use Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface;
@@ -39,6 +40,7 @@
3940
use Magento\Store\Api\GroupRepositoryInterface;
4041
use Magento\Tax\Model\TaxClass\Source\Product as TaxClassSource;
4142
use Magento\TestFramework\Helper\Bootstrap;
43+
use PHPUnit\Event\Runtime\PHP;
4244
use function PHPUnit\Framework\assertEmpty;
4345
use function PHPUnit\Framework\assertEquals;
4446

@@ -376,63 +378,70 @@ protected function validateImageUrls(ProductInterface $product, array $extracted
376378
*/
377379
protected function validateAttributeData(ProductInterface $product, array $extractedProduct) : void
378380
{
379-
$customLabel = $product->getCustomAttribute('custom_label');
380-
$customDescription = $product->getCustomAttribute('custom_description');
381-
$customSelect = $product->getCustomAttribute('custom_select');
382-
$yesNo = $product->getCustomAttribute('yes_no_attribute');
383-
$newsFromDate = $product->getNewsFromDate();
384-
$newsToDate = $product->getNewsToDate();
385381
$attributes = null;
386-
if ($customLabel) {
382+
if ($product->hasData('custom_label')) {
383+
$customLabel = $product->getCustomAttribute('custom_label');
387384
$attributes[$customLabel->getAttributeCode()] = [
388385
'attributeCode' => $customLabel->getAttributeCode(),
389386
'value' => [$customLabel->getValue()]
390387
];
391388
}
392-
if ($customDescription) {
389+
if ($product->hasData('custom_description')) {
390+
$customDescription = $product->getCustomAttribute('custom_description');
393391
$attributes[$customDescription->getAttributeCode()] = [
394392
'attributeCode' => $customDescription->getAttributeCode(),
395393
'value' => [$customDescription->getValue()]
396394
];
397395
}
398-
if ($customSelect) {
396+
if ($product->hasData('custom_select')) {
397+
$customSelect = $product->getCustomAttribute('custom_select');
399398
$attributes[$customSelect->getAttributeCode()] = [
400399
'attributeCode' => $customSelect->getAttributeCode(),
401400
'value' => [$product->getAttributeText('custom_select')]
402401
];
403402
}
404-
if ($yesNo) {
403+
if ($product->hasData('yes_no_attribute')) {
404+
$yesNo = $product->getCustomAttribute('yes_no_attribute');
405405
$yesNoValues = [0 => 'no', 1 => 'yes'];
406406
$yesNoActualValue = $product->getData('yes_no_attribute');
407407
$attributes[$yesNo->getAttributeCode()] = [
408408
'attributeCode' => $yesNo->getAttributeCode(),
409409
'value' => [$yesNoValues[$yesNoActualValue] ?? null]
410410
];
411411
}
412-
if ($newsFromDate) {
412+
if ($product->hasData('news_from_date')) {
413+
$newsFromDate = $product->getCustomAttribute('news_from_date');
413414
$attributes['news_from_date'] = [
414-
'attributeCode' => 'news_from_date',
415-
'value' => [$newsFromDate]
415+
'attributeCode' => 'news_from_date'
416416
];
417+
if ($newsFromDate !== null) {
418+
$attributes['news_from_date']['value'] = [$newsFromDate->getValue()];
419+
}
417420
}
418-
if ($newsToDate) {
421+
if ($product->hasData('news_to_date')) {
422+
$newsToDate = $product->getCustomAttribute('news_to_date');
419423
$attributes['news_to_date'] = [
420-
'attributeCode' => 'news_to_date',
421-
'value' => [$newsToDate]
424+
'attributeCode' => 'news_to_date'
422425
];
426+
if ($newsToDate !== null) {
427+
$attributes['news_to_date']['value'] = [$newsToDate->getValue()];
428+
}
423429
}
424430
$feedAttributes = null;
425431
if (isset($extractedProduct['feedData']['attributes'])) {
426-
$feedAttributesData = $extractedProduct['feedData']['attributes'];
427-
foreach ($feedAttributesData as $feed) {
428-
$feedAttributes[$feed['attributeCode']] = [
429-
'attributeCode' => $feed['attributeCode'],
430-
'value' => $feed['value']
431-
];
432+
foreach ($extractedProduct['feedData']['attributes'] as $feed) {
433+
$feedAttributes[$feed['attributeCode']] = $feed;
432434
}
433435
}
434436

435-
$this->assertEquals($attributes, $feedAttributes);
437+
try {
438+
$this->assertJsonStringEqualsJsonString(
439+
json_encode($attributes, JSON_THROW_ON_ERROR),
440+
json_encode($feedAttributes, JSON_THROW_ON_ERROR)
441+
);
442+
} catch (JsonException $e) {
443+
$this->fail($e->getMessage());
444+
}
436445
}
437446

438447
/**

ProductPriceDataExporter/Test/Integration/AbstractProductPriceTestHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ protected function emulateCustomersBehaviorAfterDeleteAction(): void
104104
*/
105105
protected function checkExpectedItemsAreExportedInFeed(array $expectedItems): void
106106
{
107+
$this->emulateCustomersBehaviorAfterDeleteAction();
107108
$processor = $this->objectManager->create(Processor::class);
108109
$processor->updateMview();
109110
$processor->reindexAllInvalid();

ProductPriceDataExporter/Test/Integration/ExportSingleProductPriceTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function testExportSimpleProductsWithDisabledCatalogPriceRulePrices(array
8383
$rule->setIsActive(0);
8484
$this->catalogRuleRepository->save($rule);
8585
$ruleProductProcessor->getIndexer()->reindexAll();
86-
$this->emulateCustomersBehaviorAfterDeleteAction();
8786
$this->checkExpectedItemsAreExportedInFeed($expectedSimpleProductPrices);
8887
}
8988

0 commit comments

Comments
 (0)