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

File

tests/configTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * Tests for Configuration Management commands for D8+.
  5. * @group commands
  6. */
  7. class ConfigCase extends CommandUnishTestCase {
  8. function setUp() {
  9. if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
  10. $this->markTestSkipped('Config only available on D8+.');
  11. }
  12. if (!$this->getSites()) {
  13. $this->setUpDrupal(1, TRUE);
  14. }
  15. }
  16. function testConfigGetSet() {
  17. $options = $this->options();
  18. $this->drush('config-set', array('system.site', 'name', 'config_test'), $options);
  19. $this->drush('config-get', array('system.site', 'name'), $options);
  20. $this->assertEquals("'system.site:name': config_test", $this->getOutput(), 'Config was successfully set and get.');
  21. }
  22. function testConfigList() {
  23. $options = $this->options();
  24. $this->drush('config-list', array(), $options);
  25. $result = $this->getOutputAsList();
  26. $this->assertNotEmpty($result, 'An array of config names was returned.');
  27. $this->assertTrue(in_array('update.settings', $result), 'update.settings name found in the config names.');
  28. $this->drush('config-list', array('system'), $options);
  29. $result = $this->getOutputAsList();
  30. $this->assertTrue(in_array('system.site', $result), 'system.site found in list of config names with "system" prefix.');
  31. $this->drush('config-list', array('system'), $options + array('format' => 'json'));
  32. $result = $this->getOutputFromJSON();
  33. $this->assertNotEmpty($result, 'Valid, non-empty JSON output was returned.');
  34. }
  35. function testConfigExportImport() {
  36. $options = $this->options();
  37. // Get path to staging dir.
  38. $this->drush('core-status', array(), $options + array('format' => 'json'));
  39. $staging = $this->webroot() . '/' . $this->getOutputFromJSON('config-staging');
  40. $system_site_yml = $staging . '/system.site.yml';
  41. // Test export
  42. $this->drush('config-export', array(), $options);
  43. $this->assertFileExists($system_site_yml);
  44. // Test import by finish the round trip.
  45. $contents = file_get_contents($system_site_yml);
  46. $contents = str_replace('front: user', 'front: unish', $contents);
  47. $contents = file_put_contents($system_site_yml, $contents);
  48. $this->drush('config-import', array(), $options);
  49. $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json'));
  50. $page = $this->getOutputFromJSON('system.site:page');
  51. $this->assertContains('unish', $page->front, 'Config was successfully imported.');
  52. }
  53. /**
  54. * Tests editing config from a file (not interactively).
  55. */
  56. public function testConfigEdit() {
  57. // Write out edits to a file.
  58. $config = "name: 'TEST NAME'\nmail: test@testmail.example.org";
  59. $path = UNISH_SANDBOX . '/system.site.yml';
  60. file_put_contents($path, $config);
  61. $options = $this->options();
  62. $options += array(
  63. 'file' => $path,
  64. 'yes' => NULL,
  65. );
  66. $this->drush('config-edit', array(), $options);
  67. $this->drush('config-get', array('system.site'), $this->options());
  68. $this->assertEquals($config, $this->getOutput());
  69. }
  70. function options() {
  71. return array(
  72. 'yes' => NULL,
  73. 'root' => $this->webroot(),
  74. 'uri' => key($this->getSites()),
  75. );
  76. }
  77. }