annotate core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\taxonomy\Functional;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Tests the taxonomy vocabulary permissions.
Chris@0 7 *
Chris@0 8 * @group taxonomy
Chris@0 9 */
Chris@0 10 class VocabularyPermissionsTest extends TaxonomyTestBase {
Chris@0 11
Chris@0 12 protected function setUp() {
Chris@0 13 parent::setUp();
Chris@0 14
Chris@0 15 $this->drupalPlaceBlock('page_title_block');
Chris@0 16 }
Chris@0 17
Chris@0 18 /**
Chris@0 19 * Create, edit and delete a taxonomy term via the user interface.
Chris@0 20 */
Chris@0 21 public function testVocabularyPermissionsTaxonomyTerm() {
Chris@0 22 // Vocabulary used for creating, removing and editing terms.
Chris@0 23 $vocabulary = $this->createVocabulary();
Chris@0 24
Chris@0 25 // Test as admin user.
Chris@0 26 $user = $this->drupalCreateUser(['administer taxonomy']);
Chris@0 27 $this->drupalLogin($user);
Chris@0 28
Chris@0 29 // Visit the main taxonomy administration page.
Chris@0 30 $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
Chris@0 31 $this->assertResponse(200);
Chris@0 32 $this->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.');
Chris@0 33
Chris@0 34 // Submit the term.
Chris@0 35 $edit = [];
Chris@0 36 $edit['name[0][value]'] = $this->randomMachineName();
Chris@0 37
Chris@0 38 $this->drupalPostForm(NULL, $edit, t('Save'));
Chris@0 39 $this->assertText(t('Created new term @name.', ['@name' => $edit['name[0][value]']]), 'Term created successfully.');
Chris@0 40
Chris@0 41 // Verify that the creation message contains a link to a term.
Chris@0 42 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
Chris@0 43 $this->assert(isset($view_link), 'The message area contains a link to a term');
Chris@0 44
Chris@0 45 $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
Chris@0 46 $term = reset($terms);
Chris@0 47
Chris@0 48 // Edit the term.
Chris@0 49 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
Chris@0 50 $this->assertResponse(200);
Chris@0 51 $this->assertText($edit['name[0][value]'], 'Edit taxonomy term form opened successfully.');
Chris@0 52
Chris@0 53 $edit['name[0][value]'] = $this->randomMachineName();
Chris@0 54 $this->drupalPostForm(NULL, $edit, t('Save'));
Chris@0 55 $this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
Chris@0 56
Chris@0 57 // Delete the vocabulary.
Chris@0 58 $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
Chris@0 59 $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 60
Chris@0 61 // Confirm deletion.
Chris@0 62 $this->drupalPostForm(NULL, NULL, t('Delete'));
Chris@0 63 $this->assertRaw(t('Deleted term %name.', ['%name' => $edit['name[0][value]']]), 'Term deleted.');
Chris@0 64
Chris@0 65 // Test as user with "edit" permissions.
Chris@0 66 $user = $this->drupalCreateUser(["edit terms in {$vocabulary->id()}"]);
Chris@0 67 $this->drupalLogin($user);
Chris@0 68
Chris@0 69 // Visit the main taxonomy administration page.
Chris@0 70 $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
Chris@0 71 $this->assertResponse(403, 'Add taxonomy term form open failed.');
Chris@0 72
Chris@0 73 // Create a test term.
Chris@0 74 $term = $this->createTerm($vocabulary);
Chris@0 75
Chris@0 76 // Edit the term.
Chris@0 77 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
Chris@0 78 $this->assertResponse(200);
Chris@0 79 $this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.');
Chris@0 80
Chris@0 81 $edit['name[0][value]'] = $this->randomMachineName();
Chris@0 82 $this->drupalPostForm(NULL, $edit, t('Save'));
Chris@0 83 $this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
Chris@0 84
Chris@0 85 // Verify that the update message contains a link to a term.
Chris@0 86 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
Chris@0 87 $this->assert(isset($view_link), 'The message area contains a link to a term');
Chris@0 88
Chris@0 89 // Delete the vocabulary.
Chris@0 90 $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
Chris@0 91 $this->assertResponse(403, 'Delete taxonomy term form open failed.');
Chris@0 92
Chris@0 93 // Test as user with "delete" permissions.
Chris@0 94 $user = $this->drupalCreateUser(["delete terms in {$vocabulary->id()}"]);
Chris@0 95 $this->drupalLogin($user);
Chris@0 96
Chris@0 97 // Visit the main taxonomy administration page.
Chris@0 98 $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
Chris@0 99 $this->assertResponse(403, 'Add taxonomy term form open failed.');
Chris@0 100
Chris@0 101 // Create a test term.
Chris@0 102 $term = $this->createTerm($vocabulary);
Chris@0 103
Chris@0 104 // Edit the term.
Chris@0 105 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
Chris@0 106 $this->assertResponse(403, 'Edit taxonomy term form open failed.');
Chris@0 107
Chris@0 108 // Delete the vocabulary.
Chris@0 109 $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
Chris@0 110 $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 111
Chris@0 112 // Confirm deletion.
Chris@0 113 $this->drupalPostForm(NULL, NULL, t('Delete'));
Chris@0 114 $this->assertRaw(t('Deleted term %name.', ['%name' => $term->getName()]), 'Term deleted.');
Chris@0 115
Chris@0 116 // Test as user without proper permissions.
Chris@0 117 $user = $this->drupalCreateUser();
Chris@0 118 $this->drupalLogin($user);
Chris@0 119
Chris@0 120 // Visit the main taxonomy administration page.
Chris@0 121 $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
Chris@0 122 $this->assertResponse(403, 'Add taxonomy term form open failed.');
Chris@0 123
Chris@0 124 // Create a test term.
Chris@0 125 $term = $this->createTerm($vocabulary);
Chris@0 126
Chris@0 127 // Edit the term.
Chris@0 128 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
Chris@0 129 $this->assertResponse(403, 'Edit taxonomy term form open failed.');
Chris@0 130
Chris@0 131 // Delete the vocabulary.
Chris@0 132 $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
Chris@0 133 $this->assertResponse(403, 'Delete taxonomy term form open failed.');
Chris@0 134 }
Chris@0 135
Chris@0 136 }