function OgVocabApiTestCase::testLabelUrlCallbacks in OG Vocabulary 7
Test the entity_label() and entity_uri() callbacks.
File
- ./
og_vocab.test, line 431 - Test organic groups vocabulary module.
Class
Code
function testLabelUrlCallbacks() {
global $user;
$admin1 = $this
->drupalCreateUser(array(
'administer taxonomy',
));
$type = $this->type;
$vocab = taxonomy_vocabulary_load($this->vid);
$group = node_load($this->gid);
$og_vocab = og_vocab_create_og_vocab($this->vid, 'node', $type->type);
$og_vocab
->save();
$this
->drupalLogin($admin1);
$label = entity_label('og_vocab', $og_vocab);
$params = array(
'@id' => $og_vocab->id,
'@bundle' => $type->name,
'@name' => $vocab->name,
);
$expected_label = t('@bundle bundle in @name vocabulary (OG Vocabulary ID @id)', $params);
$this
->assertEqual($label, $expected_label, 'Correct label for admin user.');
$uri = entity_uri('og_vocab', $og_vocab);
$this
->assertEqual($uri['path'], 'admin/structure/taxonomy/terms/edit', 'Correct URL for admin user.');
// Assert the fragment.
$this
->assertEqual($uri['options']['fragment'], 'og-vocab-node-' . $type->type, 'Correct URL fragment.');
$this
->drupalLogin($this->user2);
// This is needed as otherwise og_user_access() fails.
$user = $this->user2;
$label = entity_label('og_vocab', $og_vocab);
$expected_label = t('OG Vocabulary ID @id', array(
'@id' => $og_vocab->id,
));
$this
->assertEqual($label, $expected_label, 'Correct label for authenticated user.');
$uri = entity_uri('og_vocab', $og_vocab);
$this
->assertTrue(empty($uri['path']), 'User has no access to the URL.');
// Set group permissions.
$roles = array_flip(og_roles('node', $group->type));
og_role_change_permissions($roles[OG_AUTHENTICATED_ROLE], array(
'administer taxonomy' => 1,
));
// Add user to group.
og_group('node', $this->gid, array(
'entity' => $this->user2,
));
$uri = entity_uri('og_vocab', $og_vocab);
$this
->assertEqual($uri['path'], "group/node/{$this->gid}/admin/taxonomy/{$vocab->machine_name}/edit", 'Correct URL for authenticated user that is a group member.');
}