You are here

public function ServicesClientPluginsTestCase::testServicesClientUserRoleCondition in Services Client 7.2

File

tests/plugin.test, line 502
Rules tests.

Class

ServicesClientPluginsTestCase
@file Rules tests.

Code

public function testServicesClientUserRoleCondition() {
  $this
    ->loadFiles();
  $event = $this
    ->createFakeEvent(array(
    'entity_type' => 'user',
  ));
  $user = new stdClass();
  $user->roles = array(
    '1',
    '2',
    '4',
  );
  $condition = new ServicesClientUserRoleCondition($event, $event->config);
  $this
    ->assertIdentical($condition
    ->getSummary(), "[ User roles condition - not configured ]", "Uncofigured user roles condition returns correct summary.");
  $condition
    ->setConfiguration(array(
    'roles' => array(
      '1' => '1',
      '2' => '2',
      '3' => '3',
    ),
    'intersect' => FALSE,
    'reverse' => FALSE,
  ) + $condition
    ->getConfiguration());

  // getSummary method contains user_role_load() that uses DB
  // $this->assertIdentical($condition->getSummary(), 'User has one of these roles: ', "Configured field condition plugin returns correct summary.");
  $this
    ->assertTrue($condition
    ->match($user));
  $condition
    ->setConfiguration(array(
    'intersect' => TRUE,
  ) + $condition
    ->getConfiguration());
  $this
    ->assertFalse($condition
    ->match($user));
  $condition
    ->setConfiguration(array(
    'reverse' => TRUE,
  ) + $condition
    ->getConfiguration());
  $this
    ->assertTrue($condition
    ->match($user));
}