Commit cb8aeb33 authored by tlyngej's avatar tlyngej

Move the rest of the simpletest testst to phpunit tests

parent 4a735f98
<?php
namespace Drupal\config_ignore\Tests;
use Drupal\config_ignore\Plugin\ConfigFilter\IgnoreFilter;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Serialization\Yaml;
/**
* Class ConfigIgnoreTest.
*
* @package Drupal\config_ignore\Tests
* @group config_ignore
*/
class ConfigIgnoreTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['config_ignore'];
/**
* The profile to install as a basis for testing.
*
* We need to change it form the standard 'testing' profile as that will not
* print the title on the page, which we use for testing.'*'
*
* @var string
*/
protected $profile = 'minimal';
/**
* Verify that config can get ignored.
*/
public function testValidateIgnoring() {
// Login with a user that has permission to import config.
$this->drupalLogin($this->drupalCreateUser(['import configuration']));
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be ignored upon config import.
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.site'])->save();
// Assemble a change that will try and override the current value.
$config = $this->config('system.site')->set('name', 'Import has changed title');
$edit = [
'config_type' => 'system.simple',
'config_name' => $config->getName(),
'import' => Yaml::encode($config->get()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, array(), t('Confirm'));
//
// // Validate if the title from the imported config was rejected.
// $this->assertText('Test import');
//
// // Validate that the user gets a message about what has been ignored.
// $this->assertText('The following config entity was ignored');
}
/**
* Verify all wildcard asterisk is working.
*/
public function testValidateIgnoringWithWildcard() {
// Login with a user that has permission to import config.
$this->drupalLogin($this->drupalCreateUser(['import configuration']));
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be ignored upon config import.
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.' . IgnoreFilter::INCLUDE_SUFFIX])->save();
// Assemble a change that will try and override the current value.
$config = $this->config('system.site')->set('name', 'Import has changed title');
$edit = [
'config_type' => 'system.simple',
'config_name' => $config->getName(),
'import' => Yaml::encode($config->get()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, array(), t('Confirm'));
//
// // Validate if the title from the imported config was rejected.
// $this->assertText('Test import');
//
// // Validate that the user gets a message about what has been ignored.
// $this->assertText('The following config entity was ignored');
}
/**
* Verify Force Import syntax is working.
*
* This test makes sure we avoid regression issues.
*/
public function testValidateForceImporting() {
// Login with a user that has permission to import config.
$this->drupalLogin($this->drupalCreateUser(['import configuration']));
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be (force-) imported upon config import.
$settings = [IgnoreFilter::FORCE_EXCLUSION_PREFIX . 'system.site'];
$this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
// Assemble a change that will try and override the current value.
$config = $this->config('system.site')->set('name', 'Import has changed title');
$edit = [
'config_type' => 'system.simple',
'config_name' => $config->getName(),
'import' => Yaml::encode($config->get()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, [], t('Confirm'));
//
// // Validate if the title from the imported config was imported.
// $this->assertText('Import has changed title');
//
// // Validate that the user does NOT get the message about configuration
// // been ignored.
// $this->assertNoText('The following config entity was ignored');
}
/**
* Verify excluded configuration works with wildcards.
*
* This test cover the scenario where a wildcard matches a specific
* configuration, but that's still imported due exclusion.
*/
public function testValidateForceImportingWithWildcard() {
// Login with a user that has permission to import config.
$this->drupalLogin($this->drupalCreateUser(['import configuration']));
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set system.* configs to be ignored and system.site:name to be (force-)
// imported upon config import.
$settings = [
'system.' . IgnoreFilter::INCLUDE_SUFFIX,
IgnoreFilter::FORCE_EXCLUSION_PREFIX . 'system.site',
];
$this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
// Assemble a change that will try and override the current value.
$config = $this->config('system.site')->set('name', 'Import has changed title');
$edit = [
'config_type' => 'system.simple',
'config_name' => $config->getName(),
'import' => Yaml::encode($config->get()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, [], t('Confirm'));
//
// // Validate if the title from the imported config was imported.
// $this->assertText('Import has changed title');
}
}
...@@ -22,25 +22,17 @@ abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase { ...@@ -22,25 +22,17 @@ abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase {
public static $modules = ['config_ignore', 'config', 'config_filter']; public static $modules = ['config_ignore', 'config', 'config_filter'];
/** /**
* Config Importer object used for testing. * Perform a config import from sync. folder.
*
* @var \Drupal\Core\Config\ConfigImporter
*/
protected $configImporter;
/**
* {@inheritdoc}
*/ */
public function setUp() { public function doImport() {
parent::setUp();
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage'),
$this->container->get('config.manager') $this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter(
$config_importer = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),
$this->container->get('event_dispatcher'), $this->container->get('event_dispatcher'),
$this->container->get('config.manager'), $this->container->get('config.manager'),
...@@ -51,13 +43,8 @@ abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase { ...@@ -51,13 +43,8 @@ abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase {
$this->container->get('theme_handler'), $this->container->get('theme_handler'),
$this->container->get('string_translation') $this->container->get('string_translation')
); );
}
/** $config_importer->reset()->import();
* Perform a config import from sync. folder.
*/
public function doImport() {
$this->configImporter->reset()->import();
} }
/** /**
......
...@@ -33,6 +33,8 @@ class ConfigIgnoreHookTest extends ConfigIgnoreBrowserTestBase { ...@@ -33,6 +33,8 @@ class ConfigIgnoreHookTest extends ConfigIgnoreBrowserTestBase {
$this->doImport(); $this->doImport();
// Test if the `config_ignore_hook_test` module got to ignore the site name
// config.
$this->assertEquals('Changed title', $this->config('system.site')->get('name')); $this->assertEquals('Changed title', $this->config('system.site')->get('name'));
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\Tests\config_ignore\Functional; namespace Drupal\Tests\config_ignore\Functional;
use Drupal\config_ignore\Plugin\ConfigFilter\IgnoreFilter;
/** /**
* Test functionality of config_ignore module. * Test functionality of config_ignore module.
* *
...@@ -67,4 +69,93 @@ class ConfigIgnoreTest extends ConfigIgnoreBrowserTestBase { ...@@ -67,4 +69,93 @@ class ConfigIgnoreTest extends ConfigIgnoreBrowserTestBase {
$this->assertEqual($settings, ['config.test']); $this->assertEqual($settings, ['config.test']);
} }
/**
* Verify that config can get ignored.
*/
public function testValidateIgnoring() {
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be ignored upon config import.
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.site'])->save();
$this->doExport();
// Change the site name, perform an import and see if the site name remains
// the same, as it should.
$this->config('system.site')->set('name', 'Changed title')->save();
$this->doImport();
$this->assertEquals('Changed title', $this->config('system.site')->get('name'));
}
/**
* Verify all wildcard asterisk is working.
*/
public function testValidateIgnoringWithWildcard() {
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be ignored upon config import.
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.' . IgnoreFilter::INCLUDE_SUFFIX])->save();
$this->doExport();
// Change the site name, perform an import and see if the site name remains
// the same, as it should.
$this->config('system.site')->set('name', 'Changed title')->save();
$this->doImport();
$this->assertEquals('Changed title', $this->config('system.site')->get('name'));
}
/**
* Verify Force Import syntax is working.
*
* This test makes sure we avoid regression issues.
*/
public function testValidateForceImporting() {
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be (force-) imported upon config import.
$settings = [IgnoreFilter::FORCE_EXCLUSION_PREFIX . 'system.site'];
$this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
$this->doExport();
// Change the site name, perform an import and see if the site name remains
// the same, as it should.
$this->config('system.site')->set('name', 'Changed title')->save();
$this->doImport();
$this->assertEquals('Test import', $this->config('system.site')->get('name'));
}
/**
* Verify excluded configuration works with wildcards.
*
* This test cover the scenario where a wildcard matches a specific
* configuration, but that's still imported due exclusion.
*/
public function testValidateForceImportingWithWildcard() {
// Set the site name to a known value that we later will try and overwrite.
$this->config('system.site')->set('name', 'Test import')->save();
// Set the system.site:name to be (force-) imported upon config import.
$settings = ['system.' . IgnoreFilter::INCLUDE_SUFFIX, IgnoreFilter::FORCE_EXCLUSION_PREFIX . 'system.site'];
$this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
$this->doExport();
// Change the site name, perform an import and see if the site name remains
// the same, as it should.
$this->config('system.site')->set('name', 'Changed title')->save();
$this->doImport();
$this->assertEquals('Test import', $this->config('system.site')->get('name'));
}
} }
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