SelectProfileFormTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests\Core\Installer\Form;
  3. use Drupal\Core\DependencyInjection\ContainerBuilder;
  4. use Drupal\Core\Language\Language;
  5. use Drupal\Core\Session\UserSession;
  6. use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware;
  7. use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
  8. use GuzzleHttp\HandlerStack;
  9. use Symfony\Component\DependencyInjection\Reference;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. /**
  13. * Tests the select profile form.
  14. *
  15. * @group Installer
  16. */
  17. class SelectProfileFormTest extends JavascriptTestBase {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function setUp() {
  22. $this->setupBaseUrl();
  23. $this->prepareDatabasePrefix();
  24. // Install Drupal test site.
  25. $this->prepareEnvironment();
  26. // Define information about the user 1 account.
  27. $this->rootUser = new UserSession([
  28. 'uid' => 1,
  29. 'name' => 'admin',
  30. 'mail' => 'admin@example.com',
  31. 'pass_raw' => $this->randomMachineName(),
  32. ]);
  33. // If any $settings are defined for this test, copy and prepare an actual
  34. // settings.php, so as to resemble a regular installation.
  35. if (!empty($this->settings)) {
  36. // Not using File API; a potential error must trigger a PHP warning.
  37. copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
  38. $this->writeSettings($this->settings);
  39. }
  40. // Note that FunctionalTestSetupTrait::installParameters() returns form
  41. // input values suitable for a programmed
  42. // \Drupal::formBuilder()->submitForm().
  43. // @see InstallerTestBase::translatePostValues()
  44. $this->parameters = $this->installParameters();
  45. // Set up a minimal container (required by BrowserTestBase). Set cookie and
  46. // server information so that XDebug works.
  47. // @see install_begin_request()
  48. $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $_COOKIE, [], $_SERVER);
  49. $this->container = new ContainerBuilder();
  50. $request_stack = new RequestStack();
  51. $request_stack->push($request);
  52. $this->container
  53. ->set('request_stack', $request_stack);
  54. $this->container
  55. ->setParameter('language.default_values', Language::$defaultValues);
  56. $this->container
  57. ->register('language.default', 'Drupal\Core\Language\LanguageDefault')
  58. ->addArgument('%language.default_values%');
  59. $this->container
  60. ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
  61. ->addArgument(new Reference('language.default'));
  62. $this->container
  63. ->register('http_client', 'GuzzleHttp\Client')
  64. ->setFactory('http_client_factory:fromOptions');
  65. $this->container
  66. ->register('http_client_factory', 'Drupal\Core\Http\ClientFactory')
  67. ->setArguments([new Reference('http_handler_stack')]);
  68. $handler_stack = HandlerStack::create();
  69. $test_http_client_middleware = new TestHttpClientMiddleware();
  70. $handler_stack->push($test_http_client_middleware(), 'test.http_client.middleware');
  71. $this->container
  72. ->set('http_handler_stack', $handler_stack);
  73. $this->container
  74. ->set('app.root', DRUPAL_ROOT);
  75. \Drupal::setContainer($this->container);
  76. // Setup Mink.
  77. $this->initMink();
  78. }
  79. /**
  80. * {@inheritdoc}
  81. */
  82. protected function initMink() {
  83. // The temporary files directory doesn't exist yet, as install_base_system()
  84. // has not run. We need to create the template cache directory recursively.
  85. $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache';
  86. if (!file_exists($path)) {
  87. mkdir($path, 0777, TRUE);
  88. }
  89. parent::initMink();
  90. }
  91. /**
  92. * {@inheritdoc}
  93. *
  94. * BrowserTestBase::refreshVariables() tries to operate on persistent storage,
  95. * which is only available after the installer completed.
  96. */
  97. protected function refreshVariables() {
  98. // Intentionally empty as the site is not yet installed.
  99. }
  100. /**
  101. * Tests a warning message is displayed when the Umami profile is selected.
  102. */
  103. public function testUmamiProfileWarningMessage() {
  104. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
  105. $edit = [
  106. 'langcode' => 'en',
  107. ];
  108. $this->drupalPostForm(NULL, $edit, 'Save and continue');
  109. $page = $this->getSession()->getPage();
  110. $warning_message = $page->find('css', '.description .messages--warning');
  111. $this->assertFalse($warning_message->isVisible());
  112. $page->selectFieldOption('profile', 'demo_umami');
  113. $this->assertTrue($warning_message->isVisible());
  114. }
  115. }