Issue #3056617 by jcisio, tstoeckler, alexpott: NullStorage does not support collection
parent
a0ebbf57de
commit
cd325f157a
|
@ -18,6 +18,24 @@ namespace Drupal\Core\Config;
|
||||||
*/
|
*/
|
||||||
class NullStorage implements StorageInterface {
|
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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -92,13 +110,14 @@ class NullStorage implements StorageInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function createCollection($collection) {
|
public function createCollection($collection) {
|
||||||
// No op.
|
return new static($collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getAllCollectionNames() {
|
public function getAllCollectionNames() {
|
||||||
|
// Returns only non empty collections.
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +125,7 @@ class NullStorage implements StorageInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getCollectionName() {
|
public function getCollectionName() {
|
||||||
return '';
|
return $this->collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue