function ForumTest::doAdminTests

Same name in other branches
  1. 9 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::doAdminTests()
  2. 8.9.x core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::doAdminTests()
  3. 11.x 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 315

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->drupalGet('admin/structure/menu/manage/tools');
    $this->submitForm($edit, '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->assertSession()
        ->pageTextContains('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->assertSession()
        ->pageTextContains('Edit 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->assertSession()
        ->pageTextContains('Edit 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->drupalGet('admin/structure/forum/');
    $this->submitForm([], 'Save');
    $this->assertSession()
        ->pageTextContains('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->assertSession()
        ->fieldNotExists('parent[]');
    // 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('Delete');
    // Test tags vocabulary term form is not affected.
    $this->drupalGet('admin/structure/taxonomy/manage/tags/add');
    $this->assertSession()
        ->fieldExists('parent[]');
    // Test relations widget exists.
    $this->assertSession()
        ->elementExists('xpath', "//details[@id='edit-relations']");
}

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