ConfigSnapshotStorageTest.php in Config Snapshot 8
File
tests/src/Kernel/ConfigSnapshotStorageTest.php
View source
<?php
namespace Drupal\Tests\config_snapshot\Kernel;
use Drupal\config_snapshot\ConfigSnapshotStorage;
use Drupal\config_snapshot\Entity\ConfigSnapshot;
use Drupal\Core\Config\StorageInterface;
use Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase;
class ConfigSnapshotStorageTest extends ConfigStorageTestBase {
protected $strictConfigSchema = FALSE;
public static $modules = [
'config_snapshot',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('config_snapshot');
$this->storage = new ConfigSnapshotStorage('example', 'module', 'example_module');
$this->storage
->write('system.performance', []);
}
protected function read($name) {
$config_snapshot = ConfigSnapshot::load('example.module.example_module');
if ($item = $config_snapshot
->getItem($this->storage
->getCollectionName(), $name)) {
return $item['data'];
}
return FALSE;
}
protected function insert($name, $data) {
$config_snapshot = ConfigSnapshot::load('example.module.example_module');
$config_snapshot
->setItem($this->storage
->getCollectionName(), $name, $data)
->save();
return TRUE;
}
protected function update($name, $data) {
$config_snapshot = ConfigSnapshot::load('example.module.example_module');
$config_snapshot
->setItem($this->storage
->getCollectionName(), $name, $data)
->save();
return TRUE;
}
protected function delete($name) {
$config_snapshot = ConfigSnapshot::load('example.module.example_module');
if ($this->storage
->exists($name)) {
$config_snapshot
->clearItem($this->storage
->getCollectionName(), $name)
->save();
return TRUE;
}
return FALSE;
}
public function testInvalidStorage() {
$this
->markTestSkipped('ConfigSnapshotStorage cannot be invalid.');
}
public function testCreateCollection($collection) {
$initial_collection_name = $this->storage
->getCollectionName();
$new_storage = $this->storage
->createCollection($collection);
$this
->assertSame($collection, $new_storage
->getCollectionName());
$this
->assertSame($initial_collection_name, $this->storage
->getCollectionName());
}
public function providerCollections() {
return [
[
StorageInterface::DEFAULT_COLLECTION,
],
[
'foo.bar',
],
];
}
}