Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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']; | |
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 basic form functionality. | |
72 */ | |
73 public function testForm() { | |
74 // Ensure the proper response code for a _form route. | |
75 $this->drupalGet('form-test/object-builder'); | |
76 $this->assertSession()->statusCodeEquals(200); | |
77 | |
78 // Ensure the form and text field exist. | |
79 $this->assertSession()->elementExists('css', 'form#form-test-form-test-object'); | |
80 $this->assertSession()->fieldExists('bananas'); | |
81 | |
82 // Check that the hidden field exists and has a specific value. | |
83 $this->assertSession()->hiddenFieldExists('strawberry'); | |
84 $this->assertSession()->hiddenFieldExists('red'); | |
85 $this->assertSession()->hiddenFieldExists('redstrawberryhiddenfield'); | |
86 $this->assertSession()->hiddenFieldValueNotEquals('strawberry', 'brown'); | |
87 $this->assertSession()->hiddenFieldValueEquals('strawberry', 'red'); | |
88 | |
89 // Check that a hidden field does not exist. | |
90 $this->assertSession()->hiddenFieldNotExists('bananas'); | |
91 $this->assertSession()->hiddenFieldNotExists('pineapple'); | |
92 | |
93 $edit = ['bananas' => 'green']; | |
94 $this->submitForm($edit, 'Save', 'form-test-form-test-object'); | |
95 | |
96 $config_factory = $this->container->get('config.factory'); | |
97 $value = $config_factory->get('form_test.object')->get('bananas'); | |
98 $this->assertSame('green', $value); | |
99 | |
100 // Test drupalPostForm(). | |
101 $edit = ['bananas' => 'red']; | |
102 $result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save'); | |
103 $this->assertSame($this->getSession()->getPage()->getContent(), $result); | |
104 $value = $config_factory->get('form_test.object')->get('bananas'); | |
105 $this->assertSame('red', $value); | |
106 | |
107 $this->drupalPostForm('form-test/object-builder', NULL, 'Save'); | |
108 $value = $config_factory->get('form_test.object')->get('bananas'); | |
109 $this->assertSame('', $value); | |
110 | |
111 // Test drupalPostForm() with no-html response. | |
112 $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit'))); | |
113 $this->assertTrue(1000, $values['beer']); | |
114 } | |
115 | |
116 /** | |
117 * Tests clickLink() functionality. | |
118 */ | |
119 public function testClickLink() { | |
120 $this->drupalGet('test-page'); | |
121 $this->clickLink('Visually identical test links'); | |
122 $this->assertContains('user/login', $this->getSession()->getCurrentUrl()); | |
123 $this->drupalGet('test-page'); | |
124 $this->clickLink('Visually identical test links', 0); | |
125 $this->assertContains('user/login', $this->getSession()->getCurrentUrl()); | |
126 $this->drupalGet('test-page'); | |
127 $this->clickLink('Visually identical test links', 1); | |
128 $this->assertContains('user/register', $this->getSession()->getCurrentUrl()); | |
129 } | |
130 | |
131 public function testError() { | |
132 $this->setExpectedException('\Exception', 'User notice: foo'); | |
133 $this->drupalGet('test-error'); | |
134 } | |
135 | |
136 /** | |
137 * Tests linkExists() with pipe character (|) in locator. | |
138 * | |
139 * @see \Drupal\Tests\WebAssert::linkExists() | |
140 */ | |
141 public function testPipeCharInLocator() { | |
142 $this->drupalGet('test-pipe-char'); | |
143 $this->assertSession()->linkExists('foo|bar|baz'); | |
144 } | |
145 | |
146 /** | |
147 * Tests linkExistsExact() functionality. | |
148 * | |
149 * @see \Drupal\Tests\WebAssert::linkExistsExact() | |
150 */ | |
151 public function testLinkExistsExact() { | |
152 $this->drupalGet('test-pipe-char'); | |
153 $this->assertSession()->linkExistsExact('foo|bar|baz'); | |
154 } | |
155 | |
156 /** | |
157 * Tests linkExistsExact() functionality fail. | |
158 * | |
159 * @see \Drupal\Tests\WebAssert::linkExistsExact() | |
160 */ | |
161 public function testInvalidLinkExistsExact() { | |
162 $this->drupalGet('test-pipe-char'); | |
163 $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found'); | |
164 $this->assertSession()->linkExistsExact('foo|bar'); | |
165 } | |
166 | |
167 /** | |
168 * Tests linkNotExistsExact() functionality. | |
169 * | |
170 * @see \Drupal\Tests\WebAssert::linkNotExistsExact() | |
171 */ | |
172 public function testLinkNotExistsExact() { | |
173 $this->drupalGet('test-pipe-char'); | |
174 $this->assertSession()->linkNotExistsExact('foo|bar'); | |
175 } | |
176 | |
177 /** | |
178 * Tests linkNotExistsExact() functionality fail. | |
179 * | |
180 * @see \Drupal\Tests\WebAssert::linkNotExistsExact() | |
181 */ | |
182 public function testInvalidLinkNotExistsExact() { | |
183 $this->drupalGet('test-pipe-char'); | |
184 $this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found'); | |
185 $this->assertSession()->linkNotExistsExact('foo|bar|baz'); | |
186 } | |
187 | |
188 /** | |
189 * Tests legacy text asserts. | |
190 */ | |
191 public function testLegacyTextAsserts() { | |
192 $this->drupalGet('test-encoded'); | |
193 $dangerous = 'Bad html <script>alert(123);</script>'; | |
194 $sanitized = Html::escape($dangerous); | |
195 $this->assertNoText($dangerous); | |
196 $this->assertText($sanitized); | |
197 | |
198 // Test getRawContent(). | |
199 $this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent()); | |
200 } | |
201 | |
202 /** | |
203 * Tests legacy field asserts which use xpath directly. | |
204 */ | |
205 public function testLegacyXpathAsserts() { | |
206 $this->drupalGet('test-field-xpath'); | |
207 $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL); | |
208 $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one'); | |
209 $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one'); | |
210 | |
211 $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name'); | |
212 $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name'); | |
213 $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2'); | |
214 $this->assertFieldByXPath("//select[@id = 'edit-options']", '2'); | |
215 | |
216 $this->assertNoFieldByXPath('//notexisting'); | |
217 $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); | |
218 | |
219 // Test that the assertion fails correctly. | |
220 try { | |
221 $this->assertFieldByXPath("//input[@id = 'notexisting']"); | |
222 $this->fail('The "notexisting" field was found.'); | |
223 } | |
224 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
225 $this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.'); | |
226 } | |
227 | |
228 try { | |
229 $this->assertNoFieldByXPath("//input[@id = 'edit-name']"); | |
230 $this->fail('The "edit-name" field was not found.'); | |
231 } | |
232 catch (ExpectationException $e) { | |
233 $this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.'); | |
234 } | |
235 | |
236 try { | |
237 $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value'); | |
238 $this->fail('The "edit-name" field is found with the value "not the value".'); | |
239 } | |
240 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
241 $this->pass('The "edit-name" field is not found with the value "not the value".'); | |
242 } | |
243 } | |
244 | |
245 /** | |
246 * Tests legacy field asserts using textfields. | |
247 */ | |
248 public function testLegacyFieldAssertsForTextfields() { | |
249 $this->drupalGet('test-field-xpath'); | |
250 | |
251 // *** 1. assertNoField(). | |
252 $this->assertNoField('invalid_name_and_id'); | |
253 | |
254 // Test that the assertion fails correctly when searching by name. | |
255 try { | |
256 $this->assertNoField('name'); | |
257 $this->fail('The "name" field was not found based on name.'); | |
258 } | |
259 catch (ExpectationException $e) { | |
260 $this->pass('assertNoField correctly failed. The "name" field was found by name.'); | |
261 } | |
262 | |
263 // Test that the assertion fails correctly when searching by id. | |
264 try { | |
265 $this->assertNoField('edit-name'); | |
266 $this->fail('The "name" field was not found based on id.'); | |
267 } | |
268 catch (ExpectationException $e) { | |
269 $this->pass('assertNoField correctly failed. The "name" field was found by id.'); | |
270 } | |
271 | |
272 // *** 2. assertField(). | |
273 $this->assertField('name'); | |
274 $this->assertField('edit-name'); | |
275 | |
276 // Test that the assertion fails correctly if the field does not exist. | |
277 try { | |
278 $this->assertField('invalid_name_and_id'); | |
279 $this->fail('The "invalid_name_and_id" field was found.'); | |
280 } | |
281 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
282 $this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.'); | |
283 } | |
284 | |
285 // *** 3. assertNoFieldById(). | |
286 $this->assertNoFieldById('name'); | |
287 $this->assertNoFieldById('name', 'not the value'); | |
288 $this->assertNoFieldById('notexisting'); | |
289 $this->assertNoFieldById('notexisting', NULL); | |
290 | |
291 // Test that the assertion fails correctly if no value is passed in. | |
292 try { | |
293 $this->assertNoFieldById('edit-description'); | |
294 $this->fail('The "description" field, with no value was not found.'); | |
295 } | |
296 catch (ExpectationException $e) { | |
297 $this->pass('The "description" field, with no value was found.'); | |
298 } | |
299 | |
300 // Test that the assertion fails correctly if a NULL value is passed in. | |
301 try { | |
302 $this->assertNoFieldById('edit-name', NULL); | |
303 $this->fail('The "name" field was not found.'); | |
304 } | |
305 catch (ExpectationException $e) { | |
306 $this->pass('The "name" field was found.'); | |
307 } | |
308 | |
309 // *** 4. assertFieldById(). | |
310 $this->assertFieldById('edit-name', NULL); | |
311 $this->assertFieldById('edit-name', 'Test name'); | |
312 $this->assertFieldById('edit-description', NULL); | |
313 $this->assertFieldById('edit-description'); | |
314 | |
315 // Test that the assertion fails correctly if no value is passed in. | |
316 try { | |
317 $this->assertFieldById('edit-name'); | |
318 $this->fail('The "edit-name" field with no value was found.'); | |
319 } | |
320 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
321 $this->pass('The "edit-name" field with no value was not found.'); | |
322 } | |
323 | |
324 // Test that the assertion fails correctly if the wrong value is passed in. | |
325 try { | |
326 $this->assertFieldById('edit-name', 'not the value'); | |
327 $this->fail('The "name" field was found, using the wrong value.'); | |
328 } | |
329 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
330 $this->pass('The "name" field was not found, using the wrong value.'); | |
331 } | |
332 | |
333 // *** 5. assertNoFieldByName(). | |
334 $this->assertNoFieldByName('name'); | |
335 $this->assertNoFieldByName('name', 'not the value'); | |
336 $this->assertNoFieldByName('notexisting'); | |
337 $this->assertNoFieldByName('notexisting', NULL); | |
338 | |
339 // Test that the assertion fails correctly if no value is passed in. | |
340 try { | |
341 $this->assertNoFieldByName('description'); | |
342 $this->fail('The "description" field, with no value was not found.'); | |
343 } | |
344 catch (ExpectationException $e) { | |
345 $this->pass('The "description" field, with no value was found.'); | |
346 } | |
347 | |
348 // Test that the assertion fails correctly if a NULL value is passed in. | |
349 try { | |
350 $this->assertNoFieldByName('name', NULL); | |
351 $this->fail('The "name" field was not found.'); | |
352 } | |
353 catch (ExpectationException $e) { | |
354 $this->pass('The "name" field was found.'); | |
355 } | |
356 | |
357 // *** 6. assertFieldByName(). | |
358 $this->assertFieldByName('name'); | |
359 $this->assertFieldByName('name', NULL); | |
360 $this->assertFieldByName('name', 'Test name'); | |
361 $this->assertFieldByName('description'); | |
362 $this->assertFieldByName('description', ''); | |
363 $this->assertFieldByName('description', NULL); | |
364 | |
365 // Test that the assertion fails correctly if given the wrong name. | |
366 try { | |
367 $this->assertFieldByName('non-existing-name'); | |
368 $this->fail('The "non-existing-name" field was found.'); | |
369 } | |
370 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
371 $this->pass('The "non-existing-name" field was not found'); | |
372 } | |
373 | |
374 // Test that the assertion fails correctly if given the wrong value. | |
375 try { | |
376 $this->assertFieldByName('name', 'not the value'); | |
377 $this->fail('The "name" field with incorrect value was found.'); | |
378 } | |
379 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
380 $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.'); | |
381 } | |
382 | |
383 // Test that text areas can contain new lines. | |
384 $this->assertFieldsByValue($this->xpath("//textarea[@id = 'edit-test-textarea-with-newline']"), "Test text with\nnewline"); | |
385 } | |
386 | |
387 /** | |
388 * Tests legacy field asserts for options field type. | |
389 */ | |
390 public function testLegacyFieldAssertsForOptions() { | |
391 $this->drupalGet('test-field-xpath'); | |
392 | |
393 // Option field type. | |
394 $this->assertOptionByText('options', 'one'); | |
395 try { | |
396 $this->assertOptionByText('options', 'four'); | |
397 $this->fail('The select option "four" was found.'); | |
398 } | |
399 catch (ExpectationException $e) { | |
400 $this->pass($e->getMessage()); | |
401 } | |
402 | |
403 $this->assertOption('options', 1); | |
404 try { | |
405 $this->assertOption('options', 4); | |
406 $this->fail('The select option "4" was found.'); | |
407 } | |
408 catch (ExpectationException $e) { | |
409 $this->pass($e->getMessage()); | |
410 } | |
411 | |
412 $this->assertNoOption('options', 'non-existing'); | |
413 try { | |
414 $this->assertNoOption('options', 'one'); | |
415 $this->fail('The select option "one" was not found.'); | |
416 } | |
417 catch (ExpectationException $e) { | |
418 $this->pass($e->getMessage()); | |
419 } | |
420 | |
421 $this->assertOptionSelected('options', 2); | |
422 try { | |
423 $this->assertOptionSelected('options', 4); | |
424 $this->fail('The select option "4" was selected.'); | |
425 } | |
426 catch (ExpectationException $e) { | |
427 $this->pass($e->getMessage()); | |
428 } | |
429 | |
430 try { | |
431 $this->assertOptionSelected('options', 1); | |
432 $this->fail('The select option "1" was selected.'); | |
433 } | |
434 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
435 $this->pass($e->getMessage()); | |
436 } | |
437 | |
438 // Test \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions. | |
439 $this->drupalGet('/form-test/select'); | |
440 $this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0])); | |
441 } | |
442 | |
443 /** | |
444 * Tests legacy field asserts for button field type. | |
445 */ | |
446 public function testLegacyFieldAssertsForButton() { | |
447 $this->drupalGet('test-field-xpath'); | |
448 | |
449 $this->assertFieldById('edit-save', NULL); | |
450 // Test that the assertion fails correctly if the field value is passed in | |
451 // rather than the id. | |
452 try { | |
453 $this->assertFieldById('Save', NULL); | |
454 $this->fail('The field with id of "Save" was found.'); | |
455 } | |
456 catch (\PHPUnit_Framework_ExpectationFailedException $e) { | |
457 $this->pass($e->getMessage()); | |
458 } | |
459 | |
460 $this->assertNoFieldById('Save', NULL); | |
461 // Test that the assertion fails correctly if the id of an actual field is | |
462 // passed in. | |
463 try { | |
464 $this->assertNoFieldById('edit-save', NULL); | |
465 $this->fail('The field with id of "edit-save" was not found.'); | |
466 } | |
467 catch (ExpectationException $e) { | |
468 $this->pass($e->getMessage()); | |
469 } | |
470 | |
471 // Test that multiple fields with the same name are validated correctly. | |
472 $this->assertFieldByName('duplicate_button', 'Duplicate button 1'); | |
473 $this->assertFieldByName('duplicate_button', 'Duplicate button 2'); | |
474 $this->assertNoFieldByName('duplicate_button', 'Rabbit'); | |
475 | |
476 try { | |
477 $this->assertNoFieldByName('duplicate_button', 'Duplicate button 2'); | |
478 $this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.'); | |
479 } | |
480 catch (ExpectationException $e) { | |
481 $this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.'); | |
482 } | |
483 } | |
484 | |
485 /** | |
486 * Tests legacy field asserts for checkbox field type. | |
487 */ | |
488 public function testLegacyFieldAssertsForCheckbox() { | |
489 $this->drupalGet('test-field-xpath'); | |
490 | |
491 // Part 1 - Test by name. | |
492 // Test that checkboxes are found/not found correctly by name, when using | |
493 // TRUE or FALSE to match their 'checked' state. | |
494 $this->assertFieldByName('checkbox_enabled', TRUE); | |
495 $this->assertFieldByName('checkbox_disabled', FALSE); | |
496 $this->assertNoFieldByName('checkbox_enabled', FALSE); | |
497 $this->assertNoFieldByName('checkbox_disabled', TRUE); | |
498 | |
499 // Test that checkboxes are found by name when using NULL to ignore the | |
500 // 'checked' state. | |
501 $this->assertFieldByName('checkbox_enabled', NULL); | |
502 $this->assertFieldByName('checkbox_disabled', NULL); | |
503 | |
504 // Test that checkboxes are found by name when passing no second parameter. | |
505 $this->assertFieldByName('checkbox_enabled'); | |
506 $this->assertFieldByName('checkbox_disabled'); | |
507 | |
508 // Test that we have legacy support. | |
509 $this->assertFieldByName('checkbox_enabled', '1'); | |
510 $this->assertFieldByName('checkbox_disabled', ''); | |
511 | |
512 // Test that the assertion fails correctly when using NULL to ignore state. | |
513 try { | |
514 $this->assertNoFieldByName('checkbox_enabled', NULL); | |
515 $this->fail('The "checkbox_enabled" field was not found by name, using NULL value.'); | |
516 } | |
517 catch (ExpectationException $e) { | |
518 $this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.'); | |
519 } | |
520 | |
521 // Part 2 - Test by ID. | |
522 // Test that checkboxes are found/not found correctly by ID, when using | |
523 // TRUE or FALSE to match their 'checked' state. | |
524 $this->assertFieldById('edit-checkbox-enabled', TRUE); | |
525 $this->assertFieldById('edit-checkbox-disabled', FALSE); | |
526 $this->assertNoFieldById('edit-checkbox-enabled', FALSE); | |
527 $this->assertNoFieldById('edit-checkbox-disabled', TRUE); | |
528 | |
529 // Test that checkboxes are found by ID, when using NULL to ignore the | |
530 // 'checked' state. | |
531 $this->assertFieldById('edit-checkbox-enabled', NULL); | |
532 $this->assertFieldById('edit-checkbox-disabled', NULL); | |
533 | |
534 // Test that checkboxes are found by ID when passing no second parameter. | |
535 $this->assertFieldById('edit-checkbox-enabled'); | |
536 $this->assertFieldById('edit-checkbox-disabled'); | |
537 | |
538 // Test that we have legacy support. | |
539 $this->assertFieldById('edit-checkbox-enabled', '1'); | |
540 $this->assertFieldById('edit-checkbox-disabled', ''); | |
541 | |
542 // Test that the assertion fails correctly when using NULL to ignore state. | |
543 try { | |
544 $this->assertNoFieldById('edit-checkbox-disabled', NULL); | |
545 $this->fail('The "edit-checkbox-disabled" field was not found by ID, using NULL value.'); | |
546 } | |
547 catch (ExpectationException $e) { | |
548 $this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.'); | |
549 } | |
550 | |
551 // Part 3 - Test the specific 'checked' assertions. | |
552 $this->assertFieldChecked('edit-checkbox-enabled'); | |
553 $this->assertNoFieldChecked('edit-checkbox-disabled'); | |
554 | |
555 // Test that the assertion fails correctly with non-existant field id. | |
556 try { | |
557 $this->assertNoFieldChecked('incorrect_checkbox_id'); | |
558 $this->fail('The "incorrect_checkbox_id" field was found'); | |
559 } | |
560 catch (ExpectationException $e) { | |
561 $this->pass('assertNoFieldChecked correctly failed. The "incorrect_checkbox_id" field was not found.'); | |
562 } | |
563 | |
564 // Test that the assertion fails correctly for a checkbox that is checked. | |
565 try { | |
566 $this->assertNoFieldChecked('edit-checkbox-enabled'); | |
567 $this->fail('The "edit-checkbox-enabled" field was not found in a checked state.'); | |
568 } | |
569 catch (ExpectationException $e) { | |
570 $this->pass('assertNoFieldChecked correctly failed. The "edit-checkbox-enabled" field was found in a checked state.'); | |
571 } | |
572 | |
573 // Test that the assertion fails correctly for a checkbox that is not | |
574 // checked. | |
575 try { | |
576 $this->assertFieldChecked('edit-checkbox-disabled'); | |
577 $this->fail('The "edit-checkbox-disabled" field was found and checked.'); | |
578 } | |
579 catch (ExpectationException $e) { | |
580 $this->pass('assertFieldChecked correctly failed. The "edit-checkbox-disabled" field was not found in a checked state.'); | |
581 } | |
582 } | |
583 | |
584 /** | |
585 * Tests the ::cronRun() method. | |
586 */ | |
587 public function testCronRun() { | |
588 $last_cron_time = \Drupal::state()->get('system.cron_last'); | |
589 $this->cronRun(); | |
590 $this->assertSession()->statusCodeEquals(204); | |
591 $next_cron_time = \Drupal::state()->get('system.cron_last'); | |
592 | |
593 $this->assertGreaterThan($last_cron_time, $next_cron_time); | |
594 } | |
595 | |
596 /** | |
597 * Tests the Drupal install done in \Drupal\Tests\BrowserTestBase::setUp(). | |
598 */ | |
599 public function testInstall() { | |
600 $htaccess_filename = $this->tempFilesDirectory . '/.htaccess'; | |
601 $this->assertTrue(file_exists($htaccess_filename), "$htaccess_filename exists"); | |
602 } | |
603 | |
604 /** | |
605 * Tests the assumption that local time is in 'Australia/Sydney'. | |
606 */ | |
607 public function testLocalTimeZone() { | |
608 // The 'Australia/Sydney' time zone is set in core/tests/bootstrap.php | |
609 $this->assertEquals('Australia/Sydney', date_default_timezone_get()); | |
610 | |
611 // The 'Australia/Sydney' time zone is also set in | |
612 // FunctionalTestSetupTrait::initConfig(). | |
613 $config_factory = $this->container->get('config.factory'); | |
614 $value = $config_factory->get('system.date')->get('timezone.default'); | |
615 $this->assertEquals('Australia/Sydney', $value); | |
616 } | |
617 | |
618 /** | |
619 * Tests the ::checkForMetaRefresh() method. | |
620 */ | |
621 public function testCheckForMetaRefresh() { | |
622 // Disable following redirects in the client. | |
623 $this->getSession()->getDriver()->getClient()->followRedirects(FALSE); | |
624 // Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't | |
625 // happen when doing a drupalGet. | |
626 $this->maximumMetaRefreshCount = 0; | |
627 $this->drupalGet('test-meta-refresh'); | |
628 $this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]')); | |
629 // Allow one redirect to happen. | |
630 $this->maximumMetaRefreshCount = 1; | |
631 $this->checkForMetaRefresh(); | |
632 // Check that we are now on the test page. | |
633 $this->assertSession()->pageTextContains('Test page text.'); | |
634 } | |
635 | |
636 } |