ConfigFilterStorageFactoryTest.php in Config Filter 8
File
tests/src/Kernel/ConfigFilterStorageFactoryTest.php
View source
<?php
namespace Drupal\Tests\config_filter\Kernel;
use Drupal\config_filter\Config\FilteredStorageInterface;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\KernelTests\KernelTestBase;
class ConfigFilterStorageFactoryTest extends KernelTestBase {
public static $modules = [
'system',
'config_filter',
'config_filter_test',
'config_filter_split_test',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
}
public function testServiceProvider() {
$this
->assertInstanceOf(FilteredStorageInterface::class, $this->container
->get('config.storage.sync'));
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$this
->assertEquals([
'system.site',
], $this
->configImporter()
->getStorageComparer()
->getChangelist('update'));
$this
->assertEmpty($this
->configImporter()
->getStorageComparer()
->getChangelist('create'));
$this
->assertEmpty($this
->configImporter()
->getStorageComparer()
->getChangelist('delete'));
$this
->assertEmpty($this
->configImporter()
->getStorageComparer()
->getChangelist('rename'));
$config = $this
->config('system.site')
->getRawData();
$config['name'] .= ' Arrr';
$config['slogan'] .= ' Arrr';
$this
->assertEquals($config, $this->container
->get('config.storage.sync')
->read('system.site'));
}
public function testStorageFactory() {
$database = $this->container
->get('database');
$destination = new DatabaseStorage($database, 'config_filter_source_test');
$filtered = $this->container
->get('config_filter.storage_factory')
->getFilteredStorage($destination, [
'test_storage',
]);
$active = $this->container
->get('config.storage');
$this
->copyConfig($active, $filtered);
$splitStorage = new DatabaseStorage($database, 'config_filter_split_test');
$this
->assertTrue(count($destination
->listAll()) > 0);
$this
->assertTrue(count($splitStorage
->listAll()) > 0);
$this
->assertEquals(count($active
->listAll()), count($destination
->listAll()) + count($splitStorage
->listAll()));
$this
->assertEquals($active
->listAll('core'), $splitStorage
->listAll());
$this
->assertEquals($active
->listAll('system'), $destination
->listAll('system'));
$this
->assertEquals($active
->readMultiple($active
->listAll('core')), $splitStorage
->readMultiple($splitStorage
->listAll()));
$this
->assertEquals($active
->readMultiple($active
->listAll('system')), $destination
->readMultiple($destination
->listAll('system')));
$this
->assertEquals($active
->listAll(), $filtered
->listAll());
$this
->assertEquals($active
->readMultiple($active
->listAll()), $filtered
->readMultiple($filtered
->listAll()));
}
public function testListAll() {
$filtered = $this->container
->get('config_filter.storage_factory')
->getSync();
$this
->assertNotContains('system.pirates', $filtered
->listAll());
$this
->assertFalse($filtered
->exists('system.pirates'));
\Drupal::state()
->set('config_filter_test_bluff', TRUE);
$this
->assertContains('system.pirates', $filtered
->listAll());
$this
->assertTrue($filtered
->exists('system.pirates'));
}
}