public function SplitFilterTest::testFilterRead in Configuration Split 8
Test that the filter reads correctly.
File
- src/
Tests/ SplitFilterTest.php, line 190
Class
- SplitFilterTest
- Test filter plugin.
Namespace
Drupal\config_split\TestsCode
public function testFilterRead() {
// Transparent filter.
$name = $this
->randomMachineName();
$data = (array) $this
->getRandomGenerator()
->object();
$filter = $this
->getFilter();
$this
->assertEquals($data, $filter
->filterRead($name, $data));
// Filter with a storage that has an alternative.
$name2 = $this
->randomMachineName();
$data2 = (array) $this
->getRandomGenerator()
->object();
$storage = $this
->prophesize(StorageInterface::class);
$storage
->read($name)
->willReturn(NULL);
$storage
->read($name2)
->willReturn($data2);
$filter = $this
->getFilter($storage
->reveal());
$this
->assertEquals($data, $filter
->filterRead($name, $data));
$this
->assertEquals($data2, $filter
->filterRead($name2, $data));
// Test that extensions are correctly added.
$extensions = [
'module' => [
'config' => 0,
'user' => 0,
'views_ui' => 0,
'menu_link_content' => 1,
'views' => 10,
],
'theme' => [
'stable' => 0,
'classy' => 0,
],
];
$modules = [
'module1' => 0,
'module2' => 1,
];
$themes = [
'custom_theme' => 0,
];
$extensions_extra = [
'module' => [
'config' => 0,
'module1' => 0,
'user' => 0,
'views_ui' => 0,
'menu_link_content' => 1,
'module2' => 1,
'views' => 10,
],
'theme' => [
'stable' => 0,
'classy' => 0,
'custom_theme' => 0,
],
];
$filter = $this
->getFilter(NULL, [], $modules, $themes);
$this
->assertEquals($extensions_extra, $filter
->filterRead('core.extension', $extensions));
$this
->assertEquals($extensions_extra, $filter
->filterRead('core.extension', $extensions_extra));
// Test with reading from the wrapper storage.
$filter = $this
->getFilter(NULL, [], [
'none' => 0,
], [
'none' => 0,
], [], $name);
$storage = $this
->prophesize(StorageInterface::class);
$storage
->read($name)
->willReturn([
'module' => $modules,
'theme' => $themes,
]);
$filter
->setFilteredStorage($storage
->reveal());
$this
->assertEquals($extensions_extra, $filter
->filterRead('core.extension', $extensions));
$this
->assertEquals($extensions_extra, $filter
->filterRead('core.extension', $extensions_extra));
// Test with reading from the wrapper storage.
$filter = $this
->getFilter(NULL, [], [
'none' => 0,
], [
'none' => 0,
], [], $name);
$storage = $this
->prophesize(StorageInterface::class);
$storage
->read($name)
->willReturn(FALSE);
$filter
->setFilteredStorage($storage
->reveal());
$this
->assertEquals($extensions, $filter
->filterRead('core.extension', $extensions));
$this
->assertEquals($extensions_extra, $filter
->filterRead('core.extension', $extensions_extra));
}