ConfigUpdaterTest.php in Commerce Core 8.2
File
tests/src/Kernel/ConfigUpdaterTest.php
View source
<?php
namespace Drupal\Tests\commerce\Kernel;
class ConfigUpdaterTest extends CommerceKernelTestBase {
public static $modules = [
'commerce_update_test',
];
protected $configUpdater;
protected function setUp() : void {
parent::setUp();
$this
->installConfig('commerce_update_test');
$this->configUpdater = $this->container
->get('commerce.config_updater');
}
public function testLoadFromActive() {
$config_name = 'commerce_store.commerce_store_type.testing';
$data = $this->configUpdater
->loadFromActive($config_name);
$this
->assertEquals($data['id'], 'testing');
}
public function testLoadFromExtension() {
$config_name = 'views.view.commerce_stores';
$data = $this->configUpdater
->loadFromExtension($config_name);
$this
->assertEquals($data['id'], 'commerce_stores');
}
public function testIsModified() {
$config_name = 'commerce_store.commerce_store_type.testing';
$config = $this->configUpdater
->loadFromActive($config_name);
$this
->assertEmpty($this->configUpdater
->isModified($config));
$store_type = \Drupal::entityTypeManager()
->getStorage('commerce_store_type')
->load('testing');
$store_type
->setDescription('The default store');
$store_type
->save();
$config = $this->configUpdater
->loadFromActive($config_name);
$this
->assertNotEmpty($this->configUpdater
->isModified($config));
}
public function testImport() {
$config_name = 'commerce_store.commerce_store_type.testing';
$this->configUpdater
->delete([
$config_name,
]);
$result = $this->configUpdater
->import([
$config_name,
]);
$failed = $result
->getFailed();
$succeeded = $result
->getSucceeded();
$this
->assertEmpty($failed);
$this
->assertEquals($succeeded[$config_name], "{$config_name} was successfully imported");
$result = $this->configUpdater
->import([
$config_name,
]);
$failed = $result
->getFailed();
$succeeded = $result
->getSucceeded();
$this
->assertEmpty($succeeded);
$this
->assertEquals($failed[$config_name], "{$config_name} already exists, use revert to update");
}
public function testRevert() {
$config_name = 'commerce_store.commerce_store_type.testing';
$store_type = \Drupal::entityTypeManager()
->getStorage('commerce_store_type')
->load('testing');
$store_type
->setDescription('The default store');
$store_type
->save();
$result = $this->configUpdater
->revert([
$config_name,
]);
$failed = $result
->getFailed();
$succeeded = $result
->getSucceeded();
$this
->assertEmpty($failed);
$this
->assertEquals($succeeded[$config_name], "Skipped: {$config_name} was not reverted because it was modified by the user");
$result = $this->configUpdater
->revert([
$config_name,
], FALSE);
$succeeded = $result
->getSucceeded();
$this
->assertNotEmpty($succeeded);
$this
->assertEquals($succeeded[$config_name], "{$config_name} was successfully reverted");
$store_type = \Drupal::entityTypeManager()
->getStorage('commerce_store_type')
->load('testing');
$this
->assertEmpty($store_type
->getDescription());
}
public function testDelete() {
$config_name = 'commerce_store.commerce_store_type.testing';
$result = $this->configUpdater
->delete([
$config_name,
]);
$failed = $result
->getFailed();
$succeeded = $result
->getSucceeded();
$this
->assertEmpty($failed);
$this
->assertEquals($succeeded[$config_name], "{$config_name} was successfully deleted");
}
}