View source
<?php
namespace Drupal\Tests\thunder\Functional\Installer;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\UserSession;
use Drupal\Core\Site\Settings;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware;
use Drupal\FunctionalTests\Installer\InstallerTestBase;
use GuzzleHttp\HandlerStack;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class ThunderInstallerTest extends InstallerTestBase {
protected $knownWarnings = 0;
protected function setUp() {
parent::setUpAppRoot();
$this->isInstalled = FALSE;
$this
->setupBaseUrl();
$this
->prepareDatabasePrefix();
$this
->prepareEnvironment();
$this->rootUser = new UserSession([
'uid' => 1,
'name' => 'admin',
'mail' => 'admin@example.com',
'pass_raw' => $this
->randomMachineName(),
]);
if (!empty($this->settings)) {
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
$this
->writeSettings($this->settings);
}
$this->parameters = $this
->installParameters();
$global_request = Request::createFromGlobals();
$request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $global_request->cookies
->all(), [], $global_request->server
->all());
$this->container = new ContainerBuilder();
$request_stack = new RequestStack();
$request_stack
->push($request);
$this->container
->set('request_stack', $request_stack);
$this->container
->setParameter('language.default_values', Language::$defaultValues);
$this->container
->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')
->addArgument('%language.default_values%');
$this->container
->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')
->addArgument(new Reference('language.default'));
$this->container
->register('http_client', 'GuzzleHttp\\Client')
->setFactory('http_client_factory:fromOptions');
$this->container
->register('http_client_factory', 'Drupal\\Core\\Http\\ClientFactory')
->setArguments([
new Reference('http_handler_stack'),
]);
$handler_stack = HandlerStack::create();
$test_http_client_middleware = new TestHttpClientMiddleware();
$handler_stack
->push($test_http_client_middleware(), 'test.http_client.middleware');
$this->container
->set('http_handler_stack', $handler_stack);
$this->container
->set('app.root', DRUPAL_ROOT);
\Drupal::setContainer($this->container);
$this
->initMink();
$this
->initBrowserOutputFile();
$this
->visitInstaller();
$this
->setUpLanguage();
$this
->setUpProfile();
$this
->setUpRequirementsProblem();
$this
->setUpSettings();
$this
->setUpSite();
$this
->setUpModules();
if ($this->isInstalled) {
$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);
chmod($this->container
->get('app.root') . '/' . $this->siteDirectory, 0777);
$this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
$this->kernel
->boot();
$this->kernel
->preHandle($request);
$this->container = $this->kernel
->getContainer();
$this->container
->get('config.factory')
->getEditable('system.mail')
->set('interface.default', 'test_mail_collector')
->save();
$this
->installDefaultThemeFromClassProperty($this->container);
}
}
protected function setUpLanguage() {
$this
->assertSession()
->responseContains('thunder');
$this
->assertSession()
->pageTextNotContains('Choose profile');
parent::setUpLanguage();
}
protected function setUpProfile() {
}
protected function setUpSite() {
$edit = $this
->translatePostValues($this->parameters['forms']['install_configure_form']);
$edit['enable_update_status_module'] = NULL;
$edit['enable_update_status_emails'] = NULL;
$this
->submitForm($edit, $this->translations['Save and continue']);
}
protected function setUpModules() {
$this
->submitForm([], $this->translations['Save and continue']);
$this->isInstalled = TRUE;
}
public function testInstalled() {
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->rootUser
->getAccountName());
$message = strip_tags(new TranslatableMarkup('Congratulations, you installed @drupal!', [
'@drupal' => 'Thunder',
], [
'langcode' => $this->langcode,
]));
$this
->assertSession()
->pageTextContains($message);
$query = \Drupal::database()
->select('watchdog', 'w')
->condition('severity', 4, '<');
$this
->assertEquals($this->knownWarnings, $query
->countQuery()
->execute()
->fetchField());
}
}