Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / config / tests / src / Functional / ConfigImportInstallProfileTest.php
1 <?php
2
3 namespace Drupal\Tests\config\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the importing/exporting configuration based on the install profile.
9  *
10  * @group config
11  */
12 class ConfigImportInstallProfileTest extends BrowserTestBase {
13
14   /**
15    * The profile to install as a basis for testing.
16    *
17    * @var string
18    */
19   protected $profile = 'testing_config_import';
20
21   /**
22    * Modules to install.
23    *
24    * @var array
25    */
26   public static $modules = ['config'];
27
28   /**
29    * A user with the 'synchronize configuration' permission.
30    *
31    * @var \Drupal\user\UserInterface
32    */
33   protected $webUser;
34
35   protected function setUp() {
36     parent::setUp();
37
38     $this->webUser = $this->drupalCreateUser(['synchronize configuration']);
39     $this->drupalLogin($this->webUser);
40     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
41   }
42
43   /**
44    * Tests config importer cannot uninstall install profiles.
45    *
46    * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber
47    */
48   public function testInstallProfileValidation() {
49     $sync = $this->container->get('config.storage.sync');
50     $this->copyConfig($this->container->get('config.storage'), $sync);
51     $core = $sync->read('core.extension');
52
53     // Ensure install profiles can not be uninstalled.
54     unset($core['module']['testing_config_import']);
55     $sync->write('core.extension', $core);
56
57     $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
58     $this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
59     $this->assertText('Unable to uninstall the Testing config import profile since it is the install profile.');
60
61     // Uninstall dependencies of testing_config_import.
62     $core['module']['testing_config_import'] = 0;
63     unset($core['module']['syslog']);
64     unset($core['theme']['stark']);
65     $core['theme']['stable'] = 0;
66     $core['theme']['classy'] = 0;
67     $sync->write('core.extension', $core);
68     $sync->deleteAll('syslog.');
69     $theme = $sync->read('system.theme');
70     $theme['default'] = 'classy';
71     $sync->write('system.theme', $theme);
72     $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
73     $this->assertText('The configuration was imported successfully.');
74     $this->rebuildContainer();
75     $this->assertFalse(\Drupal::moduleHandler()->moduleExists('syslog'), 'The syslog module has been uninstalled.');
76     $this->assertFalse(\Drupal::service('theme_handler')->themeExists('stark'), 'The stark theme has been uninstalled.');
77     $this->assertTrue(\Drupal::service('theme_handler')->themeExists('classy'), 'The classy theme has been installed.');
78   }
79
80 }