Author: sb
Date: Fri Aug 10 10:32:55 2007
New Revision: 5860
Log:
- Implement issue #10883: Apply comparison conditions to two variables.
Added:
trunk/Workflow/src/conditions/variables.php
- copied, changed from r5852, trunk/Workflow/src/conditions/variable.php
trunk/Workflow/tests/data/VariableEqualsVariable_1.xml (with props)
Modified:
trunk/Workflow/ChangeLog
trunk/Workflow/design/class_diagram.png
trunk/Workflow/src/definition_storage/xml.php
trunk/Workflow/src/workflow_autoload.php
trunk/Workflow/tests/case.php
trunk/Workflow/tests/condition_test.php
trunk/Workflow/tests/definition_xml_test.php
trunk/Workflow/tests/execution_test.php
Modified: trunk/Workflow/ChangeLog
==============================================================================
--- trunk/Workflow/ChangeLog [iso-8859-1] (original)
+++ trunk/Workflow/ChangeLog [iso-8859-1] Fri Aug 10 10:32:55 2007
@@ -4,6 +4,7 @@
- The marshalling of the node configuration is now handled in the individual
node classes. This makes it possible to have custom node classes handled by
the XML definition storage.
+- 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.
- Fixed issue #11068: Implement ezcWorkflowExecution::hasVariable().
Modified: trunk/Workflow/design/class_diagram.png
==============================================================================
Binary files - no diff available.
Copied: trunk/Workflow/src/conditions/variables.php (from r5852,
trunk/Workflow/src/conditions/variable.php)
==============================================================================
--- trunk/Workflow/src/conditions/variable.php [iso-8859-1] (original)
+++ trunk/Workflow/src/conditions/variables.php [iso-8859-1] Fri Aug 10
10:32:55 2007
@@ -1,6 +1,6 @@
<?php
/**
- * File containing the ezcWorkflowConditionVariable class.
+ * File containing the ezcWorkflowConditionVariables class.
*
* @package Workflow
* @version //autogen//
@@ -9,23 +9,46 @@
*/
/**
- * Wrapper that applies a condition to a workflow variable.
+ * Wrapper that applies a condition to two workflow variables.
*
* @package Workflow
* @version //autogen//
*/
-class ezcWorkflowConditionVariable implements ezcWorkflowCondition
+class ezcWorkflowConditionVariables implements ezcWorkflowCondition
{
+ /**
+ * @var string
+ */
+ protected $variableNameA;
+
+ /**
+ * @var string
+ */
+ protected $variableNameB;
+
+ /**
+ * @var string
+ */
+ protected $ezcWorkflowCondition;
+
/**
* Constructor.
*
- * @param string $variableName
+ * @param string $variableNameA
+ * @param string $variableNameB
* @param ezcWorkflowCondition $condition
+ * @throws ezcWorkflowInvalidWorkflowException
*/
- public function __construct( $variableName, ezcWorkflowCondition
$condition )
+ public function __construct( $variableNameA, $variableNameB,
ezcWorkflowCondition $condition )
{
- $this->variableName = $variableName;
- $this->condition = $condition;
+ if ( !$condition instanceof ezcWorkflowConditionComparison )
+ {
+ throw new ezcWorkflowInvalidWorkflowException;
+ }
+
+ $this->variableNameA = $variableNameA;
+ $this->variableNameB = $variableNameB;
+ $this->condition = $condition;
}
/**
@@ -37,36 +60,17 @@
*/
public function evaluate( $value )
{
- if ( is_array( $value ) && isset( $value[$this->variableName] ) )
+ if ( is_array( $value ) &&
+ isset( $value[$this->variableNameA] ) &&
+ isset( $value[$this->variableNameB] ) )
{
- return $this->condition->evaluate( $value[$this->variableName] );
+ $this->condition->setValue( $value[$this->variableNameA] );
+ return $this->condition->evaluate( $value[$this->variableNameB] );
}
else
{
return false;
}
- }
-
- /**
- * Returns a textual representation of this condition.
- *
- * @return string
- * @ignore
- */
- public function __toString()
- {
- return $this->variableName . ' ' . (string)$this->condition;
- }
-
- /**
- * Returns the name of the variable the condition is evaluated for.
- *
- * @return string
- * @ignore
- */
- public function getVariableName()
- {
- return $this->variableName;
}
/**
@@ -79,5 +83,33 @@
{
return $this->condition;
}
+
+ /**
+ * Returns the names of the variables the condition is evaluated for.
+ *
+ * @return array
+ * @ignore
+ */
+ public function getVariableNames()
+ {
+ return array( $this->variableNameA, $this->variableNameB );
+ }
+
+ /**
+ * Returns a textual representation of this condition.
+ *
+ * @return string
+ * @ignore
+ */
+ public function __toString()
+ {
+ return sprintf(
+ '%s %s %s',
+
+ $this->variableNameA,
+ $this->condition->getOperator(),
+ $this->variableNameB
+ );
+ }
}
?>
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] Fri Aug 10
10:32:55 2007
@@ -295,6 +295,18 @@
}
break;
+ case 'ezcWorkflowConditionVariables': {
+ list( $variableNameA, $variableNameB ) =
$condition->getVariableNames();
+
+ $xmlCondition->setAttribute( 'a', $variableNameA );
+ $xmlCondition->setAttribute( 'b', $variableNameB );
+
+ $xmlCondition->appendChild(
+ self::conditionToXml( $condition->getCondition(), $document )
+ );
+ }
+ break;
+
case 'ezcWorkflowConditionAnd':
case 'ezcWorkflowConditionOr':
case 'ezcWorkflowConditionXor': {
@@ -343,6 +355,15 @@
case 'ezcWorkflowConditionVariable': {
return new $class(
$element->getAttribute( 'name' ),
+ self::xmlToCondition( $element->childNodes->item( 1 ) )
+ );
+ }
+ break;
+
+ case 'ezcWorkflowConditionVariables': {
+ return new $class(
+ $element->getAttribute( 'a' ),
+ $element->getAttribute( 'b' ),
self::xmlToCondition( $element->childNodes->item( 1 ) )
);
}
Modified: trunk/Workflow/src/workflow_autoload.php
==============================================================================
--- trunk/Workflow/src/workflow_autoload.php [iso-8859-1] (original)
+++ trunk/Workflow/src/workflow_autoload.php [iso-8859-1] Fri Aug 10 10:32:55
2007
@@ -49,6 +49,7 @@
'ezcWorkflowConditionNot' =>
'Workflow/conditions/not.php',
'ezcWorkflowConditionOr' => 'Workflow/conditions/or.php',
'ezcWorkflowConditionVariable' =>
'Workflow/conditions/variable.php',
+ 'ezcWorkflowConditionVariables' =>
'Workflow/conditions/variables.php',
'ezcWorkflowConditionXor' =>
'Workflow/conditions/xor.php',
'ezcWorkflowDefinitionStorageXml' =>
'Workflow/definition_storage/xml.php',
'ezcWorkflowExecutionListener' =>
'Workflow/interfaces/execution_listener.php',
Modified: trunk/Workflow/tests/case.php
==============================================================================
--- trunk/Workflow/tests/case.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/case.php [iso-8859-1] Fri Aug 10 10:32:55 2007
@@ -228,6 +228,49 @@
$this->startNode->addOutNode( $set );
$set->addOutNode( $add );
$this->endNode->addInNode( $add );
+ }
+
+ protected function setUpVariableEqualsVariable()
+ {
+ $this->workflow = new ezcWorkflow( 'VariableEqualsVariable' );
+ $this->setUpReferences();
+
+ $set = new ezcWorkflowNodeVariableSet(
+ array( 'a' => 1, 'b' => 1 )
+ );
+
+ $set2 = new ezcWorkflowNodeVariableSet(
+ array( 'c' => 1 )
+ );
+
+ $set3 = new ezcWorkflowNodeVariableSet(
+ array( 'c' => 0 )
+ );
+
+ $this->branchNode = new ezcWorkflowNodeExclusiveChoice;
+ $this->branchNode->addInNode( $set );
+
+ $this->branchNode->addConditionalOutNode(
+ new ezcWorkflowConditionVariables(
+ 'a', 'b', new ezcWorkflowConditionIsEqual
+ ),
+ $set2
+ );
+
+ $this->branchNode->addConditionalOutNode(
+ new ezcWorkflowConditionVariables(
+ 'a', 'b', new ezcWorkflowConditionIsNotEqual
+ ),
+ $set3
+ );
+
+ $simpleMerge = new ezcWorkflowNodeSimpleMerge;
+
+ $simpleMerge->addInNode( $set2 )
+ ->addInNode( $set3 );
+
+ $this->startNode->addOutNode( $set );
+ $this->endNode->addInNode( $simpleMerge );
}
protected function setUpParallelSplitSynchronization()
Modified: trunk/Workflow/tests/condition_test.php
==============================================================================
--- trunk/Workflow/tests/condition_test.php [iso-8859-1] (original)
+++ trunk/Workflow/tests/condition_test.php [iso-8859-1] Fri Aug 10 10:32:55
2007
@@ -190,6 +190,18 @@
$this->assertFalse( $condition->evaluate( array( 'bar' => 'foo' ) ) );
}
+ public function testVariables()
+ {
+ $condition = new ezcWorkflowConditionVariables(
+ 'foo',
+ 'bar',
+ new ezcWorkflowConditionIsEqual
+ );
+
+ $this->assertTrue( $condition->evaluate( array( 'foo' => 'baz', 'bar'
=> 'baz' ) ) );
+ $this->assertFalse( $condition->evaluate( array( 'foo' => 'bar', 'bar'
=> 'foo' ) ) );
+ }
+
public function testAnd()
{
$true = new ezcWorkflowConditionIsTrue;
Added: trunk/Workflow/tests/data/VariableEqualsVariable_1.xml
==============================================================================
--- trunk/Workflow/tests/data/VariableEqualsVariable_1.xml (added)
+++ trunk/Workflow/tests/data/VariableEqualsVariable_1.xml [iso-8859-1] Fri Aug
10 10:32:55 2007
@@ -1,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<workflow name="VariableEqualsVariable" version="1">
+ <node id="1" type="Start">
+ <outNode id="2"/>
+ </node>
+ <node id="2" type="VariableSet">
+ <variable name="a">
+ <integer>1</integer>
+ </variable>
+ <variable name="b">
+ <integer>1</integer>
+ </variable>
+ <outNode id="3"/>
+ </node>
+ <node id="3" type="ExclusiveChoice">
+ <condition type="Variables" a="a" b="b">
+ <condition type="IsEqual" value=""/>
+ <outNode id="4"/>
+ </condition>
+ <condition type="Variables" a="a" b="b">
+ <condition type="IsNotEqual" value=""/>
+ <outNode id="7"/>
+ </condition>
+ </node>
+ <node id="4" type="VariableSet">
+ <variable name="c">
+ <integer>1</integer>
+ </variable>
+ <outNode id="5"/>
+ </node>
+ <node id="5" type="SimpleMerge">
+ <outNode id="6"/>
+ </node>
+ <node id="6" type="End"/>
+ <node id="7" type="VariableSet">
+ <variable name="c">
+ <integer>0</integer>
+ </variable>
+ <outNode id="5"/>
+ </node>
+</workflow>
Propchange: trunk/Workflow/tests/data/VariableEqualsVariable_1.xml
------------------------------------------------------------------------------
svn:eol-style = native
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] Fri Aug 10
10:32:55 2007
@@ -119,6 +119,17 @@
);
}
+ public function testSaveVariableEqualsVariable()
+ {
+ $this->setUpVariableEqualsVariable();
+ $this->definition->save( $this->workflow );
+
+ $this->assertEquals(
+ $this->readExpected( 'VariableEqualsVariable' ),
+ $this->readActual( 'VariableEqualsVariable' )
+ );
+ }
+
public function testSaveParallelSplitSynchronization()
{
$this->setUpParallelSplitSynchronization();
@@ -337,6 +348,17 @@
$this->assertEquals(
$this->readExpected( 'AddVariables' ),
$this->readActual( 'AddVariables' )
+ );
+ }
+
+ public function testLoadVariableEqualsVariable()
+ {
+ $this->workflow = $this->definition->loadByName(
'VariableEqualsVariable' );
+ $this->definition->save( $this->workflow );
+
+ $this->assertEquals(
+ $this->readExpected( 'VariableEqualsVariable' ),
+ $this->readActual( 'VariableEqualsVariable' )
);
}
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] Fri Aug 10 10:32:55
2007
@@ -300,6 +300,18 @@
$this->fail();
}
+ public function testExecuteVariableEqualsVariable()
+ {
+ $this->setUpVariableEqualsVariable();
+ $this->execution->workflow = $this->workflow;
+ $this->execution->start();
+
+ $this->assertTrue( $this->execution->hasEnded() );
+ $this->assertFalse( $this->execution->isResumed() );
+ $this->assertFalse( $this->execution->isSuspended() );
+ $this->assertEquals( 1, $this->execution->getVariable( 'c' ) );
+ }
+
public function testExecuteParallelSplitSynchronization()
{
$this->setUpParallelSplitSynchronization();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components