Esempio n. 1
0
 /**
  * @param array|ReservationListItem[] $reservations
  * @return ReservationListing
  */
 private function Create($reservations)
 {
     $reservationListing = new ReservationListing($this->timezone);
     if ($reservations != null) {
         foreach ($reservations as $reservation) {
             $reservationListing->AddItem($reservation);
         }
     }
     return $reservationListing;
 }
 public function testReservationSpanningMultipleDaysIsReturnedOnAllOfThem()
 {
     $res1 = $this->GetReservation('2009-10-09 22:00:00', '2009-10-09 23:00:00', 1);
     // 2009-10-09 17:00:00 - 2009-10-09 18:00:00 CST
     $res2 = $this->GetReservation('2009-10-10 01:00:00', '2009-10-10 07:00:00', 2);
     // 2009-10-09 20:00:00 - 2009-10-10 02:00:00 CST
     $res3 = $this->GetReservation('2009-10-10 10:00:00', '2009-10-13 10:00:00', 1);
     // 2009-10-10 05:00:00 - 2009-10-13 05:00:00 CST
     $res4 = $this->GetReservation('2009-10-14 01:00:00', '2009-10-16 01:00:00', 2);
     // 2009-10-13 20:00:00 - 2009-10-15 20:00:00 CST
     $res5 = $this->GetReservation('2009-10-13 10:00:00', '2009-10-13 15:00:00', 1);
     // 2009-10-13 05:00:00 - 2009-10-13 10:00:00 CST
     $reservationListing = new ReservationListing("America/Chicago");
     $reservationListing->Add($res4);
     $reservationListing->Add($res1);
     $reservationListing->Add($res3);
     $reservationListing->Add($res2);
     $reservationListing->Add($res5);
     $blackout1 = new TestBlackoutItemView(1, $res1->StartDate, $res1->EndDate, $res1->ResourceId);
     $blackout2 = new TestBlackoutItemView(2, $res2->StartDate, $res2->EndDate, $res2->ResourceId);
     $reservationListing->AddBlackout($blackout1);
     $reservationListing->AddBlackout($blackout2);
     $onDate1 = $reservationListing->OnDate(Date::Parse('2009-10-09', 'CST'));
     $onDate2 = $reservationListing->OnDate(Date::Parse('2009-10-10', 'CST'));
     $onDate3 = $reservationListing->OnDate(Date::Parse('2009-10-11', 'CST'));
     $onDate4 = $reservationListing->OnDate(Date::Parse('2009-10-12', 'CST'));
     $onDate5 = $reservationListing->OnDate(Date::Parse('2009-10-13', 'CST'));
     $onDate6 = $reservationListing->OnDate(Date::Parse('2009-10-14', 'CST'));
     $onDate7 = $reservationListing->OnDate(Date::Parse('2009-10-15', 'CST'));
     $onDate8 = $reservationListing->OnDate(Date::Parse('2009-10-16', 'CST'));
     $this->assertEquals(4, $onDate1->Count(), "2 reservations 2 blackouts");
     $this->assertEquals(3, $onDate2->Count(), "2 reservations 1 blackout");
     $this->assertEquals(1, $onDate3->Count());
     $this->assertEquals(1, $onDate4->Count());
     $this->assertEquals(3, $onDate5->Count());
     $this->assertEquals(1, $onDate6->Count());
     $this->assertEquals(1, $onDate7->Count());
     $this->assertEquals(0, $onDate8->Count());
     $this->assertEquals(4, $reservationListing->ForResource(1)->Count());
     $this->assertEquals(2, $onDate1->ForResource(1)->Count());
     $this->assertEquals(2, count($reservationListing->OnDateForResource(Date::Parse('2009-10-09', 'CST'), 1)));
     $this->assertEquals(2, count($reservationListing->OnDateForResource(Date::Parse('2009-10-09', 'CST'), 2)));
     $this->assertEquals(1, count($reservationListing->OnDateForResource(Date::Parse('2009-10-10', 'CST'), 1)));
     $this->assertEquals(0, count($reservationListing->OnDateForResource(Date::Parse('2009-10-10', 'CST'), 999)));
     $date1Items = $onDate1->Reservations();
     $this->assertTrue(in_array(new ReservationListItem($res1), $date1Items));
     $this->assertTrue(in_array(new ReservationListItem($res2), $date1Items));
     $this->assertTrue(in_array(new BlackoutListItem($blackout1), $date1Items));
     $this->assertTrue(in_array(new BlackoutListItem($blackout2), $date1Items));
     $date2Items = $onDate2->Reservations();
     $this->assertTrue(in_array(new ReservationListItem($res2), $date2Items));
     $this->assertTrue(in_array(new ReservationListItem($res3), $date2Items));
     $this->assertTrue(in_array(new BlackoutListItem($blackout2), $date2Items));
 }