Chris@0: drupalPlaceBlock('page_title_block'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Create, edit and delete a taxonomy term via the user interface. Chris@0: */ Chris@0: public function testVocabularyPermissionsTaxonomyTerm() { Chris@0: // Vocabulary used for creating, removing and editing terms. Chris@0: $vocabulary = $this->createVocabulary(); Chris@0: Chris@0: // Test as admin user. Chris@0: $user = $this->drupalCreateUser(['administer taxonomy']); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: // Visit the main taxonomy administration page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.'); Chris@0: Chris@0: // Submit the term. Chris@0: $edit = []; Chris@0: $edit['name[0][value]'] = $this->randomMachineName(); Chris@0: Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $this->assertText(t('Created new term @name.', ['@name' => $edit['name[0][value]']]), 'Term created successfully.'); Chris@0: Chris@0: // Verify that the creation message contains a link to a term. Chris@0: $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']); Chris@0: $this->assert(isset($view_link), 'The message area contains a link to a term'); Chris@0: Chris@0: $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']); Chris@0: $term = reset($terms); Chris@0: Chris@0: // Edit the term. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertText($edit['name[0][value]'], 'Edit taxonomy term form opened successfully.'); Chris@0: Chris@0: $edit['name[0][value]'] = $this->randomMachineName(); Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.'); Chris@0: Chris@0: // Delete the vocabulary. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); Chris@0: $this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $edit['name[0][value]']]), 'Delete taxonomy term form opened successfully.'); Chris@0: Chris@0: // Confirm deletion. Chris@0: $this->drupalPostForm(NULL, NULL, t('Delete')); Chris@0: $this->assertRaw(t('Deleted term %name.', ['%name' => $edit['name[0][value]']]), 'Term deleted.'); Chris@0: Chris@0: // Test as user with "edit" permissions. Chris@0: $user = $this->drupalCreateUser(["edit terms in {$vocabulary->id()}"]); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: // Visit the main taxonomy administration page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); Chris@0: $this->assertResponse(403, 'Add taxonomy term form open failed.'); Chris@0: Chris@0: // Create a test term. Chris@0: $term = $this->createTerm($vocabulary); Chris@0: Chris@0: // Edit the term. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertResponse(200); Chris@0: $this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.'); Chris@0: Chris@0: $edit['name[0][value]'] = $this->randomMachineName(); Chris@0: $this->drupalPostForm(NULL, $edit, t('Save')); Chris@0: $this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.'); Chris@0: Chris@0: // Verify that the update message contains a link to a term. Chris@0: $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']); Chris@0: $this->assert(isset($view_link), 'The message area contains a link to a term'); Chris@0: Chris@0: // Delete the vocabulary. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); Chris@0: $this->assertResponse(403, 'Delete taxonomy term form open failed.'); Chris@0: Chris@0: // Test as user with "delete" permissions. Chris@0: $user = $this->drupalCreateUser(["delete terms in {$vocabulary->id()}"]); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: // Visit the main taxonomy administration page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); Chris@0: $this->assertResponse(403, 'Add taxonomy term form open failed.'); Chris@0: Chris@0: // Create a test term. Chris@0: $term = $this->createTerm($vocabulary); Chris@0: Chris@0: // Edit the term. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertResponse(403, 'Edit taxonomy term form open failed.'); Chris@0: Chris@0: // Delete the vocabulary. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); Chris@0: $this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $term->getName()]), 'Delete taxonomy term form opened successfully.'); Chris@0: Chris@0: // Confirm deletion. Chris@0: $this->drupalPostForm(NULL, NULL, t('Delete')); Chris@0: $this->assertRaw(t('Deleted term %name.', ['%name' => $term->getName()]), 'Term deleted.'); Chris@0: Chris@0: // Test as user without proper permissions. Chris@0: $user = $this->drupalCreateUser(); Chris@0: $this->drupalLogin($user); Chris@0: Chris@0: // Visit the main taxonomy administration page. Chris@0: $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); Chris@0: $this->assertResponse(403, 'Add taxonomy term form open failed.'); Chris@0: Chris@0: // Create a test term. Chris@0: $term = $this->createTerm($vocabulary); Chris@0: Chris@0: // Edit the term. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); Chris@0: $this->assertResponse(403, 'Edit taxonomy term form open failed.'); Chris@0: Chris@0: // Delete the vocabulary. Chris@0: $this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); Chris@0: $this->assertResponse(403, 'Delete taxonomy term form open failed.'); Chris@0: } Chris@0: Chris@0: }