Commit 7f779ce7 authored by alexpott's avatar alexpott

Issue #3056617 by jcisio, tstoeckler, alexpott: NullStorage does not support collection

(cherry picked from commit cd325f15)
parent 6740a58e
......@@ -18,6 +18,24 @@
*/
class NullStorage implements StorageInterface {
/**
* The storage collection.
*
* @var string
*/
protected $collection;
/**
* Constructs a new NullStorage.
*
* @param string $collection
* (optional) The collection to store configuration in. Defaults to the
* default collection.
*/
public function __construct($collection = StorageInterface::DEFAULT_COLLECTION) {
$this->collection = $collection;
}
/**
* {@inheritdoc}
*/
......@@ -92,13 +110,14 @@ public function deleteAll($prefix = '') {
* {@inheritdoc}
*/
public function createCollection($collection) {
// No op.
return new static($collection);
}
/**
* {@inheritdoc}
*/
public function getAllCollectionNames() {
// Returns only non empty collections.
return [];
}
......@@ -106,7 +125,7 @@ public function getAllCollectionNames() {
* {@inheritdoc}
*/
public function getCollectionName() {
return '';
return $this->collection;
}
}
<?php
namespace Drupal\Tests\Core\Config;
use Drupal\Core\Config\NullStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Tests\UnitTestCase;
/**
* Tests the NullStorage.
*
* @group Config
*/
class NullStorageTest extends UnitTestCase {
/**
* Test createCollection.
*/
public function testCollection() {
$nullStorage = new NullStorage();
$collection = $nullStorage->createCollection('test');
$this->assertInstanceOf(StorageInterface::class, $collection);
$this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $nullStorage->getCollectionName());
$this->assertEquals('test', $collection->getCollectionName());
$this->assertArrayEquals([], $collection->getAllCollectionNames());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment