private function ForumTest::verifyForums in Drupal 10
Same name and namespace in other branches
- 8 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::verifyForums()
- 9 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.
File
- core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php, line 622
Class
- ForumTest
- Tests for forum.module.
Namespace
Drupal\Tests\forum\FunctionalCode
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('Home', '<front>'),
Link::createFromRoute('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.");
}
}