You are here

private function ForumTest::verifyForums in Drupal 9

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

Verifies that the logged in user has access to a forum node.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node being checked.

bool $admin: Boolean to indicate whether the user can 'access administration pages'.

int $response: The expected HTTP response code.

2 calls to ForumTest::verifyForums()
ForumTest::doBasicTests in core/modules/forum/tests/src/Functional/ForumTest.php
Runs basic tests on the indicated user.
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 624

Class

ForumTest
Tests for forum.module.

Namespace

Drupal\Tests\forum\Functional

Code

private function verifyForums(EntityInterface $node, $admin, $response = 200) {
  $response2 = $admin ? 200 : 403;

  // View forum help node.
  $this
    ->drupalGet('admin/help/forum');
  $this
    ->assertSession()
    ->statusCodeEquals($response2);
  if ($response2 == 200) {
    $this
      ->assertSession()
      ->titleEquals('Forum | Drupal');
    $this
      ->assertSession()
      ->pageTextContains('Forum');
  }

  // View forum container page.
  $this
    ->verifyForumView($this->forumContainer);

  // View forum page.
  $this
    ->verifyForumView($this->forum, $this->forumContainer);

  // View root forum page.
  $this
    ->verifyForumView($this->rootForum);

  // View forum node.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->titleEquals($node
    ->label() . ' | Drupal');
  $breadcrumb_build = [
    Link::createFromRoute(t('Home'), '<front>'),
    Link::createFromRoute(t('Forums'), 'forum.index'),
    Link::createFromRoute($this->forumContainer['name'], 'forum.page', [
      'taxonomy_term' => $this->forumContainer['tid'],
    ]),
    Link::createFromRoute($this->forum['name'], 'forum.page', [
      'taxonomy_term' => $this->forum['tid'],
    ]),
  ];
  $breadcrumb = [
    '#theme' => 'breadcrumb',
    '#links' => $breadcrumb_build,
  ];
  $this
    ->assertSession()
    ->responseContains(\Drupal::service('renderer')
    ->renderRoot($breadcrumb));

  // View forum edit node.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->statusCodeEquals($response);
  if ($response == 200) {
    $this
      ->assertSession()
      ->titleEquals('Edit Forum topic ' . $node
      ->label() . ' | Drupal');
  }
  if ($response == 200) {

    // Edit forum node (including moving it to another forum).
    $edit = [];
    $edit['title[0][value]'] = 'node/' . $node
      ->id();
    $edit['body[0][value]'] = $this
      ->randomMachineName(256);

    // Assume the topic is initially associated with $forum.
    $edit['taxonomy_forums'] = $this->rootForum['tid'];
    $edit['shadow'] = TRUE;
    $this
      ->drupalGet('node/' . $node
      ->id() . '/edit');
    $this
      ->submitForm($edit, 'Save');
    $this
      ->assertSession()
      ->pageTextContains('Forum topic ' . $edit['title[0][value]'] . ' has been updated.');

    // Verify topic was moved to a different forum.
    $forum_tid = $this->container
      ->get('database')
      ->select('forum', 'f')
      ->fields('f', [
      'tid',
    ])
      ->condition('nid', $node
      ->id())
      ->condition('vid', $node
      ->getRevisionId())
      ->execute()
      ->fetchField();
    $this
      ->assertSame($this->rootForum['tid'], $forum_tid, 'The forum topic is linked to a different forum');

    // Delete forum node.
    $this
      ->drupalGet('node/' . $node
      ->id() . '/delete');
    $this
      ->submitForm([], 'Delete');
    $this
      ->assertSession()
      ->statusCodeEquals($response);
    $this
      ->assertSession()
      ->pageTextContains("Forum topic {$edit['title[0][value]']} has been deleted.");
  }
}