Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / tests / configTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * Tests for Configuration Management commands for D8+.
7  * @group commands
8  * @group config
9  */
10 class ConfigCase extends CommandUnishTestCase {
11
12   function setUp() {
13     if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
14       $this->markTestSkipped('Config only available on D8+.');
15     }
16
17     if (!$this->getSites()) {
18       $this->setUpDrupal(1, TRUE);
19       $this->drush('pm-enable', array('config'), $this->options());
20     }
21   }
22
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.');
28   }
29
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.');
36
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.');
40
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.');
44   }
45
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';
53
54     // Test export
55     $this->drush('config-export', array(), $options);
56     $this->assertFileExists($system_site_yml);
57
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.');
66
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';
71     mkdir($partial_path);
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.');
77   }
78
79   function options() {
80     return array(
81       'yes' => NULL,
82       'root' => $this->webroot(),
83       'uri' => key($this->getSites()),
84     );
85   }
86 }