Skip to content

Commit

Permalink
Merge pull request #44 from muckiware/33-wrong-default-value-for-mapp…
Browse files Browse the repository at this point in the history
…ingproductfields-plugin-config-field

33 wrong default value for mappingproductfields plugin config field
  • Loading branch information
torstenfreyda authored Feb 24, 2024
2 parents 25ae96b + dd47d75 commit 164ce40
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<name>indexNamePattern</name>
<label>Index Name Pattern</label>
<defaultValue>{{salesChannelId}}-{{entity}}-{{languageId}}</defaultValue>
<helpText>Dynamic fields with Twig notation.</helpText>
<helpText lang="de-DE">Dynamische Felder mit Twig-Notation.</helpText>
</input-field>
</card>
<card>
Expand All @@ -100,9 +102,11 @@
<title lang="de-DE">Suchfelder Zuordnung</title>
<input-field type="text">
<name>mappingProductFields</name>
<label>Product fields for mapping</label>
<label lang="de-DE">Produktfelder für Zuordnung</label>
<defaultValue>id,productNumber</defaultValue>
<label>Default product fields for index mapping</label>
<label lang="de-DE">Standard Produktfelder für Index Zuordnung</label>
<defaultValue>id:string,productNumber:string</defaultValue>
<helpText>Field definition separate by comma. Example: id:string,productNumber:string</helpText>
<helpText lang="de-DE">Felddefinition durch Komma getrennt. Beispiel: id:string,productNumber:string</helpText>
</input-field>
</card>
<card>
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public function getServerType(): string
public function getMappingProductFields(): array
{
$mappingProductFields = array();
if($this->config->getString($this::CONFIG_PATH_MAPPING_PRODUCT_FIELDS) !== '') {
$configDefaultProductMappings = $this->config->getString($this::CONFIG_PATH_MAPPING_PRODUCT_FIELDS);
$configStr = $this->config->getString($this::CONFIG_PATH_MAPPING_PRODUCT_FIELDS);
if($configStr !== '' && str_contains(':', $configStr)) {
$configDefaultProductMappings = $configStr;
} else {
$configDefaultProductMappings = Defaults::DEFAULT_PRODUCT_MAPPINGS;
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Services/SettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace MuckiSearchPlugin\Services;

use PHPUnit\Framework\TestCase;
use Twig\Environment;
use Psr\Log\LoggerInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;

use MuckiSearchPlugin\Services\Settings as PluginSettings;

class SettingsTest extends TestCase
{
public function testGetMappingProductFieldsDefaultInput()
{
$systemConfigService = $this->createMock(SystemConfigService::class);
$systemConfigService->method('getString')->willReturnCallback(
fn () => ''
);

$instance = $this->getInstance($systemConfigService);
$mappingProductFieldsResults = $instance->getMappingProductFields();
$this->assertIsArray($mappingProductFieldsResults, 'GetMappingProductFields is not an array');
$this->assertArrayHasKey('field', $mappingProductFieldsResults[0], 'Missing field key of GetMappingProductFields method');
$this->assertArrayHasKey('type', $mappingProductFieldsResults[0], 'Missing type key of GetMappingProductFields method');
$this->assertSame('id', $mappingProductFieldsResults[0]['field'], 'Missing correct [0] field value');
$this->assertSame('keyword', $mappingProductFieldsResults[0]['type'], 'Missing correct [0] type value');
$this->assertSame('productNumber', $mappingProductFieldsResults[1]['field'], 'Missing correct [1] field value');
$this->assertSame('keyword', $mappingProductFieldsResults[1]['type'], 'Missing correct [1] type value');
$this->assertSame('translations.DEFAULT.name', $mappingProductFieldsResults[2]['field'], 'Missing correct [2] field value');
$this->assertSame('text', $mappingProductFieldsResults[2]['type'], 'Missing correct [2] type value');
$this->assertSame('translations.DEFAULT.description', $mappingProductFieldsResults[3]['field'], 'Missing correct [3] field value');
$this->assertSame('text', $mappingProductFieldsResults[3]['type'], 'Missing correct [3] type value');
$this->assertSame('cover.media.url', $mappingProductFieldsResults[4]['field'], 'Missing correct [4] field value');
$this->assertSame('text', $mappingProductFieldsResults[4]['type'], 'Missing correct [4] type value');
}

private function getInstance($systemConfigService): PluginSettings
{
return new PluginSettings($systemConfigService);
}
}

0 comments on commit 164ce40

Please sign in to comment.