You are here

public function GlobalRedirectTest::testRedirects in Global Redirect 8

Will test the redirects.

File

src/Tests/GlobalRedirectTest.php, line 121
Global Redirect functionality tests

Class

GlobalRedirectTest
Global redirect test cases.

Namespace

Drupal\globalredirect\Tests

Code

public function testRedirects() {

  // Test alias normalization.
  $this->config
    ->set('normalize_aliases', TRUE)
    ->save();
  $this
    ->assertRedirect('node/' . $this->node
    ->id(), 'test-node');
  $this
    ->assertRedirect('Test-node', 'test-node');
  $this->config
    ->set('normalize_aliases', FALSE)
    ->save();
  $this
    ->assertRedirect('node/' . $this->node
    ->id(), NULL, 'HTTP/1.1 200 OK');
  $this
    ->assertRedirect('Test-node', NULL, 'HTTP/1.1 200 OK');

  // Test deslashing.
  $this->config
    ->set('deslash', TRUE)
    ->save();
  $this
    ->assertRedirect('test-node/', 'test-node');
  $this->config
    ->set('deslash', FALSE)
    ->save();
  $this
    ->assertRedirect('test-node/', NULL, 'HTTP/1.1 200 OK');

  // Test front page redirects.
  $this->config
    ->set('frontpage_redirect', TRUE)
    ->save();
  $this
    ->config('system.site')
    ->set('page.front', 'node')
    ->save();
  $this
    ->assertRedirect('node', '<front>');

  // Test front page redirects with an alias.
  \Drupal::service('path.alias_storage')
    ->save('node', 'node-alias');
  $this
    ->assertRedirect('node-alias', '<front>');
  $this->config
    ->set('frontpage_redirect', FALSE)
    ->save();
  $this
    ->assertRedirect('node', NULL, 'HTTP/1.1 200 OK');
  $this
    ->assertRedirect('node-alias', NULL, 'HTTP/1.1 200 OK');

  // Test the access checking.
  $this->config
    ->set('normalize_aliases', TRUE)
    ->save();
  $this->config
    ->set('access_check', TRUE)
    ->save();
  $this
    ->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 403 Forbidden');
  $this->config
    ->set('access_check', FALSE)
    ->save();

  // @todo - here it seems that the access check runs prior to our redirecting
  //   check why so and enable the test.

  //$this->assertRedirect('admin/config/system/site-information', 'site-info');

  // Login as user with admin privileges.
  $this
    ->drupalLogin($this->adminUser);

  // Test ignoring admin paths.
  $this->config
    ->set('ignore_admin_path', FALSE)
    ->save();
  $this
    ->assertRedirect('admin/config/system/site-information', 'site-info');
  $this->config
    ->set('ignore_admin_path', TRUE)
    ->save();
  $this
    ->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 200 OK');
}