Commit 1c4a1a0c authored by bircher's avatar bircher

Issue #2925084: Add test for generic createCollection setup

parent f0500b7d
......@@ -31,12 +31,8 @@ class FilteredStorageTest extends CachedStorageTest {
* Test that the storage is set on the filters.
*/
public function testSettingStorages() {
$filterReflection = new \ReflectionClass(FilteredStorage::class);
$filtersProperty = $filterReflection->getProperty('filters');
$filtersProperty->setAccessible(TRUE);
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
$filters = $filtersProperty->getValue($this->storage);
$filters = static::getProtectedFilters($this->storage);
foreach ($filters as $filter) {
// Test that the source storage is a ReadonlyStorage and wraps the cached
// storage from the inherited test.
......@@ -53,6 +49,31 @@ class FilteredStorageTest extends CachedStorageTest {
}
}
/**
* Test setting up filters in FilteredStorage::createCollection().
*/
public function testCreateCollectionFilter() {
$collection = $this->randomString();
$filteredCollection = $this->randomString();
$filter = $this->prophesizeFilter();
$filterC = $this->prophesizeFilter();
$filterC->filterGetCollectionName($collection)->willReturn($filteredCollection);
$filter->filterCreateCollection($collection)->willReturn($filterC->reveal());
$source = $this->prophesize(StorageInterface::class);
$sourceC = $this->prophesize(StorageInterface::class);
$sourceC->getCollectionName()->willReturn($collection);
$source->createCollection($collection)->willReturn($sourceC->reveal());
$storage = new FilteredStorage($source->reveal(), [$filter->reveal()]);
// Creating a collection makes sure the filters were correctly set up.
$storageC = $storage->createCollection($collection);
// Test that the collection is filtered in the collection storage.
$this->assertEquals($filteredCollection, $storageC->getCollectionName());
}
/**
* Test the read methods invokes the correct filter methods.
*
......@@ -288,6 +309,23 @@ class FilteredStorageTest extends CachedStorageTest {
return $filter;
}
/**
* Get the filters from a FilteredStorageInterface.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* The storage with the protected filters property.
*
* @return \Drupal\config_filter\Config\StorageFilterInterface[]
* The array of filters.
*/
protected static function getProtectedFilters(StorageInterface $storage) {
$filterReflection = new \ReflectionClass(FilteredStorage::class);
$filtersProperty = $filterReflection->getProperty('filters');
$filtersProperty->setAccessible(TRUE);
return $filtersProperty->getValue($storage);
}
/**
* Create a random array.
*/
......
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