|
| 1 | +<?php |
| 2 | + |
| 3 | +use Fhaculty\Graph\Graph; |
| 4 | +use Fhaculty\Graph\Attribute\AttributeBagNamespaced; |
| 5 | +use Fhaculty\Graph\Attribute\AttributeAware; |
| 6 | +use Fhaculty\Graph\Attribute\AttributeBagContainer; |
| 7 | + |
| 8 | +class AtributeBagNamespacedTest extends TestCase |
| 9 | +{ |
| 10 | + public function testBagContainer() |
| 11 | + { |
| 12 | + $container = new AttributeBagContainer(); |
| 13 | + $bag = new AttributeBagNamespaced($container, 'test.'); |
| 14 | + $this->assertSame($bag, $bag->getAttributeBag()); |
| 15 | + |
| 16 | + $container->setAttribute('a.b', 'c'); |
| 17 | + $container->setAttribute('test.d', 'e'); |
| 18 | + |
| 19 | + $this->assertEquals('e', $bag->getAttribute('d')); |
| 20 | + |
| 21 | + $bag->setAttribute('d', 'test'); |
| 22 | + |
| 23 | + $this->assertEquals('test', $bag->getAttribute('d')); |
| 24 | + $this->assertEquals('test', $container->getAttribute('test.d')); |
| 25 | + |
| 26 | + $bag->setAttributes(array('d' => 'd', 'e' => 'e')); |
| 27 | + |
| 28 | + $this->assertEquals(array('d', 'e'), $bag->getNames()); |
| 29 | + $this->assertEquals(array('a.b', 'test.d', 'test.e'), $container->getNames()); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * |
| 34 | + * @param AttributeAware $entity |
| 35 | + * @dataProvider provideNamespacable |
| 36 | + */ |
| 37 | + public function testReadableEntities(AttributeAware $entity) |
| 38 | + { |
| 39 | + $bag = new AttributeBagNamespaced($entity, 'test.'); |
| 40 | + $this->assertSame($bag, $bag->getAttributeBag()); |
| 41 | + |
| 42 | + $entity->setAttribute('a.b', 'c'); |
| 43 | + $entity->setAttribute('test.d', 'e'); |
| 44 | + |
| 45 | + $this->assertEquals('e', $bag->getAttribute('d')); |
| 46 | + |
| 47 | + $this->assertNull($bag->getAttribute('a.b')); |
| 48 | + $this->assertNull($bag->getAttribute('test.d')); |
| 49 | + |
| 50 | + $this->assertEquals(array('d' => 'e'), $bag->getAttributes()); |
| 51 | + $this->assertEquals(array('d'), $bag->getNames()); |
| 52 | + } |
| 53 | + |
| 54 | + public function provideNamespacable() |
| 55 | + { |
| 56 | + $graph = new Graph(); |
| 57 | + $vertex = $graph->createVertex(); |
| 58 | + $bag = $vertex->getAttributeBag(); |
| 59 | + $subNamespace = new AttributeBagNamespaced($bag, 'prefix'); |
| 60 | + |
| 61 | + return array( |
| 62 | + array($graph), |
| 63 | + array($vertex), |
| 64 | + array($bag), |
| 65 | + array($subNamespace), |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
0 commit comments