pagenotfound.test in Customerror 5
File
tests/pagenotfound.test
View source
<?php
class PageNotFoundTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('404 Page not found'),
'desc' => t('Check that the custom error message is displayed when a page is not found.'),
'group' => t('CustomError'),
);
}
function testPageNotFoundMessage() {
$this
->drupalModuleEnable('customerror');
$error_code = 404;
$title = $this
->randomName($number = 10, $prefix = 'simpletest_');
$this
->drupalVariableSet('customerror_' . $error_code . '_title', $title);
$description = $this
->randomName($number = 512, $prefix = 'simpletest_');
$this
->drupalVariableSet('customerror_' . $error_code, $description);
$this
->get(url('customerror/' . $error_code, NULL, NULL, TRUE));
$this
->assertText($title, 'Title on ' . $error_code . ' error page set when accessed directly');
$this
->assertText($description, 'Description on ' . $error_code . ' error page set when accessed directly');
$this
->drupalVariableSet('site_' . $error_code, 'customerror/' . $error_code);
$user = $this
->drupalCreateUserRolePerm(array(
'access content',
));
$this
->drupalLoginUser($user);
$this
->get(url('node/' . db_next_id('{node}_nid'), NULL, NULL, TRUE));
$this
->assertResponse($error_code, 'Response code on ' . $error_code . ' error page set when accessed at non-existent URL');
$this
->assertText($title, 'Title on ' . $error_code . ' error page set when accessed at non-existent URL');
$this
->assertText($description, 'Description on ' . $error_code . ' error page set when accessed at non-existent URL');
}
}