public function testBindsDefaultScheduleByMonthWhenNothingSelected()
 {
     $showInaccessible = true;
     $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true');
     $userId = $this->fakeUser->UserId;
     $defaultScheduleId = 10;
     $userTimezone = "America/New_York";
     $calendarType = CalendarTypes::Month;
     $requestedDay = 4;
     $requestedMonth = 3;
     $requestedYear = 2011;
     $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone);
     $startDate = Date::Parse('2011-01-01', 'UTC');
     $endDate = Date::Parse('2011-01-02', 'UTC');
     $summary = 'foo summary';
     $resourceId = 3;
     $fname = 'fname';
     $lname = 'lname';
     $referenceNumber = 'refnum';
     $resourceName = 'resource name';
     //$res = new ScheduleReservation(1, $startDate, $endDate, null, $summary, $resourceId, $userId, $fname, $lname, $referenceNumber, ReservationStatus::Created);
     $res = new ReservationItemView($referenceNumber, $startDate, $endDate, 'resource name', $resourceId, 1, null, null, $summary, null, $fname, $lname, $userId);
     $r1 = new FakeBookableResource(1, 'dude1');
     $r2 = new FakeBookableResource($resourceId, $resourceName);
     $reservations = array($res);
     $resources = array($r1, $r2);
     /** @var Schedule[] $schedules */
     $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null));
     $this->scheduleRepository->expects($this->atLeastOnce())->method('GetAll')->will($this->returnValue($schedules));
     $this->resourceService->expects($this->atLeastOnce())->method('GetAllResources')->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser))->will($this->returnValue($resources));
     $this->resourceService->expects($this->atLeastOnce())->method('GetResourceGroups')->with($this->equalTo(null), $this->equalTo($this->fakeUser))->will($this->returnValue(new ResourceGroupTree()));
     $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue(null));
     $this->repository->expects($this->atLeastOnce())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($reservations));
     $this->page->expects($this->atLeastOnce())->method('GetCalendarType')->will($this->returnValue($calendarType));
     $this->page->expects($this->atLeastOnce())->method('GetDay')->will($this->returnValue($requestedDay));
     $this->page->expects($this->atLeastOnce())->method('GetMonth')->will($this->returnValue($requestedMonth));
     $this->page->expects($this->atLeastOnce())->method('GetYear')->will($this->returnValue($requestedYear));
     $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart()));
     $this->calendarFactory->expects($this->atLeastOnce())->method('Create')->with($this->equalTo($calendarType), $this->equalTo($requestedYear), $this->equalTo($requestedMonth), $this->equalTo($requestedDay), $this->equalTo($userTimezone))->will($this->returnValue($month));
     $this->page->expects($this->atLeastOnce())->method('BindCalendar')->with($this->equalTo($month));
     $details = new CalendarSubscriptionDetails(true);
     $this->subscriptionService->expects($this->once())->method('ForSchedule')->with($this->equalTo($defaultScheduleId))->will($this->returnValue($details));
     $this->page->expects($this->atLeastOnce())->method('BindSubscription')->with($this->equalTo($details));
     $calendarFilters = new CalendarFilters($schedules, $resources, null, null, new ResourceGroupTree());
     $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters));
     $this->presenter->PageLoad($this->fakeUser, $userTimezone);
     $actualReservations = $month->Reservations();
     $expectedReservations = CalendarReservation::FromScheduleReservationList($reservations, $resources, $this->fakeUser);
     $this->assertEquals($expectedReservations, $actualReservations);
 }
 public function testBindsEmptyCalendarToPageWhenNoReservationsAreFound()
 {
     $userId = 10;
     $this->fakeUser->UserId = $userId;
     $userTimezone = "America/New_York";
     $calendarType = CalendarTypes::Month;
     $requestedDay = 4;
     $requestedMonth = 3;
     $requestedYear = 2011;
     $month = new CalendarMonth($requestedMonth, $requestedYear, $userTimezone);
     $reservations = array();
     $showInaccessible = true;
     $this->fakeConfig->SetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, 'true');
     $resourceId = 1;
     $resourceName = 'rn';
     $defaultScheduleId = 12;
     $r1 = new FakeBookableResource(1, 'dude1');
     $r2 = new FakeBookableResource($resourceId, $resourceName);
     $resources = array($r1, $r2);
     $resourceGroupTree = new ResourceGroupTree();
     $schedules = array(new Schedule(1, null, false, 2, null), new Schedule($defaultScheduleId, null, true, 3, null));
     $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue(null));
     $this->repository->expects($this->once())->method('GetReservationList')->with($this->equalTo($month->FirstDay()), $this->equalTo($month->LastDay()->AddDays(1)), $this->equalTo($userId), $this->equalTo(ReservationUserLevel::ALL), $this->isNull(), $this->isNull())->will($this->returnValue($reservations));
     $this->page->expects($this->once())->method('GetCalendarType')->will($this->returnValue($calendarType));
     $this->page->expects($this->once())->method('GetDay')->will($this->returnValue($requestedDay));
     $this->page->expects($this->once())->method('GetMonth')->will($this->returnValue($requestedMonth));
     $this->page->expects($this->once())->method('GetYear')->will($this->returnValue($requestedYear));
     $this->calendarFactory->expects($this->once())->method('Create')->with($this->equalTo($calendarType), $this->equalTo($requestedYear), $this->equalTo($requestedMonth), $this->equalTo($requestedDay), $this->equalTo($userTimezone))->will($this->returnValue($month));
     $this->page->expects($this->once())->method('BindCalendar')->with($this->equalTo($month));
     $details = new CalendarSubscriptionDetails(true);
     $this->subscriptionService->expects($this->once())->method('ForUser')->with($this->equalTo($userId))->will($this->returnValue($details));
     $this->page->expects($this->once())->method('BindSubscription')->with($this->equalTo($details));
     $this->scheduleRepository->expects($this->atLeastOnce())->method('GetAll')->will($this->returnValue($schedules));
     $this->resourceService->expects($this->atLeastOnce())->method('GetAllResources')->with($this->equalTo($showInaccessible), $this->equalTo($this->fakeUser))->will($this->returnValue($resources));
     $this->resourceService->expects($this->atLeastOnce())->method('GetResourceGroups')->with($this->anything(), $this->equalTo($this->fakeUser))->will($this->returnValue($resourceGroupTree));
     $this->page->expects($this->atLeastOnce())->method('SetFirstDay')->with($this->equalTo($schedules[1]->GetWeekdayStart()));
     $calendarFilters = new CalendarFilters($schedules, $resources, null, null, $resourceGroupTree);
     $this->page->expects($this->atLeastOnce())->method('BindFilters')->with($this->equalTo($calendarFilters));
     $this->presenter->PageLoad($this->fakeUser, $userTimezone);
 }
 public function testAddsReservationsToCalendar()
 {
     $startsBeforeMonth = new ReservationItemView();
     $startsBeforeMonth->StartDate = Date::Parse('2011-11-25', 'UTC');
     $startsBeforeMonth->EndDate = Date::Parse('2011-12-01 12:25', 'UTC');
     $startsBeforeMonth->ResourceName = 'Something Fun';
     $startsBeforeMonth->UserLevelId = ReservationUserLevel::OWNER;
     $endsAfterMonth = new ReservationItemView();
     $endsAfterMonth->StartDate = Date::Parse('2011-12-25', 'UTC');
     $endsAfterMonth->EndDate = Date::Parse('2012-01-25', 'UTC');
     $endsAfterMonth->ResourceName = 'Something Fun';
     $endsAfterMonth->UserLevelId = ReservationUserLevel::PARTICIPANT;
     $firstDayOnly = new ReservationItemView();
     $firstDayOnly->StartDate = Date::Parse('2011-12-01 14:00', 'UTC');
     $firstDayOnly->EndDate = Date::Parse('2011-12-01 16:25', 'UTC');
     $firstDayOnly->ResourceName = 'Something Fun';
     $firstDayOnly->UserLevelId = ReservationUserLevel::OWNER;
     $secondAndThirdDay = new ReservationItemView();
     $secondAndThirdDay->StartDate = Date::Parse('2011-12-02 14:00', 'UTC');
     $secondAndThirdDay->EndDate = Date::Parse('2011-12-03 16:25', 'UTC');
     $secondAndThirdDay->ResourceName = 'Something Fun';
     $secondAndThirdDay->UserLevelId = ReservationUserLevel::INVITEE;
     $notInMonth = new ReservationItemView();
     $notInMonth->StartDate = Date::Parse('2011-11-02 14:00', 'UTC');
     $notInMonth->EndDate = Date::Parse('2011-11-03 16:25', 'UTC');
     $notInMonth->ResourceName = 'Something Fun';
     $notInMonth->UserLevelId = ReservationUserLevel::OWNER;
     $reservations = array($startsBeforeMonth, $endsAfterMonth, $firstDayOnly, $secondAndThirdDay, $notInMonth);
     $timezone = 'America/Chicago';
     $calendarReservations = CalendarReservation::FromViewList($reservations, $timezone, $this->fakeUser);
     $month = new CalendarMonth(12, 2011, $timezone);
     $month->AddReservations($calendarReservations);
     $expectedFirstDay = Date::Parse('2011-12-01', $timezone);
     $expectedLastDay = Date::Parse('2012-01-01', $timezone);
     $this->assertEquals($expectedFirstDay, $month->FirstDay());
     $this->assertEquals($expectedLastDay, $month->LastDay());
     $nullDay = CalendarDay::Null();
     $day1 = new CalendarDay($expectedFirstDay);
     $day1->AddReservation(CalendarReservation::FromView($startsBeforeMonth, $timezone, $this->fakeUser));
     $day1->AddReservation(CalendarReservation::FromView($firstDayOnly, $timezone, $this->fakeUser));
     $day2 = new CalendarDay($expectedFirstDay->AddDays(1));
     $day2->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $day3 = new CalendarDay($expectedFirstDay->AddDays(2));
     $day3->AddReservation(CalendarReservation::FromView($secondAndThirdDay, $timezone, $this->fakeUser));
     $weeks = $month->Weeks();
     /** @var $actualWeek1 CalendarWeek */
     $actualWeek1 = $weeks[0];
     /** @var $actualDays array|CalendarDay[] */
     $actualDays = $actualWeek1->Days();
     $this->assertEquals(5, count($weeks));
     $this->assertEquals(7, count($actualDays));
     $this->assertEquals($nullDay, $actualDays[0]);
     $this->assertEquals($nullDay, $actualDays[1]);
     $this->assertEquals($nullDay, $actualDays[2]);
     $this->assertEquals($nullDay, $actualDays[3]);
     $this->assertEquals(2, count($actualDays[4]->Reservations()));
     $this->assertEquals($day1, $actualDays[4]);
     $this->assertEquals($day2, $actualDays[5]);
     $this->assertEquals($day3, $actualDays[6]);
     $lastWeekDays = $weeks[4]->Days();
     $lastDayReservations = $lastWeekDays[6]->Reservations();
     $this->assertEquals(CalendarReservation::FromView($endsAfterMonth, $timezone, $this->fakeUser), $lastDayReservations[0]);
     $next = Date::Parse('2012-01-01', $timezone);
     $prev = Date::Parse('2011-11-01', $timezone);
     $this->assertEquals($next, $month->GetNextDate());
     $this->assertEquals($prev, $month->GetPreviousDate());
 }