public function testValidatesCreateRequest() { $request = CreateUserRequest::Example(); $session = new FakeWebServiceUserSession(123); $errors = array('error'); $this->requestValidator->expects($this->once())->method('ValidateCreateRequest')->with($this->equalTo($request))->will($this->returnValue($errors)); $result = $this->controller->Create($request, $session); $this->assertFalse($result->WasSuccessful()); $this->assertEquals($errors, $result->Errors()); }
/** * @param CreateUserRequest|UpdateUserRequest $request * @param IValidator[] $additionalValidators * @return array|string[] */ private function Validate($request, $additionalValidators = array()) { $validators = $additionalValidators; $validators[] = new RequestRequiredValueValidator($request->firstName, 'firstName'); $validators[] = new RequestRequiredValueValidator($request->lastName, 'lastName'); $validators[] = new RequestRequiredValueValidator($request->userName, 'userName'); $validators[] = new RequestRequiredValueValidator($request->timezone, 'timezone'); $validators[] = new EmailValidator($request->emailAddress); $attributes = array(); foreach ($request->GetCustomAttributes() as $attribute) { $attributes[] = new AttributeValue($attribute->attributeId, $attribute->attributeValue); } $validators[] = new AttributeValidator($this->attributeService, CustomAttributeCategory::USER, $attributes); $errors = array(); /** @var $validator IValidator */ foreach ($validators as $validator) { $validator->Validate(); if (!$validator->IsValid()) { foreach ($validator->Messages() as $message) { $errors[] = $message; } } } return $errors; }
public function testCreateValidatesAttributes() { $request = CreateUserRequest::Example(); $result = new AttributeServiceValidationResult(false, array('error')); $this->attributeService->expects($this->once())->method('Validate')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array(new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue))))->will($this->returnValue($result)); $errors = $this->validator->ValidateCreateRequest($request); $this->assertTrue(count($errors) == 1); }
/** * @param CreateUserRequest $request * @return mixed */ public function store(CreateUserRequest $request) { $this->users->create($request->except('assignees_roles', 'permission_user'), $request->only('assignees_roles'), $request->only('permission_user')); return redirect()->route('admin.access.users.index')->withFlashSuccess('The user was successfully created.'); }