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. }
  16. }
  17. function testConfigGetSet() {
  18. $options = $this->options();
  19. $this->drush('config-set', array('system.site', 'name', 'config_test'), $options);
  20. $this->drush('config-get', array('system.site', 'name'), $options);
  21. $this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
  22. }
  23. function testConfigList() {
  24. $options = $this->options();
  25. $this->drush('config-list', array(), $options);
  26. $result = $this->getOutputAsList();
  27. $this->assertNotEmpty($result, 'An array of config names was returned.');
  28. $this->assertTrue(in_array('update.settings', $result), 'update.settings name found in the config names.');
  29. $this->drush('config-list', array('system'), $options);
  30. $result = $this->getOutputAsList();
  31. $this->assertTrue(in_array('system.site', $result), 'system.site found in list of config names with "system" prefix.');
  32. $this->drush('config-list', array('system'), $options + array('format' => 'json'));
  33. $result = $this->getOutputFromJSON();
  34. $this->assertNotEmpty($result, 'Valid, non-empty JSON output was returned.');
  35. }
  36. function testConfigExportImport() {
  37. $options = $this->options();
  38. // Get path to sync dir.
  39. $this->drush('core-status', array(), $options + array('format' => 'json'));
  40. $sync = $this->webroot() . '/' . $this->getOutputFromJSON('config-sync');
  41. $system_site_yml = $sync . '/system.site.yml';
  42. $core_extension_yml = $sync . '/core.extension.yml';
  43. // Test export
  44. $this->drush('config-export', array(), $options);
  45. $this->assertFileExists($system_site_yml);
  46. // Test import by finish the round trip.
  47. $contents = file_get_contents($system_site_yml);
  48. $contents = preg_replace('/front: .*/', 'front: unish', $contents);
  49. $contents = file_put_contents($system_site_yml, $contents);
  50. $this->drush('config-import', array(), $options);
  51. $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
  52. $page = $this->getOutputFromJSON('system.site:page');
  53. $this->assertContains('unish', $page->front, 'Config was successfully imported.');
  54. $this->drush('pm-enable', array('tracker'), $options);
  55. $ignored_modules = array('skip-modules' => 'tracker');
  56. // Run config-export again - note that 'tracker' is enabled, but we
  57. // are going to ignore it on write, so no changes should be written
  58. // to core.extension when it is exported.
  59. $this->drush('config-export', array(), $options + $ignored_modules);
  60. $this->assertFileExists($core_extension_yml);
  61. $contents = file_get_contents($core_extension_yml);
  62. $this->assertNotContains('tracker', $contents);
  63. // Run config-import again, but ignore 'tracker' when importing.
  64. // It is not presently in the exported configuration, because we enabled
  65. // it after export. If we imported again without adding 'tracker' with
  66. // 'skip-modules' option, then it would be disabled.
  67. $this->drush('config-import', array(), $options + $ignored_modules);
  68. $this->drush('config-get', array('core.extension', 'module'), $options + array('format' => 'yaml'));
  69. $modules = $this->getOutput();
  70. $this->assertContains('tracker', $modules, 'Tracker module appears in extension list after import, as it should.');
  71. // Run config-export one final time. 'tracker' is still enabled, even
  72. // though it was ignored in the previous import/export operations.
  73. // When we remove the skip-modules option, then 'tracker' will
  74. // be exported.
  75. $this->drush('config-export', array(), $options);
  76. $this->assertFileExists($core_extension_yml);
  77. $contents = file_get_contents($core_extension_yml);
  78. $this->assertContains('tracker', $contents);
  79. }
  80. /**
  81. * Tests editing config from a file (not interactively).
  82. */
  83. public function testConfigEdit() {
  84. // Write out edits to a file.
  85. $config = "name: 'TEST NAME'\nmail: test@testmail.example.org";
  86. $path = UNISH_SANDBOX . '/system.site.yml';
  87. file_put_contents($path, $config);
  88. $options = $this->options();
  89. $options += array(
  90. 'file' => $path,
  91. 'yes' => NULL,
  92. );
  93. $this->drush('config-edit', array(), $options);
  94. $this->drush('config-get', array('system.site'), $this->options());
  95. $this->assertEquals($config, $this->getOutput());
  96. }
  97. function options() {
  98. return array(
  99. 'yes' => NULL,
  100. 'root' => $this->webroot(),
  101. 'uri' => key($this->getSites()),
  102. );
  103. }
  104. }