class SettingsHelperTest in Acquia Lift Connector 8.3
Same name and namespace in other branches
- 8.4 tests/src/Unit/Service/Helper/SettingsHelperTest.php \Drupal\Tests\acquia_lift\Unit\Service\Helper\SettingsHelperTest
SettingsHelper Test.
@coversDefaultClass Drupal\acquia_lift\Service\Helper\SettingsHelper @group acquia_lift
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\acquia_lift\Unit\Service\Helper\SettingsHelperTest uses SettingsDataTrait
Expanded class hierarchy of SettingsHelperTest
File
- tests/
src/ Unit/ Service/ Helper/ SettingsHelperTest.php, line 15
Namespace
Drupal\Tests\acquia_lift\Unit\Service\HelperView source
class SettingsHelperTest extends UnitTestCase {
use SettingsDataTrait;
protected function setUp() {
parent::setUp();
}
/**
* Tests the isInvalidCredentialAccountId() method.
*
* @covers ::isInvalidCredentialAccountId
*
* @param string $setting
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredentialAccountId
*/
public function testIsInvalidCredentialAccountId($setting, $expected) {
$result = SettingsHelper::isInvalidCredentialAccountId($setting);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredentialAccountId().
*/
public function providerTestIsInvalidCredentialAccountId() {
$data = [];
$data['invalid null'] = [
NULL,
TRUE,
];
$data['invalid empty'] = [
'',
TRUE,
];
$data['invalid start with number'] = [
'1a',
TRUE,
];
$data['invalid has "~" sign'] = [
'a~',
TRUE,
];
$data['valid has "_" sign'] = [
'a_',
FALSE,
];
$data['valid start with alphabetic then alphanumeric'] = [
'a123',
FALSE,
];
return $data;
}
/**
* Tests the isInvalidCredentialSiteId() method.
*
* @covers ::isInvalidCredentialSiteId
*
* @param string $setting
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredentialSiteId
*/
public function testIsInvalidCredentialSiteId($setting, $expected) {
$result = SettingsHelper::isInvalidCredentialSiteId($setting);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredentialSiteId().
*/
public function providerTestIsInvalidCredentialSiteId() {
$data = [];
$data['invalid null'] = [
NULL,
TRUE,
];
$data['invalid empty'] = [
'',
TRUE,
];
$data['valid has "~" sign'] = [
'a~',
FALSE,
];
$data['valid alphanumeric 1'] = [
'a123',
FALSE,
];
$data['valid alphanumeric 2'] = [
'3Ab',
FALSE,
];
return $data;
}
/**
* Tests the isInvalidCredentialAssetsUrl() method.
*
* @covers ::isInvalidCredentialAssetsUrl
*
* @param string $setting
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredentialAssetsUrl
*/
public function testIsInvalidCredentialAssetsUrl($setting, $expected) {
$result = SettingsHelper::isInvalidCredentialAssetsUrl($setting);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredentialAssetsUrl().
*/
public function providerTestIsInvalidCredentialAssetsUrl() {
$data = [];
$data['invalid null'] = [
NULL,
TRUE,
];
$data['invalid empty'] = [
'',
TRUE,
];
$data['invalid has non-ascii characters'] = [
'不合法',
TRUE,
];
$data['valid url 1'] = [
'acquia',
FALSE,
];
$data['valid url 2'] = [
'acquia.com',
FALSE,
];
return $data;
}
/**
* Tests the isInvalidCredentialDecisionApiUrl() method.
*
* @covers ::isInvalidCredentialDecisionApiUrl
*
* @param string $setting
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredentialDecisionApiUrl
*/
public function testIsInvalidCredentialDecisionApiUrl($setting, $expected) {
$result = SettingsHelper::isInvalidCredentialDecisionApiUrl($setting);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredentialDecisionApiUrl().
*/
public function providerTestIsInvalidCredentialDecisionApiUrl() {
$data = [];
$data['invalid has non-ascii characters'] = [
'不合法',
TRUE,
];
$data['valid null'] = [
NULL,
FALSE,
];
$data['valid empty'] = [
'',
FALSE,
];
$data['valid url 1'] = [
'acquia',
FALSE,
];
$data['valid url 2'] = [
'acquia.com',
FALSE,
];
return $data;
}
/**
* Tests the isInvalidCredentialOauthUrl() method.
*
* @covers ::isInvalidCredentialOauthUrl
*
* @param string $setting
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredentialOauthUrl
*/
public function testIsInvalidCredentialOauthUrl($setting, $expected) {
$result = SettingsHelper::isInvalidCredentialOauthUrl($setting);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredentialOauthUrl().
*/
public function providerTestIsInvalidCredentialOauthUrl() {
$data = [];
$data['invalid has non-ascii characters'] = [
'不合法',
TRUE,
];
$data['valid null'] = [
NULL,
FALSE,
];
$data['valid empty'] = [
'',
FALSE,
];
$data['valid url 1'] = [
'acquia',
FALSE,
];
$data['valid url 2'] = [
'acquia.com',
FALSE,
];
return $data;
}
/**
* Tests the isInvalidCredential() method.
*
* @covers ::isInvalidCredential
*
* @param array $full_settings
* @param boolean $expected
*
* @dataProvider providerTestIsInvalidCredential
*/
public function testIsInvalidCredential($full_settings, $expected) {
$result = SettingsHelper::isInvalidCredential($full_settings);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsInvalidCredential().
*/
public function providerTestIsInvalidCredential() {
$data = [];
$valid_settings = $this
->getValidCredentialSettings();
$data['valid data 1'] = [
$valid_settings,
FALSE,
];
$data['valid data 2'] = [
$valid_settings,
FALSE,
];
$data['missing account_id'] = [
$valid_settings,
TRUE,
];
$data['invalid assets_url URL'] = [
$valid_settings,
TRUE,
];
$data['invalid decision_api_url URL'] = [
$valid_settings,
TRUE,
];
$data['valid data 2'][0]['account_id'] = 'accountId2';
$data['valid data 2'][0]['site_id'] = '2222';
$data['valid data 2'][0]['assets_url'] = 'assets_url_2';
$data['missing account_id'][0]['account_id'] = '';
$data['invalid assets_url URL'][0]['assets_url'] = 'invalid assets URL';
$data['invalid decision_api_url URL'][0]['decision_api_url'] = '\\\\////\\\\////';
return $data;
}
/**
* Tests the isValidContentReplacementMode() method.
*
* @covers ::isValidContentReplacementMode
*
* @param string $test_value
* @param boolean $expected
*
* @dataProvider providerTestIsValidContentReplacementMode
*/
public function testIsValidContentReplacementMode($test_value, $expected) {
$result = SettingsHelper::isValidContentReplacementMode($test_value);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testIsValidContentReplacementMode().
*/
public function providerTestIsValidContentReplacementMode() {
$data = [];
$data['valid trusted'] = [
'trusted',
TRUE,
];
$data['valid untrusted'] = [
'untrusted',
TRUE,
];
$data['valid customized'] = [
'customized',
TRUE,
];
$data['invalid null'] = [
NULL,
FALSE,
];
$data['invalid value'] = [
'another',
FALSE,
];
return $data;
}
/**
* Tests the getUdfLimitsForType() method.
*
* @covers ::getUdfLimitsForType
*
* @param string $test_value
* @param boolean $expected
*
* @dataProvider providerTestGetUdfLimitsForType
*/
public function testGetUdfLimitsForType($test_value, $expected) {
$result = SettingsHelper::getUdfLimitsForType($test_value);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testGetUdfLimitsForType().
*/
public function providerTestGetUdfLimitsForType() {
$data = [];
$data['person'] = [
'person',
50,
];
$data['touch'] = [
'touch',
20,
];
$data['event'] = [
'event',
50,
];
return $data;
}
/**
* Tests the getUdfLimitsForType() method, expected exception.
*
* @covers ::getUdfLimitsForType
*
* @expectedException \Exception
* @expectedExceptionCode 0
* @expectedExceptionMessage This UDF Field type is not supported.
*/
public function testGetUdfLimitsForTypeExpectedException() {
SettingsHelper::getUdfLimitsForType('non_exist');
}
/**
* Tests the pingUri() method.
*
* @covers ::pingUri
*
* @param string $test_value
* @param boolean $expected
*
* @dataProvider providerTestPingUri
*/
public function testPingUri($test_value, $expected) {
$response = $this
->prophesize(\Psr\Http\Message\ResponseInterface::class);
$response
->getStatusCode()
->willReturn($expected['statusCode']);
$response
->getReasonPhrase()
->willReturn($expected['reasonPhrase']);
$client = $this
->prophesize(\GuzzleHttp\Client::class);
$client
->get($test_value[1], [
'http_errors' => false,
])
->willReturn($response
->reveal());
$clientFactory = $this
->prophesize(\Drupal\Core\Http\ClientFactory::class);
$clientFactory
->fromOptions(\Prophecy\Argument::any())
->willReturn($client
->reveal());
$container = $this
->prophesize(\Drupal\Core\DependencyInjection\ContainerBuilder::class);
$container
->get('http_client_factory')
->willReturn($clientFactory
->reveal());
\Drupal::setContainer($container
->reveal());
$result = SettingsHelper::pingUri($test_value[0], $test_value[1]);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for testPingUri().
*/
public function providerTestPingUri() {
$data = [];
$data['invalid uri'] = [
[
'uri_1',
'',
],
[
'statusCode' => '',
'reasonPhrase' => '',
],
];
$data['valid uri 1'] = [
[
'uri_1',
'path_1',
],
[
'statusCode' => 123,
'reasonPhrase' => 'a:1:{s:8:"base_uri";s:5:"uri_1";} path_1 a:1:{s:11:"http_errors";b:0;}',
],
];
$data['valid uri 2'] = [
[
'uri_2',
'path_2',
],
[
'statusCode' => 123,
'reasonPhrase' => 'a:1:{s:8:"base_uri";s:5:"uri_2";} path_2 a:1:{s:11:"http_errors";b:0;}',
],
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SettingsDataTrait:: |
private | function | Get a valid advanced settings array. | |
SettingsDataTrait:: |
private | function | Get a valid credential settings array. | |
SettingsDataTrait:: |
private | function | Get a valid field mappings settings array. | |
SettingsDataTrait:: |
private | function | Get a valid identity settings array. | |
SettingsDataTrait:: |
private | function | Get a valid udf event mappings settings array. | |
SettingsDataTrait:: |
private | function | Get a valid udf person mappings settings array. | |
SettingsDataTrait:: |
private | function | Get a valid udf touch mappings settings array. | |
SettingsDataTrait:: |
private | function | Get a valid visibility settings array. | |
SettingsHelperTest:: |
public | function | Data provider for testGetUdfLimitsForType(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredential(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredentialAccountId(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredentialAssetsUrl(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredentialDecisionApiUrl(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredentialOauthUrl(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsInvalidCredentialSiteId(). | |
SettingsHelperTest:: |
public | function | Data provider for testIsValidContentReplacementMode(). | |
SettingsHelperTest:: |
public | function | Data provider for testPingUri(). | |
SettingsHelperTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SettingsHelperTest:: |
public | function | Tests the getUdfLimitsForType() method. | |
SettingsHelperTest:: |
public | function | Tests the getUdfLimitsForType() method, expected exception. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredential() method. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredentialAccountId() method. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredentialAssetsUrl() method. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredentialDecisionApiUrl() method. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredentialOauthUrl() method. | |
SettingsHelperTest:: |
public | function | Tests the isInvalidCredentialSiteId() method. | |
SettingsHelperTest:: |
public | function | Tests the isValidContentReplacementMode() method. | |
SettingsHelperTest:: |
public | function | Tests the pingUri() method. | |
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. |