Skip to content

Commit

Permalink
OXDEV-7456: Add mutation to change theme string setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Nov 20, 2023
1 parent ece7379 commit 3ac3574
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Setting/Infrastructure/ThemeSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public function saveBooleanSetting(ID $name, bool $value, string $themeId): void

public function saveStringSetting(ID $name, string $value, string $themeId): void
{
// TODO: Implement saveStringSetting() method.
$value = $this->shopSettingEncoder->encode(FieldType::STRING, $value);

$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveSelectSetting(ID $name, string $value, string $themeId): void
Expand Down
41 changes: 39 additions & 2 deletions tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testSaveNotExistingIntegerSetting(): void
public function testSaveAndGetFloatSetting(): void
{
$name = "coolFloatSetting";
$eventDispatcher = $this->getEventDispatcherMock("coolFloatSetting");
$eventDispatcher = $this->getEventDispatcherMock($name);
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $this->get(QueryBuilderFactoryInterface::class);

Expand Down Expand Up @@ -100,7 +100,7 @@ public function testSaveNotExistingFloatSetting(): void
public function testSaveAndGetBooleanSetting(): void
{
$name = "coolBooleanSetting";
$eventDispatcher = $this->getEventDispatcherMock("coolBooleanSetting");
$eventDispatcher = $this->getEventDispatcherMock($name);
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $this->get(QueryBuilderFactoryInterface::class);

Expand Down Expand Up @@ -134,6 +134,43 @@ public function testSaveNotExistingBooleanSetting(): void
$repository->saveBooleanSetting(new ID('notExistingSetting'), true, 'awesomeTheme');
}

public function testSaveAndGetStringSetting(): void
{
$name = 'coolBooleanString';
$eventDispatcher = $this->getEventDispatcherMock($name);
/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $this->get(QueryBuilderFactoryInterface::class);

$repository = $this->getSut(
eventDispatcher: $eventDispatcher,
queryBuilderFactory: $queryBuilderFactory
);

$this->createThemeSetting(
$queryBuilderFactory,
$name,
FieldType::STRING,
'default'
);

$repository->saveStringSetting(new ID($name), 'new value', 'awesomeTheme');
$stringResult = $repository->getString(new ID($name), 'awesomeTheme');

$this->assertSame('new value', $stringResult);
}

public function testSaveNotExistingStringSetting(): void
{
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$eventDispatcher->expects($this->never())
->method('dispatch');
$repository = $this->getSut(eventDispatcher: $eventDispatcher);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('Configuration "notExistingSetting" was not found for awesomeTheme');
$repository->saveStringSetting(new ID('notExistingSetting'), 'new value', 'awesomeTheme');
}

private function getSut(
?BasicContextInterface $basicContext = null,
?EventDispatcherInterface $eventDispatcher = null,
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Infrastructure/ChangeThemeSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ public function testChangeThemeSettingBoolean(): void
$repository->saveBooleanSetting($nameID, false, 'awesomeTheme');
}

public function testChangeThemeSettingString(): void
{
$nameID = new ID('stringSetting');

$settingEncoder = $this->getShopSettingEncoderMock(
FieldType::STRING,
'default',
'default'
);
$repository = $this->getSut(settingEncoder: $settingEncoder);
$repository->expects($this->once())
->method('saveSettingValue')
->with($nameID, 'awesomeTheme', 'default');

$repository->saveStringSetting($nameID, 'default', 'awesomeTheme');
}

public function getShopSettingEncoderMock(
string $fieldType,
mixed $decodedValue,
Expand Down

0 comments on commit 3ac3574

Please sign in to comment.