Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down
74 changes: 74 additions & 0 deletions tests/Unit/Entities/PresentationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Tests\Unit\Entities;

/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Models\Foundation\Summit\Factories\PresentationFactory;
use models\summit\Presentation;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;

/**
* attending_media is a boolean column. The payload may omit it (summit-admin strips it
* and SelectionPlan::curatePayloadByPresentationAllowedQuestions() drops it when the
* selection plan does not allow that question), in which case the stored value must be
* left alone; when present it must land as a strict bool, never as int 0 / 1.
*/
class PresentationFactoryTest extends TestCase
{
public function testPayloadWithoutAttendingMediaLeavesNewPresentationAsBoolFalse(): void
{
$presentation = new Presentation();

PresentationFactory::populate($presentation, []);

$this->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());
}
}
Loading