class ConfigListerTest in Configuration Update Manager 8
Tests the \Drupal\config_update\ConfigListerWithProviders class.
The methods from \Drupal\config_update\ConfigLister are also tested.
@group config_update
@coversDefaultClass \Drupal\config_update\ConfigListerWithProviders
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\config_update\Unit\ConfigUpdateUnitTestBase
- class \Drupal\Tests\config_update\Unit\ConfigListerTest
- class \Drupal\Tests\config_update\Unit\ConfigUpdateUnitTestBase
Expanded class hierarchy of ConfigListerTest
File
- tests/
src/ Unit/ ConfigListerTest.php, line 14
Namespace
Drupal\Tests\config_update\UnitView source
class ConfigListerTest extends ConfigUpdateUnitTestBase {
/**
* The config lister to test.
*
* @var \Drupal\config_update\ConfigListerWithProviders
*/
protected $configLister;
/**
* List of configuration by provider in the mocks.
*
* This is an array whose keys are provider names, and whose values are
* each an array containing the provider type, an array of config items
* mocked to be in config/install, and the same for config/optional. In
* all cases, the first item in the array of config items should be tested
* to be provided by that provider, and any others should not be there.
*
* @var array
*/
protected $configProviderList = [
'foo_module' => [
'module',
[
'foo.barbaz.one',
'baz.bar.one',
],
[
'foo.barbaz.two',
],
],
'foo_theme' => [
'theme',
[
'foo.bar.one',
],
[
'foo.bar.two',
],
],
'standard' => [
'profile',
[
'baz.bar.one',
],
[
'baz.bar.two',
],
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$lister = $this
->getMockBuilder('Drupal\\config_update\\ConfigListerWithProviders')
->setConstructorArgs([
$this
->getEntityManagerMock(),
$this
->getConfigStorageMock('active'),
$this
->getConfigStorageMock('extension'),
$this
->getConfigStorageMock('optional'),
$this
->getModuleHandlerMock(),
$this
->getThemeHandlerMock(),
])
->setMethods([
'listProvidedItems',
'getProfileName',
])
->getMock();
$lister
->method('getProfileName')
->willReturn('standard');
$map = [];
foreach ($this->configProviderList as $provider => $info) {
// Info has: [type, install storage items, optional storage items].
// Map needs: [type, provider name, isOptional, [config items]].
$map[] = [
$info[0],
$provider,
FALSE,
$info[1],
];
$map[] = [
$info[0],
$provider,
TRUE,
$info[2],
];
}
$lister
->method('listProvidedItems')
->will($this
->returnValueMap($map));
$this->configLister = $lister;
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::listConfig
* @dataProvider listConfigProvider
*/
public function testListConfig($a, $b, $expected) {
$this
->assertEquals($expected, $this->configLister
->listConfig($a, $b));
}
/**
* Data provider for self:testListConfig().
*/
public function listConfigProvider() {
return [
// Arguments are $list_type, $name, and return value is that list of
// configuration in active, extension, and optional storage.
[
'type',
'system.all',
[
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.three',
'foo.barbaz.four',
'foo.barbaz.five',
'foo.barbaz.six',
'something.else',
'another.one',
],
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.seven',
'foo.barbaz.four',
'foo.barnot.three',
'something.else',
],
[
'foo.barbaz.four',
],
],
],
[
'type',
'system.simple',
[
[
'something.else',
'another.one',
],
[
'foo.barnot.three',
'something.else',
],
[],
],
],
[
'type',
'foo',
[
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.three',
],
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.seven',
],
[],
],
],
[
'type',
'unknown.type',
[
[],
[],
[],
],
],
[
'profile',
'dummy',
[
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.three',
'foo.barbaz.four',
'foo.barbaz.five',
'foo.barbaz.six',
'something.else',
'another.one',
],
[
'baz.bar.one',
],
[
'baz.bar.two',
],
],
],
[
'module',
'foo_module',
[
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.three',
'foo.barbaz.four',
'foo.barbaz.five',
'foo.barbaz.six',
'something.else',
'another.one',
],
[
'foo.barbaz.one',
'baz.bar.one',
],
[
'foo.barbaz.two',
],
],
],
[
'theme',
'foo_theme',
[
[
'foo.bar.one',
'foo.bar.two',
'foo.bar.three',
'foo.barbaz.four',
'foo.barbaz.five',
'foo.barbaz.six',
'something.else',
'another.one',
],
[
'foo.bar.one',
],
[
'foo.bar.two',
],
],
],
];
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::getType
*/
public function testGetType() {
$return = $this->configLister
->getType('not_in_list');
$this
->assertNull($return);
foreach ($this->entityDefinitionInformation as $info) {
$return = $this->configLister
->getType($info['type']);
$this
->assertEquals($return
->getConfigPrefix(), $info['prefix']);
}
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::getTypeByPrefix
*/
public function testGetTypeByPrefix() {
$return = $this->configLister
->getTypeByPrefix('not_in_list');
$this
->assertNull($return);
foreach ($this->entityDefinitionInformation as $info) {
$return = $this->configLister
->getTypeByPrefix($info['prefix']);
$this
->assertEquals($return
->getConfigPrefix(), $info['prefix']);
}
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::getTypeNameByConfigName
*/
public function testGetTypeNameByConfigName() {
$return = $this->configLister
->getTypeNameByConfigName('not_in_list');
$this
->assertNull($return);
foreach ($this->entityDefinitionInformation as $info) {
$return = $this->configLister
->getTypeNameByConfigName($info['prefix'] . '.something');
$this
->assertEquals($return, $info['type']);
}
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::listTypes
*/
public function testListTypes() {
$return = $this->configLister
->listTypes();
// Should return an array in sorted order, of just the config entities
// that $this->getEntityManagerMock() set up.
$expected = [
'bar' => 'foo.barbaz',
'baz' => 'baz.foo',
'foo' => 'foo.bar',
];
$this
->assertEquals(array_keys($return), array_keys($expected));
foreach ($return as $key => $definition) {
$this
->assertTrue($definition
->entityClassImplements('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface'));
$this
->assertEquals($definition
->getConfigPrefix(), $expected[$key]);
}
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::listProviders
*/
public function testListProviders() {
// This method's return value is not sorted in any particular way.
$return = $this->configLister
->listProviders();
$expected = [];
foreach ($this->configProviderList as $provider => $info) {
// Info has: [type, install storage items, optional storage items], with
// only the first item in each list that should be present in
// listProviders().
// Expected needs: key is item name, value is [type, provider name].
$expected[$info[1][0]] = [
$info[0],
$provider,
];
$expected[$info[2][0]] = [
$info[0],
$provider,
];
}
ksort($return);
ksort($expected);
$this
->assertEquals($return, $expected);
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::getConfigProvider
* @dataProvider getConfigProviderProvider
*/
public function testGetConfigProvider($a, $expected) {
$this
->assertEquals($expected, $this->configLister
->getConfigProvider($a));
}
/**
* Data provider for self:testGetConfigProvider().
*/
public function getConfigProviderProvider() {
$values = [];
foreach ($this->configProviderList as $provider => $info) {
// Info has: [type, install storage items, optional storage items], with
// the first item in each list that should be OK to test with
// getConfigProvider().
// Values needs: [item, [type, provider name]].
$values[] = [
$info[1][0],
[
$info[0],
$provider,
],
];
$values[] = [
$info[2][0],
[
$info[0],
$provider,
],
];
}
$values[] = [
'not.a.config.item',
NULL,
];
return $values;
}
/**
* @covers \Drupal\config_update\ConfigListerWithProviders::providerHasConfig
* @dataProvider providerHasConfigProvider
*/
public function testProviderHasConfig($a, $b, $expected) {
$this
->assertEquals($expected, $this->configLister
->providerHasConfig($a, $b));
}
/**
* Data provider for self:testProviderHasConfig().
*/
public function providerHasConfigProvider() {
$values = [];
foreach ($this->configProviderList as $provider => $info) {
// Info has: [type, install storage items, optional storage items].
// Values needs: [type, provider name, TRUE] for valid providers,
// change the last to FALSE for invalid providers.
$values[] = [
$info[0],
$provider,
TRUE,
];
$values[] = [
$info[0],
$provider . '_suffix',
FALSE,
];
}
$values[] = [
'invalid_type',
'foo_module',
FALSE,
];
return $values;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigListerTest:: |
protected | property | The config lister to test. | |
ConfigListerTest:: |
protected | property | List of configuration by provider in the mocks. | |
ConfigListerTest:: |
public | function | Data provider for self:testGetConfigProvider(). | |
ConfigListerTest:: |
public | function | Data provider for self:testListConfig(). | |
ConfigListerTest:: |
public | function | Data provider for self:testProviderHasConfig(). | |
ConfigListerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::getConfigProvider @dataProvider getConfigProviderProvider | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::getType | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::getTypeByPrefix | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::getTypeNameByConfigName | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::listConfig @dataProvider listConfigProvider | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::listProviders | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::listTypes | |
ConfigListerTest:: |
public | function | @covers \Drupal\config_update\ConfigListerWithProviders::providerHasConfig @dataProvider providerHasConfigProvider | |
ConfigUpdateUnitTestBase:: |
protected | property | Mock config storage for the mock config factory. | |
ConfigUpdateUnitTestBase:: |
protected | property | Array of active configuration information for mocking. | |
ConfigUpdateUnitTestBase:: |
protected | property | Array of extension configuration information for mocking. | |
ConfigUpdateUnitTestBase:: |
protected | property | Array of optional configuration information for mocking. | |
ConfigUpdateUnitTestBase:: |
protected | property | List of mock-dispatched events. | |
ConfigUpdateUnitTestBase:: |
protected | property | The mocked entity definition information. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock config factory class for the test. | |
ConfigUpdateUnitTestBase:: |
public | function | Gets the value of the mocked config storage. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock config storage object for the test. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock entity manager for the test. | |
ConfigUpdateUnitTestBase:: |
protected | function | Mocks the event dispatcher service. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock module handler for the test. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock theme handler for the test. | |
ConfigUpdateUnitTestBase:: |
protected | function | Creates a mock string translation class for the test. | |
ConfigUpdateUnitTestBase:: |
public | function | Mocks event dispatch. | |
ConfigUpdateUnitTestBase:: |
public | function | Mocks the getEditable() method for the mock config factory. | |
ConfigUpdateUnitTestBase:: |
public | function | Mocks the getStorage() method for the entity manager. | |
ConfigUpdateUnitTestBase:: |
public | function | Mocks the translateString() method for the string translation mock object. | |
ConfigUpdateUnitTestBase:: |
public | function | Sets the value of the mocked config storage. | |
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. |