Adjust set highlight in Demand

This commit is contained in:
Daniel Siepmann 2022-07-12 09:50:21 +02:00
parent 9678884de4
commit 605ad9f9ae
2 changed files with 54 additions and 2 deletions

View file

@ -115,7 +115,7 @@ class DateDemand
} }
if ($submittedValues['highlight'] ?? false) { if ($submittedValues['highlight'] ?? false) {
$instance->setHighlight($settings['highlight'] ?? false); $instance->setHighlight(true);
} }
if (isset($submittedValues['start']) && $submittedValues['start'] !== '') { if (isset($submittedValues['start']) && $submittedValues['start'] !== '') {

View file

@ -266,7 +266,6 @@ class DateDemandTest extends TestCase
*/ */
public function returnsEndsOnSameDayIfBothAreOnDifferentDays(): void public function returnsEndsOnSameDayIfBothAreOnDifferentDays(): void
{ {
$result = DateDemand::createFromRequestValues( $result = DateDemand::createFromRequestValues(
[ [
'start' => '2022-07-12', 'start' => '2022-07-12',
@ -280,4 +279,57 @@ class DateDemandTest extends TestCase
$result->getEndsOnSameDay() $result->getEndsOnSameDay()
); );
} }
/**
* @test
* @dataProvider possibleSubmittedHighlights
*
* @param mixed $highlight
*/
public function returnsHighlightIfSet($highlight): void
{
$result = DateDemand::createFromRequestValues(
[
'highlight' => $highlight,
],
[
]
);
self::assertTrue($result->getHighlight());
}
public function possibleSubmittedHighlights(): \Generator
{
yield 'true' => ['highlight' => true];
yield '1 as integer' => ['highlight' => 1];
yield '1 as string' => ['highlight' => '1'];
}
/**
* @test
* @dataProvider possibleSubmittedFalsyHighlights
*
* @param mixed $highlight
*/
public function returnsNoHighlightIfNotSet($highlight): void
{
$result = DateDemand::createFromRequestValues(
[
'highlight' => $highlight,
],
[
]
);
self::assertFalse($result->getHighlight());
}
public function possibleSubmittedFalsyHighlights(): \Generator
{
yield 'false' => ['highlight' => false];
yield '0 as integer' => ['highlight' => 0];
yield '0 as string' => ['highlight' => '0'];
yield 'empty string' => ['highlight' => ''];
}
} }