public function testScheduleResponseReturnsLayoutForEachDayOfWeek() { $schedule = new FakeSchedule(); $layout = $this->getMock('IScheduleLayout'); $timezone = $this->server->GetSession()->Timezone; $date1 = Date::Now()->ToTimezone($timezone); $date2 = $date1->AddDays(1); $date3 = $date1->AddDays(2); $date4 = $date1->AddDays(3); $date5 = $date1->AddDays(4); $date6 = $date1->AddDays(5); $date7 = $date1->AddDays(6); $periods1 = array(new SchedulePeriod($date1, $date1)); $periods2 = array(new SchedulePeriod($date2, $date2)); $periods3 = array(new SchedulePeriod($date3, $date3)); $periods4 = array(new SchedulePeriod($date4, $date4)); $periods5 = array(new SchedulePeriod($date5, $date5)); $periods6 = array(new SchedulePeriod($date6, $date6)); $periods7 = array(new SchedulePeriod($date7, $date7)); $layout->expects($this->at(0))->method('GetLayout')->with($this->equalTo($date1))->will($this->returnValue($periods1)); $layout->expects($this->at(1))->method('GetLayout')->with($this->equalTo($date2))->will($this->returnValue($periods2)); $layout->expects($this->at(2))->method('GetLayout')->with($this->equalTo($date3))->will($this->returnValue($periods3)); $layout->expects($this->at(3))->method('GetLayout')->with($this->equalTo($date4))->will($this->returnValue($periods4)); $layout->expects($this->at(4))->method('GetLayout')->with($this->equalTo($date5))->will($this->returnValue($periods5)); $layout->expects($this->at(5))->method('GetLayout')->with($this->equalTo($date6))->will($this->returnValue($periods6)); $layout->expects($this->at(6))->method('GetLayout')->with($this->equalTo($date7))->will($this->returnValue($periods7)); $response = new ScheduleResponse($this->server, $schedule, $layout); $this->assertEquals(array(new SchedulePeriodResponse($periods1[0])), $response->periods[$date1->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods2[0])), $response->periods[$date2->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods3[0])), $response->periods[$date3->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods4[0])), $response->periods[$date4->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods5[0])), $response->periods[$date5->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods6[0])), $response->periods[$date6->Weekday()]); $this->assertEquals(array(new SchedulePeriodResponse($periods7[0])), $response->periods[$date7->Weekday()]); }
public function testFailedDelete() { $userId = 123; $errors = array('error'); $controllerResult = new UserControllerResult(null, $errors); $this->controller->expects($this->once())->method('Delete')->with($this->equalTo($userId), $this->equalTo($this->server->GetSession()))->will($this->returnValue($controllerResult)); $this->service->Delete($userId); $this->assertEquals(new FailedResponse($this->server, $errors), $this->server->_LastResponse); $this->assertEquals(RestResponse::BAD_REQUEST_CODE, $this->server->_LastResponseCode); }
public function testWhenApproveValidationFails() { $referenceNumber = '123'; $errors = array('error'); $controllerResult = new ReservationControllerResult($referenceNumber); $controllerResult->SetErrors($errors); $this->controller->expects($this->once())->method('Approve')->with($this->equalTo($this->server->GetSession()), $this->equalTo($referenceNumber))->will($this->returnValue($controllerResult)); $this->service->Approve($referenceNumber); $expectedResponse = new FailedResponse($this->server, $errors); $this->assertEquals($expectedResponse, $this->server->_LastResponse); $this->assertEquals(RestResponse::BAD_REQUEST_CODE, $this->server->_LastResponseCode); }
public function testWhenNotHidingUserDetails() { $this->HideUsers(false); $userId = 999; $user = new FakeUser($userId); $attributes = $this->getMock('IEntityAttributeList'); $this->userRepositoryFactory->expects($this->once())->method('Create')->with($this->equalTo($this->server->GetSession()))->will($this->returnValue($this->userRepository)); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes)); $expectedResponse = new UserResponse($this->server, $user, $attributes); $this->service->GetUser($userId); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }