Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / BrowserTestBaseTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests;
4
5 use Behat\Mink\Exception\ExpectationException;
6 use Drupal\Component\Serialization\Json;
7 use Drupal\Component\Utility\Html;
8 use Drupal\Core\Url;
9 use Drupal\Tests\BrowserTestBase;
10 use Drupal\Tests\Traits\Core\CronRunTrait;
11
12 /**
13  * Tests BrowserTestBase functionality.
14  *
15  * @group browsertestbase
16  */
17 class BrowserTestBaseTest extends BrowserTestBase {
18
19   use CronRunTrait;
20
21   /**
22    * Modules to enable.
23    *
24    * @var array
25    */
26   public static $modules = ['test_page_test', 'form_test', 'system_test', 'node'];
27
28   /**
29    * Tests basic page test.
30    */
31   public function testGoTo() {
32     $account = $this->drupalCreateUser();
33     $this->drupalLogin($account);
34
35     // Visit a Drupal page that requires login.
36     $this->drupalGet('test-page');
37     $this->assertSession()->statusCodeEquals(200);
38
39     // Test page contains some text.
40     $this->assertSession()->pageTextContains('Test page text.');
41
42     // Check that returned plain text is correct.
43     $text = $this->getTextContent();
44     $this->assertContains('Test page text.', $text);
45     $this->assertNotContains('</html>', $text);
46
47     // Response includes cache tags that we can assert.
48     $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response rendered');
49
50     // Test that we can read the JS settings.
51     $js_settings = $this->getDrupalSettings();
52     $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
53
54     // Test drupalGet with a url object.
55     $url = Url::fromRoute('test_page_test.render_title');
56     $this->drupalGet($url);
57     $this->assertSession()->statusCodeEquals(200);
58
59     // Test page contains some text.
60     $this->assertSession()->pageTextContains('Hello Drupal');
61
62     // Test that setting headers with drupalGet() works.
63     $this->drupalGet('system-test/header', [], [
64       'Test-Header' => 'header value',
65     ]);
66     $returned_header = $this->getSession()->getResponseHeader('Test-Header');
67     $this->assertSame('header value', $returned_header);
68   }
69
70   /**
71    * Tests drupalGet().
72    */
73   public function testDrupalGet() {
74     $this->drupalGet('test-page');
75     $this->assertSession()->statusCodeEquals(200);
76     $this->assertSession()->addressEquals('test-page');
77     $this->drupalGet('/test-page');
78     $this->assertSession()->statusCodeEquals(200);
79     $this->assertSession()->addressEquals('test-page');
80     $this->drupalGet('/test-page/');
81     $this->assertSession()->statusCodeEquals(200);
82     $this->assertSession()->addressEquals('/test-page/');
83   }
84
85   /**
86    * Tests basic form functionality.
87    */
88   public function testForm() {
89     // Ensure the proper response code for a _form route.
90     $this->drupalGet('form-test/object-builder');
91     $this->assertSession()->statusCodeEquals(200);
92
93     // Ensure the form and text field exist.
94     $this->assertSession()->elementExists('css', 'form#form-test-form-test-object');
95     $this->assertSession()->fieldExists('bananas');
96
97     // Check that the hidden field exists and has a specific value.
98     $this->assertSession()->hiddenFieldExists('strawberry');
99     $this->assertSession()->hiddenFieldExists('red');
100     $this->assertSession()->hiddenFieldExists('redstrawberryhiddenfield');
101     $this->assertSession()->hiddenFieldValueNotEquals('strawberry', 'brown');
102     $this->assertSession()->hiddenFieldValueEquals('strawberry', 'red');
103
104     // Check that a hidden field does not exist.
105     $this->assertSession()->hiddenFieldNotExists('bananas');
106     $this->assertSession()->hiddenFieldNotExists('pineapple');
107
108     $edit = ['bananas' => 'green'];
109     $this->submitForm($edit, 'Save', 'form-test-form-test-object');
110
111     $config_factory = $this->container->get('config.factory');
112     $value = $config_factory->get('form_test.object')->get('bananas');
113     $this->assertSame('green', $value);
114
115     // Test drupalPostForm().
116     $edit = ['bananas' => 'red'];
117     $result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save');
118     $this->assertSame($this->getSession()->getPage()->getContent(), $result);
119     $value = $config_factory->get('form_test.object')->get('bananas');
120     $this->assertSame('red', $value);
121
122     $this->drupalPostForm('form-test/object-builder', NULL, 'Save');
123     $value = $config_factory->get('form_test.object')->get('bananas');
124     $this->assertSame('', $value);
125
126     // Test drupalPostForm() with no-html response.
127     $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
128     $this->assertTrue(1000, $values['beer']);
129
130     // Test drupalPostForm() with form by HTML id.
131     $this->drupalCreateContentType(['type' => 'page']);
132     $this->drupalLogin($this->drupalCreateUser(['create page content']));
133     $this->drupalGet('form-test/two-instances-of-same-form');
134     $this->getSession()->getPage()->fillField('edit-title-0-value', 'form1');
135     $this->getSession()->getPage()->fillField('edit-title-0-value--2', 'form2');
136     $this->drupalPostForm(NULL, [], 'Save', [], 'node-page-form--2');
137     $this->assertSession()->pageTextContains('Page form2 has been created.');
138   }
139
140   /**
141    * Tests clickLink() functionality.
142    */
143   public function testClickLink() {
144     $this->drupalGet('test-page');
145     $this->clickLink('Visually identical test links');
146     $this->assertContains('user/login', $this->getSession()->getCurrentUrl());
147     $this->drupalGet('test-page');
148     $this->clickLink('Visually identical test links', 0);
149     $this->assertContains('user/login', $this->getSession()->getCurrentUrl());
150     $this->drupalGet('test-page');
151     $this->clickLink('Visually identical test links', 1);
152     $this->assertContains('user/register', $this->getSession()->getCurrentUrl());
153   }
154
155   public function testError() {
156     $this->setExpectedException('\Exception', 'User notice: foo');
157     $this->drupalGet('test-error');
158   }
159
160   /**
161    * Tests linkExists() with pipe character (|) in locator.
162    *
163    * @see \Drupal\Tests\WebAssert::linkExists()
164    */
165   public function testPipeCharInLocator() {
166     $this->drupalGet('test-pipe-char');
167     $this->assertSession()->linkExists('foo|bar|baz');
168   }
169
170   /**
171    * Tests linkExistsExact() functionality.
172    *
173    * @see \Drupal\Tests\WebAssert::linkExistsExact()
174    */
175   public function testLinkExistsExact() {
176     $this->drupalGet('test-pipe-char');
177     $this->assertSession()->linkExistsExact('foo|bar|baz');
178   }
179
180   /**
181    * Tests linkExistsExact() functionality fail.
182    *
183    * @see \Drupal\Tests\WebAssert::linkExistsExact()
184    */
185   public function testInvalidLinkExistsExact() {
186     $this->drupalGet('test-pipe-char');
187     $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found');
188     $this->assertSession()->linkExistsExact('foo|bar');
189   }
190
191   /**
192    * Tests linkNotExistsExact() functionality.
193    *
194    * @see \Drupal\Tests\WebAssert::linkNotExistsExact()
195    */
196   public function testLinkNotExistsExact() {
197     $this->drupalGet('test-pipe-char');
198     $this->assertSession()->linkNotExistsExact('foo|bar');
199   }
200
201   /**
202    * Tests linkNotExistsExact() functionality fail.
203    *
204    * @see \Drupal\Tests\WebAssert::linkNotExistsExact()
205    */
206   public function testInvalidLinkNotExistsExact() {
207     $this->drupalGet('test-pipe-char');
208     $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found');
209     $this->assertSession()->linkNotExistsExact('foo|bar|baz');
210   }
211
212   /**
213    * Tests legacy text asserts.
214    */
215   public function testTextAsserts() {
216     $this->drupalGet('test-encoded');
217     $dangerous = 'Bad html <script>alert(123);</script>';
218     $sanitized = Html::escape($dangerous);
219     $this->assertNoText($dangerous);
220     $this->assertText($sanitized);
221
222     // Test getRawContent().
223     $this->assertSame($this->getSession()->getPage()->getContent(), $this->getSession()->getPage()->getContent());
224   }
225
226   /**
227    * Tests legacy field asserts which use xpath directly.
228    */
229   public function testXpathAsserts() {
230     $this->drupalGet('test-field-xpath');
231     $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
232     $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
233     $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one');
234
235     $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name');
236     $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name');
237     $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2');
238     $this->assertFieldByXPath("//select[@id = 'edit-options']", '2');
239
240     $this->assertNoFieldByXPath('//notexisting');
241     $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
242
243     // Test that the assertion fails correctly.
244     try {
245       $this->assertFieldByXPath("//input[@id = 'notexisting']");
246       $this->fail('The "notexisting" field was found.');
247     }
248     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
249       $this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.');
250     }
251
252     try {
253       $this->assertNoFieldByXPath("//input[@id = 'edit-name']");
254       $this->fail('The "edit-name" field was not found.');
255     }
256     catch (ExpectationException $e) {
257       $this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.');
258     }
259
260     try {
261       $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value');
262       $this->fail('The "edit-name" field is found with the value "not the value".');
263     }
264     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
265       $this->pass('The "edit-name" field is not found with the value "not the value".');
266     }
267   }
268
269   /**
270    * Tests legacy field asserts using textfields.
271    */
272   public function testFieldAssertsForTextfields() {
273     $this->drupalGet('test-field-xpath');
274
275     // *** 1. assertNoField().
276     $this->assertNoField('invalid_name_and_id');
277
278     // Test that the assertion fails correctly when searching by name.
279     try {
280       $this->assertNoField('name');
281       $this->fail('The "name" field was not found based on name.');
282     }
283     catch (ExpectationException $e) {
284       $this->pass('assertNoField correctly failed. The "name" field was found by name.');
285     }
286
287     // Test that the assertion fails correctly when searching by id.
288     try {
289       $this->assertNoField('edit-name');
290       $this->fail('The "name" field was not found based on id.');
291     }
292     catch (ExpectationException $e) {
293       $this->pass('assertNoField correctly failed. The "name" field was found by id.');
294     }
295
296     // *** 2. assertField().
297     $this->assertField('name');
298     $this->assertField('edit-name');
299
300     // Test that the assertion fails correctly if the field does not exist.
301     try {
302       $this->assertField('invalid_name_and_id');
303       $this->fail('The "invalid_name_and_id" field was found.');
304     }
305     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
306       $this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
307     }
308
309     // *** 3. assertNoFieldById().
310     $this->assertNoFieldById('name');
311     $this->assertNoFieldById('name', 'not the value');
312     $this->assertNoFieldById('notexisting');
313     $this->assertNoFieldById('notexisting', NULL);
314
315     // Test that the assertion fails correctly if no value is passed in.
316     try {
317       $this->assertNoFieldById('edit-description');
318       $this->fail('The "description" field, with no value was not found.');
319     }
320     catch (ExpectationException $e) {
321       $this->pass('The "description" field, with no value was found.');
322     }
323
324     // Test that the assertion fails correctly if a NULL value is passed in.
325     try {
326       $this->assertNoFieldById('edit-name', NULL);
327       $this->fail('The "name" field was not found.');
328     }
329     catch (ExpectationException $e) {
330       $this->pass('The "name" field was found.');
331     }
332
333     // *** 4. assertFieldById().
334     $this->assertFieldById('edit-name', NULL);
335     $this->assertFieldById('edit-name', 'Test name');
336     $this->assertFieldById('edit-description', NULL);
337     $this->assertFieldById('edit-description');
338
339     // Test that the assertion fails correctly if no value is passed in.
340     try {
341       $this->assertFieldById('edit-name');
342       $this->fail('The "edit-name" field with no value was found.');
343     }
344     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
345       $this->pass('The "edit-name" field with no value was not found.');
346     }
347
348     // Test that the assertion fails correctly if the wrong value is passed in.
349     try {
350       $this->assertFieldById('edit-name', 'not the value');
351       $this->fail('The "name" field was found, using the wrong value.');
352     }
353     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
354       $this->pass('The "name" field was not found, using the wrong value.');
355     }
356
357     // *** 5. assertNoFieldByName().
358     $this->assertNoFieldByName('name');
359     $this->assertNoFieldByName('name', 'not the value');
360     $this->assertNoFieldByName('notexisting');
361     $this->assertNoFieldByName('notexisting', NULL);
362
363     // Test that the assertion fails correctly if no value is passed in.
364     try {
365       $this->assertNoFieldByName('description');
366       $this->fail('The "description" field, with no value was not found.');
367     }
368     catch (ExpectationException $e) {
369       $this->pass('The "description" field, with no value was found.');
370     }
371
372     // Test that the assertion fails correctly if a NULL value is passed in.
373     try {
374       $this->assertNoFieldByName('name', NULL);
375       $this->fail('The "name" field was not found.');
376     }
377     catch (ExpectationException $e) {
378       $this->pass('The "name" field was found.');
379     }
380
381     // *** 6. assertFieldByName().
382     $this->assertFieldByName('name');
383     $this->assertFieldByName('name', NULL);
384     $this->assertFieldByName('name', 'Test name');
385     $this->assertFieldByName('description');
386     $this->assertFieldByName('description', '');
387     $this->assertFieldByName('description', NULL);
388
389     // Test that the assertion fails correctly if given the wrong name.
390     try {
391       $this->assertFieldByName('non-existing-name');
392       $this->fail('The "non-existing-name" field was found.');
393     }
394     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
395       $this->pass('The "non-existing-name" field was not found');
396     }
397
398     // Test that the assertion fails correctly if given the wrong value.
399     try {
400       $this->assertFieldByName('name', 'not the value');
401       $this->fail('The "name" field with incorrect value was found.');
402     }
403     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
404       $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
405     }
406
407     // Test that text areas can contain new lines.
408     $this->assertFieldsByValue($this->xpath("//textarea[@id = 'edit-test-textarea-with-newline']"), "Test text with\nnewline");
409   }
410
411   /**
412    * Tests legacy field asserts for options field type.
413    */
414   public function testFieldAssertsForOptions() {
415     $this->drupalGet('test-field-xpath');
416
417     // Option field type.
418     $this->assertOptionByText('options', 'one');
419     try {
420       $this->assertOptionByText('options', 'four');
421       $this->fail('The select option "four" was found.');
422     }
423     catch (ExpectationException $e) {
424       $this->pass($e->getMessage());
425     }
426
427     $this->assertOption('options', 1);
428     try {
429       $this->assertOption('options', 4);
430       $this->fail('The select option "4" was found.');
431     }
432     catch (ExpectationException $e) {
433       $this->pass($e->getMessage());
434     }
435
436     $this->assertNoOption('options', 'non-existing');
437     try {
438       $this->assertNoOption('options', 'one');
439       $this->fail('The select option "one" was not found.');
440     }
441     catch (ExpectationException $e) {
442       $this->pass($e->getMessage());
443     }
444
445     $this->assertOptionSelected('options', 2);
446     try {
447       $this->assertOptionSelected('options', 4);
448       $this->fail('The select option "4" was selected.');
449     }
450     catch (ExpectationException $e) {
451       $this->pass($e->getMessage());
452     }
453
454     try {
455       $this->assertOptionSelected('options', 1);
456       $this->fail('The select option "1" was selected.');
457     }
458     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
459       $this->pass($e->getMessage());
460     }
461
462     // Test \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions.
463     $this->drupalGet('/form-test/select');
464     $this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0]));
465   }
466
467   /**
468    * Tests legacy field asserts for button field type.
469    */
470   public function testFieldAssertsForButton() {
471     $this->drupalGet('test-field-xpath');
472
473     $this->assertFieldById('edit-save', NULL);
474     // Test that the assertion fails correctly if the field value is passed in
475     // rather than the id.
476     try {
477       $this->assertFieldById('Save', NULL);
478       $this->fail('The field with id of "Save" was found.');
479     }
480     catch (\PHPUnit_Framework_ExpectationFailedException $e) {
481       $this->pass($e->getMessage());
482     }
483
484     $this->assertNoFieldById('Save', NULL);
485     // Test that the assertion fails correctly if the id of an actual field is
486     // passed in.
487     try {
488       $this->assertNoFieldById('edit-save', NULL);
489       $this->fail('The field with id of "edit-save" was not found.');
490     }
491     catch (ExpectationException $e) {
492       $this->pass($e->getMessage());
493     }
494
495     // Test that multiple fields with the same name are validated correctly.
496     $this->assertFieldByName('duplicate_button', 'Duplicate button 1');
497     $this->assertFieldByName('duplicate_button', 'Duplicate button 2');
498     $this->assertNoFieldByName('duplicate_button', 'Rabbit');
499
500     try {
501       $this->assertNoFieldByName('duplicate_button', 'Duplicate button 2');
502       $this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.');
503     }
504     catch (ExpectationException $e) {
505       $this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.');
506     }
507   }
508
509   /**
510    * Tests legacy field asserts for checkbox field type.
511    */
512   public function testFieldAssertsForCheckbox() {
513     $this->drupalGet('test-field-xpath');
514
515     // Part 1 - Test by name.
516     // Test that checkboxes are found/not found correctly by name, when using
517     // TRUE or FALSE to match their 'checked' state.
518     $this->assertFieldByName('checkbox_enabled', TRUE);
519     $this->assertFieldByName('checkbox_disabled', FALSE);
520     $this->assertNoFieldByName('checkbox_enabled', FALSE);
521     $this->assertNoFieldByName('checkbox_disabled', TRUE);
522
523     // Test that checkboxes are found by name when using NULL to ignore the
524     // 'checked' state.
525     $this->assertFieldByName('checkbox_enabled', NULL);
526     $this->assertFieldByName('checkbox_disabled', NULL);
527
528     // Test that checkboxes are found by name when passing no second parameter.
529     $this->assertFieldByName('checkbox_enabled');
530     $this->assertFieldByName('checkbox_disabled');
531
532     // Test that we have legacy support.
533     $this->assertFieldByName('checkbox_enabled', '1');
534     $this->assertFieldByName('checkbox_disabled', '');
535
536     // Test that the assertion fails correctly when using NULL to ignore state.
537     try {
538       $this->assertNoFieldByName('checkbox_enabled', NULL);
539       $this->fail('The "checkbox_enabled" field was not found by name, using NULL value.');
540     }
541     catch (ExpectationException $e) {
542       $this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.');
543     }
544
545     // Part 2 - Test by ID.
546     // Test that checkboxes are found/not found correctly by ID, when using
547     // TRUE or FALSE to match their 'checked' state.
548     $this->assertFieldById('edit-checkbox-enabled', TRUE);
549     $this->assertFieldById('edit-checkbox-disabled', FALSE);
550     $this->assertNoFieldById('edit-checkbox-enabled', FALSE);
551     $this->assertNoFieldById('edit-checkbox-disabled', TRUE);
552
553     // Test that checkboxes are found by ID, when using NULL to ignore the
554     // 'checked' state.
555     $this->assertFieldById('edit-checkbox-enabled', NULL);
556     $this->assertFieldById('edit-checkbox-disabled', NULL);
557
558     // Test that checkboxes are found by ID when passing no second parameter.
559     $this->assertFieldById('edit-checkbox-enabled');
560     $this->assertFieldById('edit-checkbox-disabled');
561
562     // Test that we have legacy support.
563     $this->assertFieldById('edit-checkbox-enabled', '1');
564     $this->assertFieldById('edit-checkbox-disabled', '');
565
566     // Test that the assertion fails correctly when using NULL to ignore state.
567     try {
568       $this->assertNoFieldById('edit-checkbox-disabled', NULL);
569       $this->fail('The "edit-checkbox-disabled" field was not found by ID, using NULL value.');
570     }
571     catch (ExpectationException $e) {
572       $this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.');
573     }
574
575     // Part 3 - Test the specific 'checked' assertions.
576     $this->assertFieldChecked('edit-checkbox-enabled');
577     $this->assertNoFieldChecked('edit-checkbox-disabled');
578
579     // Test that the assertion fails correctly with non-existent field id.
580     try {
581       $this->assertNoFieldChecked('incorrect_checkbox_id');
582       $this->fail('The "incorrect_checkbox_id" field was found');
583     }
584     catch (ExpectationException $e) {
585       $this->pass('assertNoFieldChecked correctly failed. The "incorrect_checkbox_id" field was not found.');
586     }
587
588     // Test that the assertion fails correctly for a checkbox that is checked.
589     try {
590       $this->assertNoFieldChecked('edit-checkbox-enabled');
591       $this->fail('The "edit-checkbox-enabled" field was not found in a checked state.');
592     }
593     catch (ExpectationException $e) {
594       $this->pass('assertNoFieldChecked correctly failed. The "edit-checkbox-enabled" field was found in a checked state.');
595     }
596
597     // Test that the assertion fails correctly for a checkbox that is not
598     // checked.
599     try {
600       $this->assertFieldChecked('edit-checkbox-disabled');
601       $this->fail('The "edit-checkbox-disabled" field was found and checked.');
602     }
603     catch (ExpectationException $e) {
604       $this->pass('assertFieldChecked correctly failed. The "edit-checkbox-disabled" field was not found in a checked state.');
605     }
606   }
607
608   /**
609    * Tests the ::cronRun() method.
610    */
611   public function testCronRun() {
612     $last_cron_time = \Drupal::state()->get('system.cron_last');
613     $this->cronRun();
614     $this->assertSession()->statusCodeEquals(204);
615     $next_cron_time = \Drupal::state()->get('system.cron_last');
616
617     $this->assertGreaterThan($last_cron_time, $next_cron_time);
618   }
619
620   /**
621    * Tests the Drupal install done in \Drupal\Tests\BrowserTestBase::setUp().
622    */
623   public function testInstall() {
624     $htaccess_filename = $this->tempFilesDirectory . '/.htaccess';
625     $this->assertTrue(file_exists($htaccess_filename), "$htaccess_filename exists");
626   }
627
628   /**
629    * Tests the assumption that local time is in 'Australia/Sydney'.
630    */
631   public function testLocalTimeZone() {
632     // The 'Australia/Sydney' time zone is set in core/tests/bootstrap.php
633     $this->assertEquals('Australia/Sydney', date_default_timezone_get());
634
635     // The 'Australia/Sydney' time zone is also set in
636     // FunctionalTestSetupTrait::initConfig().
637     $config_factory = $this->container->get('config.factory');
638     $value = $config_factory->get('system.date')->get('timezone.default');
639     $this->assertEquals('Australia/Sydney', $value);
640   }
641
642   /**
643    * Tests the ::checkForMetaRefresh() method.
644    */
645   public function testCheckForMetaRefresh() {
646     // Disable following redirects in the client.
647     $this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
648     // Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't
649     // happen when doing a drupalGet.
650     $this->maximumMetaRefreshCount = 0;
651     $this->drupalGet('test-meta-refresh');
652     $this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]'));
653     // Allow one redirect to happen.
654     $this->maximumMetaRefreshCount = 1;
655     $this->checkForMetaRefresh();
656     // Check that we are now on the test page.
657     $this->assertSession()->pageTextContains('Test page text.');
658   }
659
660   public function testGetDefaultDriveInstance() {
661     putenv('MINK_DRIVER_ARGS=' . json_encode([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]]));
662     $this->getDefaultDriverInstance();
663     $this->assertEquals([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]], $this->minkDefaultDriverArgs);
664   }
665
666   /**
667    * Ensures we can't access modules we shouldn't be able to after install.
668    */
669   public function testProfileModules() {
670     $this->setExpectedException(\InvalidArgumentException::class, 'The module demo_umami_content does not exist.');
671     $this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml');
672     \Drupal::service('extension.list.module')->getPathname('demo_umami_content');
673   }
674
675 }