public function FilteredStorageTest::testCollectionStorages in Config Filter 8
Same name and namespace in other branches
- 8.2 src/Tests/FilteredStorageTest.php \Drupal\config_filter\Tests\FilteredStorageTest::testCollectionStorages()
Test that creating collections keeps filters set to the correct storages.
File
- src/
Tests/ FilteredStorageTest.php, line 57
Class
- FilteredStorageTest
- Tests StorageWrapper operations using the CachedStorage.
Namespace
Drupal\config_filter\TestsCode
public function testCollectionStorages() {
$collection = $this
->randomString();
// The storage is in its default state.
$this
->assertEquals(StorageInterface::DEFAULT_COLLECTION, $this->storage
->getCollectionName());
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
$filters = static::getProtectedFilters($this->storage);
foreach ($filters as $filter) {
// Test that the filters have the correct storage set.
$this
->assertEquals($this->storage, $filter
->getPrivateFilteredStorage());
$this
->assertEquals(StorageInterface::DEFAULT_COLLECTION, $filter
->getPrivateSourceStorage()
->getCollectionName());
}
// Create a collection which creates a clone of the storage and filters.
$collectionStorage = $this->storage
->createCollection($collection);
$this
->assertInstanceOf(FilteredStorageInterface::class, $collectionStorage);
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $collectionFilters */
$collectionFilters = static::getProtectedFilters($collectionStorage);
foreach ($collectionFilters as $filter) {
// Test that the cloned filter has the correct storage set.
$this
->assertEquals($collectionStorage, $filter
->getPrivateFilteredStorage());
$this
->assertEquals($collection, $filter
->getPrivateSourceStorage()
->getCollectionName());
}
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
$filters = static::getProtectedFilters($this->storage);
foreach ($filters as $filter) {
// Test that the filters on the original storage are still correctly set.
$this
->assertEquals($this->storage, $filter
->getPrivateFilteredStorage());
$this
->assertEquals(StorageInterface::DEFAULT_COLLECTION, $filter
->getPrivateSourceStorage()
->getCollectionName());
}
}