Perforce Chronicle 2012.2/486814
API Documentation
|
Test workflow 'Contains' condition class. More...
Public Member Functions | |
testEvaluate () | |
Test evaluate() method. | |
Protected Member Functions | |
_evaluateRunner (array $records, Workflow_ConditionAbstract $condition) | |
Helper function to filter records array by condition evaluated in their context. |
Test workflow 'Contains' condition class.
Workflow_Test_ConditionContainsTest::_evaluateRunner | ( | array $ | records, |
Workflow_ConditionAbstract $ | condition | ||
) | [protected] |
Helper function to filter records array by condition evaluated in their context.
Returns array with record keys where given condition is met when evaluated in record context.
array | $records | records to filter by condition. |
Workflow_ConditionAbstract | $condition | condition to be evaluated in record context. |
{ $filteredRecords = array_filter( $records, function ($record) use ($condition) { return $condition->evaluate(new Workflow_Model_Transition, $record); } ); return array_keys($filteredRecords); }
Workflow_Test_ConditionContainsTest::testEvaluate | ( | ) |
Test evaluate() method.
{ // create few records to test with $recordA = P4Cms_Record::create( array( 'field1' => 'test field1 value', 'field2' => 'abc123 baz', 'field3' => 'foo bar' ) ); $recordA->setFieldMetadata('field1', array('type' => 'foo', 'mimeType' => 'bogus')); $recordB = P4Cms_Record::create( array( 'field1' => 'test field1 value', 'fieldY' => 'abc123 baz', 'fieldZ' => 'foo bar' ) ); $recordB->setFieldMetadata('field1', array('mimeType' => 'text/ascii')); $recordC = P4Cms_Record::create( array( 'r' => 'test fieldr value', 's' => 'abc123 baz', 't' => 'foo bar' ) ); $recordC->setFieldMetadata('s', array('mimeType' => 'foo')); // define tests $tests = array( array( 'options' => array(), 'expected' => array(), 'message' => __LINE__ . ": no options" ), array( 'options' => array( 'fields' => array('o1', 'o2', 'o3') ), 'expected' => array(), 'message' => __LINE__ . ": bogus fields" ), array( 'options' => array( 'string' => 'test1a' ), 'expected' => array(), 'message' => __LINE__ . ": literal match" ), array( 'options' => array( 'string' => 'test' ), 'expected' => array('b', 'c'), 'message' => __LINE__ . ": literal match" ), array( 'options' => array( 'string' => 'TEST', 'fields' => 'field1' ), 'expected' => array('b'), 'message' => __LINE__ . ": literal match, specified fields" ), array( 'options' => array( 'pattern' => '/./' ), 'expected' => array('a', 'b', 'c'), 'message' => __LINE__ . ": regex match" ), array( 'options' => array( 'pattern' => '/\d{1,}/' ), 'expected' => array('a', 'b'), 'message' => __LINE__ . ": regex match" ), array( 'options' => array( 'pattern' => '/./', 'fields' => array('fieldY', 't', 'foo', 'bar') ), 'expected' => array('b', 'c'), 'message' => __LINE__ . ": regex match, specified fields" ), array( 'options' => array( 'pattern' => '/./', 'string' => 'string-that-is-not-present', ), 'expected' => array('a', 'b', 'c'), 'message' => __LINE__ . ": regex and literal match" ), array( 'options' => array( 'pattern' => '/\d{100}/', 'string' => 'foo', ), 'expected' => array('a', 'b', 'c'), 'message' => __LINE__ . ": regex and literal match" ), array( 'options' => array( 'pattern' => '/\d\w/', 'string' => 'd1 val', ), 'expected' => array('a', 'b'), 'message' => __LINE__ . ": regex and literal match" ), array( 'options' => array( 'pattern' => '/\d\w/', 'string' => 'd1 val', 'fields' => array('fieldQ') ), 'expected' => array(), 'message' => __LINE__ . ": regex and literal match, selected fields" ), array( 'options' => array( 'pattern' => '/\d\w/', 'string' => 'd1 val', 'fields' => array('field1', 's') ), 'expected' => array('b'), 'message' => __LINE__ . ": regex and literal match, selected fields" ) ); // instantiate condition contains class $class = Workflow_Module::getPluginLoader('condition')->load('contains'); $condition = new $class; // create records array for the runner $records = array('a' => $recordA, 'b' => $recordB, 'c' => $recordC); // run tests foreach ($tests as $test) { $condition->setOptions($test['options']); $this->assertSame( $test['expected'], $this->_evaluateRunner($records, $condition), 'Line ' . $test['message'] ); } }