You are here

RedirectStatusCodeTest.php in Redirect 403 to User Login 8

Same filename and directory in other branches
  1. 2.x tests/src/Functional/RedirectStatusCodeTest.php

File

tests/src/Functional/RedirectStatusCodeTest.php
View source
<?php

namespace Drupal\Tests\r4032login\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Test the behavior of the "HTTP redirect code" option.
 *
 * @group r4032login
 */
class RedirectStatusCodeTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'r4032login',
  ];

  /**
   * Test the behavior of the "HTTP redirect code" option.
   *
   * @param int $optionValue
   *   The option value for the "HTTP redirect code" option.
   * @param int $expectedCode
   *   Expected redirect code.
   *
   * @throws \GuzzleHttp\Exception\GuzzleException
   *
   * @dataProvider redirectStatusCodeDataProvider
   */
  public function testRedirectStatusCode($optionValue, $expectedCode) {
    $config = $this
      ->config('r4032login.settings');
    $config
      ->set('default_redirect_code', $optionValue);
    $config
      ->save();
    $client = $this
      ->getHttpClient();
    $url = $this
      ->getAbsoluteUrl('/admin/config');
    $response = $client
      ->request('GET', $url, [
      'allow_redirects' => FALSE,
    ]);
    $this
      ->assertEquals($response
      ->getStatusCode(), $expectedCode);
  }

  /**
   * Data provider for testRedirectStatusCode.
   */
  public function redirectStatusCodeDataProvider() {
    return [
      [
        301,
        301,
      ],
      [
        302,
        302,
      ],
      [
        307,
        307,
      ],
    ];
  }

}

Classes

Namesort descending Description
RedirectStatusCodeTest Test the behavior of the "HTTP redirect code" option.