private function ForumTest::verifyForums in Drupal 8
Same name and namespace in other branches
- 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.
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 620
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
->assertTitle('Forum | Drupal');
$this
->assertText(t('Forum'), 'Forum help node was displayed');
}
// 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
->assertTitle($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
->assertRaw(\Drupal::service('renderer')
->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
// View forum edit node.
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->statusCodeEquals($response);
if ($response == 200) {
$this
->assertTitle('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
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save'));
$this
->assertText(t('Forum topic @title has been updated.', [
'@title' => $edit['title[0][value]'],
]), 'Forum node was edited');
// 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
->assertTrue($forum_tid == $this->rootForum['tid'], 'The forum topic is linked to a different forum');
// Delete forum node.
$this
->drupalPostForm('node/' . $node
->id() . '/delete', [], t('Delete'));
$this
->assertSession()
->statusCodeEquals($response);
$this
->assertRaw(t('Forum topic %title has been deleted.', [
'%title' => $edit['title[0][value]'],
]), 'Forum node was deleted');
}
}