function ForumTest::editForumVocabulary

Edits the forum taxonomy.

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

File

drupal/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php, line 341
Tests for forum.module.

Class

ForumTest
Provides automated tests for the Forum module.

Namespace

Drupal\forum\Tests

Code

function editForumVocabulary() {

  // Backup forum taxonomy.
  $vid = config('forum.settings')
    ->get('vocabulary');
  $original_vocabulary = entity_load('taxonomy_vocabulary', $vid);

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

  // Edit the vocabulary.
  $this
    ->drupalPost('admin/structure/taxonomy/manage/' . $original_vocabulary
    ->id() . '/edit', $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 = entity_load('taxonomy_vocabulary', $vid);

  // Make sure we actually edited the vocabulary properly.
  $this
    ->assertEqual($current_vocabulary->name, $edit['name'], 'The name was updated');
  $this
    ->assertEqual($current_vocabulary->description, $edit['description'], 'The description was updated');

  // Restore the original vocabulary's name and description.
  $current_vocabulary
    ->set('name', $original_vocabulary->name);
  $current_vocabulary
    ->set('description', $original_vocabulary->description);
  $current_vocabulary
    ->save();

  // Reload vocabulary to make sure changes are saved.
  $current_vocabulary = entity_load('taxonomy_vocabulary', $vid);
  $this
    ->assertEqual($current_vocabulary->name, $original_vocabulary->name, 'The original vocabulary settings were restored');
}