You are here

function ForumTest::editForumVocabulary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/forum/src/Tests/ForumTest.php \Drupal\forum\Tests\ForumTest::editForumVocabulary()

Edits the forum taxonomy.

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

File

core/modules/forum/src/Tests/ForumTest.php, line 365
Contains \Drupal\forum\Tests\ForumTest.

Class

ForumTest
Create, view, edit, delete, and change forum entries and verify its consistency in the database.

Namespace

Drupal\forum\Tests

Code

function editForumVocabulary() {

  // Backup forum taxonomy.
  $vid = $this
    ->config('forum.settings')
    ->get('vocabulary');
  $original_vocabulary = Vocabulary::load($vid);

  // Generate a random name and description.
  $edit = array(
    'name' => $this
      ->randomMachineName(10),
    'description' => $this
      ->randomMachineName(100),
  );

  // Edit the vocabulary.
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $original_vocabulary
    ->id(), $edit, t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertRaw(t('Updated vocabulary %name.', array(
    '%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');
}