configTest.php

  1. 8.0.x tests/configTest.php
  2. 7.x tests/configTest.php
  3. master tests/configTest.php

Namespace

Unish

Classes

Namesort descending Description
ConfigCase Tests for Configuration Management commands for D8+. @group commands @group config

File

tests/configTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests for Configuration Management commands for D8+.
  5. * @group commands
  6. * @group config
  7. */
  8. class ConfigCase extends CommandUnishTestCase {
  9. function setUp() {
  10. if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
  11. $this->markTestSkipped('Config only available on D8+.');
  12. }
  13. if (!$this->getSites()) {
  14. $this->setUpDrupal(1, TRUE);
  15. $this->drush('pm-enable', array('config'), $this->options());
  16. }
  17. }
  18. function testConfigGetSet() {
  19. $options = $this->options();
  20. $this->drush('config-set', array('system.site', 'name', 'config_test'), $options);
  21. $this->drush('config-get', array('system.site', 'name'), $options);
  22. $this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
  23. }
  24. function testConfigList() {
  25. $options = $this->options();
  26. $this->drush('config-list', array(), $options);
  27. $result = $this->getOutputAsList();
  28. $this->assertNotEmpty($result, 'An array of config names was returned.');
  29. $this->assertTrue(in_array('update.settings', $result), 'update.settings name found in the config names.');
  30. $this->drush('config-list', array('system'), $options);
  31. $result = $this->getOutputAsList();
  32. $this->assertTrue(in_array('system.site', $result), 'system.site found in list of config names with "system" prefix.');
  33. $this->drush('config-list', array('system'), $options + array('format' => 'json'));
  34. $result = $this->getOutputFromJSON();
  35. $this->assertNotEmpty($result, 'Valid, non-empty JSON output was returned.');
  36. }
  37. function testConfigExportImport() {
  38. $options = $this->options();
  39. // Get path to sync dir.
  40. $this->drush('core-status', array('config-sync'), $options + array('format' => 'json'));
  41. $sync = $this->webroot() . '/' . $this->getOutputFromJSON('config-sync');
  42. $system_site_yml = $sync . '/system.site.yml';
  43. $core_extension_yml = $sync . '/core.extension.yml';
  44. // Test export
  45. $this->drush('config-export', array(), $options);
  46. $this->assertFileExists($system_site_yml);
  47. // Test import by finishing the round trip.
  48. $contents = file_get_contents($system_site_yml);
  49. $contents = preg_replace('/front: .*/', 'front: unish', $contents);
  50. $contents = file_put_contents($system_site_yml, $contents);
  51. $this->drush('config-import', array(), $options);
  52. $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
  53. $page = $this->getOutputFromJSON('system.site:page');
  54. $this->assertContains('unish', $page->front, 'Config was successfully imported.');
  55. // Similar, but this time via --partial option.
  56. $contents = file_get_contents($system_site_yml);
  57. $contents = preg_replace('/front: .*/', 'front: unish partial', $contents);
  58. $partial_path = UNISH_SANDBOX . '/partial';
  59. mkdir($partial_path);
  60. $contents = file_put_contents($partial_path. '/system.site.yml', $contents);
  61. $this->drush('config-import', array(), $options + array('partial' => NULL, 'source' => $partial_path));
  62. $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
  63. $page = $this->getOutputFromJSON('system.site:page');
  64. $this->assertContains('unish partial', $page->front, '--partial was successfully imported.');
  65. $this->drush('pm-enable', array('tracker'), $options);
  66. $ignored_modules = array('skip-modules' => 'tracker');
  67. // Run config-export again - note that 'tracker' is enabled, but we
  68. // are going to ignore it on write, so no changes should be written
  69. // to core.extension when it is exported.
  70. $this->drush('config-export', array(), $options + $ignored_modules);
  71. $this->assertFileExists($core_extension_yml);
  72. $contents = file_get_contents($core_extension_yml);
  73. $this->assertNotContains('tracker', $contents);
  74. // Run config-import again, but ignore 'tracker' when importing.
  75. // It is not presently in the exported configuration, because we enabled
  76. // it after export. If we imported again without adding 'tracker' with
  77. // 'skip-modules' option, then it would be disabled.
  78. $this->drush('config-import', array(), $options + $ignored_modules);
  79. $this->drush('config-get', array('core.extension', 'module'), $options + array('format' => 'yaml'));
  80. $modules = $this->getOutput();
  81. $this->assertContains('tracker', $modules, 'Tracker module appears in extension list after import, as it should.');
  82. // Run config-export one final time. 'tracker' is still enabled, even
  83. // though it was ignored in the previous import/export operations.
  84. // When we remove the skip-modules option, then 'tracker' will
  85. // be exported.
  86. $this->drush('config-export', array(), $options);
  87. $this->assertFileExists($core_extension_yml);
  88. $contents = file_get_contents($core_extension_yml);
  89. $this->assertContains('tracker', $contents);
  90. }
  91. function options() {
  92. return array(
  93. 'yes' => NULL,
  94. 'root' => $this->webroot(),
  95. 'uri' => key($this->getSites()),
  96. );
  97. }
  98. }