Skip to content

Commit

Permalink
OXDEV-7667: Dispatch ThemeSettingChangedEvent only if value changed
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Dec 11, 2023
1 parent 8febff8 commit 4c5aa87
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/Theme/Infrastructure/ThemeSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,17 @@ protected function saveSettingValue(string $name, string $themeId, string $value
'value' => $value
]);

$queryBuilder->execute();

$this->eventDispatcher->dispatch(
new ThemeSettingChangedEvent(
$name,
$shopId,
$themeId
)
);
$result = $queryBuilder->execute();

if ($result !== 0) {
$this->eventDispatcher->dispatch(
new ThemeSettingChangedEvent(
$name,
$shopId,
$themeId
)
);
}
}

protected function saveSettingAsType(string $settingType, string $name, string $themeId, mixed $value): void
Expand Down
34 changes: 26 additions & 8 deletions tests/Integration/Infrastructure/ThemeSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public function testSaveAndGetIntegerSetting(): void

$sut->saveIntegerSetting($name, 124, 'awesomeTheme');
$integerResult = $sut->getInteger($name, 'awesomeTheme');

$this->assertSame(124, $integerResult);

// Check if dispatcher isn't executed again if value is the same
$sut->saveIntegerSetting($name, 124, 'awesomeTheme');
}

public function testSaveAndGetFloatSetting(): void
Expand All @@ -61,8 +63,10 @@ public function testSaveAndGetFloatSetting(): void

$sut->saveFloatSetting($name, 1.24, 'awesomeTheme');
$floatResult = $sut->getFloat($name, 'awesomeTheme');

$this->assertSame(1.24, $floatResult);

// Check if dispatcher isn't executed again if value is the same
$sut->saveFloatSetting($name, 1.24, 'awesomeTheme');
}

public function testSaveAndGetBooleanSetting(): void
Expand All @@ -81,9 +85,11 @@ public function testSaveAndGetBooleanSetting(): void
);

$sut->saveBooleanSetting($name, true, 'awesomeTheme');
$floatResult = $sut->getBoolean($name, 'awesomeTheme');
$booleanResult = $sut->getBoolean($name, 'awesomeTheme');
$this->assertSame(true, $booleanResult);

$this->assertSame(true, $floatResult);
// Check if dispatcher isn't executed again if value is the same
$sut->saveBooleanSetting($name, true, 'awesomeTheme');
}

public function testSaveAndGetStringSetting(): void
Expand All @@ -103,8 +109,10 @@ public function testSaveAndGetStringSetting(): void

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

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

// Check if dispatcher isn't executed again if value is the same
$sut->saveStringSetting($name, 'new value', 'awesomeTheme');
}

public function testSaveAndGetSelectSetting(): void
Expand All @@ -124,8 +132,10 @@ public function testSaveAndGetSelectSetting(): void

$sut->saveSelectSetting($name, 'new select value', 'awesomeTheme');
$stringResult = $sut->getSelect($name, 'awesomeTheme');

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

// Check if dispatcher isn't executed again if value is the same
$sut->saveSelectSetting($name, 'new select value', 'awesomeTheme');
}

public function testSaveAndGetCollectionSetting(): void
Expand All @@ -145,8 +155,10 @@ public function testSaveAndGetCollectionSetting(): void

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

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

// Check if dispatcher isn't executed again if value is the same
$sut->saveCollectionSetting($name, ['nice', 'cool', 'values'], 'awesomeTheme');
}

public function testSaveAndGetAssocCollectionSetting(): void
Expand All @@ -170,8 +182,14 @@ public function testSaveAndGetAssocCollectionSetting(): void
'awesomeTheme'
);
$assocCollectionResult = $sut->getAssocCollection($name, 'awesomeTheme');

$this->assertSame(['first' => '10', 'second' => '20', 'third' => '60'], $assocCollectionResult);

// Check if dispatcher isn't executed again if value is the same
$sut->saveAssocCollectionSetting(
$name,
['first' => '10', 'second' => '20', 'third' => '60'],
'awesomeTheme'
);
}

public function testGetSettingsList(): void
Expand Down

0 comments on commit 4c5aa87

Please sign in to comment.