You are here

public function EntityMetadataTaxonomyAccessTestCase::testTaxonomyMetadataAccess in Entity API 7

Runs basic tests for entity_access() function.

File

./entity.test, line 1392
Entity CRUD API tests.

Class

EntityMetadataTaxonomyAccessTestCase
Tests basic entity_access() functionality for taxonomy terms.

Code

public function testTaxonomyMetadataAccess() {
  $vocab = $this
    ->createVocabulary();
  $term = entity_property_values_create_entity('taxonomy_term', array(
    'name' => $this
      ->randomName(),
    'vocabulary' => $vocab,
  ))
    ->save()
    ->value();

  // Clear permissions static cache to get new taxonomy permissions.
  drupal_static_reset('checkPermissions');

  // Check assignment of view permissions.
  $user1 = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->assertTaxonomyMetadataAccess(array(
    'create' => FALSE,
    'view' => TRUE,
    'update' => FALSE,
    'delete' => FALSE,
  ), $term, $user1);

  // Check assignment of edit permissions.
  $user2 = $this
    ->drupalCreateUser(array(
    'edit terms in ' . $vocab->vid,
  ));
  $this
    ->assertTaxonomyMetadataAccess(array(
    'create' => FALSE,
    'view' => FALSE,
    'update' => TRUE,
    'delete' => FALSE,
  ), $term, $user2);

  // Check assignment of delete permissions.
  $user3 = $this
    ->drupalCreateUser(array(
    'delete terms in ' . $vocab->vid,
  ));
  $this
    ->assertTaxonomyMetadataAccess(array(
    'create' => FALSE,
    'view' => FALSE,
    'update' => FALSE,
    'delete' => TRUE,
  ), $term, $user3);

  // Check assignment of view, edit, delete permissions.
  $user4 = $this
    ->drupalCreateUser(array(
    'access content',
    'edit terms in ' . $vocab->vid,
    'delete terms in ' . $vocab->vid,
  ));
  $this
    ->assertTaxonomyMetadataAccess(array(
    'create' => FALSE,
    'view' => TRUE,
    'update' => TRUE,
    'delete' => TRUE,
  ), $term, $user4);

  // Check assignment of administration permissions.
  $user5 = $this
    ->drupalCreateUser(array(
    'administer taxonomy',
  ));
  $this
    ->assertTaxonomyMetadataAccess(array(
    'create' => TRUE,
    'view' => TRUE,
    'update' => TRUE,
    'delete' => TRUE,
  ), $term, $user5);
}