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