class CasServerConfigTest in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/CasServerConfigTest.php \Drupal\Tests\cas\Unit\CasServerConfigTest
CasServerConfig unit tests.
@group cas
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cas\Unit\CasServerConfigTest
Expanded class hierarchy of CasServerConfigTest
File
- tests/
src/ Unit/ CasServerConfigTest.php, line 16
Namespace
Drupal\Tests\cas\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CasServerConfigTest:: |
public | function | Data provider for testCasServerGuzzleConnectionOptions. | |
CasServerConfigTest:: |
public | function | Data provider for testGetServerBaseUrl. | |
CasServerConfigTest:: |
public | function | Test getCasServerGuzzleConnectionOptions. | |
CasServerConfigTest:: |
public | function | Test getServerBaseUrl. | |
CasServerConfigTest:: |
public | function | Test getters. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |