/**
  * @param ResourceRequest $request
  * @return array
  */
 private function ValidateCommon($request)
 {
     if (empty($request)) {
         return array('Request was not properly formatted');
     }
     $errors = array();
     $validators[] = new RequestRequiredValueValidator($request->name, 'name');
     $validators[] = new RequestRequiredValueValidator($request->scheduleId, 'scheduleId');
     $validators[] = new TimeIntervalValidator($request->minLength, 'minLength');
     $validators[] = new TimeIntervalValidator($request->maxLength, 'maxLength');
     $validators[] = new TimeIntervalValidator($request->minNotice, 'minNotice');
     $validators[] = new TimeIntervalValidator($request->maxNotice, 'maxNotice');
     $attributes = array();
     foreach ($request->GetCustomAttributes() as $attribute) {
         $attributes[] = new AttributeValue($attribute->attributeId, $attribute->attributeValue);
     }
     $validators[] = new AttributeValidator($this->attributeService, CustomAttributeCategory::RESOURCE, $attributes);
     /** @var IValidator $validator */
     foreach ($validators as $validator) {
         $validator->Validate();
         if (!$validator->IsValid()) {
             foreach ($validator->Messages() as $message) {
                 $errors[] = $message;
             }
         }
     }
     return $errors;
 }
 public function testUpdateAndDeleteRequireResourceId()
 {
     $request = ResourceRequest::Example();
     $request->customAttributes = null;
     $deleteErrors = $this->validator->ValidateDeleteRequest(null);
     $updateErrors = $this->validator->ValidateUpdateRequest('', $request);
     $this->assertEquals(1, count($deleteErrors));
     $this->assertEquals(1, count($updateErrors));
 }
 public function testWhenUpdateValidationFails()
 {
     $resourceId = 123;
     $errors = array('something failed');
     $request = ResourceRequest::Example();
     $this->validator->expects($this->once())->method('ValidateUpdateRequest')->with($this->anything(), $this->anything())->will($this->returnValue($errors));
     $response = $this->controller->Update($resourceId, $request, $this->session);
     $this->assertFalse($response->WasSuccessful());
     $this->assertNull($response->ResourceId());
     $this->assertEquals($errors, $response->Errors());
 }
Esempio n. 4
0
 /**
  * @param ResourceRequest $request
  * @param int $resourceId
  * @return BookableResource
  */
 private function BuildResource($request, $resourceId)
 {
     $resource = new BookableResource($resourceId, $request->name, $request->location, $request->contact, $request->notes, $request->minLength, $request->maxLength, $request->autoAssignPermissions, $request->requiresApproval, $request->allowMultiday, $request->maxParticipants, $request->minNotice, $request->maxNotice, $request->description, $request->scheduleId);
     $resource->SetSortOrder($request->sortOrder);
     $attributes = array();
     foreach ($request->GetCustomAttributes() as $attribute) {
         $attributes[] = new AttributeValue($attribute->attributeId, $attribute->attributeValue);
     }
     $resource->ChangeAttributes($attributes);
     if (isset($request->statusId)) {
         $resource->ChangeStatus($request->statusId, $request->statusReasonId);
     }
     return $resource;
 }