コード例 #1
0
 public function testLoadsBlackoutSeriesByBlackoutId()
 {
     $id = 19191;
     $seriesId = 110101;
     $ownerId = 919199;
     $title = 'title';
     $description = 'description';
     $tz = 'UTC';
     $repeatType = RepeatType::Daily;
     $repeatDaily = new RepeatDaily(1, Date::Parse('2013-04-15', $tz));
     $b1Start = Date::Parse('2013-04-14 12:30:00', $tz);
     $b1End = Date::Parse('2013-04-14 13:30:00', $tz);
     $series = new BlackoutSeriesRow();
     $series->With($seriesId, $ownerId, $title, $repeatType, $repeatDaily->ConfigurationString(), $b1Start, $b1End);
     $instances = new BlackoutInstanceRow();
     $instances->With($seriesId, 1, $b1Start->ToDatabase(), $b1End->ToDatabase());
     $instances->With($seriesId, 2, Date::Parse('2013-04-15 12:30:00', $tz)->ToDatabase(), Date::Parse('2013-04-15 13:30:00', $tz)->ToDatabase());
     $resources = new BlackoutResourceRow();
     $resources->With(1, 'r1', 2, 3, 4);
     $resources->With(2, 'r2', 4);
     $this->db->SetRow(0, $series->Rows());
     $this->db->SetRow(1, $instances->Rows());
     $this->db->SetRow(2, $resources->Rows());
     $loadBlackoutCommand = new GetBlackoutSeriesByBlackoutIdCommand($id);
     $loadBlackoutInstancesCommand = new GetBlackoutInstancesCommand($seriesId);
     $loadBlackoutResourcesCommand = new GetBlackoutResourcesCommand($seriesId);
     $series = $this->repository->LoadByBlackoutId($id);
     $this->assertEquals($loadBlackoutCommand, $this->db->_Commands[0]);
     $this->assertTrue($this->db->ContainsCommand($loadBlackoutInstancesCommand));
     $this->assertTrue($this->db->ContainsCommand($loadBlackoutResourcesCommand));
     $this->assertEquals($seriesId, $series->Id());
     $this->assertEquals($ownerId, $series->OwnerId());
     $this->assertEquals($title, $series->Title());
     $this->assertEquals($repeatType, $series->RepeatType());
     $this->assertEquals($repeatDaily->ConfigurationString(), $series->RepeatConfigurationString());
     $this->assertEquals(2, count($series->AllBlackouts()));
     $instances = $series->AllBlackouts();
     $this->assertEquals($b1Start, $instances[0]->StartDate());
     $this->assertEquals($b1End, $instances[0]->EndDate());
     $this->assertEquals(count($resources->Rows()), count($series->Resources()));
     $this->assertEquals($b1Start, $series->CurrentBlackout()->StartDate());
 }
コード例 #2
0
 public function testReturnsAllBlackoutInstancesWithinDateRange()
 {
     $dateRange = new TestDateRange();
     $start = Date::Now();
     $end = Date::Now();
     $instanceId = 12;
     $seriesId = 222;
     $resourceId = 333;
     $userid = 444;
     $scheduleId = 555;
     $resourceName = 'resource 123';
     $firstName = 'f';
     $lastName = 'l';
     $title = 'title';
     $description = 'description';
     $repeatType = RepeatType::Daily;
     $repeat = new RepeatDaily(1, $end->AddDays(2));
     $repeatOptions = $repeat->ConfigurationString();
     $rows[] = $this->GetBlackoutRow($instanceId, $start, $end, $resourceId, $userid, $scheduleId, $title, $description, $firstName, $lastName, $resourceName, $seriesId, $repeatType, $repeatOptions);
     $rows[] = $this->GetBlackoutRow("1", Date::Now(), Date::Now());
     $this->db->SetRows($rows);
     $getBlackoutsCommand = new GetBlackoutListCommand($dateRange->GetBegin(), $dateRange->GetEnd(), ReservationViewRepository::ALL_SCHEDULES);
     $blackouts = $this->repository->GetBlackoutsWithin($dateRange);
     $b = new BlackoutItemView($instanceId, $start->ToUtc(), $end->ToUtc(), $resourceId, $userid, $scheduleId, $title, $description, $firstName, $lastName, $resourceName, $seriesId, $repeatOptions, $repeatType);
     $this->assertEquals($getBlackoutsCommand, $this->db->_LastCommand);
     $this->assertEquals(2, count($blackouts));
     $this->assertEquals($b, $blackouts[0]);
 }
コード例 #3
0
 public function testConfigurationStringCanBeDeserialized()
 {
     $terminationDate = Date::Parse('2010-12-12 01:06:07', 'UTC');
     $dateString = $terminationDate->ToDatabase();
     $interval = 10;
     // none
     $config = RepeatConfiguration::Create(RepeatType::None, '');
     $this->assertEquals(RepeatType::None, $config->Type);
     // daily
     $daily = new RepeatDaily($interval, $terminationDate);
     $config = RepeatConfiguration::Create($daily->RepeatType(), $daily->ConfigurationString());
     $this->assertEquals(RepeatType::Daily, $config->Type);
     $this->assertEquals(10, $config->Interval);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     // weekly
     $weekdays = array(1, 3, 4, 5);
     $weekly = new RepeatWeekly($interval, $terminationDate, $weekdays);
     $config = RepeatConfiguration::Create($weekly->RepeatType(), $weekly->ConfigurationString());
     $this->assertEquals(RepeatType::Weekly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals($weekdays, $config->Weekdays);
     // day of month
     $dayOfMonth = new RepeatDayOfMonth($interval, $terminationDate);
     $config = RepeatConfiguration::Create($dayOfMonth->RepeatType(), $dayOfMonth->ConfigurationString());
     $this->assertEquals(RepeatType::Monthly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals(RepeatMonthlyType::DayOfMonth, $config->MonthlyType);
     // weekday of month
     $weekOfMonth = new RepeatWeekDayOfMonth($interval, $terminationDate);
     $config = RepeatConfiguration::Create($weekOfMonth->RepeatType(), $weekOfMonth->ConfigurationString());
     $this->assertEquals(RepeatType::Monthly, $config->Type);
     $this->assertEquals($terminationDate, $config->TerminationDate);
     $this->assertEquals(RepeatMonthlyType::DayOfWeek, $config->MonthlyType);
     // yearly
     $yearly = new RepeatYearly($interval, $terminationDate);
     $config = RepeatConfiguration::Create($yearly->RepeatType(), $yearly->ConfigurationString());
     $this->assertEquals(RepeatType::Yearly, $config->Type);
     $this->assertEquals(10, $config->Interval);
     $this->assertEquals($terminationDate, $config->TerminationDate);
 }
コード例 #4
0
 public function testChecksAndCreatesForEachRecurringDate()
 {
     $userId = $this->fakeUser->UserId;
     $start = Date::Parse('2011-01-01 01:01:01');
     $end = Date::Parse('2011-01-01 02:02:02');
     $range = new DateRange($start, $end);
     $resourceId = 1;
     $resourceIds = array($resourceId);
     $title = 'title';
     $repeatEnd = $start->AddDays(3);
     $repeatDaily = new RepeatDaily(1, $repeatEnd);
     $repeatDates = $repeatDaily->GetDates($range);
     /** @var $allDates DateRange[] */
     $allDates = array_merge(array($range), $repeatDates);
     $series = BlackoutSeries::Create($userId, $title, $range);
     $series->Repeats($repeatDaily);
     $series->AddResourceId($resourceId);
     foreach ($repeatDates as $date) {
         $series->AddBlackout(new Blackout($date));
     }
     for ($i = 0; $i < count($allDates); $i++) {
         $date = $allDates[$i];
         $this->reservationViewRepository->expects($this->at($i))->method('GetBlackoutsWithin')->with($this->equalTo($date))->will($this->returnValue(array()));
         $this->reservationViewRepository->expects($this->at($i + count($allDates)))->method('GetReservationList')->with($this->equalTo($date->GetBegin()), $this->equalTo($date->GetEnd()))->will($this->returnValue(array()));
     }
     $this->blackoutRepository->expects($this->at(0))->method('Add')->with($this->equalTo($series));
     $this->assertEquals(4, $i, 'should create 4 blackouts');
     $result = $this->service->Add($range, $resourceIds, $title, $this->conflictHandler, $repeatDaily);
     $this->assertTrue($result->WasSuccessful());
 }