public function testEnsuresThatStartMustBeBeforeEnd() { $start = Date::Parse('2010-01-01'); $reservationDate = new DateRange($start, $start->AddDays(-1)); $reservationSeries = new TestReservationSeries(); $reservationSeries->WithDuration($reservationDate); $rule = new ReservationDateTimeRule(); $result = $rule->Validate($reservationSeries); $this->assertFalse($result->IsValid()); }
public function testOkIfLatestInstanceIsBeforeTheMaximumNoticeTime() { $resource = new FakeBookableResource(1, "2"); $resource->SetMaxNotice("1h00m"); $reservation = new TestReservationSeries(); $reservation->WithResource($resource); $duration = new DateRange(Date::Now(), Date::Now()); $reservation->WithDuration($duration); $rule = new ResourceMaximumNoticeRule(); $result = $rule->Validate($reservation); $this->assertTrue($result->IsValid()); }
public function testOkIfReservationIsShorterThanTheMaximumDuration() { $resource = new FakeBookableResource(1, "2"); $resource->SetMaxLength("25h00m"); $reservation = new TestReservationSeries(); $reservation->WithResource($resource); $duration = new DateRange(Date::Now(), Date::Now()->AddDays(1)); $reservation->WithDuration($duration); $rule = new ResourceMaximumDurationRule(); $result = $rule->Validate($reservation); $this->assertTrue($result->IsValid()); }
public function testGetsConflictingReservationTimesForSingleDateSingleResourceWithBufferTimes() { $startDate = Date::Parse('2010-04-04 06:00', 'UTC'); $endDate = Date::Parse('2010-04-04 07:00', 'UTC'); $bufferTime = 60 * 60; $reservation = new TestReservationSeries(); $resource1 = new FakeBookableResource(100, null); $resource1->SetBufferTime($bufferTime); $reservation->WithDuration(new DateRange($startDate, $endDate)); $reservation->WithResource($resource1); $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource1->GetId()); $conflict1->WithBufferTime($bufferTime); $conflict2 = new TestReservationItemView(3, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource1->GetId()); $conflict2->WithBufferTime($bufferTime); $nonConflict1 = new TestReservationItemView(4, Date::Parse('2010-04-04 06:00', 'UTC'), Date::Parse('2010-04-04 07:30', 'UTC'), 2); $nonConflict1->WithBufferTime($bufferTime); $nonConflict2 = new TestReservationItemView(5, Date::Parse('2010-04-04 02:30', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId()); $nonConflict2->WithBufferTime($bufferTime); $nonConflict3 = new TestReservationItemView(6, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId()); $nonConflict3->WithBufferTime($bufferTime); $strategy = $this->getMock('IResourceAvailabilityStrategy'); $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60)))->will($this->returnValue(array($conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3))); $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC'); $result = $rule->Validate($reservation); $this->assertFalse($result->IsValid()); }
public function testValidatesEachDateThatAReservationRepeatsOn() { $start = Date::Parse('2010-01-01'); $end = Date::Parse('2010-01-02'); $reservationDates = new DateRange($start, $end); $twoRepetitions = new RepeatWeekly(1, $start->AddDays(14), array($start->Weekday())); $repeatDates = $twoRepetitions->GetDates($reservationDates); $reservation = new TestReservationSeries(); $reservation->WithResource(new FakeBookableResource(1)); $reservation->WithDuration($reservationDates); $reservation->WithRepeatOptions($twoRepetitions); $strategy = $this->getMock('IResourceAvailabilityStrategy'); $strategy->expects($this->exactly(1 + count($repeatDates)))->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue(array())); $rule = new ResourceAvailabilityRule($strategy, 'UTC'); $result = $rule->Validate($reservation); }
public function testUnlimitedQuantity() { $accessory1 = new ReservationAccessory(1, 5); $quantityAvailable = null; $startDate = Date::Parse('2010-04-04', 'UTC'); $endDate = Date::Parse('2010-04-05', 'UTC'); $reservation = new TestReservationSeries(); $reservation->WithAccessory($accessory1); $dr1 = new DateRange($startDate, $endDate); $reservation->WithDuration($dr1); $this->accessoryRepository->expects($this->at(0))->method('LoadById')->with($accessory1->AccessoryId)->will($this->returnValue(new Accessory($accessory1->AccessoryId, 'name1', $quantityAvailable))); $result = $this->rule->Validate($reservation); $this->assertTrue($result->IsValid()); }