/** * Initialize core values of the Builder. * Should be the first initialization performed in a concrete type. * @param PropertySpecification $specification */ protected function initBuilder($specification) { \assert(null !== $specification); $this->specification = $specification; $constraints = $specification->getConstraints(); if (array_key_exists('allowedValueTypes', $constraints)) { $this->allowedValueTypes = $constraints['allowedValueTypes']; } else { $this->allowedValueTypes = self::$allValueTypes; } if (array_key_exists('valueTypeDefault', $constraints)) { $this->valueTypeDefault = $constraints['valueTypeDefault']; } else { $this->valueTypeDefault = $this->getDefaultValueTypeDefault(); } }
/** * @group default * @depends testSetAndBuild */ public function testEmptyTypesPermitsAll() { $specification = new PropertySpecification('tel', PropertySpecification::MULTIPLE_PROPERTY, __NAMESPACE__ . '\\TypedPropertyBuilderImpl', PropertySpecification::$cardinalities['Zero To N'], ['allowedTypes' => []]); $builder = $specification->getBuilder(); $builder->setValue('999-555-1212')->addType('skadgamagoozie'); $property = $builder->build(); $this->assertContains('skadgamagoozie', $property->getTypes()); }
/** * @group default * @depends testSetAndBuild * @param \EVought\vCardTools\PropertySpecification $specification */ public function testPushTo(PropertySpecification $specification) { $container = new PropertyContainerImpl(); $builder = $specification->getBuilder(); $builder->setValue('http://liquor.cabi.net'); $property = $builder->pushTo($container); $this->assertEquals('http://liquor.cabi.net', $container->current()->getValue()); }
/** * @group default * @param \EVought\vCardTools\PropertySpecification $specification * @depends testSetAndBuild * @expectedException \DomainException */ public function testSetFromVCardLineTooManyFields(PropertySpecification $specification) { $vcardLine = new VCardLine('4.0'); $vcardLine->setName('adr')->setValue(';;;;;'); /* @var StructuredPropertyBuilder $builder */ $builder = $specification->getBuilder(); $builder->setFromVCardLine($vcardLine); }
/** * Convenience method to get the name of the property from the * specification. * @see Property::getName() * @return string */ public function getName() { return $this->specification->getName(); }
/** * @group default * @param \EVought\vCardTools\PropertySpecification $specification * @depends testSetAndBuild */ public function testSetFromVCardLine(PropertySpecification $specification) { $vcardLine = new VCardLine('4.0'); $vcardLine->setGroup('glurg')->setName('adr')->setValue('value1;value2')->setParameter('type', ['work']); $builder = $specification->getBuilder(); $builder->setFromVCardLine($vcardLine); $this->assertEquals('glurg', $builder->getGroup()); $this->assertEquals(['work'], $builder->getTypes()); $this->assertEquals(['Locality' => 'value1', 'Region' => 'value2'], $builder->getValue()); }
/** * @group default */ public function testGetBuilder() { $builder = $this->specification->getBuilder(); $this->assertInstanceOf(__NAMESPACE__ . '\\SimplePropertyBuilder', $builder); }