|
| 1 | +<?php |
| 2 | + |
| 3 | +use Fhaculty\Graph\Graph; |
| 4 | +use Graphp\GraphML\Exporter; |
| 5 | + |
| 6 | +class ExporterTest extends TestCase |
| 7 | +{ |
| 8 | + private $exporter; |
| 9 | + |
| 10 | + public function setUp() |
| 11 | + { |
| 12 | + $this->exporter = new Exporter(); |
| 13 | + } |
| 14 | + |
| 15 | + public function testEmpty() |
| 16 | + { |
| 17 | + $graph = new Graph(); |
| 18 | + |
| 19 | + $output = $this->exporter->getOutput($graph); |
| 20 | + $xml = new SimpleXMLElement($output); |
| 21 | + |
| 22 | + $this->assertEquals(1, count($xml)); |
| 23 | + $this->assertEquals(1, count($xml->graph)); |
| 24 | + $this->assertEquals(0, count($xml->graph->children())); |
| 25 | + } |
| 26 | + |
| 27 | + public function testSimple() |
| 28 | + { |
| 29 | + // 1 -- 2 |
| 30 | + $graph = new Graph(); |
| 31 | + $v1 = $graph->createVertex(1); |
| 32 | + $v2 = $graph->createVertex(2); |
| 33 | + $v1->createEdge($v2); |
| 34 | + |
| 35 | + $output = $this->exporter->getOutput($graph); |
| 36 | + $xml = new SimpleXMLElement($output); |
| 37 | + |
| 38 | + $this->assertEquals(1, count($xml->graph->edge)); |
| 39 | + |
| 40 | + $edgeElem = $xml->graph->edge; |
| 41 | + $this->assertEquals('1', (string)$edgeElem['source']); |
| 42 | + $this->assertEquals('2', (string)$edgeElem['target']); |
| 43 | + $this->assertFalse(isset($edgeElem['directed'])); |
| 44 | + } |
| 45 | + |
| 46 | + public function testSimpleDirected() |
| 47 | + { |
| 48 | + // 1 -> 2 |
| 49 | + $graph = new Graph(); |
| 50 | + $v1 = $graph->createVertex(1); |
| 51 | + $v2 = $graph->createVertex(2); |
| 52 | + $v1->createEdgeTo($v2); |
| 53 | + |
| 54 | + $output = $this->exporter->getOutput($graph); |
| 55 | + $xml = new SimpleXMLElement($output); |
| 56 | + |
| 57 | + $this->assertEquals(1, count($xml->graph->edge)); |
| 58 | + |
| 59 | + $edgeElem = $xml->graph->edge; |
| 60 | + $this->assertEquals('1', (string)$edgeElem['source']); |
| 61 | + $this->assertEquals('2', (string)$edgeElem['target']); |
| 62 | + $this->assertEquals('true', (string)$edgeElem['directed']); |
| 63 | + } |
| 64 | +} |
0 commit comments