You are here

function OgVocabMenuAccessTestCase::testAccess in OG Vocabulary 7

Test access to vocabulary.

  • User not a member of a group.
  • User member of group but no permissions
  • User member of group with correct permissions.
  • User is admin in group.
  • User has 'administer organic groups' permissions.

File

./og_vocab.test, line 34
Test organic groups vocabulary module.

Class

OgVocabMenuAccessTestCase
@file Test organic groups vocabulary module.

Code

function testAccess() {
  $perm = 'administer group';

  // Create two users.
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();

  // Create group owned by user1.
  $settings = array();
  $settings['type'] = 'article';
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $settings['uid'] = $user1->uid;
  $node = $this
    ->drupalCreateNode($settings);

  // Create a terms vocabulary.
  $vocabulary = new stdClass();
  $vocabulary->name = 'Terms';
  $vocabulary->machine_name = 'terms';
  taxonomy_vocabulary_save($vocabulary);

  // Create a term in the vocabulary.
  $term = new stdClass();
  $term->name = "term 1";
  $term->vid = $vocabulary->vid;
  taxonomy_term_save($term);

  // Relate vocabulary to group.
  og_vocab_relation_save($vocabulary->vid, 'node', $node->nid);
  $this
    ->assertTrue(og_user_access('node', $node->nid, 'administer taxonomy', $user1), 'User1 has access to the vocabulary.');
  $this
    ->assertFalse(og_user_access('node', $node->nid, 'administer taxonomy', $user2), 'User2 does not have access to the vocabulary.');
  $paths = array(
    'taxonomy',
    'taxonomy/add',
    'taxonomy/terms',
    'taxonomy/terms/list',
    'taxonomy/terms/edit',
    'taxonomy/terms/add',
  );
  $this
    ->drupalLogin($user1);
  foreach ($paths as $path) {
    $path = 'group/node/1/admin/' . $path;
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, format_string('User1 can access @path', array(
      '@path' => $path,
    )));
  }
  $path = 'taxonomy/term/1/edit';
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(200, format_string('User1 can access @path', array(
    '@path' => $path,
  )));
  $this
    ->drupalLogin($user2);
  foreach ($paths as $path) {
    $path = 'group/node/1/admin/' . $path;
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(403, format_string('User2 can not access @path', array(
      '@path' => $path,
    )));
  }
  $path = 'taxonomy/term/1/edit';
  $this
    ->drupalGet($path);
  $this
    ->assertResponse(403, format_string('User2 can not access @path', array(
    '@path' => $path,
  )));
}