Author: Sebastian Bergmann Date: 2007-05-03 18:00:50 +0200 (Thu, 03 May 2007) New Revision: 5026
Log: - Rename visitor. Added: trunk/Workflow/src/visitors/visualization.php trunk/Workflow/tests/visitor_visualization_test.php Removed: trunk/Workflow/src/visitors/dot.php trunk/Workflow/tests/visitor_dot_test.php Modified: trunk/Workflow/src/workflow_autoload.php trunk/Workflow/tests/suite.php trunk/WorkflowDatabaseTiein/docs/examples/visualize.php Deleted: trunk/Workflow/src/visitors/dot.php =================================================================== --- trunk/Workflow/src/visitors/dot.php 2007-05-03 15:38:21 UTC (rev 5025) +++ trunk/Workflow/src/visitors/dot.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -1,132 +0,0 @@ -<?php -/** - * File containing the ezcWorkflowVisitorDot class. - * - * @package Workflow - * @version //autogen// - * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - */ - -/** - * An implementation of the ezcWorkflowVisitor interface that - * generates GraphViz/dot markup for a workflow definition. - * - * @package Workflow - * @version //autogen// - */ -class ezcWorkflowVisitorDot implements ezcWorkflowVisitor -{ - /** - * @var array - */ - protected $nodes = array(); - - /** - * @var array - */ - protected $edges = array(); - - /** - * @var array - */ - protected $visited = array(); - - /** - * @var string - */ - protected $workflowName = 'Workflow'; - - /** - * @param ezcWorkflowVisitable $node - * @return boolean - */ - public function visit( ezcWorkflowVisitable $visitable ) - { - foreach ( $this->visited as $visited ) - { - if ( $visited === $visitable ) - { - return false; - } - } - - $this->visited[] = $visitable; - - if ( $visitable instanceof ezcWorkflow ) - { - $this->workflowName = $visitable->getName(); - - foreach ( $visitable->getNodes() as $id => $node ) - { - $node->setId( $id + 1 ); - } - } - - if ( $visitable instanceof ezcWorkflowNode ) - { - $id = $visitable->getId(); - - if ( !isset( $this->nodes[ $id ] ) ) - { - $this->nodes[ $id ] = (string)$visitable; - } - - $outNodes = array(); - - foreach ( $visitable->getOutNodes() as $outNode ) - { - $label = ''; - - if ( $visitable instanceof ezcWorkflowNodeConditionalBranch ) - { - $condition = $visitable->getCondition( $outNode ); - - if ( $condition !== false ) - { - $label = ' [label="' . (string) $condition . '"]'; - } - } - - $outNodes[] = array( $outNode->getId(), $label ); - } - - $this->edges[ $id ] = $outNodes; - } - - return true; - } - - public function __toString() - { - $dot = 'digraph ' . $this->workflowName . " {\n"; - - foreach ( $this->nodes as $key => $value ) - { - $dot .= sprintf( - "node%s [label=\"%s\"]\n", - $key, - $value - ); - } - - $dot .= "\n"; - - foreach ( $this->edges as $fromNode => $toNodes ) - { - foreach ( $toNodes as $toNode ) - { - $dot .= sprintf( - "node%s -> node%s%s\n", - - $fromNode, - $toNode[0], - $toNode[1] - ); - } - } - - return $dot . "}\n"; - } -} -?> Copied: trunk/Workflow/src/visitors/visualization.php (from rev 5024, trunk/Workflow/src/visitors/dot.php) =================================================================== --- trunk/Workflow/src/visitors/dot.php 2007-05-03 15:12:46 UTC (rev 5024) +++ trunk/Workflow/src/visitors/visualization.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -0,0 +1,132 @@ +<?php +/** + * File containing the ezcWorkflowVisitorVisualization class. + * + * @package Workflow + * @version //autogen// + * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * An implementation of the ezcWorkflowVisitor interface that + * generates GraphViz/dot markup for a workflow definition. + * + * @package Workflow + * @version //autogen// + */ +class ezcWorkflowVisitorVisualization implements ezcWorkflowVisitor +{ + /** + * @var array + */ + protected $nodes = array(); + + /** + * @var array + */ + protected $edges = array(); + + /** + * @var array + */ + protected $visited = array(); + + /** + * @var string + */ + protected $workflowName = 'Workflow'; + + /** + * @param ezcWorkflowVisitable $node + * @return boolean + */ + public function visit( ezcWorkflowVisitable $visitable ) + { + foreach ( $this->visited as $visited ) + { + if ( $visited === $visitable ) + { + return false; + } + } + + $this->visited[] = $visitable; + + if ( $visitable instanceof ezcWorkflow ) + { + $this->workflowName = $visitable->getName(); + + foreach ( $visitable->getNodes() as $id => $node ) + { + $node->setId( $id + 1 ); + } + } + + if ( $visitable instanceof ezcWorkflowNode ) + { + $id = $visitable->getId(); + + if ( !isset( $this->nodes[ $id ] ) ) + { + $this->nodes[ $id ] = (string)$visitable; + } + + $outNodes = array(); + + foreach ( $visitable->getOutNodes() as $outNode ) + { + $label = ''; + + if ( $visitable instanceof ezcWorkflowNodeConditionalBranch ) + { + $condition = $visitable->getCondition( $outNode ); + + if ( $condition !== false ) + { + $label = ' [label="' . (string) $condition . '"]'; + } + } + + $outNodes[] = array( $outNode->getId(), $label ); + } + + $this->edges[ $id ] = $outNodes; + } + + return true; + } + + public function __toString() + { + $dot = 'digraph ' . $this->workflowName . " {\n"; + + foreach ( $this->nodes as $key => $value ) + { + $dot .= sprintf( + "node%s [label=\"%s\"]\n", + $key, + $value + ); + } + + $dot .= "\n"; + + foreach ( $this->edges as $fromNode => $toNodes ) + { + foreach ( $toNodes as $toNode ) + { + $dot .= sprintf( + "node%s -> node%s%s\n", + + $fromNode, + $toNode[0], + $toNode[1] + ); + } + } + + return $dot . "}\n"; + } +} +?> Modified: trunk/Workflow/src/workflow_autoload.php =================================================================== --- trunk/Workflow/src/workflow_autoload.php 2007-05-03 15:38:21 UTC (rev 5025) +++ trunk/Workflow/src/workflow_autoload.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -76,6 +76,6 @@ 'ezcWorkflowRollbackableServiceObject' => 'Workflow/interfaces/rollbackable_service_object.php', 'ezcWorkflowUtil' => 'Workflow/util.php', 'ezcWorkflowVariableHandler' => 'Workflow/interfaces/variable_handler.php', - 'ezcWorkflowVisitorDot' => 'Workflow/visitors/dot.php', + 'ezcWorkflowVisitorVisualization' => 'Workflow/visitors/visualization.php', ); ?> Modified: trunk/Workflow/tests/suite.php =================================================================== --- trunk/Workflow/tests/suite.php 2007-05-03 15:38:21 UTC (rev 5025) +++ trunk/Workflow/tests/suite.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -12,7 +12,7 @@ require_once 'workflow_test.php'; require_once 'node_test.php'; require_once 'condition_test.php'; -require_once 'visitor_dot_test.php'; +require_once 'visitor_visualization_test.php'; /** * @package Workflow @@ -30,7 +30,7 @@ $this->addTest( ezcWorkflowTest::suite() ); $this->addTest( ezcWorkflowNodeTest::suite() ); $this->addTest( ezcWorkflowConditionTest::suite() ); - $this->addTest( ezcWorkflowVisitorDotTest::suite() ); + $this->addTest( ezcWorkflowVisitorVisualizationTest::suite() ); } public static function suite() Deleted: trunk/Workflow/tests/visitor_dot_test.php =================================================================== --- trunk/Workflow/tests/visitor_dot_test.php 2007-05-03 15:38:21 UTC (rev 5025) +++ trunk/Workflow/tests/visitor_dot_test.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -1,171 +0,0 @@ -<?php -/** - * @package Workflow - * @subpackage Tests - * @version //autogentag// - * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - */ - -require_once 'case.php'; - -/** - * @package Workflow - * @subpackage Tests - */ -class ezcWorkflowVisitorDotTest extends ezcWorkflowTestCase -{ - protected $visitor; - - public static function suite() - { - return new PHPUnit_Framework_TestSuite( 'ezcWorkflowVisitorDotTest' ); - } - - protected function setUp() - { - parent::setUp(); - - $this->visitor = new ezcWorkflowVisitorDot; - } - - public function testVisitStartEnd() - { - $this->setUpStartEnd(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'StartEnd' ), - (string)$this->visitor - ); - } - - public function testVisitStartInputEnd() - { - $this->setUpStartInputEnd(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'StartInputEnd' ), - (string)$this->visitor - ); - } - - public function testVisitStartSetUnsetEnd() - { - $this->setUpStartSetUnsetEnd(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'StartSetUnsetEnd' ), - (string)$this->visitor - ); - } - - public function testVisitIncrementingLoop() - { - $this->setUpLoop( 'increment' ); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'IncrementingLoop' ), - (string)$this->visitor - ); - } - - public function testVisitDecrementingLoop() - { - $this->setUpLoop( 'decrement' ); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'DecrementingLoop' ), - (string)$this->visitor - ); - } - - public function testVisitSetAddSubMulDiv() - { - $this->setUpSetAddSubMulDiv(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'SetAddSubMulDiv' ), - (string)$this->visitor - ); - } - - public function testVisitAddVariables() - { - $this->setUpAddVariables(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'AddVariables' ), - (string)$this->visitor - ); - } - - public function testVisitParallelSplitSynchronization() - { - $this->setUpParallelSplitSynchronization(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'ParallelSplitSynchronization' ), - (string)$this->visitor - ); - } - - public function testVisitExclusiveChoiceSimpleMerge() - { - $this->setUpExclusiveChoiceSimpleMerge(); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'ExclusiveChoiceSimpleMerge' ), - (string)$this->visitor - ); - } - - public function testVisitMultiChoiceSynchronizingMerge() - { - $this->setUpMultiChoice( 'SynchronizingMerge' ); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'MultiChoiceSynchronizingMerge' ), - (string)$this->visitor - ); - } - - public function testVisitMultiChoiceDiscriminator() - { - $this->setUpMultiChoice( 'Discriminator' ); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'MultiChoiceDiscriminator' ), - (string)$this->visitor - ); - } - - public function testVisitWorkflowWithSubWorkflow() - { - $this->setUpWorkflowWithSubWorkflow( 'StartEnd' ); - $this->workflow->accept( $this->visitor ); - - $this->assertEquals( - $this->readExpected( 'WorkflowWithSubWorkflow' ), - (string)$this->visitor - ); - } - - protected function readExpected( $name ) - { - return file_get_contents( - dirname( __FILE__ ) . '/data/' . $name . '.dot' - ); - } -} -?> Copied: trunk/Workflow/tests/visitor_visualization_test.php (from rev 5024, trunk/Workflow/tests/visitor_dot_test.php) =================================================================== --- trunk/Workflow/tests/visitor_dot_test.php 2007-05-03 15:12:46 UTC (rev 5024) +++ trunk/Workflow/tests/visitor_visualization_test.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -0,0 +1,171 @@ +<?php +/** + * @package Workflow + * @subpackage Tests + * @version //autogentag// + * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +require_once 'case.php'; + +/** + * @package Workflow + * @subpackage Tests + */ +class ezcWorkflowVisitorVisualizationTest extends ezcWorkflowTestCase +{ + protected $visitor; + + public static function suite() + { + return new PHPUnit_Framework_TestSuite( 'ezcWorkflowVisitorVisualizationTest' ); + } + + protected function setUp() + { + parent::setUp(); + + $this->visitor = new ezcWorkflowVisitorVisualization; + } + + public function testVisitStartEnd() + { + $this->setUpStartEnd(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'StartEnd' ), + (string)$this->visitor + ); + } + + public function testVisitStartInputEnd() + { + $this->setUpStartInputEnd(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'StartInputEnd' ), + (string)$this->visitor + ); + } + + public function testVisitStartSetUnsetEnd() + { + $this->setUpStartSetUnsetEnd(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'StartSetUnsetEnd' ), + (string)$this->visitor + ); + } + + public function testVisitIncrementingLoop() + { + $this->setUpLoop( 'increment' ); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'IncrementingLoop' ), + (string)$this->visitor + ); + } + + public function testVisitDecrementingLoop() + { + $this->setUpLoop( 'decrement' ); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'DecrementingLoop' ), + (string)$this->visitor + ); + } + + public function testVisitSetAddSubMulDiv() + { + $this->setUpSetAddSubMulDiv(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'SetAddSubMulDiv' ), + (string)$this->visitor + ); + } + + public function testVisitAddVariables() + { + $this->setUpAddVariables(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'AddVariables' ), + (string)$this->visitor + ); + } + + public function testVisitParallelSplitSynchronization() + { + $this->setUpParallelSplitSynchronization(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'ParallelSplitSynchronization' ), + (string)$this->visitor + ); + } + + public function testVisitExclusiveChoiceSimpleMerge() + { + $this->setUpExclusiveChoiceSimpleMerge(); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'ExclusiveChoiceSimpleMerge' ), + (string)$this->visitor + ); + } + + public function testVisitMultiChoiceSynchronizingMerge() + { + $this->setUpMultiChoice( 'SynchronizingMerge' ); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'MultiChoiceSynchronizingMerge' ), + (string)$this->visitor + ); + } + + public function testVisitMultiChoiceDiscriminator() + { + $this->setUpMultiChoice( 'Discriminator' ); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'MultiChoiceDiscriminator' ), + (string)$this->visitor + ); + } + + public function testVisitWorkflowWithSubWorkflow() + { + $this->setUpWorkflowWithSubWorkflow( 'StartEnd' ); + $this->workflow->accept( $this->visitor ); + + $this->assertEquals( + $this->readExpected( 'WorkflowWithSubWorkflow' ), + (string)$this->visitor + ); + } + + protected function readExpected( $name ) + { + return file_get_contents( + dirname( __FILE__ ) . '/data/' . $name . '.dot' + ); + } +} +?> Modified: trunk/WorkflowDatabaseTiein/docs/examples/visualize.php =================================================================== --- trunk/WorkflowDatabaseTiein/docs/examples/visualize.php 2007-05-03 15:38:21 UTC (rev 5025) +++ trunk/WorkflowDatabaseTiein/docs/examples/visualize.php 2007-05-03 16:00:50 UTC (rev 5026) @@ -11,7 +11,7 @@ $workflow = $definition->loadByName( 'Test' ); // Generate GraphViz/dot markup for workflow "Test". -$visitor = new ezcWorkflowVisitorDot; +$visitor = new ezcWorkflowVisitorVisualization; $workflow->accept( $visitor ); print $visitor; ?> -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
