Skip to content

Commit

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

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

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

public function saveAssocCollectionSetting(ID $name, array $value, string $themeId): void
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,43 @@ public function testSaveNotExistingStringSetting(): void
$repository->saveStringSetting(new ID('notExistingSetting'), 'new value', 'awesomeTheme');
}

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

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

$this->createThemeSetting(
$queryBuilderFactory,
$name,
FieldType::ARRAY,
'a:2:{i:0;s:4:"nice";i:1;s:6:"values";}'
);

$repository->saveCollectionSetting(new ID($name), ['nice', 'cool', 'values'], 'awesomeTheme');
$collectionResult = $repository->getCollection(new ID($name), 'awesomeTheme');

$this->assertSame(['nice','cool','values'], $collectionResult);
}

public function testSaveNotExistingCollectionSetting(): 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->saveCollectionSetting(new ID('notExistingSetting'), ['nice', 'cool', 'values'], '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 @@ -83,6 +83,23 @@ public function testChangeThemeSettingString(): void
$repository->saveStringSetting($nameID, 'default', 'awesomeTheme');
}

public function testChangeThemeSettingCollection(): void
{
$nameID = new ID('arraySetting');

$settingEncoder = $this->getShopSettingEncoderMock(
FieldType::ARRAY,
['nice', 'values'],
'a:2:{i:0;s:4:"nice";i:1;s:6:"values";}'
);
$repository = $this->getSut(settingEncoder: $settingEncoder);
$repository->expects($this->once())
->method('saveSettingValue')
->with($nameID, 'awesomeTheme', 'a:2:{i:0;s:4:"nice";i:1;s:6:"values";}');

$repository->saveCollectionSetting($nameID, ['nice', 'values'], 'awesomeTheme');
}

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

0 comments on commit b3a30ba

Please sign in to comment.