function ForumTest::editForumVocabulary

Same name and namespace in other branches
  1. 9 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::editForumVocabulary()
  2. 10 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::editForumVocabulary()
  3. 11.x core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::editForumVocabulary()

Edits the forum taxonomy.

1 call to ForumTest::editForumVocabulary()
ForumTest::doAdminTests in core/modules/forum/tests/src/Functional/ForumTest.php
Runs admin tests on the admin user.

File

core/modules/forum/tests/src/Functional/ForumTest.php, line 384

Class

ForumTest
Tests for <a href="/api/drupal/core%21modules%21forum%21forum.module/8.9.x" title="Provides discussion forums." class="local">forum.module</a>.

Namespace

Drupal\Tests\forum\Functional

Code

public function editForumVocabulary() {
    // Backup forum taxonomy.
    $vid = $this->config('forum.settings')
        ->get('vocabulary');
    $original_vocabulary = Vocabulary::load($vid);
    // Generate a random name and description.
    $edit = [
        'name' => $this->randomMachineName(10),
        'description' => $this->randomMachineName(100),
    ];
    // Edit the vocabulary.
    $this->drupalPostForm('admin/structure/taxonomy/manage/' . $original_vocabulary->id(), $edit, t('Save'));
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertRaw(t('Updated vocabulary %name.', [
        '%name' => $edit['name'],
    ]), 'Vocabulary was edited');
    // Grab the newly edited vocabulary.
    $current_vocabulary = Vocabulary::load($vid);
    // Make sure we actually edited the vocabulary properly.
    $this->assertEqual($current_vocabulary->label(), $edit['name'], 'The name was updated');
    $this->assertEqual($current_vocabulary->getDescription(), $edit['description'], 'The description was updated');
    // Restore the original vocabulary's name and description.
    $current_vocabulary->set('name', $original_vocabulary->label());
    $current_vocabulary->set('description', $original_vocabulary->getDescription());
    $current_vocabulary->save();
    // Reload vocabulary to make sure changes are saved.
    $current_vocabulary = Vocabulary::load($vid);
    $this->assertEqual($current_vocabulary->label(), $original_vocabulary->label(), 'The original vocabulary settings were restored');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.