1 redirect.test | RedirectFunctionalTest::testPageCache() |
Tests the links added to 404 pages for creating URL redirects.
File
- core/
modules/ redirect/ tests/ redirect.test, line 176 - Unit tests for the redirect module.
Class
Code
function testPageCache() {
// Set up cache variables.
config_set('system.core', 'cache', 1);
$edit = array(
'purge_inactive' => 604800,
);
$this->backdropPost('admin/config/urls/redirect/settings', $edit, 'Save configuration');
$this->assertText('The configuration options have been saved.');
$this->backdropLogout();
// Add a new redirect.
$redirect = $this->addRedirect('redirect', 'node');
$this->assertEqual($redirect->access, 0);
$this->assertEqual($redirect->count, 0);
$this->assertPageNotCached('redirect');
// Perform the redirect and check that count and access are updated.
$first_redirect_call = $this->assertRedirect($redirect);
$this->assertEqual($first_redirect_call->count, 1);
$this->assertTrue($first_redirect_call->access > 0);
$cache = $this->assertPageCached('redirect');
$this->assertHeader('Location', url('node', array('absolute' => TRUE)), $cache->data['headers']);
$this->assertHeader('X-Redirect-ID', $first_redirect_call->rid, $cache->data['headers']);
// Perform a second call, counts should not be updated due to the page
// cache.
$second_redirect_call = $this->assertRedirect($redirect);
$this->assertEqual($second_redirect_call->count, 1);
$this->assertEqual($second_redirect_call->access, $first_redirect_call->access);
$cache = $this->assertPageCached('redirect');
$this->assertHeader('Location', url('node', array('absolute' => TRUE)), $cache->data['headers']);
$this->assertHeader('X-Redirect-ID', $first_redirect_call->rid, $cache->data['headers']);
// Set a redirect to not accessed since the UNIX epoch, then run cron to
// see that it will be removed.
$redirect->access = 1;
redirect_save($redirect);
state_set('redirect_cron_last', 0);
$this->cronRun();
$this->assertNoRedirect($redirect);
}