/** * * @param AttributeAware $entity * @dataProvider provideNamespacable */ public function testReadableEntities(AttributeAware $entity) { $bag = new AttributeBagNamespaced($entity, 'test.'); $this->assertSame($bag, $bag->getAttributeBag()); $entity->setAttribute('a.b', 'c'); $entity->setAttribute('test.d', 'e'); $this->assertEquals('e', $bag->getAttribute('d')); $this->assertNull($bag->getAttribute('a.b')); $this->assertNull($bag->getAttribute('test.d')); $this->assertEquals(array('d' => 'e'), $bag->getAttributes()); }
private function loadAttributes(SimpleXMLElement $xml, AttributeAware $target, array $keys) { // apply all default values for this type $type = $xml->getName(); foreach ($keys as $key) { if (isset($key['default']) && ($key['for'] === $type || $key['for'] === 'all')) { $target->setAttribute($key['name'], $key['default']); } } // apply all data attributes for this element foreach ($xml->data as $dataElem) { $key = $keys[(string) $dataElem['key']]; $target->setAttribute($key['name'], $this->castAttribute((string) $dataElem, $key['type'])); } }
/** * @depends testAttributeAwareInterface * @param AttributeAware $entity */ public function testAttributeSetRemoveGet(AttributeAware $entity) { $entity->setAttribute('test', 'value'); $this->assertEquals('value', $entity->getAttribute('test')); $entity->removeAttribute('test'); $this->assertEquals(null, $entity->getAttribute('test')); }
/** * @depends testAttributeAwareInterface * @param AttributeAware $entity */ public function testAttributeSetGetDefault(AttributeAware $entity) { $entity->setAttribute('test', 'value'); $this->assertEquals('value', $entity->getAttribute('test')); $this->assertEquals(null, $entity->getAttribute('unknown')); $this->assertEquals('default', $entity->getAttribute('unknown', 'default')); }
/** * @param AttributeAware $attributeAware * @param Location $location */ private function addLocationTo(AttributeAware $attributeAware, Location $location) { $locations = $attributeAware->getAttribute('locations', array()); $locations[] = $location; $attributeAware->setAttribute('locations', $locations); }