public function ServicesClientPluginsTestCase::testServicesClientFieldCondition in Services Client 7.2
File
- tests/
plugin.test, line 455 - Rules tests.
Class
- ServicesClientPluginsTestCase
- @file Rules tests.
Code
public function testServicesClientFieldCondition() {
$this
->loadFiles();
$event = $this
->createFakeEvent();
$fake_entity = new stdClass();
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'test';
$condition = new ServicesClientFieldCondition($event, $event->config);
$this
->assertIdentical($condition
->getSummary(), "[ Field condition - not configured ]", "Uncofigured field condition returns correct summary.");
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Unconfigured field condition doesn't match.");
$condition
->setConfiguration(array(
'field' => 'field_test',
'language' => LANGUAGE_NONE,
'property' => 'value',
'condition' => 'equals',
'value' => 'test',
) + $condition
->getConfiguration());
$this
->assertIdentical($condition
->getSummary(), '<b>field_test[und][*][value]</b> equals <b>test</b>', "Configured field condition plugin returns correct summary.");
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition matches if entity has field value");
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'test1';
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Condition doesn't match if entity has field value different");
unset($fake_entity->field_test);
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Condition doesn't match if entity field doesn't exists.");
$fake_entity->field_test[LANGUAGE_NONE] = array(
array(
'value' => 'test1',
),
array(
'value' => 'test',
),
);
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition matches if entity has field value");
// Change condition configuration to empty
$condition
->setConfiguration(array(
'condition' => 'empty',
) + $condition
->getConfiguration());
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Condition doesn't match if configured to empty and entity has field value.");
unset($fake_entity->field_test);
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition matches if configured to empty and entity doens't have field.");
$condition
->setConfiguration(array(
'condition' => 'not_empty',
) + $condition
->getConfiguration());
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Condition matches if configured to not empty and entity has property value.");
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'test';
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition doesn't match if configured to not empty and entity doesn't have property value.");
$condition
->setConfiguration(array(
'condition' => 'not_equals',
) + $condition
->getConfiguration());
unset($fake_entity->field_test);
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition matches if configured to not equals and entity doesn't have field value.");
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'test1';
$fake_entity->field_test[LANGUAGE_NONE][1]['value'] = 'test2';
$fake_entity->field_test[LANGUAGE_NONE][1]['key'] = 'test3';
$this
->assertIdentical($condition
->match($fake_entity), TRUE, "Condition matches if configured to not equals and entity has different field value.");
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'test';
$this
->assertIdentical($condition
->match($fake_entity), FALSE, "Condition doesn't match if configured to not equals and entity has same field value.");
}