diff --git a/app/Models/BuildingClosure.php b/app/Models/BuildingClosure.php index 8a88905c89..fa8ae4ac39 100644 --- a/app/Models/BuildingClosure.php +++ b/app/Models/BuildingClosure.php @@ -3,10 +3,12 @@ namespace App\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Factories\HasFactory; class BuildingClosure extends AbstractModel { use Transformable; + use HasFactory; protected $presenter = 'App\Presenters\BuildingClosurePresenter'; protected $presenterAdmin = 'App\Presenters\BuildingClosurePresenter'; @@ -32,6 +34,15 @@ class BuildingClosure extends AbstractModel public $dates = ['date_start', 'date_end']; + /** + * The model's default values for attributes. + * + * @var array + */ + protected $attributes = [ + 'published' => true, + ]; + public function scopeToday($query, $type = 0) { $today = Carbon::today(); diff --git a/app/Presenters/HoursPresenter.php b/app/Presenters/HoursPresenter.php index fda14b5280..b9d443937f 100644 --- a/app/Presenters/HoursPresenter.php +++ b/app/Presenters/HoursPresenter.php @@ -270,9 +270,10 @@ private function getWhenFields($when) private function isMuseumClosedToday($when) { - $isClosed = $this->getWhenFields($when)['is_closed']; + $isHoursClosed = $this->getWhenFields($when)['is_closed']; + $isBuildingClosureClosed = $this->entity->buildingClosures()->where('date_start', '>=', $when)->where('date_end', '<=', $when)->get(); - return $isClosed ?? false; + return $isHoursClosed || $isBuildingClosureClosed->isNotEmpty(); } private function isBeforePublicOpen($when) diff --git a/database/factories/BuildingClosureFactory.php b/database/factories/BuildingClosureFactory.php new file mode 100644 index 0000000000..c8b90ceefa --- /dev/null +++ b/database/factories/BuildingClosureFactory.php @@ -0,0 +1,30 @@ + true, + 'type' => 0, + 'date_start' => today(), + 'date_end' => today(), + 'closure_copy' => 'The museum is closed', + ]; + } +} diff --git a/tests/Unit/HourTest.php b/tests/Unit/HourTest.php index 02af516b91..cb28a3d686 100644 --- a/tests/Unit/HourTest.php +++ b/tests/Unit/HourTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit; use App\Models\Hour; +use App\Models\BuildingClosure; use Carbon\Carbon; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Tests\CreatesApplication; @@ -18,7 +19,7 @@ protected function setUp(): void { parent::setUp(); - $this->hour = Hour::factory()->make([ + $this->hour = Hour::factory()->create([ 'monday_is_closed' => false, 'monday_member_open' => 'PT10H00M', 'monday_member_close' => 'PT11H00M', @@ -48,6 +49,13 @@ protected function setUp(): void 'sunday_public_close' => 'PT17H00M', ]); + $this->hour->buildingClosures()->save(BuildingClosure::factory()->create([ + 'date_start' => Carbon::now()->next('Thursday'), + 'date_end' => Carbon::now()->next('Thursday'), + 'closure_copy' => 'The museum is closed on Thursday', + 'type' => 0, + ])); + $this->hourAllClosed = Hour::factory()->make([ 'monday_is_closed' => true, 'tuesday_is_closed' => true, @@ -197,6 +205,14 @@ public function it_displays_a_closed_day_before_an_open_day() $this->assertEquals(null, $this->getHoursHeader()); } + /** @test */ + public function it_displays_when_thursday_has_an_emergency_closure(): void + { + $this->travelTo(Carbon::now('America/Chicago')->next('Thursday')->subDays(2)); + $this->assertEquals('Closed today, next open Friday.', $this->getStatusHeader()); + $this->assertEquals(null, $this->getHoursHeader()); + } + /** @test */ public function it_displays_when_closed_all_days() {