View source
<?php
namespace Drupal\config\Tests;
use Drupal\Core\Config\InstallStorage;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Config\FileStorage;
use Drupal\system\Entity\Action;
use Drupal\tour\Entity\Tour;
class ConfigInstallProfileOverrideTest extends WebTestBase {
protected $profile = 'testing_config_overrides';
function testInstallProfileConfigOverwrite() {
$config_name = 'system.cron';
$expected_original_data = array(
'threshold' => array(
'requirements_warning' => 172800,
'requirements_error' => 1209600,
),
);
$expected_profile_data = array(
'threshold' => array(
'requirements_warning' => 259200,
'requirements_error' => 1209600,
),
);
$config_dir = drupal_get_path('module', 'system') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
$this
->assertTrue(is_dir($config_dir));
$source_storage = new FileStorage($config_dir);
$data = $source_storage
->read($config_name);
$this
->assertIdentical($data, $expected_original_data);
$config = $this
->config($config_name);
$this
->assertIdentical($config
->get(), $expected_profile_data);
$action = Action::load('user_block_user_action');
$this
->assertEqual($action
->label(), 'Overridden block the selected user(s)');
$action = Action::load('user_cancel_user_action');
$this
->assertEqual($action
->label(), 'Cancel the selected user account(s)', 'Default configuration that is not overridden is not affected.');
$tour = Tour::load('language');
$this
->assertEqual(count($tour
->getTips()), 1, 'Optional configuration can be overridden. The language tour only has one tip');
$tour = Tour::load('language-add');
$this
->assertEqual(count($tour
->getTips()), 3, 'Optional configuration that is not overridden is not affected.');
$this
->assertEqual(Tour::load('testing_config_overrides')
->label(), 'Config override test');
$optional_dir = drupal_get_path('module', 'testing_config_overrides') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
$optional_storage = new FileStorage($optional_dir);
foreach ([
'config_test.dynamic.dotted.default',
'config_test.dynamic.override',
'config_test.dynamic.override_unmet',
] as $id) {
$this
->assertTrue(\Drupal::config($id)
->isNew(), "The config_test entity {$id} contained in the profile's optional directory does not exist.");
$this
->assertTrue($optional_storage
->exists($id), "The config_test entity {$id} does exist in the profile's optional directory.");
}
$this->container
->get('module_installer')
->install([
'config_test',
]);
$this
->rebuildContainer();
$config_test_storage = \Drupal::entityManager()
->getStorage('config_test');
$this
->assertEqual($config_test_storage
->load('dotted.default')
->label(), 'Default install profile override', 'The config_test entity is overridden by the profile optional configuration.');
$this
->assertEqual($config_test_storage
->load('override')
->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration.');
$this
->assertNull($config_test_storage
->load('override_unmet'), 'The optional config_test entity with unmet dependencies is not created.');
$this
->assertNull($config_test_storage
->load('completely_new'), 'The completely new optional config_test entity with unmet dependencies is not created.');
$this->container
->get('module_installer')
->install([
'dblog',
]);
$this
->rebuildContainer();
$this
->assertEqual($config_test_storage
->load('override_unmet')
->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration and is installed when its dependencies are met.');
$this
->assertEqual($config_test_storage
->load('completely_new')
->label(), 'Completely new optional configuration', 'The optional config_test entity is provided by the profile optional configuration and is installed when its dependencies are met.');
}
}