View source
<?php
namespace Drupal\taxonomy\Tests;
class VocabularyPermissionsTest extends TaxonomyTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
function testVocabularyPermissionsTaxonomyTerm() {
$vocabulary = $this
->createVocabulary();
$user = $this
->drupalCreateUser(array(
'administer taxonomy',
));
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertResponse(200);
$this
->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.');
$edit = array();
$edit['name[0][value]'] = $this
->randomMachineName();
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('Created new term %name.', array(
'%name' => $edit['name[0][value]'],
)), 'Term created successfully.');
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertText($edit['name[0][value]'], 'Edit taxonomy term form opened successfully.');
$edit['name[0][value]'] = $this
->randomMachineName();
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('Updated term %name.', array(
'%name' => $edit['name[0][value]'],
)), 'Term updated successfully.');
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/delete');
$this
->assertRaw(t('Are you sure you want to delete the @entity-type %label?', array(
'@entity-type' => 'taxonomy term',
'%label' => $edit['name[0][value]'],
)), 'Delete taxonomy term form opened successfully.');
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('Deleted term %name.', array(
'%name' => $edit['name[0][value]'],
)), 'Term deleted.');
$user = $this
->drupalCreateUser(array(
"edit terms in {$vocabulary->id()}",
));
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertResponse(403, 'Add taxonomy term form open failed.');
$term = $this
->createTerm($vocabulary);
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertText($term
->getName(), 'Edit taxonomy term form opened successfully.');
$edit['name[0][value]'] = $this
->randomMachineName();
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('Updated term %name.', array(
'%name' => $edit['name[0][value]'],
)), 'Term updated successfully.');
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/delete');
$this
->assertResponse(403, 'Delete taxonomy term form open failed.');
$user = $this
->drupalCreateUser(array(
"delete terms in {$vocabulary->id()}",
));
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertResponse(403, 'Add taxonomy term form open failed.');
$term = $this
->createTerm($vocabulary);
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/edit');
$this
->assertResponse(403, 'Edit taxonomy term form open failed.');
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/delete');
$this
->assertRaw(t('Are you sure you want to delete the @entity-type %label?', array(
'@entity-type' => 'taxonomy term',
'%label' => $term
->getName(),
)), 'Delete taxonomy term form opened successfully.');
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('Deleted term %name.', array(
'%name' => $term
->getName(),
)), 'Term deleted.');
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary
->id() . '/add');
$this
->assertResponse(403, 'Add taxonomy term form open failed.');
$term = $this
->createTerm($vocabulary);
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/edit');
$this
->assertResponse(403, 'Edit taxonomy term form open failed.');
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/delete');
$this
->assertResponse(403, 'Delete taxonomy term form open failed.');
}
}