public function ForumTest::createForumTopic in Drupal 9
Same name and namespace in other branches
- 8 core/modules/forum/tests/src/Functional/ForumTest.php \Drupal\Tests\forum\Functional\ForumTest::createForumTopic()
Creates a forum topic.
Parameters
array $forum: A forum array.
bool $container: TRUE if $forum is a container; FALSE otherwise.
Return value
object|null The created topic node or NULL if the forum is a container.
4 calls to ForumTest::createForumTopic()
- ForumTest::doBasicTests in core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php - Runs basic tests on the indicated user.
- ForumTest::generateForumTopics in core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php - Generates forum topics.
- ForumTest::testForum in core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php - Tests forum functionality through the admin and user interfaces.
- ForumTest::testForumWithNewPost in core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php - Tests a forum with a new post displays properly.
File
- core/
modules/ forum/ tests/ src/ Functional/ ForumTest.php, line 572
Class
- ForumTest
- Tests for forum.module.
Namespace
Drupal\Tests\forum\FunctionalCode
public function createForumTopic($forum, $container = FALSE) {
// Generate a random subject/body.
$title = $this
->randomMachineName(20);
$body = $this
->randomMachineName(200);
$edit = [
'title[0][value]' => $title,
'body[0][value]' => $body,
];
$tid = $forum['tid'];
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this
->drupalGet('node/add/forum', [
'query' => [
'forum_id' => $tid,
],
]);
$this
->submitForm($edit, 'Save');
$type = t('Forum topic');
if ($container) {
$this
->assertSession()
->pageTextNotContains("{$type} {$title} has been created.");
$this
->assertSession()
->pageTextContains("The item {$forum['name']} is a forum container, not a forum.");
return;
}
else {
$this
->assertSession()
->pageTextContains($type . ' ' . $title . ' has been created.');
$this
->assertSession()
->pageTextNotContains("The item {$forum['name']} is a forum container, not a forum.");
// Verify that the creation message contains a link to a node.
$this
->assertSession()
->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
}
// Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this
->drupalGetNodeByTitle($title);
$this
->assertNotNull($node, new FormattableMarkup('Node @title was loaded', [
'@title' => $title,
]));
$this
->assertEquals($tid, $node->taxonomy_forums->target_id, 'Saved forum topic was in the expected forum');
// View forum topic.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains($title);
$this
->assertSession()
->pageTextContains($body);
return $node;
}