public function RedirectManagerTest::testCheckDomain in Domain 301 Redirect 8
Check that the the redirect domain resolves to this site.
File
- tests/
src/ Functional/ RedirectManagerTest.php, line 63
Class
- RedirectManagerTest
- Test the Domain301RedirectManager service.
Namespace
Drupal\Tests\domain_301_redirect\FunctionalCode
public function testCheckDomain() {
$isDomainOk = $this->redirectManager
->checkDomain($this->domain);
$this
->assertTrue($isDomainOk, 'The domain resolves.');
$this
->enableRedirect($this->notTheDomain);
$isDomainOk = $this->redirectManager
->checkDomain($this->notTheDomain);
list($statusCode, ) = $this
->getRedirect($this->domain);
$this
->assertEquals(301, $statusCode, 'The site is redirecting.');
$this
->assertFalse($isDomainOk, 'The redirect domain does not resolve.');
// Run cron which should disable the 301 redirect.
Drupal::service('cron')
->run();
$this->configFactory
->clearStaticCache();
$config = $this->configFactory
->get('domain_301_redirect.settings');
$enabled = $config
->get('enabled');
$this
->assertEquals(0, $enabled, 'The 301 redirect is no longer enabled.');
// Request the site and see that it doesn't redirect.
$this
->drupalGet('<front>');
$statusCode = $this
->getSession()
->getStatusCode();
$this
->assertEquals(200, $statusCode, 'The site is not redirecting.');
}