diff --git a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php index 9641ede5f..d2e5c9c78 100644 --- a/app/Models/Foundation/Summit/Events/Presentations/Presentation.php +++ b/app/Models/Foundation/Summit/Events/Presentations/Presentation.php @@ -994,7 +994,7 @@ public function getAttendingMedia() /** * @param bool $attending_media */ - public function setAttendingMedia($attending_media) + public function setAttendingMedia(bool $attending_media): void { $this->attending_media = $attending_media; } diff --git a/app/Models/Foundation/Summit/Factories/PresentationFactory.php b/app/Models/Foundation/Summit/Factories/PresentationFactory.php index 973b8b822..ecb24f75e 100644 --- a/app/Models/Foundation/Summit/Factories/PresentationFactory.php +++ b/app/Models/Foundation/Summit/Factories/PresentationFactory.php @@ -108,8 +108,8 @@ public static function populate(Presentation $presentation, array $payload, $onl if (isset($payload['attendees_expected_learnt'])) $presentation->setAttendeesExpectedLearnt(html_entity_decode($payload['attendees_expected_learnt'])); - $presentation->setAttendingMedia(isset($payload['attending_media']) ? - filter_var($payload['attending_media'], FILTER_VALIDATE_BOOLEAN) : 0); + if (isset($payload['attending_media'])) + $presentation->setAttendingMedia(filter_var($payload['attending_media'], FILTER_VALIDATE_BOOLEAN)); if (isset($payload['to_record'])) $presentation->setToRecord(boolval($payload['to_record'])); diff --git a/tests/Unit/Entities/PresentationFactoryTest.php b/tests/Unit/Entities/PresentationFactoryTest.php new file mode 100644 index 000000000..18f543856 --- /dev/null +++ b/tests/Unit/Entities/PresentationFactoryTest.php @@ -0,0 +1,74 @@ +assertSame(false, $presentation->getAttendingMedia()); + } + + public function testPayloadWithoutAttendingMediaKeepsCurrentValue(): void + { + $presentation = new Presentation(); + $presentation->setAttendingMedia(true); + + PresentationFactory::populate($presentation, ['title' => 'Edited title']); + + $this->assertSame(true, $presentation->getAttendingMedia()); + } + + public static function attendingMediaPayloadProvider(): array + { + return [ + 'bool true' => [true, true], + 'string true' => ['true', true], + 'string 1' => ['1', true], + 'int 1' => [1, true], + 'bool false' => [false, false], + 'string false' => ['false', false], + 'string 0' => ['0', false], + 'int 0' => [0, false], + ]; + } + + #[DataProvider('attendingMediaPayloadProvider')] + public function testAttendingMediaPayloadIsStoredAsStrictBool($payload_value, bool $expected): void + { + $presentation = new Presentation(); + $presentation->setAttendingMedia(!$expected); + + PresentationFactory::populate($presentation, ['attending_media' => $payload_value]); + + $this->assertSame($expected, $presentation->getAttendingMedia()); + } +}