You are here

public function ServicesClientPluginsTestCase::testServicesClientPropertyCondition in Services Client 7.2

File

tests/plugin.test, line 418
Rules tests.

Class

ServicesClientPluginsTestCase
@file Rules tests.

Code

public function testServicesClientPropertyCondition() {
  $this
    ->loadFiles();
  $event = $this
    ->createFakeEvent();
  $fake_entity = new stdClass();
  $fake_entity->test_prop = 'test';
  $condition = new ServicesClientPropertyCondition($event, $event->config);
  $this
    ->assertIdentical($condition
    ->getSummary(), "[ Property condition - not configured ]", "Uncofigured property condition returns correct summary.");
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Unconfigured property condition returns FALSE");
  $condition
    ->setConfiguration(array(
    'property' => 'test_prop',
    'condition' => 'equals',
    'value' => 'test',
  ) + $condition
    ->getConfiguration());
  $this
    ->assertIdentical($condition
    ->getSummary(), '<b>test_prop</b> equals <b>test</b>', "Configured property condition plugin returns correct summary.");
  $this
    ->assertIdentical($condition
    ->match($fake_entity), TRUE, "Condition matches if entity has property value");
  $fake_entity->test_prop = 'test1';
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Condition doesn't match if entity has property value different");
  unset($fake_entity->test_prop);
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Condition doesn't match if entity has property doesn't exists.");

  // Change condition configuration to empty
  $condition
    ->setConfiguration(array(
    'condition' => 'empty',
  ) + $condition
    ->getConfiguration());
  $this
    ->assertIdentical($condition
    ->match($fake_entity), TRUE, "Condition matches if configured to empty and entity has doesn't have property.");
  $fake_entity->test_prop = 'test';
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Condition doesn't match if configured to empty and entity has property value.");
  $condition
    ->setConfiguration(array(
    'condition' => 'not_empty',
  ) + $condition
    ->getConfiguration());
  $this
    ->assertIdentical($condition
    ->match($fake_entity), TRUE, "Condition matches if configured to not empty and entity has property value.");
  unset($fake_entity->test_prop);
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Condition doesn't match if configured to not empty and entity doesn't have property value.");
  $condition
    ->setConfiguration(array(
    'condition' => 'not_equals',
  ) + $condition
    ->getConfiguration());
  $this
    ->assertIdentical($condition
    ->match($fake_entity), TRUE, "Condition matches if configured to not equals and entity doesn't have property value.");
  $fake_entity->test_prop = 'test1';
  $this
    ->assertIdentical($condition
    ->match($fake_entity), TRUE, "Condition matches if configured to not equals and entity  has different property value.");
  $fake_entity->test_prop = 'test';
  $this
    ->assertIdentical($condition
    ->match($fake_entity), FALSE, "Condition doesn't match if configured to not equals and entity has same property value.");
}