function ForumIndexTestCase::testForumIndexStatus

Tests the forum index for published and unpublished nodes.

File

modules/forum/forum.test, line 695

Class

ForumIndexTestCase
Tests the forum index listing.

Code

function testForumIndexStatus() {
    $langcode = LANGUAGE_NONE;
    // The forum ID to use.
    $tid = 1;
    // Create a test node.
    $title = $this->randomName(20);
    $edit = array(
        "title" => $title,
        "body[{$langcode}][0][value]" => $this->randomName(200),
    );
    // Create the forum topic, preselecting the forum ID via a URL parameter.
    $this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
    // Check that the node exists in the database.
    $node = $this->drupalGetNodeByTitle($title);
    $this->assertTrue(!empty($node), 'New forum node found in database.');
    // Verify that the node appears on the index.
    $this->drupalGet('forum/' . $tid);
    $this->assertText($title, 'Published forum topic appears on index.');
    // Unpublish the node.
    $edit = array(
        'status' => FALSE,
    );
    $this->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));
    $this->drupalGet("node/{$node->nid}");
    $this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');
    // Verify that the node no longer appears on the index.
    $this->drupalGet('forum/' . $tid);
    $this->assertNoText($title, 'Unpublished forum topic no longer appears on index.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.