class ConfigEntityTypeTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityTypeTest
@coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityType @group Config
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Config\Entity\ConfigEntityTypeTest
Expanded class hierarchy of ConfigEntityTypeTest
File
- core/
tests/ Drupal/ Tests/ Core/ Config/ Entity/ ConfigEntityTypeTest.php, line 17 - Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityTypeTest.
Namespace
Drupal\Tests\Core\Config\EntityView source
class ConfigEntityTypeTest extends UnitTestCase {
/**
* Sets up a ConfigEntityType object for a given set of values.
*
* @param array $definition
* An array of values to use for the ConfigEntityType.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityTypeInterface
*/
protected function setUpConfigEntityType($definition) {
if (!isset($definition['id'])) {
$definition += array(
'id' => 'example_config_entity_type',
);
}
return new ConfigEntityType($definition);
}
/**
* Tests that we get an exception when the length of the config prefix that is
* returned by getConfigPrefix() exceeds the maximum defined prefix length.
*
* @covers ::getConfigPrefix
*/
public function testConfigPrefixLengthExceeds() {
// A provider length of 24 and config_prefix length of 59 (+1 for the .)
// results in a config length of 84, which is too long.
$definition = array(
'provider' => $this
->randomMachineName(24),
'config_prefix' => $this
->randomMachineName(59),
);
$config_entity = $this
->setUpConfigEntityType($definition);
$this
->setExpectedException('\\Drupal\\Core\\Config\\ConfigPrefixLengthException', "The configuration file name prefix {$definition['provider']}.{$definition['config_prefix']} exceeds the maximum character limit of " . ConfigEntityType::PREFIX_LENGTH);
$this
->assertEmpty($config_entity
->getConfigPrefix());
}
/**
* Tests that a valid config prefix returned by getConfigPrefix()
* does not throw an exception and is formatted as expected.
*
* @covers ::getConfigPrefix
*/
public function testConfigPrefixLengthValid() {
// A provider length of 24 and config_prefix length of 58 (+1 for the .)
// results in a config length of 83, which is right at the limit.
$definition = array(
'provider' => $this
->randomMachineName(24),
'config_prefix' => $this
->randomMachineName(58),
);
$config_entity = $this
->setUpConfigEntityType($definition);
$expected_prefix = $definition['provider'] . '.' . $definition['config_prefix'];
$this
->assertEquals($expected_prefix, $config_entity
->getConfigPrefix());
}
/**
* @covers ::__construct
*/
public function testConstruct() {
$config_entity = new ConfigEntityType([
'id' => 'example_config_entity_type',
]);
$this
->assertEquals('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage', $config_entity
->getStorageClass());
}
/**
* @covers ::__construct
*
* @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
* @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it
*/
public function testConstructBadStorage() {
new ConfigEntityType([
'id' => 'example_config_entity_type',
'handlers' => [
'storage' => '\\Drupal\\Core\\Entity\\KeyValueStore\\KeyValueEntityStorage',
],
]);
}
/**
* @covers ::setStorageClass
*
* @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
* @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it
*/
public function testSetStorageClass() {
$config_entity = $this
->setUpConfigEntityType([]);
$config_entity
->setStorageClass('\\Drupal\\Core\\Entity\\KeyValueStore\\KeyValueEntityStorage');
}
/**
* Tests the getConfigPrefix() method.
*
* @dataProvider providerTestGetConfigPrefix
*
* @covers ::getConfigPrefix
*/
public function testGetConfigPrefix($definition, $expected) {
$entity_type = $this
->setUpConfigEntityType($definition);
$this
->assertSame($expected, $entity_type
->getConfigPrefix());
}
/**
* Provides test data.
*/
public function providerTestGetConfigPrefix() {
return array(
array(
array(
'provider' => 'node',
'id' => 'node_type',
'config_prefix' => 'type',
),
'node.type',
),
array(
array(
'provider' => 'views',
'id' => 'view',
),
'views.view',
),
);
}
/**
* @covers ::getPropertiesToExport
*
* @dataProvider providerGetPropertiesToExport
*/
public function testGetPropertiesToExport($definition, $expected) {
$entity_type = $this
->setUpConfigEntityType($definition);
$properties_to_export = $entity_type
->getPropertiesToExport();
$this
->assertSame($expected, $properties_to_export);
// Ensure the method is idempotent.
$properties_to_export = $entity_type
->getPropertiesToExport();
$this
->assertSame($expected, $properties_to_export);
}
public function providerGetPropertiesToExport() {
$data = [];
$data[] = [
[],
NULL,
];
$data[] = [
[
'config_export' => [
'id',
'custom_property' => 'customProperty',
],
],
[
'uuid' => 'uuid',
'langcode' => 'langcode',
'status' => 'status',
'dependencies' => 'dependencies',
'third_party_settings' => 'third_party_settings',
'id' => 'id',
'custom_property' => 'customProperty',
],
];
$data[] = [
[
'config_export' => [
'id',
],
'mergedConfigExport' => [
'random_key' => 'random_key',
],
],
[
'random_key' => 'random_key',
],
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityTypeTest:: |
public | function | ||
ConfigEntityTypeTest:: |
public | function | Provides test data. | |
ConfigEntityTypeTest:: |
protected | function | Sets up a ConfigEntityType object for a given set of values. | |
ConfigEntityTypeTest:: |
public | function | Tests that we get an exception when the length of the config prefix that is returned by getConfigPrefix() exceeds the maximum defined prefix length. | |
ConfigEntityTypeTest:: |
public | function | Tests that a valid config prefix returned by getConfigPrefix() does not throw an exception and is formatted as expected. | |
ConfigEntityTypeTest:: |
public | function | @covers ::__construct | |
ConfigEntityTypeTest:: |
public | function | @covers ::__construct | |
ConfigEntityTypeTest:: |
public | function | Tests the getConfigPrefix() method. | |
ConfigEntityTypeTest:: |
public | function | @covers ::getPropertiesToExport | |
ConfigEntityTypeTest:: |
public | function | @covers ::setStorageClass | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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 | 259 |