-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-4358: Adding property mapper for product eav attribute -> sear…
…ch weight. #17668
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/code/Magento/CatalogSearch/Model/ResourceModel/Setup/PropertyMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\CatalogSearch\Model\ResourceModel\Setup; | ||
|
||
use Magento\Eav\Model\Entity\Setup\PropertyMapperAbstract; | ||
|
||
/** | ||
* Class PropertyMapper | ||
* | ||
* @package Magento\CatalogSearch\Model\ResourceModel\Setup | ||
*/ | ||
class PropertyMapper extends PropertyMapperAbstract | ||
{ | ||
/** | ||
* Map input attribute properties to storage representation | ||
* | ||
* @param array $input | ||
* @param int $entityTypeId | ||
* @return array | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function map(array $input, $entityTypeId): array | ||
{ | ||
return [ | ||
'search_weight' => $this->_getValue($input, 'search_weight', 1), | ||
]; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Setup/PropertyMapperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup; | ||
|
||
use Magento\CatalogSearch\Model\ResourceModel\Setup\PropertyMapper; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class PropertyMapperTest | ||
* | ||
* @package Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup | ||
*/ | ||
class PropertyMapperTest extends TestCase | ||
{ | ||
/** | ||
* @var PropertyMapper | ||
*/ | ||
private $propertyMapper; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->propertyMapper = new PropertyMapper(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function caseProvider(): array | ||
{ | ||
return [ | ||
[ | ||
['search_weight' => 9, 'something_other' => '3'], | ||
['search_weight' => 9] | ||
], | ||
[ | ||
['something' => 3], | ||
['search_weight' => 1] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider caseProvider | ||
* | ||
* @test | ||
* | ||
* @param array $input | ||
* @param array $result | ||
* @return void | ||
*/ | ||
public function testMapCorrectlyMapsValue(array $input, array $result): void | ||
{ | ||
//Second parameter doesn't matter as it is not used | ||
$this->assertSame($result, $this->propertyMapper->map($input, 4)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters