1 taxonomy.test | TaxonomyVocabularyFunctionalTest::testVocabularyPermissions() |
Tests that vocabulary permissions are correctly set from the Taxonomy UI.
File
- core/
modules/ taxonomy/ tests/ taxonomy.test, line 144 - Tests for taxonomy.module.
Class
- TaxonomyVocabularyFunctionalTest
- Tests the taxonomy vocabulary interface.
Code
function testVocabularyPermissions() {
// Create admin user.
$admin_user = $this->backdropCreateUser(array(
'administer taxonomy',
'administer permissions',
'assign roles',
'administer users',
'access user profiles',
));
$this->backdropLogin($admin_user);
// Create new role
$role_name = $this->backdropCreateRole(array('access content'));
$web_user = $this->backdropCreateUser();
// Assign the role to a user.
$this->backdropPost('user/' . $web_user->uid . '/edit', array("roles[$role_name]" => $role_name), t('Save'));
// Check that the new role appears on the Vocabulary edit page.
$this->backdropGet('admin/structure/taxonomy/tags/configure');
$this->assertText($role_name, "$role_name is found on vocabulary form.");
// Check that the new role does not have a permission which wasn't granted.
$this->assertFieldByName($role_name . '[edit terms in tags]', 'edit terms in tags', "Role $role_name does not have edit terms in tags permission.");
// On the Vocabulary page: change permissions.
$edit = array(
$role_name . '[edit terms in tags]' => TRUE,
);
$this->backdropPost('admin/structure/taxonomy/tags/configure', $edit, t('Save vocabulary'));
// Check that the permission changes are saved on the permissions page.
$this->backdropGet('admin/config/people/permissions');
$this->assertFieldByName($role_name . '[edit terms in tags]', 'edit terms in tags', "Role $role_name has edit terms in tags permission.");
// Check that the new role does not have a permission which wasn't granted.
$this->assertFieldByName($role_name . '[delete terms in tags]', 'delete terms in tags', "Role $role_name does not have delete terms in tags permission.");
// On the Permissions page: change permissions for the "tags" vocabulary.
$edit = array(
$role_name . '[delete terms in tags]' => TRUE,
);
$this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
// Check that this permission is now selected on the vocabulary page.
$this->backdropGet('admin/structure/taxonomy/tags/configure');
$this->assertFieldByName($role_name . '[delete terms in tags]', 'delete terms in tags', "Role $role_name has delete terms in tags permission.");
// Test that the permissions actually exist
$this->backdropLogin($web_user);
backdrop_static_reset('user_roles');
backdrop_static_reset('user_access');
$account = user_load($web_user->uid, TRUE);
$this->assertTrue(user_access('edit terms in tags', $account), "Web user has edit terms in tags permission.");
$this->assertTrue(user_access('delete terms in tags', $account), "Web user has delete terms in tags permission.");
$vocabulary = taxonomy_vocabulary_load('tags');
$this->createTerm($vocabulary);
$this->createTerm($vocabulary);
$this->backdropGet('admin/structure/taxonomy/tags');
$this->assertText(t('Edit'), "Edit action is found on vocabulary form.");
$this->assertText(t('Delete'), "Delete action is found on vocabulary form.");
$this->assertNoText(t('Add term'), "Add term link found on vocabulary form.");
$this->assertText(t('Weight for added term'), 'Weight visible on term listing page.');
// Add "create term" permissions for the "tags" vocabulary.
$this->backdropLogin($admin_user);
backdrop_static_reset('user_roles');
backdrop_static_reset('user_access');
$edit = array(
$role_name . '[create terms in tags]' => TRUE,
);
$this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
// Test that the permissions actually exist
$this->backdropLogin($web_user);
backdrop_static_reset('user_roles');
backdrop_static_reset('user_access');
$this->backdropGet('admin/structure/taxonomy/tags');
$this->assertText(t('Add term'), "Add term link found on vocabulary form.");
}