You are here

class CasServerConfigTest in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/CasServerConfigTest.php \Drupal\Tests\cas\Unit\CasServerConfigTest

CasServerConfig unit tests.

@group cas

Hierarchy

Expanded class hierarchy of CasServerConfigTest

File

tests/src/Unit/CasServerConfigTest.php, line 16

Namespace

Drupal\Tests\cas\Unit
View source
class CasServerConfigTest extends UnitTestCase {

  /**
   * Test getters.
   */
  public function testGetters() {
    $configFactory = $this
      ->getConfigFactoryStub([
      'cas.settings' => [
        'server.hostname' => 'example.com',
        'server.protocol' => 'https',
        'server.port' => 443,
        'server.path' => '/cas',
        'server.version' => '1.0',
        'server.verify' => CasHelper::CA_DEFAULT,
        'server.cert' => 'foo',
        'advanced.connection_timeout' => 30,
      ],
    ]);
    $serverConfig = CasServerConfig::createFromModuleConfig($configFactory
      ->get('cas.settings'));
    $this
      ->assertEquals('example.com', $serverConfig
      ->getHostname());
    $this
      ->assertEquals('https', $serverConfig
      ->getHttpScheme());
    $this
      ->assertEquals(443, $serverConfig
      ->getPort());
    $this
      ->assertEquals('/cas', $serverConfig
      ->getPath());
    $this
      ->assertEquals('1.0', $serverConfig
      ->getProtocolVerison());
    $this
      ->assertEquals('foo', $serverConfig
      ->getCustomRootCertBundlePath());
    $this
      ->assertEquals(CasHelper::CA_DEFAULT, $serverConfig
      ->getVerify());
    $this
      ->assertEquals(30, $serverConfig
      ->getDirectConnectionTimeout());
  }

  /**
   * Test getCasServerGuzzleConnectionOptions.
   *
   * @dataProvider casServerConnectionOptionsDataProvider
   */
  public function testCasServerGuzzleConnectionOptions($sslVerifyMethod) {
    $configFactory = $this
      ->getConfigFactoryStub([
      'cas.settings' => [
        'server.hostname' => 'example.com',
        'server.protocol' => 'https',
        'server.port' => 443,
        'server.path' => '/cas',
        'server.version' => '1.0',
        'server.verify' => $sslVerifyMethod,
        'server.cert' => 'foo',
        'advanced.connection_timeout' => 30,
      ],
    ]);
    $serverConfig = CasServerConfig::createFromModuleConfig($configFactory
      ->get('cas.settings'));
    switch ($sslVerifyMethod) {
      case CasHelper::CA_CUSTOM:
        $this
          ->assertArrayEquals([
          'verify' => 'foo',
          'timeout' => 30,
        ], $serverConfig
          ->getCasServerGuzzleConnectionOptions());
        break;
      case CasHelper::CA_NONE:
        $this
          ->assertArrayEquals([
          'verify' => FALSE,
          'timeout' => 30,
        ], $serverConfig
          ->getCasServerGuzzleConnectionOptions());
        break;
      default:
        $this
          ->assertArrayEquals([
          'verify' => TRUE,
          'timeout' => 30,
        ], $serverConfig
          ->getCasServerGuzzleConnectionOptions());
        break;
    }
  }

  /**
   * Data provider for testCasServerGuzzleConnectionOptions.
   *
   * @return array
   *   The data to provide.
   */
  public function casServerConnectionOptionsDataProvider() {
    return [
      [
        CasHelper::CA_NONE,
      ],
      [
        CasHelper::CA_CUSTOM,
      ],
      [
        CasHelper::CA_DEFAULT,
      ],
    ];
  }

  /**
   * Test getServerBaseUrl.
   *
   * @dataProvider getServerBaseUrlDataProvider
   */
  public function testGetServerBaseUrl($serverConfig, $expectedBaseUrl) {
    $config_factory = $this
      ->getConfigFactoryStub([
      'cas.settings' => $serverConfig,
    ]);
    $casServerConfig = CasServerConfig::createFromModuleConfig($config_factory
      ->get('cas.settings'));
    $this
      ->assertEquals($expectedBaseUrl, $casServerConfig
      ->getServerBaseUrl());
  }

  /**
   * Data provider for testGetServerBaseUrl.
   */
  public function getServerBaseUrlDataProvider() {
    return [
      [
        [
          'server.protocol' => 'https',
          'server.hostname' => 'example.com',
          'server.port' => 443,
          'server.path' => '/cas',
        ],
        'https://example.com/cas/',
      ],
      [
        [
          'server.protocol' => 'http',
          'server.hostname' => 'foobar.net',
          'server.port' => 4433,
          'server.path' => '/cas-alt',
        ],
        'http://foobar.net:4433/cas-alt/',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasServerConfigTest::casServerConnectionOptionsDataProvider public function Data provider for testCasServerGuzzleConnectionOptions.
CasServerConfigTest::getServerBaseUrlDataProvider public function Data provider for testGetServerBaseUrl.
CasServerConfigTest::testCasServerGuzzleConnectionOptions public function Test getCasServerGuzzleConnectionOptions.
CasServerConfigTest::testGetServerBaseUrl public function Test getServerBaseUrl.
CasServerConfigTest::testGetters public function Test getters.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340