6 * Tests for Configuration Management commands for D8+.
10 class ConfigCase extends CommandUnishTestCase {
13 if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
14 $this->markTestSkipped('Config only available on D8+.');
17 if (!$this->getSites()) {
18 $this->setUpDrupal(1, TRUE);
19 $this->drush('pm-enable', array('config'), $this->options());
23 function testConfigGetSet() {
24 $options = $this->options();
25 $this->drush('config-set', array('system.site', 'name', 'config_test'), $options);
26 $this->drush('config-get', array('system.site', 'name'), $options);
27 $this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
30 function testConfigList() {
31 $options = $this->options();
32 $this->drush('config-list', array(), $options);
33 $result = $this->getOutputAsList();
34 $this->assertNotEmpty($result, 'An array of config names was returned.');
35 $this->assertTrue(in_array('update.settings', $result), 'update.settings name found in the config names.');
37 $this->drush('config-list', array('system'), $options);
38 $result = $this->getOutputAsList();
39 $this->assertTrue(in_array('system.site', $result), 'system.site found in list of config names with "system" prefix.');
41 $this->drush('config-list', array('system'), $options + array('format' => 'json'));
42 $result = $this->getOutputFromJSON();
43 $this->assertNotEmpty($result, 'Valid, non-empty JSON output was returned.');
46 function testConfigExportImport() {
47 $options = $this->options();
48 // Get path to sync dir.
49 $this->drush('core-status', array('config-sync'), $options + array('format' => 'json'));
50 $sync = $this->webroot() . '/' . $this->getOutputFromJSON('config-sync');
51 $system_site_yml = $sync . '/system.site.yml';
52 $core_extension_yml = $sync . '/core.extension.yml';
55 $this->drush('config-export', array(), $options);
56 $this->assertFileExists($system_site_yml);
58 // Test import by finishing the round trip.
59 $contents = file_get_contents($system_site_yml);
60 $contents = preg_replace('/front: .*/', 'front: unish', $contents);
61 $contents = file_put_contents($system_site_yml, $contents);
62 $this->drush('config-import', array(), $options);
63 $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
64 $page = $this->getOutputFromJSON('system.site:page');
65 $this->assertContains('unish', $page->front, 'Config was successfully imported.');
67 // Similar, but this time via --partial option.
68 $contents = file_get_contents($system_site_yml);
69 $contents = preg_replace('/front: .*/', 'front: unish partial', $contents);
70 $partial_path = UNISH_SANDBOX . '/partial';
72 $contents = file_put_contents($partial_path. '/system.site.yml', $contents);
73 $this->drush('config-import', array(), $options + array('partial' => NULL, 'source' => $partial_path));
74 $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
75 $page = $this->getOutputFromJSON('system.site:page');
76 $this->assertContains('unish partial', $page->front, '--partial was successfully imported.');
82 'root' => $this->webroot(),
83 'uri' => key($this->getSites()),