comparison core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
21 /** 21 /**
22 * Modules to enable. 22 * Modules to enable.
23 * 23 *
24 * @var array 24 * @var array
25 */ 25 */
26 public static $modules = ['test_page_test', 'form_test', 'system_test']; 26 public static $modules = ['test_page_test', 'form_test', 'system_test', 'node'];
27 27
28 /** 28 /**
29 * Tests basic page test. 29 * Tests basic page test.
30 */ 30 */
31 public function testGoTo() { 31 public function testGoTo() {
112 $value = $config_factory->get('form_test.object')->get('bananas'); 112 $value = $config_factory->get('form_test.object')->get('bananas');
113 $this->assertSame('green', $value); 113 $this->assertSame('green', $value);
114 114
115 // Test drupalPostForm(). 115 // Test drupalPostForm().
116 $edit = ['bananas' => 'red']; 116 $edit = ['bananas' => 'red'];
117 // Submit the form using the button label.
117 $result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save'); 118 $result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save');
118 $this->assertSame($this->getSession()->getPage()->getContent(), $result); 119 $this->assertSame($this->getSession()->getPage()->getContent(), $result);
119 $value = $config_factory->get('form_test.object')->get('bananas'); 120 $value = $config_factory->get('form_test.object')->get('bananas');
120 $this->assertSame('red', $value); 121 $this->assertSame('red', $value);
121 122
122 $this->drupalPostForm('form-test/object-builder', NULL, 'Save'); 123 $this->drupalPostForm('form-test/object-builder', NULL, 'Save');
123 $value = $config_factory->get('form_test.object')->get('bananas'); 124 $value = $config_factory->get('form_test.object')->get('bananas');
124 $this->assertSame('', $value); 125 $this->assertSame('', $value);
125 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
126 // Test drupalPostForm() with no-html response. 141 // Test drupalPostForm() with no-html response.
127 $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit'))); 142 $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
128 $this->assertTrue(1000, $values['beer']); 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.');
129 } 153 }
130 154
131 /** 155 /**
132 * Tests clickLink() functionality. 156 * Tests clickLink() functionality.
133 */ 157 */
209 $sanitized = Html::escape($dangerous); 233 $sanitized = Html::escape($dangerous);
210 $this->assertNoText($dangerous); 234 $this->assertNoText($dangerous);
211 $this->assertText($sanitized); 235 $this->assertText($sanitized);
212 236
213 // Test getRawContent(). 237 // Test getRawContent().
214 $this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent()); 238 $this->assertSame($this->getSession()->getPage()->getContent(), $this->getSession()->getPage()->getContent());
215 } 239 }
216 240
217 /** 241 /**
218 * Tests legacy field asserts which use xpath directly. 242 * Tests legacy field asserts which use xpath directly.
219 */ 243 */
565 589
566 // Part 3 - Test the specific 'checked' assertions. 590 // Part 3 - Test the specific 'checked' assertions.
567 $this->assertFieldChecked('edit-checkbox-enabled'); 591 $this->assertFieldChecked('edit-checkbox-enabled');
568 $this->assertNoFieldChecked('edit-checkbox-disabled'); 592 $this->assertNoFieldChecked('edit-checkbox-disabled');
569 593
570 // Test that the assertion fails correctly with non-existant field id. 594 // Test that the assertion fails correctly with non-existent field id.
571 try { 595 try {
572 $this->assertNoFieldChecked('incorrect_checkbox_id'); 596 $this->assertNoFieldChecked('incorrect_checkbox_id');
573 $this->fail('The "incorrect_checkbox_id" field was found'); 597 $this->fail('The "incorrect_checkbox_id" field was found');
574 } 598 }
575 catch (ExpectationException $e) { 599 catch (ExpectationException $e) {
652 putenv('MINK_DRIVER_ARGS=' . json_encode([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]])); 676 putenv('MINK_DRIVER_ARGS=' . json_encode([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]]));
653 $this->getDefaultDriverInstance(); 677 $this->getDefaultDriverInstance();
654 $this->assertEquals([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]], $this->minkDefaultDriverArgs); 678 $this->assertEquals([NULL, ['key1' => ['key2' => ['key3' => 3, 'key3.1' => 3.1]]]], $this->minkDefaultDriverArgs);
655 } 679 }
656 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
657 } 690 }