Author: sb
Date: Tue Oct 2 18:55:15 2007
New Revision: 6343
Log:
- Implement issue #11003: Add ELSE option to exclusive choice.
Added:
trunk/Workflow/tests/data/ExclusiveChoiceWithElseSimpleMerge_1.xml
Modified:
trunk/Workflow/ChangeLog
trunk/Workflow/src/definition_storage/xml.php
trunk/Workflow/src/interfaces/node_conditional_branch.php
trunk/Workflow/tests/case.php
trunk/Workflow/tests/definition_xml_test.php
trunk/Workflow/tests/execution_test.php
trunk/WorkflowDatabaseTiein/tests/definition_test.php
Modified: trunk/Workflow/ChangeLog
==============================================================================
--- trunk/Workflow/ChangeLog [iso-8859-1] (original)
+++ trunk/Workflow/ChangeLog [iso-8859-1] Tue Oct 2 18:55:15 2007
@@ -13,6 +13,7 @@
- Implemented issue #10883: Apply comparison conditions to two variables.
- Implemented issue #10918: Error messages when loading invalid XML.
- Implemented issue #10985: Mapping variables between parent and sub workflows.
+- Implemented issue #11003: Add ELSE option to exclusive choice.
- Fixed issue #11068: Implement ezcWorkflowExecution::hasVariable().
Modified: trunk/Workflow/src/definition_storage/xml.php
==============================================================================
--- trunk/Workflow/src/definition_storage/xml.php [iso-8859-1] (original)
+++ trunk/Workflow/src/definition_storage/xml.php [iso-8859-1] Tue Oct 2
18:55:15 2007
@@ -152,14 +152,35 @@
{
if ( $childNode instanceof DOMElement &&
$childNode->tagName == 'condition' )
{
+ foreach ( $childNode->getElementsByTagName( 'else' )
as $elseNode )
+ {
+ foreach ( $elseNode->getElementsByTagName(
'outNode' ) as $outNode )
+ {
+ $elseId = (int)$outNode->getAttribute( 'id' );
+ }
+ }
+
$condition = $this->xmlToCondition( $childNode );
foreach ( $childNode->getElementsByTagName( 'outNode'
) as $outNode )
{
- $nodes[$id]->addConditionalOutNode(
- $condition,
- $nodes[(int)$outNode->getAttribute( 'id' )]
- );
+ if ( !isset( $elseId ) )
+ {
+ $nodes[$id]->addConditionalOutNode(
+ $condition,
+ $nodes[(int)$outNode->getAttribute( 'id' )]
+ );
+ }
+ else
+ {
+ $nodes[$id]->addConditionalOutNode(
+ $condition,
+ $nodes[(int)$outNode->getAttribute( 'id' )],
+ $nodes[$elseId]
+ );
+
+ unset( $elseId );
+ }
}
}
}
@@ -228,11 +249,15 @@
$node->configurationtoXML( $xmlNode );
$root->appendChild( $xmlNode );
- foreach ( $node->getOutNodes() as $outNode )
+ $outNodes = $node->getOutNodes();
+ $_keys = array_keys( $outNodes );
+ $numOutNodes = count( $_keys );
+
+ for ( $j = 0; $j < $numOutNodes; $j++ )
{
foreach ( $nodes as $outNodeId => $_node )
{
- if ( $_node === $outNode )
+ if ( $_node === $outNodes[$_keys[$j]] )
{
break;
}
@@ -242,15 +267,23 @@
$xmlOutNode->setAttribute( 'id', $outNodeId );
if ( is_subclass_of( $nodeClass,
'ezcWorkflowNodeConditionalBranch' ) &&
- $condition = $node->getCondition( $outNode ) )
- {
- $xmlCondition = self::conditionToXml(
- $condition,
- $document
- );
-
- $xmlCondition->appendChild( $xmlOutNode );
- $xmlNode->appendChild( $xmlCondition );
+ $condition = $node->getCondition( $outNodes[$_keys[$j]]
) )
+ {
+ if ( !$node->isElse( $outNodes[$_keys[$j]] ) )
+ {
+ $xmlCondition = self::conditionToXml(
+ $condition,
+ $document
+ );
+
+ $xmlCondition->appendChild( $xmlOutNode );
+ $xmlNode->appendChild( $xmlCondition );
+ }
+ else
+ {
+ $xmlElse = $xmlCondition->appendChild(
$document->createElement( 'else' ) );
+ $xmlElse->appendChild( $xmlOutNode );
+ }
}
else
{
Modified: trunk/Workflow/src/interfaces/node_conditional_branch.php
==============================================================================
--- trunk/Workflow/src/interfaces/node_conditional_branch.php [iso-8859-1]
(original)
+++ trunk/Workflow/src/interfaces/node_conditional_branch.php [iso-8859-1] Tue
Oct 2 18:55:15 2007
@@ -48,22 +48,36 @@
*
* The key is the position of the out node in the array of out nodes.
*
- * @var array( 'int' => ezcWorkflowCondtion )
+ * @var array( 'condition' => array( 'int' => ezcWorkflowCondtion ) )
*/
- protected $configuration = array();
-
+ protected $configuration = array(
+ 'condition' => array(),
+ 'else' => array()
+ );
/**
- * Adds the conditional outgoing node $outNode to this node with the
condition $condition.
+ * Adds the conditional outgoing node $outNode to this node with the
+ * condition $condition. Optionally, an $else node can be specified that is
+ * activated when the $condition evaluates to false.
*
* @param ezcWorkflowCondition $condition
- * @param ezcWorkflowNode $outNode
+ * @param ezcWorkflowNode $outNode
+ * @param ezcWorkflowNode $else
* @return ezcWorkflowNode
*/
- public function addConditionalOutNode( ezcWorkflowCondition $condition,
ezcWorkflowNode $outNode )
+ public function addConditionalOutNode( ezcWorkflowCondition $condition,
ezcWorkflowNode $outNode, ezcWorkflowNode $else = null )
{
$this->addOutNode( $outNode );
- $this->configuration[ezcWorkflowUtil::findObject( $this->outNodes,
$outNode )] = $condition;
+ $this->configuration['condition'][ezcWorkflowUtil::findObject(
$this->outNodes, $outNode )] = $condition;
+
+ if ( !is_null( $else ) )
+ {
+ $this->addOutNode( $else );
+
+ $key = ezcWorkflowUtil::findObject( $this->outNodes, $else );
+ $this->configuration['condition'][$key] = new
ezcWorkflowConditionNot( $condition );
+ $this->configuration['else'][$key] = true;
+ }
return $this;
}
@@ -86,9 +100,9 @@
{
if ( $this->outNodes[$keys[$i]] === $node )
{
- if ( isset( $this->configuration[$keys[$i]] ) )
+ if ( isset( $this->configuration['condition'][$keys[$i]] ) )
{
- return $this->configuration[$keys[$i]];
+ return $this->configuration['condition'][$keys[$i]];
}
else
{
@@ -98,6 +112,18 @@
}
return false;
+ }
+
+ /**
+ * Returns true when the $node belongs to an ELSE condition.
+ *
+ * @param ezcWorkflowNode $node
+ * @return bool
+ * @ignore
+ */
+ public function isElse( ezcWorkflowNode $node )
+ {
+ return isset(
$this->configuration['else'][ezcWorkflowUtil::findObject( $this->outNodes,
$node )] );
}
/**
@@ -116,10 +142,10 @@
for ( $i = 0; $i < $numKeys; $i++ )
{
- if ( isset( $this->configuration[$keys[$i]] ) )
+ if ( isset( $this->configuration['condition'][$keys[$i]] ) )
{
// Conditional outgoing node.
- if ( $this->configuration[$keys[$i]]->evaluate(
$execution->getVariables() ) )
+ if ( $this->configuration['condition'][$keys[$i]]->evaluate(
$execution->getVariables() ) )
{
$nodesToStart[] = $this->outNodes[$keys[$i]];
$numActivatedConditionalOutNodes++;
@@ -158,7 +184,7 @@
{
parent::verify();
- $numConditionalOutNodes = count( $this->configuration );
+ $numConditionalOutNodes = count( $this->configuration['condition'] );
if ( $this->minConditionalOutNodes !== false &&
$numConditionalOutNodes < $this->minConditionalOutNodes )
{
Modified: trunk/Workflow/tests/case.php
==============================================================================
--- trunk/Workflow/tests/case.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/case.php [iso-8859-1] Tue Oct 2 18:55:15 2007
@@ -352,6 +352,39 @@
$simpleMerge->addInNode( $actionNodeA );
$simpleMerge->addInNode( $actionNodeB );
+
+ $this->startNode->addOutNode( $this->branchNode );
+ $this->endNode->addInNode( $simpleMerge );
+ }
+
+ protected function setUpExclusiveChoiceWithElseSimpleMerge()
+ {
+ $this->workflow = new ezcWorkflow(
'ExclusiveChoiceWithElseSimpleMerge' );
+ $this->setUpReferences();
+
+ $this->branchNode = new ezcWorkflowNodeExclusiveChoice;
+
+ $setX = new ezcWorkflowNodeVariableSet(
+ array( 'x' => true )
+ );
+
+ $setY = new ezcWorkflowNodeVariableSet(
+ array( 'y' => true )
+ );
+
+ $this->branchNode->addConditionalOutNode(
+ new ezcWorkflowConditionVariable(
+ 'condition',
+ new ezcWorkflowConditionIsTrue
+ ),
+ $setX,
+ $setY
+ );
+
+ $simpleMerge = new ezcWorkflowNodeSimpleMerge;
+
+ $simpleMerge->addInNode( $setX );
+ $simpleMerge->addInNode( $setY );
$this->startNode->addOutNode( $this->branchNode );
$this->endNode->addInNode( $simpleMerge );
Added: trunk/Workflow/tests/data/ExclusiveChoiceWithElseSimpleMerge_1.xml
==============================================================================
--- trunk/Workflow/tests/data/ExclusiveChoiceWithElseSimpleMerge_1.xml (added)
+++ trunk/Workflow/tests/data/ExclusiveChoiceWithElseSimpleMerge_1.xml
[iso-8859-1] Tue Oct 2 18:55:15 2007
@@ -1,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<workflow name="ExclusiveChoiceWithElseSimpleMerge" version="1">
+ <node id="1" type="Start">
+ <outNode id="2"/>
+ </node>
+ <node id="2" type="ExclusiveChoice">
+ <condition type="Variable" name="condition">
+ <condition type="IsTrue"/>
+ <outNode id="3"/>
+ <else>
+ <outNode id="6"/>
+ </else>
+ </condition>
+ </node>
+ <node id="3" type="VariableSet">
+ <variable name="x">
+ <boolean>true</boolean>
+ </variable>
+ <outNode id="4"/>
+ </node>
+ <node id="4" type="SimpleMerge">
+ <outNode id="5"/>
+ </node>
+ <node id="5" type="End"/>
+ <node id="6" type="VariableSet">
+ <variable name="y">
+ <boolean>true</boolean>
+ </variable>
+ <outNode id="4"/>
+ </node>
+</workflow>
Modified: trunk/Workflow/tests/definition_xml_test.php
==============================================================================
--- trunk/Workflow/tests/definition_xml_test.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/definition_xml_test.php [iso-8859-1] Tue Oct 2
18:55:15 2007
@@ -174,6 +174,17 @@
);
}
+ public function testSaveExclusiveChoiceWithElseSimpleMerge()
+ {
+ $this->setUpExclusiveChoiceWithElseSimpleMerge();
+ $this->definition->save( $this->workflow );
+
+ $this->assertEquals(
+ $this->readExpected( 'ExclusiveChoiceWithElseSimpleMerge' ),
+ $this->readActual( 'ExclusiveChoiceWithElseSimpleMerge' )
+ );
+ }
+
public function
testSaveExclusiveChoiceWithUnconditionalOutNodeSimpleMerge()
{
$this->setUpExclusiveChoiceWithUnconditionalOutNodeSimpleMerge();
@@ -381,6 +392,17 @@
$this->assertEquals(
$this->readExpected( 'ExclusiveChoiceSimpleMerge' ),
$this->readActual( 'ExclusiveChoiceSimpleMerge' )
+ );
+ }
+
+ public function testLoadExclusiveChoiceWithElseSimpleMerge()
+ {
+ $this->workflow = $this->definition->loadByName(
'ExclusiveChoiceWithElseSimpleMerge' );
+ $this->definition->save( $this->workflow );
+
+ $this->assertEquals(
+ $this->readExpected( 'ExclusiveChoiceWithElseSimpleMerge' ),
+ $this->readActual( 'ExclusiveChoiceWithElseSimpleMerge' )
);
}
Modified: trunk/Workflow/tests/execution_test.php
==============================================================================
--- trunk/Workflow/tests/execution_test.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/execution_test.php [iso-8859-1] Tue Oct 2 18:55:15
2007
@@ -415,6 +415,32 @@
$this->fail();
}
+ public function testExclusiveChoiceWithElseSimpleMerge()
+ {
+ $this->setUpExclusiveChoiceWithElseSimpleMerge();
+ $this->execution->workflow = $this->workflow;
+ $this->execution->setVariables( array( 'condition' => true ) );
+ $this->execution->start();
+
+ $this->assertTrue( $this->execution->hasEnded() );
+ $this->assertFalse( $this->execution->isResumed() );
+ $this->assertFalse( $this->execution->isSuspended() );
+ $this->assertEquals( true, $this->execution->getVariable( 'x' ) );
+ }
+
+ public function testExclusiveChoiceWithElseSimpleMerge2()
+ {
+ $this->setUpExclusiveChoiceWithElseSimpleMerge();
+ $this->execution->workflow = $this->workflow;
+ $this->execution->setVariables( array( 'condition' => false ) );
+ $this->execution->start();
+
+ $this->assertTrue( $this->execution->hasEnded() );
+ $this->assertFalse( $this->execution->isResumed() );
+ $this->assertFalse( $this->execution->isSuspended() );
+ $this->assertEquals( true, $this->execution->getVariable( 'y' ) );
+ }
+
public function testExclusiveChoiceWithUnconditionalOutNodeSimpleMerge()
{
$this->setUpExclusiveChoiceWithUnconditionalOutNodeSimpleMerge();
Modified: trunk/WorkflowDatabaseTiein/tests/definition_test.php
==============================================================================
--- trunk/WorkflowDatabaseTiein/tests/definition_test.php [iso-8859-1]
(original)
+++ trunk/WorkflowDatabaseTiein/tests/definition_test.php [iso-8859-1] Tue Oct
2 18:55:15 2007
@@ -114,6 +114,15 @@
$this->assertEquals( $this->workflow, $workflow, '', 0, 5 );
}
+ public function testSaveAndLoadExclusiveChoiceWithElseSimpleMerge()
+ {
+ $this->setUpExclusiveChoiceWithElseSimpleMerge();
+ $this->definition->save( $this->workflow );
+ $workflow = $this->definition->loadByName(
'ExclusiveChoiceWithElseSimpleMerge' );
+
+ $this->assertEquals( $this->workflow, $workflow, '', 0, 5 );
+ }
+
public function testExceptionWhenLoadingNotExistingWorkflow()
{
try
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components