function PageNotFoundTestCase::testPageNotFound

File

modules/system/system.test, line 1158

Class

PageNotFoundTestCase

Code

function testPageNotFound() {
    $this->drupalGet($this->randomName(10));
    $this->assertText(t('Page not found'), 'Found the default 404 page');
    $edit = array(
        'title' => $this->randomName(10),
        'body' => array(
            LANGUAGE_NONE => array(
                array(
                    'value' => $this->randomName(100),
                ),
            ),
        ),
    );
    $node = $this->drupalCreateNode($edit);
    // As node IDs must be integers, make sure requests for non-integer IDs
    // return a page not found error.
    $this->drupalGet('node/invalid');
    $this->assertResponse(404);
    // Use a custom 404 page.
    $this->drupalPost('admin/config/system/site-information', array(
        'site_404' => 'node/' . $node->nid,
    ), t('Save configuration'));
    $this->drupalGet($this->randomName(10));
    $this->assertText($node->title, 'Found the custom 404 page');
}

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