You are here

private function ForumTest::doAdminTests in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::doAdminTests()

Runs admin tests on the admin user.

Parameters

object $user: The logged-in user.

1 call to ForumTest::doAdminTests()
ForumTest::testForum in core/modules/forum/tests/src/Functional/ForumTest.php
Tests forum functionality through the admin and user interfaces.

File

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

Class

ForumTest
Tests for forum.module.

Namespace

Drupal\Tests\forum\Functional

Code

private function doAdminTests($user) {

  // Log in the user.
  $this
    ->drupalLogin($user);

  // Add forum to the Tools menu.
  $edit = [];
  $this
    ->drupalPostForm('admin/structure/menu/manage/tools', $edit, t('Save'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Edit forum taxonomy.
  // Restoration of the settings fails and causes subsequent tests to fail.
  $this
    ->editForumVocabulary();

  // Create forum container.
  $this->forumContainer = $this
    ->createForum('container');

  // Verify "edit container" link exists and functions correctly.
  $this
    ->drupalGet('admin/structure/forum');

  // Verify help text is shown.
  $this
    ->assertText(t('Forums contain forum topics. Use containers to group related forums'));

  // Verify action links are there.
  $this
    ->assertSession()
    ->linkExists('Add forum');
  $this
    ->assertSession()
    ->linkExists('Add container');
  $this
    ->clickLink('edit container');
  $this
    ->assertRaw('Edit container', 'Followed the link to edit the container');

  // Create forum inside the forum container.
  $this->forum = $this
    ->createForum('forum', $this->forumContainer['tid']);

  // Verify the "edit forum" link exists and functions correctly.
  $this
    ->drupalGet('admin/structure/forum');
  $this
    ->clickLink('edit forum');
  $this
    ->assertRaw('Edit forum', 'Followed the link to edit the forum');

  // Navigate back to forum structure page.
  $this
    ->drupalGet('admin/structure/forum');

  // Create second forum in container, destined to be deleted below.
  $delete_forum = $this
    ->createForum('forum', $this->forumContainer['tid']);

  // Save forum overview.
  $this
    ->drupalPostForm('admin/structure/forum/', [], t('Save'));
  $this
    ->assertRaw(t('The configuration options have been saved.'));

  // Delete this second forum.
  $this
    ->deleteForum($delete_forum['tid']);

  // Create forum at the top (root) level.
  $this->rootForum = $this
    ->createForum('forum');

  // Test vocabulary form alterations.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/forums');
  $this
    ->assertSession()
    ->buttonExists('Save');
  $this
    ->assertSession()
    ->buttonNotExists('Delete');

  // Test term edit form alterations.
  $this
    ->drupalGet('taxonomy/term/' . $this->forumContainer['tid'] . '/edit');

  // Test parent field been hidden by forum module.
  $this
    ->assertNoField('parent[]', 'Parent field not found.');

  // Create a default vocabulary named "Tags".
  $description = 'Use tags to group articles on similar topics into categories.';
  $help = 'Enter a comma-separated list of words to describe your content.';
  $vocabulary = Vocabulary::create([
    'name' => 'Tags',
    'description' => $description,
    'vid' => 'tags',
    'langcode' => \Drupal::languageManager()
      ->getDefaultLanguage()
      ->getId(),
    'help' => $help,
  ]);
  $vocabulary
    ->save();

  // Test tags vocabulary form is not affected.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/tags');
  $this
    ->assertSession()
    ->buttonExists('Save');
  $this
    ->assertSession()
    ->linkExists(t('Delete'));

  // Test tags vocabulary term form is not affected.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/tags/add');
  $this
    ->assertField('parent[]', 'Parent field found.');

  // Test relations widget exists.
  $relations_widget = $this
    ->xpath("//details[@id='edit-relations']");
  $this
    ->assertTrue(isset($relations_widget[0]), 'Relations widget element found.');
}