You are here

public function FilteredStorageTest::testDeleteAllFilter in Config Filter 8

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

Test the deleteAll method invokes the filterDeleteAll in filters.

@dataProvider deleteAllFilterProvider

File

src/Tests/FilteredStorageTest.php, line 331

Class

FilteredStorageTest
Tests StorageWrapper operations using the CachedStorage.

Namespace

Drupal\config_filter\Tests

Code

public function testDeleteAllFilter($interim, $expected) {
  $name = $this
    ->randomString();
  $source = $this
    ->prophesize(StorageInterface::class);
  $filterA = $this
    ->prophesizeFilter();
  $filterB = $this
    ->prophesizeFilter();
  $filterA
    ->filterDeleteAll($name, TRUE)
    ->willReturn($interim);
  $filterB
    ->filterDeleteAll($name, $interim)
    ->willReturn($expected);
  if ($expected) {
    $source
      ->deleteAll($name)
      ->willReturn(TRUE);
  }
  else {
    $source
      ->deleteAll(Argument::any())
      ->shouldNotBeCalled();
    $all = [
      $this
        ->randomString(),
      $this
        ->randomString(),
    ];
    $source
      ->listAll($name)
      ->willReturn($all);
    foreach ($all as $item) {
      $filterA
        ->filterDelete($item, TRUE)
        ->willReturn(TRUE);
      $filterB
        ->filterDelete($item, TRUE)
        ->willReturn(FALSE);
    }
  }
  $storage = new FilteredStorage($source
    ->reveal(), [
    $filterA
      ->reveal(),
    $filterB
      ->reveal(),
  ]);
  $this
    ->assertTrue($storage
    ->deleteAll($name));
}