Commit 164f8dde authored by tlyngej's avatar tlyngej

Add test for hook implementation

parent 136e74a5
......@@ -60,7 +60,7 @@ function config_ignore_form_config_admin_import_form_alter(&$form, FormStateInte
$form['ignored'] = [
'#type' => 'table',
'#header' => ['Config name', 'Action'],
'#caption' => t('The following configuration entities are ignored due to the <a href="@url">Config Ignore Settings</a> and therefore not displayed in the list above', [
'#caption' => t('<h3>The following configuration entities are ignored due to the <a href="@url">Config Ignore Settings</a> and therefore not displayed in the list above</h3>', [
'@url' => Url::fromRoute('config_ignore.settings')
->toString()
]),
......
<?php
namespace Drupal\Tests\config_ignore\Functional;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\StorageComparer;
use Drupal\Tests\BrowserTestBase;
/**
* Class ConfigIgnoreBrowserTestBase.
*
* @package Drupal\Tests\config_ignore
*/
abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['config_ignore', 'config', 'config_filter'];
/**
* Config Importer object used for testing.
*
* @var \Drupal\Core\Config\ConfigImporter
*/
protected $configImporter;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
$this->container->get('event_dispatcher'),
$this->container->get('config.manager'),
$this->container->get('lock'),
$this->container->get('config.typed'),
$this->container->get('module_handler'),
$this->container->get('module_installer'),
$this->container->get('theme_handler'),
$this->container->get('string_translation')
);
}
/**
* Perform a config import from sync. folder.
*/
public function doImport() {
$this->configImporter->reset()->import();
}
/**
* Perform a config export to sync. folder.
*/
public function doExport() {
// Setup a config sync. dir with a, more or less, know set of config
// entities. This is a full blown export of yaml files, written to the disk.
$destination = CONFIG_SYNC_DIRECTORY;
$destination_dir = config_get_config_directory($destination);
/** @var \Drupal\Core\Config\CachedStorage $source_storage */
$source_storage = \Drupal::service('config.storage');
$destination_storage = new FileStorage($destination_dir);
foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
}
}
<?php
namespace Drupal\Tests\config_ignore\Functional;
/**
* Test hook implementation of another module.
*
* @package Drupal\Tests\config_ignore\Functional
*
* @group config_ignore
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class ConfigIgnoreHookTest extends ConfigIgnoreBrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['config_ignore', 'config', 'config_filter', 'config_ignore_hook_test'];
/**
* Test hook implementation of another module.
*/
public function testSettingsAlterHook() {
$this->config('system.site')->set('name', 'Test import')->save();
$this->doExport();
$this->config('system.site')->set('name', 'Changed title')->save();
$this->doImport();
$this->assertEquals('Changed title', $this->config('system.site')->get('name'));
}
}
......@@ -2,12 +2,8 @@
namespace Drupal\Tests\config_ignore\Functional;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Config\FileStorage;
use Drupal\Tests\BrowserTestBase;
/**
* Class ConfigIgnoreTest.
* Test functionality of config_ignore module.
*
* @package Drupal\Tests\config_ignore\Functional
*
......@@ -15,34 +11,18 @@ use Drupal\Tests\BrowserTestBase;
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class ConfigIgnoreTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['config_ignore', 'config', 'config_filter'];
class ConfigIgnoreTest extends ConfigIgnoreBrowserTestBase {
/**
* Verify that the Sync. table gets update with appropriate ignore actions.
*/
public function testSyncTableUpdate() {
// Setup a config sync. dir with a, more or less, know set of config
// entities. This is a full blown export of yaml files, written to the disk.
$this->config('system.site')->set('name', 'Test import')->save();
$this->config('system.date')->set('first_day', '0')->save();
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.site'])->save();
$destination = CONFIG_SYNC_DIRECTORY;
$destination_dir = config_get_config_directory($destination);
/** @var CachedStorage $source_storage */
$source_storage = \Drupal::service('config.storage');
$destination_storage = new FileStorage($destination_dir);
foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
$this->doExport();
// Login with a user that has permission to sync. config.
$this->drupalLogin($this->drupalCreateUser(['synchronize configuration']));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment