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