ConfigInstallerTestBase.php in Configuration installer 8
File
tests/src/Functional/ConfigInstallerTestBase.php
View source
<?php
namespace Drupal\Tests\config_installer\Functional;
use Drupal\config\Controller\ConfigController;
use Drupal\Core\Archiver\ArchiveTar;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Site\Settings;
use Drupal\FunctionalTests\Installer\InstallerTestBase;
use Symfony\Component\HttpFoundation\Request;
abstract class ConfigInstallerTestBase extends InstallerTestBase {
protected $profile = 'config_installer';
protected function setUp() {
parent::setUp();
if ($this->isInstalled) {
$this
->rebuildAll();
$sync = \Drupal::service('config.storage.sync');
$sync_core_extension = $sync
->read('core.extension');
if (version_compare(\Drupal::VERSION, '8.3', '>=')) {
$this
->assertEqual($sync_core_extension['profile'], \Drupal::installProfile());
}
else {
$listing = new ExtensionDiscovery(\Drupal::root());
$listing
->setProfileDirectories([]);
$profiles = array_intersect_key($listing
->scan('profile'), $sync_core_extension['module']);
$current_profile = Settings::get('install_profile');
$this
->assertFalse(empty($current_profile), 'The $install_profile setting exists');
$this
->assertEqual($current_profile, key($profiles));
}
$this
->assertNoSynDifferences();
}
}
public function testInstaller() {
$this
->assertUrl('user/1');
$this
->assertResponse(200);
$this
->assertText($this->rootUser
->getUsername());
require_once \Drupal::root() . '/core/includes/install.inc';
$this
->assertRaw(t('Congratulations, you installed @drupal!', [
'@drupal' => drupal_install_profile_distribution_name(),
]));
}
protected function setUpSite() {
$request = Request::createFromGlobals();
$class_loader = (require $this->container
->get('app.root') . '/autoload.php');
Settings::initialize($this->container
->get('app.root'), DrupalKernel::findSitePath($request), $class_loader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel
->prepareLegacyRequest($request);
$this->container = $this->kernel
->getContainer();
$this
->setUpSyncForm();
$this
->setUpInstallConfigureForm();
$this->isInstalled = TRUE;
}
protected abstract function setUpSyncForm();
protected function setUpInstallConfigureForm() {
$params = $this->parameters['forms']['install_configure_form'];
unset($params['site_name']);
unset($params['site_mail']);
unset($params['update_status_module']);
$edit = $this
->translatePostValues($params);
$this
->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
}
protected function getTarball() {
return $this
->versionTarball('minimal.tar.gz');
}
protected function versionTarball($tarball) {
include_once \Drupal::root() . '/core/includes/install.core.inc';
$version = _install_get_version_info(\Drupal::VERSION);
$versioned_file = dirname(dirname(__DIR__)) . '/Fixtures/' . $version['major'] . '.' . $version['minor'] . '/' . $tarball;
if (file_exists($versioned_file)) {
return $versioned_file;
}
return dirname(dirname(__DIR__)) . '/Fixtures/' . $tarball;
}
protected function extractTarball($tarball_path, $directory) {
$archiver = new ArchiveTar($tarball_path, 'gz');
$files = [];
$list = $archiver
->listContent();
if (is_array($list)) {
foreach ($list as $file) {
$files[] = $file['filename'];
}
}
$archiver
->extractList($files, $directory);
return $files;
}
protected function assertNoSynDifferences() {
$sync = $this->container
->get('config.storage.sync');
$active = $this->container
->get('config.storage');
$storage_comparer = new StorageComparer($sync, $active, $this->container
->get('config.manager'));
$changelist = $storage_comparer
->createChangelist()
->getChangelist();
$key = array_search('system.mail', $changelist['update'], TRUE);
if ($key !== FALSE) {
unset($changelist['update'][$key]);
}
$return = $this
->assertIdentical($changelist, $storage_comparer
->getEmptyChangelist());
$controller = ConfigController::create($this->container);
foreach ($changelist['update'] as $config_name) {
$diff = $controller
->diff($config_name);
$this
->verbose(\Drupal::service('renderer')
->renderPlain($diff));
}
return $return;
}
}