annotate core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigTestBase.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\FunctionalTests\Installer;
Chris@17 4
Chris@17 5 use Drupal\Component\Serialization\Yaml;
Chris@17 6 use Drupal\Core\Archiver\ArchiveTar;
Chris@17 7 use Drupal\Core\Installer\Form\SelectProfileForm;
Chris@17 8
Chris@17 9 /**
Chris@17 10 * Provides a base class for testing installing from existing configuration.
Chris@17 11 */
Chris@17 12 abstract class InstallerExistingConfigTestBase extends InstallerTestBase {
Chris@17 13
Chris@17 14 /**
Chris@17 15 * This is set by the profile in the core.extension extracted.
Chris@17 16 */
Chris@17 17 protected $profile = NULL;
Chris@17 18
Chris@17 19 /**
Chris@17 20 * @todo
Chris@17 21 */
Chris@17 22 protected $existingSyncDirectory = FALSE;
Chris@17 23
Chris@17 24 /**
Chris@17 25 * {@inheritdoc}
Chris@17 26 */
Chris@17 27 protected function prepareEnvironment() {
Chris@17 28 parent::prepareEnvironment();
Chris@17 29 $archiver = new ArchiveTar($this->getConfigTarball(), 'gz');
Chris@17 30
Chris@17 31 if ($this->profile === NULL) {
Chris@17 32 $core_extension = Yaml::decode($archiver->extractInString('core.extension.yml'));
Chris@17 33 $this->profile = $core_extension['profile'];
Chris@17 34 }
Chris@17 35
Chris@17 36 // Create a profile for testing.
Chris@17 37 $info = [
Chris@17 38 'type' => 'profile',
Chris@17 39 'core' => \Drupal::CORE_COMPATIBILITY,
Chris@17 40 'name' => 'Configuration installation test profile (' . $this->profile . ')',
Chris@17 41 ];
Chris@17 42
Chris@17 43 // File API functions are not available yet.
Chris@17 44 $path = $this->siteDirectory . '/profiles/' . $this->profile;
Chris@17 45 if ($this->existingSyncDirectory) {
Chris@17 46 $config_sync_directory = $this->siteDirectory . '/config/sync';
Chris@17 47 $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
Chris@17 48 'value' => $config_sync_directory,
Chris@17 49 'required' => TRUE,
Chris@17 50 ];
Chris@17 51 }
Chris@17 52 else {
Chris@17 53 // Put the sync directory inside the profile.
Chris@17 54 $config_sync_directory = $path . '/config/sync';
Chris@17 55 }
Chris@17 56
Chris@17 57 mkdir($path, 0777, TRUE);
Chris@17 58 file_put_contents("$path/{$this->profile}.info.yml", Yaml::encode($info));
Chris@17 59
Chris@17 60 // Create config/sync directory and extract tarball contents to it.
Chris@17 61 mkdir($config_sync_directory, 0777, TRUE);
Chris@17 62 $files = [];
Chris@17 63 $list = $archiver->listContent();
Chris@17 64 if (is_array($list)) {
Chris@17 65 /** @var array $list */
Chris@17 66 foreach ($list as $file) {
Chris@17 67 $files[] = $file['filename'];
Chris@17 68 }
Chris@17 69 $archiver->extractList($files, $config_sync_directory);
Chris@17 70 }
Chris@17 71 }
Chris@17 72
Chris@17 73 /**
Chris@17 74 * Gets the filepath to the configuration tarball.
Chris@17 75 *
Chris@17 76 * The tarball will be extracted to the install profile's config/sync
Chris@17 77 * directory for testing.
Chris@17 78 *
Chris@17 79 * @return string
Chris@17 80 * The filepath to the configuration tarball.
Chris@17 81 */
Chris@17 82 abstract protected function getConfigTarball();
Chris@17 83
Chris@17 84 /**
Chris@17 85 * {@inheritdoc}
Chris@17 86 */
Chris@17 87 protected function installParameters() {
Chris@17 88 $parameters = parent::installParameters();
Chris@17 89
Chris@17 90 // The options that change configuration are disabled when installing from
Chris@17 91 // existing configuration.
Chris@17 92 unset($parameters['forms']['install_configure_form']['site_name']);
Chris@17 93 unset($parameters['forms']['install_configure_form']['site_mail']);
Chris@17 94 unset($parameters['forms']['install_configure_form']['update_status_module']);
Chris@17 95
Chris@17 96 return $parameters;
Chris@17 97 }
Chris@17 98
Chris@17 99 /**
Chris@17 100 * Confirms that the installation installed the configuration correctly.
Chris@17 101 */
Chris@17 102 public function testConfigSync() {
Chris@17 103 // After installation there is no snapshot and nothing to import.
Chris@17 104 $change_list = $this->configImporter()->getStorageComparer()->getChangelist();
Chris@17 105 $expected = [
Chris@17 106 'create' => [],
Chris@17 107 // The system.mail is changed configuration because the test system
Chris@17 108 // changes it to ensure that mails are not sent.
Chris@17 109 'update' => ['system.mail'],
Chris@17 110 'delete' => [],
Chris@17 111 'rename' => [],
Chris@17 112 ];
Chris@17 113 $this->assertEqual($expected, $change_list);
Chris@17 114 }
Chris@17 115
Chris@17 116 /**
Chris@17 117 * Installer step: Select installation profile.
Chris@17 118 */
Chris@17 119 protected function setUpProfile() {
Chris@17 120 if ($this->existingSyncDirectory) {
Chris@17 121 $edit = [
Chris@17 122 'profile' => SelectProfileForm::CONFIG_INSTALL_PROFILE_KEY,
Chris@17 123 ];
Chris@17 124 $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
Chris@17 125 }
Chris@17 126 else {
Chris@17 127 parent::setUpProfile();
Chris@17 128 }
Chris@17 129 }
Chris@17 130
Chris@17 131 }