FarmUpdateTest.php in farmOS 2.x
File
modules/core/update/tests/src/Kernel/FarmUpdateTest.php
View source
<?php
namespace Drupal\Tests\farm_update\Kernel;
use Drupal\KernelTests\KernelTestBase;
class FarmUpdateTest extends KernelTestBase {
protected $configFactory;
protected $farmUpdate;
protected static $modules = [
'config_update',
'farm_update',
'farm_update_test',
'farm_flag',
];
protected function setUp() : void {
parent::setUp();
$this->configFactory = \Drupal::service('config.factory');
$this->farmUpdate = \Drupal::service('farm.update');
$this
->installEntitySchema('flag');
$this
->installConfig([
'farm_update_test',
'farm_flag',
]);
}
public function testFarmUpdate() {
$this
->farmUpdateTestRevertSetting('farm_flag.flag.monitor', 'label', 'Changed');
$this
->farmUpdateTestRevertSetting('farm_flag.flag.priority', 'label', 'Changed', TRUE);
$this
->farmUpdateTestRevertSetting('farm_flag.flag.review', 'label', 'Changed', TRUE);
}
protected function farmUpdateTestRevertSetting(string $config, string $setting, string $override, bool $excluded = FALSE) {
$original = \Drupal::config($config)
->get($setting);
$this->configFactory
->getEditable($config)
->set($setting, $override)
->save();
$this
->assertEquals($override, \Drupal::config($config)
->get($setting), 'Setting is overridden before rebuild.');
$this->farmUpdate
->rebuild();
$expected_value = $excluded ? $override : $original;
$expected_message = $excluded ? 'Setting is overridden after rebuild.' : 'Setting is reverted after rebuild.';
$this
->assertEquals($expected_value, \Drupal::config($config)
->get($setting), $expected_message);
}
}