22
33namespace Unish ;
44
5+ use Composer \Semver \Comparator ;
6+
57/**
68 * Tests for Configuration Management commands for D8+.
79 * @group commands
@@ -14,24 +16,25 @@ public function setUp()
1416 {
1517 if (!$ this ->getSites ()) {
1618 $ this ->setUpDrupal (1 , true );
17- $ this ->drush ('pm-enable ' , ['config ' ]);
19+ // Field module is needed for now for --existing-config. It is not actually
20+ // enabled after testing profile is installed. Its required by file and update though.
21+ $ this ->drush ('pm:enable ' , ['config, field ' ]);
1822 }
1923 }
2024
2125 public function testConfigGetSet ()
2226 {
23- $ this ->drush ('config- set ' , ['system.site ' , 'name ' , 'config_test ' ]);
24- $ this ->drush ('config- get ' , ['system.site ' , 'name ' ]);
27+ $ this ->drush ('config: set ' , ['system.site ' , 'name ' , 'config_test ' ]);
28+ $ this ->drush ('config: get ' , ['system.site ' , 'name ' ]);
2529 $ this ->assertEquals ("'system.site:name': config_test " , $ this ->getOutput (), 'Config was successfully set and get. ' );
2630 }
2731
28- public function testConfigExportImportStatus ()
32+ public function testConfigExportImportStatusExistingConfig ()
2933 {
3034 // Get path to sync dir.
31- $ this ->drush ('core- status ' , [], ['format ' => 'json ' , 'fields ' => 'config-sync ' ]);
35+ $ this ->drush ('core: status ' , [], ['format ' => 'json ' , 'fields ' => 'config-sync ' ]);
3236 $ sync = $ this ->webroot () . '/ ' . $ this ->getOutputFromJSON ('config-sync ' );
3337 $ system_site_yml = $ sync . '/system.site.yml ' ;
34- $ core_extension_yml = $ sync . '/core.extension.yml ' ;
3538
3639 // Test export.
3740 $ this ->drush ('config-export ' );
@@ -40,12 +43,12 @@ public function testConfigExportImportStatus()
4043 // Test import and status by finishing the round trip.
4144 $ contents = file_get_contents ($ system_site_yml );
4245 $ contents = preg_replace ('/front: .*/ ' , 'front: unish ' , $ contents );
43- $ contents = file_put_contents ($ system_site_yml , $ contents );
44-
46+ file_put_contents ($ system_site_yml , $ contents );
47+
4548 // Test status of changed configuration.
4649 $ this ->drush ('config:status ' );
4750 $ this ->assertContains ('system.site ' , $ this ->getOutput (), 'config:status correctly reports changes. ' );
48-
51+
4952 // Test import.
5053 $ this ->drush ('config-import ' );
5154 $ this ->drush ('config-get ' , ['system.site ' , 'page ' ], ['format ' => 'json ' ]);
@@ -55,7 +58,7 @@ public function testConfigExportImportStatus()
5558 // Test status of identical configuration.
5659 $ this ->drush ('config:status ' , [], ['format ' => 'list ' ]);
5760 $ this ->assertEquals ('' , $ this ->getOutput (), 'config:status correctly reports identical config. ' );
58-
61+
5962 // Similar, but this time via --partial option.
6063 $ contents = file_get_contents ($ system_site_yml );
6164 $ contents = preg_replace ('/front: .*/ ' , 'front: unish partial ' , $ contents );
@@ -66,5 +69,18 @@ public function testConfigExportImportStatus()
6669 $ this ->drush ('config-get ' , ['system.site ' , 'page ' ], ['format ' => 'json ' ]);
6770 $ page = $ this ->getOutputFromJSON ('system.site:page ' );
6871 $ this ->assertContains ('unish partial ' , $ page ->front , '--partial was successfully imported. ' );
72+
73+ // Test the --existing-config option for site:install.
74+ $ this ->drush ('core:status ' , ['drupal-version ' ], ['format ' => 'string ' ]);
75+ $ drupal_version = $ this ->getOutputRaw ();
76+ if (Comparator::greaterThanOrEqualTo ($ drupal_version , '8.6 ' )) {
77+ $ contents = file_get_contents ($ system_site_yml );
78+ $ contents = preg_replace ('/front: .*/ ' , 'front: unish existing ' , $ contents );
79+ file_put_contents ($ system_site_yml , $ contents );
80+ $ this ->setUpDrupal (1 , true , ['existing-config ' => null ]);
81+ $ this ->drush ('config-get ' , ['system.site ' , 'page ' ], ['format ' => 'json ' ]);
82+ $ page = $ this ->getOutputFromJSON ('system.site:page ' );
83+ $ this ->assertContains ('unish existing ' , $ page ->front , 'Existing config was successfully imported during site:install. ' );
84+ }
6985 }
7086}
0 commit comments