function ForumTest::createForumTopic in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/forum/src/Tests/ForumTest.php \Drupal\forum\Tests\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 The created topic node.
4 calls to ForumTest::createForumTopic()
- ForumTest::doBasicTests in core/
modules/ forum/ src/ Tests/ ForumTest.php - Runs basic tests on the indicated user.
- ForumTest::generateForumTopics in core/
modules/ forum/ src/ Tests/ ForumTest.php - Generates forum topics.
- ForumTest::testForum in core/
modules/ forum/ src/ Tests/ ForumTest.php - Tests forum functionality through the admin and user interfaces.
- ForumTest::testForumWithNewPost in core/
modules/ forum/ src/ Tests/ ForumTest.php - Tests a forum with a new post displays properly.
File
- core/
modules/ forum/ src/ Tests/ ForumTest.php, line 530 - Contains \Drupal\forum\Tests\ForumTest.
Class
- ForumTest
- Create, view, edit, delete, and change forum entries and verify its consistency in the database.
Namespace
Drupal\forum\TestsCode
function createForumTopic($forum, $container = FALSE) {
// Generate a random subject/body.
$title = $this
->randomMachineName(20);
$body = $this
->randomMachineName(200);
$edit = array(
'title[0][value]' => $title,
'body[0][value]' => $body,
);
$tid = $forum['tid'];
// Create the forum topic, preselecting the forum ID via a URL parameter.
$this
->drupalPostForm('node/add/forum', $edit, t('Save'), array(
'query' => array(
'forum_id' => $tid,
),
));
$type = t('Forum topic');
if ($container) {
$this
->assertNoRaw(t('@type %title has been created.', array(
'@type' => $type,
'%title' => $title,
)), 'Forum topic was not created');
$this
->assertRaw(t('The item %title is a forum container, not a forum.', array(
'%title' => $forum['name'],
)), 'Error message was shown');
return;
}
else {
$this
->assertRaw(t('@type %title has been created.', array(
'@type' => $type,
'%title' => $title,
)), 'Forum topic was created');
$this
->assertNoRaw(t('The item %title is a forum container, not a forum.', array(
'%title' => $forum['name'],
)), 'No error message was shown');
}
// Retrieve node object, ensure that the topic was created and in the proper forum.
$node = $this
->drupalGetNodeByTitle($title);
$this
->assertTrue($node != NULL, format_string('Node @title was loaded', array(
'@title' => $title,
)));
$this
->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum');
// View forum topic.
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw($title, 'Subject was found');
$this
->assertRaw($body, 'Body was found');
return $node;
}