84f42d0882c7b7e725274301271d9f991c8e4cfd
[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
13     public function setUp()
14     {
15         if (!$this->getSites()) {
16             $this->setUpDrupal(1, true);
17             $this->drush('pm-enable', ['config']);
18         }
19     }
20
21     public function testConfigGetSet()
22     {
23         $this->drush('config-set', ['system.site', 'name', 'config_test']);
24         $this->drush('config-get', ['system.site', 'name']);
25         $this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
26     }
27
28     public function testConfigExportImportStatus()
29     {
30         // Get path to sync dir.
31         $this->drush('core-status', [], ['format' => 'json', 'fields' => 'config-sync']);
32         $sync = $this->webroot() . '/' . $this->getOutputFromJSON('config-sync');
33         $system_site_yml = $sync . '/system.site.yml';
34         $core_extension_yml = $sync . '/core.extension.yml';
35
36         // Test export.
37         $this->drush('config-export');
38         $this->assertFileExists($system_site_yml);
39
40         // Test import and status by finishing the round trip.
41         $contents = file_get_contents($system_site_yml);
42         $contents = preg_replace('/front: .*/', 'front: unish', $contents);
43         $contents = file_put_contents($system_site_yml, $contents);
44     
45         // Test status of changed configuration.
46         $this->drush('config:status');
47         $this->assertContains('system.site', $this->getOutput(), 'config:status correctly reports changes.');
48     
49         // Test import.
50         $this->drush('config-import');
51         $this->drush('config-get', ['system.site', 'page'], ['format' => 'json']);
52         $page = $this->getOutputFromJSON('system.site:page');
53         $this->assertContains('unish', $page->front, 'Config was successfully imported.');
54
55         // Test status of identical configuration.
56         $this->drush('config:status', [], ['format' => 'list']);
57         $this->assertEquals('', $this->getOutput(), 'config:status correctly reports identical config.');
58       
59         // Similar, but this time via --partial option.
60         $contents = file_get_contents($system_site_yml);
61         $contents = preg_replace('/front: .*/', 'front: unish partial', $contents);
62         $partial_path = self::getSandbox() . '/partial';
63         $this->mkdir($partial_path);
64         $contents = file_put_contents($partial_path. '/system.site.yml', $contents);
65         $this->drush('config-import', [], ['partial' => null, 'source' => $partial_path]);
66         $this->drush('config-get', ['system.site', 'page'], ['format' => 'json']);
67         $page = $this->getOutputFromJSON('system.site:page');
68         $this->assertContains('unish partial', $page->front, '--partial was successfully imported.');
69     }
70 }