public function setup() { parent::setup(); $this->now = Date::Parse('2011-07-20 13:41:22', 'America/Chicago'); Date::_SetNow($this->now); $this->timezone = $this->now->Timezone(); }
public function setup() { parent::setup(); Date::_SetNow(new Date()); $this->page = new FakeAnnouncementsControl(); $this->announcements = new FakeAnnouncementRepository(); $this->presenter = new AnnouncementPresenter($this->page, $this->announcements); }
public function setup() { Date::_SetNow(Date::Now()); $this->db = new FakeDatabase(); $this->fakeServer = new FakeServer(); $this->fakeEmailService = new FakeEmailService(); $this->fakeConfig = new FakeConfig(); $this->fakeConfig->SetKey(ConfigKeys::DEFAULT_TIMEZONE, 'America/Chicago'); $this->fakeResources = new FakeResources(); $this->fakeUser = $this->fakeServer->UserSession; $this->fakePluginManager = new FakePluginManager(); $this->fileSystem = new FakeFileSystem(); ServiceLocator::SetDatabase($this->db); ServiceLocator::SetServer($this->fakeServer); ServiceLocator::SetEmailService($this->fakeEmailService); ServiceLocator::SetFileSystem($this->fileSystem); Configuration::SetInstance($this->fakeConfig); Resources::SetInstance($this->fakeResources); PluginManager::SetInstance($this->fakePluginManager); }
public function testGroupsReservations() { $now = Date::Parse('2011-03-24'); // thursday Date::_SetNow($now); $today = new ReservationItemView('1', $now, $now); $tomorrow = new ReservationItemView('2', $now->AddDays(1), $now->AddDays(1)); // friday $thisWeek = new ReservationItemView('3', $now->AddDays(2), $now->AddDays(2)); // saturday $nextWeek = new ReservationItemView('3', $now->AddDays(3), $now->AddDays(3)); // sunday of next week $reservations[] = $today; $reservations[] = $tomorrow; $reservations[] = $thisWeek; $reservations[] = $nextWeek; $this->repository->expects($this->once())->method('GetReservationList')->with($this->anything(), $this->anything(), $this->anything())->will($this->returnValue($reservations)); $this->control->expects($this->once())->method('BindToday')->with($this->equalTo(array($today))); $this->control->expects($this->once())->method('BindTomorrow')->with($this->equalTo(array($tomorrow))); $this->control->expects($this->once())->method('BindThisWeek')->with($this->equalTo(array($thisWeek))); $this->control->expects($this->once())->method('BindNextWeek')->with($this->equalTo(array($nextWeek))); $presenter = new UpcomingReservationsPresenter($this->control, $this->repository); $presenter->PageLoad(); }
public function testCorrectDatesAreUsedWhenTheUsersTimezoneIsBehindByAWeek() { $timezone = 'PST'; // sunday $currentServerDate = Date::Create(2009, 07, 19, 00, 30, 00, 'CST'); Date::_SetNow($currentServerDate); $startDay = 0; $daysVisible = 7; // previous sunday $expectedStart = Date::Create(2009, 07, 12, 00, 00, 00, $timezone); $expectedEnd = $expectedStart->AddDays($daysVisible); $expectedScheduleDates = new DateRange($expectedStart, $expectedEnd); $user = new UserSession(1); $user->Timezone = $timezone; $this->fakeConfig->SetTimezone('CST'); $schedule = $this->getMock('ISchedule'); $schedulePage = $this->getMock('ISchedulePage'); $schedulePage->expects($this->once())->method('GetSelectedDate')->will($this->returnValue(null)); $schedule->expects($this->once())->method('GetWeekdayStart')->will($this->returnValue($startDay)); $schedule->expects($this->once())->method('GetDaysVisible')->will($this->returnValue($daysVisible)); $pageBuilder = new SchedulePageBuilder(); $dates = $pageBuilder->GetScheduleDates($user, $schedule, $schedulePage); $this->assertEquals($expectedScheduleDates, $dates); }
public function testWhenNotConstrainedByTime() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::NONE); $now = Date::Parse('2011-04-04 12:13:15', 'UTC'); Date::_SetNow($now); $start = Date::Parse('2011-04-04 12:13:14', 'UTC'); $end = $start->AddDays(5); $reservation = new TestReservationSeries(); $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end))); $rule = new ReservationStartTimeRule($this->scheduleRepository); $result = $rule->Validate($reservation); $this->assertTrue($result->IsValid()); }
public function teardown() { parent::teardown(); Date::_SetNow(null); }
public function testAddReservationWithOneUserAndOneResource() { $seriesId = 100; $reservationId = 428; $userId = 232; $resourceId = 10978; $title = 'title'; $description = 'description'; $startCst = '2010-02-15 16:30'; $endCst = '2010-02-16 17:00'; $duration = DateRange::Create($startCst, $endCst, 'CST'); $levelId = ReservationUserLevel::OWNER; $repeatOptions = new RepeatNone(); $participantIds = array(2, 9); $inviteeIds = array(20, 90); $accessory = new ReservationAccessory(928, 3); $attribute = new AttributeValue(1, 'value'); $attachment = new FakeReservationAttachment(1); $allowParticipation = true; $startUtc = Date::Parse($startCst, 'CST')->ToUtc(); $endUtc = Date::Parse($endCst, 'CST')->ToUtc(); $dateCreatedUtc = Date::Parse('2010-01-01 12:14:16', 'UTC'); Date::_SetNow($dateCreatedUtc); $attachmentId = 499; $this->db->_ExpectedInsertIds[0] = $seriesId; $this->db->_ExpectedInsertIds[1] = $attachmentId; $this->db->_ExpectedInsertIds[2] = $reservationId; $userSession = new FakeUserSession(); $reservation = ReservationSeries::Create($userId, new FakeBookableResource($resourceId), $title, $description, $duration, $repeatOptions, $userSession); $repeatType = $repeatOptions->RepeatType(); $repeatOptionsString = $repeatOptions->ConfigurationString(); $referenceNumber = $reservation->CurrentInstance()->ReferenceNumber(); $reservation->ChangeParticipants($participantIds); $reservation->ChangeInvitees($inviteeIds); $reservation->AddAccessory($accessory); $reservation->AddAttributeValue($attribute); $reservation->AddAttachment($attachment); $reservation->AllowParticipation($allowParticipation); $this->repository->Add($reservation); $insertReservationSeries = new AddReservationSeriesCommand($dateCreatedUtc, $title, $description, $repeatType, $repeatOptionsString, ReservationTypes::Reservation, ReservationStatus::Created, $userId, $allowParticipation); $insertReservation = new AddReservationCommand($startUtc, $endUtc, $referenceNumber, $seriesId); $insertReservationResource = new AddReservationResourceCommand($seriesId, $resourceId, ResourceLevel::Primary); $insertReservationUser = $this->GetAddUserCommand($reservationId, $userId, $levelId); $insertReservationAccessory = new AddReservationAccessoryCommand($accessory->AccessoryId, $accessory->QuantityReserved, $seriesId); $insertReservationAttribute = new AddAttributeValueCommand($attribute->AttributeId, $attribute->Value, $seriesId, CustomAttributeCategory::RESERVATION); $insertParticipant1 = $this->GetAddUserCommand($reservationId, $participantIds[0], ReservationUserLevel::PARTICIPANT); $insertParticipant2 = $this->GetAddUserCommand($reservationId, $participantIds[1], ReservationUserLevel::PARTICIPANT); $insertInvitee1 = $this->GetAddUserCommand($reservationId, $inviteeIds[0], ReservationUserLevel::INVITEE); $insertInvitee2 = $this->GetAddUserCommand($reservationId, $inviteeIds[1], ReservationUserLevel::INVITEE); $addAttachment = new AddReservationAttachmentCommand($attachment->FileName(), $attachment->FileType(), $attachment->FileSize(), $attachment->FileExtension(), $seriesId); $this->assertEquals(11, count($this->db->_Commands)); $this->assertEquals($insertReservationSeries, $this->db->_Commands[0]); $this->assertEquals($insertReservationResource, $this->db->_Commands[1]); $this->assertTrue($this->db->ContainsCommand($insertReservation)); $this->assertTrue($this->db->ContainsCommand($insertReservationUser)); $this->assertTrue($this->db->ContainsCommand($insertParticipant1)); $this->assertTrue($this->db->ContainsCommand($insertParticipant2)); $this->assertTrue($this->db->ContainsCommand($insertInvitee1)); $this->assertTrue($this->db->ContainsCommand($insertInvitee2)); $this->assertTrue($this->db->ContainsCommand($insertReservationAccessory)); $this->assertTrue($this->db->ContainsCommand($insertReservationAttribute)); $this->assertTrue($this->db->ContainsCommand($addAttachment)); $this->assertEquals($attachment->FileContents(), $this->fileSystem->_AddedFileContents); }
public function testWhenApplyingSimpleUpdatesToFullSeriesAndThereIsNoStartTimeConstraint() { $this->fakeConfig->SetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_START_TIME_CONSTRAINT, ReservationStartTimeConstraint::NONE); $timezone = 'UTC'; $currentResource = new FakeBookableResource(8); $newResource = new FakeBookableResource(10); $dateRange = DateRange::Create('2010-01-01 00:00', '2010-01-01 5:00', $timezone); Date::_SetNow(Date::Parse('2010-01-05 2:00', $timezone)); $builder = new ExistingReservationSeriesBuilder(); $builder->WithPrimaryResource($currentResource); $builder->WithCurrentInstance(new TestReservation('1', $dateRange)); $series = $builder->Build(); $series->ApplyChangesTo(SeriesUpdateScope::FullSeries); $series->Update($series->UserId(), $newResource, 'new', 'new', new FakeUserSession()); $this->assertEquals($newResource, $series->Resource()); $this->assertEquals(1, count($series->Instances())); }
public function setup() { parent::setup(); Date::_SetNow(new Date()); $this->repository = new AnnouncementRepository(); }