You are here

public function FilteredStorageTest::testCreateCollectionFilter in Config Filter 8

Same name and namespace in other branches
  1. 8.2 src/Tests/FilteredStorageTest.php \Drupal\config_filter\Tests\FilteredStorageTest::testCreateCollectionFilter()

Test setting up filters in FilteredStorage::createCollection().

File

src/Tests/FilteredStorageTest.php, line 95

Class

FilteredStorageTest
Tests StorageWrapper operations using the CachedStorage.

Namespace

Drupal\config_filter\Tests

Code

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());
}