diff --git a/core/lib/Drupal/Core/Config/ConfigCollectionException.php b/core/lib/Drupal/Core/Config/ConfigCollectionException.php new file mode 100644 index 0000000..430d067 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigCollectionException.php @@ -0,0 +1,13 @@ + static::COLLECTION_MAX_LENGTH) { + throw new ConfigCollectionException(String::format('The collection name !collection is longer than !max_length.', array('!collection' => $collection, '!max_length' => static::COLLECTION_MAX_LENGTH))); + } $this->collections[$collection] = $override_service; } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 99c638e..a2672bb 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -191,14 +191,16 @@ protected static function schemaDefinition() { 'collection' => array( 'description' => 'Primary Key: Config object collection.', 'type' => 'varchar', - 'length' => 255, + // @see \Drupal\Core\Config\ConfigCollectionInfo::COLLECTION_MAX_LENGTH + 'length' => 80, 'not null' => TRUE, 'default' => '', ), 'name' => array( 'description' => 'Primary Key: Config object name.', 'type' => 'varchar', - 'length' => 255, + // @see \Drupal\Core\Config\ConfigBase::MAX_NAME_LENGTH + 'length' => 250, 'not null' => TRUE, 'default' => '', ), diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigCollectionInfoTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigCollectionInfoTest.php new file mode 100644 index 0000000..7b5fe45 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/ConfigCollectionInfoTest.php @@ -0,0 +1,78 @@ + '', + 'name' => '\Drupal\Core\Config\ConfigCollectionInfoTest unit test', + 'group' => 'Configuration', + ); + } + + /** + * @covers ::addCollection + * @covers ::getCollectionNames + */ + public function testaddCollection() { + $info = new ConfigCollectionInfo(); + $collection = $this->randomName($info::COLLECTION_MAX_LENGTH); + $info->addCollection($collection); + $collections = $info->getCollectionNames(); + $this->assertEquals(array(StorageInterface::DEFAULT_COLLECTION, $collection), $collections); + $collections = $info->getCollectionNames(FALSE); + $this->assertEquals(array($collection), $collections); + } + + /** + * @covers ::addCollection + * @covers ::getCollectionNames + */ + public function testaddCollectionWithOverrideService() { + $info = new ConfigCollectionInfo(); + $collection_with_service = $this->randomName($info::COLLECTION_MAX_LENGTH); + $overrider = $this->getMock('\Drupal\Core\Config\ConfigFactoryOverrideInterface'); + $info->addCollection($collection_with_service, $overrider); + $collection_without_service = $this->randomName($info::COLLECTION_MAX_LENGTH -1); + $info->addCollection($collection_without_service); + + $this->assertEquals($overrider, $info->getOverrideService($collection_with_service)); + $this->assertNull($info->getOverrideService($collection_without_service)); + } + + /** + * @covers ::addCollection + * @expectedException \Drupal\Core\Config\ConfigCollectionException + */ + public function testaddCollectionConfigCollectionException() { + $info = new ConfigCollectionInfo(); + $info->addCollection($this->randomName($info::COLLECTION_MAX_LENGTH + 1)); + } + + /** + * @covers ::addCollection + * @expectedException \InvalidArgumentException + */ + public function testaddCollectionInvalidArgumentException() { + $info = new ConfigCollectionInfo(); + $info->addCollection(StorageInterface::DEFAULT_COLLECTION); + } + +}