Пример #1
0
 public function testTrimsOffPossibleValueWhiteSpace()
 {
     $attribute = CustomAttribute::Create(null, 1, 1, null, false, '  1, abc    ,1abc3   ', '    1   ');
     $list = $attribute->PossibleValueList();
     $this->assertTrue(in_array('1', $list));
     $this->assertTrue(in_array('abc', $list));
     $this->assertTrue(in_array('1abc3', $list));
     $this->assertEquals(1, $attribute->SortOrder());
 }
Пример #2
0
 public function AddAttribute()
 {
     $attributeName = $this->page->GetLabel();
     $type = $this->page->GetType();
     $scope = $this->page->GetCategory();
     $regex = $this->page->GetValidationExpression();
     $required = $this->page->GetIsRequired();
     $possibleValues = $this->page->GetPossibleValues();
     $sortOrder = $this->page->GetSortOrder();
     $entityId = $this->page->GetEntityId();
     Log::Debug('Adding new attribute named: %s', $attributeName);
     $attribute = CustomAttribute::Create($attributeName, $type, $scope, $regex, $required, $possibleValues, $sortOrder, $entityId);
     $this->attributeRepository->Add($attribute);
 }
 public function testAddsAttribute()
 {
     $label = 'label';
     $type = CustomAttributeTypes::SINGLE_LINE_TEXTBOX;
     $category = CustomAttributeCategory::RESERVATION;
     $regex = 'regex';
     $required = false;
     $possibleValues = '';
     $sortOrder = '4';
     $entityId = 12;
     $attribute = CustomAttribute::Create($label, $type, $category, $regex, $required, $possibleValues, $sortOrder, $entityId);
     $this->repository->Add($attribute);
     $this->assertEquals(new AddAttributeCommand($label, $type, $category, $regex, $required, $possibleValues, $sortOrder, $entityId), $this->db->_LastCommand);
 }
 public function testAddsAttribute()
 {
     $request = new CustomAttributeRequest();
     $request->label = 'attributename';
     $request->type = CustomAttributeTypes::SELECT_LIST;
     $request->categoryId = CustomAttributeCategory::USER;
     $request->regex = 'regex';
     $request->required = true;
     $request->possibleValues = '1,2,3';
     $request->sortOrder = 9;
     $request->appliesToId = 100;
     $result = $this->controller->Create($request, $this->session);
     $this->assertEquals(true, $result->WasSuccessful());
     $this->assertEquals($this->attributeRepository->_LastCreateId, $result->AttributeId());
     $expected = CustomAttribute::Create($request->label, $request->type, $request->categoryId, $request->regex, $request->required, $request->possibleValues, $request->sortOrder, $request->appliesToId);
     $this->assertEquals($expected, $this->attributeRepository->_Added);
 }
 public function testUpdatesAttribute()
 {
     $attributeId = 1091;
     $label = 'new label';
     $required = true;
     $regex = '/$\\d^/';
     $possibleValues = '1,2,3';
     $sortOrder = "5";
     $entityId = true;
     $this->page->_label = $label;
     $this->page->_required = $required;
     $this->page->_regex = $regex;
     $this->page->_possibleValues = $possibleValues;
     $this->page->_attributeId = $attributeId;
     $this->page->_sortOrder = $sortOrder;
     $this->page->_entityId = $entityId;
     $expectedAttribute = CustomAttribute::Create('', CustomAttributeTypes::CHECKBOX, CustomAttributeCategory::USER, null, false, null, $sortOrder, $entityId);
     $this->attributeRepository->expects($this->once())->method('LoadById')->with($this->equalTo($attributeId))->will($this->returnValue($expectedAttribute));
     $this->attributeRepository->expects($this->once())->method('Update')->with($this->equalTo($expectedAttribute));
     $this->presenter->UpdateAttribute();
     $this->assertEquals($label, $expectedAttribute->Label());
     $this->assertEquals($regex, $expectedAttribute->Regex());
     $this->assertEquals($required, $expectedAttribute->Required());
     $this->assertEquals($possibleValues, $expectedAttribute->PossibleValues());
     $this->assertEquals($sortOrder, $expectedAttribute->SortOrder());
     $this->assertEquals($entityId, $expectedAttribute->EntityId());
 }
Пример #6
0
 /**
  * @param CustomAttributeRequest $request
  * @param WebServiceUserSession $session
  * @return AttributeControllerResult
  */
 public function Create($request, $session)
 {
     $errors = $this->ValidateRequest($request);
     if (!empty($errors)) {
         return new AttributeControllerResult(null, $errors);
     }
     $attribute = CustomAttribute::Create($request->label, $request->type, $request->categoryId, $request->regex . '', (int) $request->required, $this->GetPossibleValues($request), $request->sortOrder, $request->appliesToId);
     $attributeId = $this->repository->Add($attribute);
     return new AttributeControllerResult($attributeId, null);
 }
 public function testBindsCustomAttributes()
 {
     $binder = new ReservationCustomAttributeBinder($this->attributeRepository);
     $attributes = array(CustomAttribute::Create('1', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 1), CustomAttribute::Create('2', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 2));
     $this->attributeRepository->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($attributes));
     $this->initializer->expects($this->at(0))->method('AddAttribute')->with($this->equalTo($attributes[0]), $this->equalTo(null));
     $this->initializer->expects($this->at(1))->method('AddAttribute')->with($this->equalTo($attributes[1]), $this->equalTo(null));
     $binder->Bind($this->initializer);
 }