diff --git a/core/modules/filter/tests/src/Functional/FilterAdminTest.php b/core/modules/filter/tests/src/Functional/FilterAdminTest.php index 102852b..83746e1 100644 --- a/core/modules/filter/tests/src/Functional/FilterAdminTest.php +++ b/core/modules/filter/tests/src/Functional/FilterAdminTest.php @@ -142,7 +142,7 @@ public function testFormatAdmin() { $edit_link = $this->xpath('//a[@href=:href]', [ ':href' => \Drupal::url('entity.filter_format.edit_form', ['filter_format' => $format_id]) ]); - $this->assertTrue($edit_link, format_string('Link href %href found.', + $this->assertTrue(!empty($edit_link), format_string('Link href %href found.', ['%href' => 'admin/config/content/formats/manage/' . $format_id] )); $this->drupalGet('admin/config/content/formats/manage/' . $format_id); @@ -260,9 +260,9 @@ public function testFilterAdmin() { $format = FilterFormat::load($edit['format']); $this->assertNotNull($format, 'Format found in database.'); $this->drupalGet('admin/config/content/formats/manage/' . $format->id()); - $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.'); - $this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.'); - $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'URL filter found.'); + $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', RoleInterface::AUTHENTICATED_ID); + $this->assertFieldByName('filters[' . $second_filter . '][status]', TRUE); + $this->assertFieldByName('filters[' . $first_filter . '][status]', TRUE); // Disable new filter. $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable')); @@ -297,8 +297,8 @@ public function testFilterAdmin() { $this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Filtered node created.'); // Verify that the creation message contains a link to a node. - $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']); - $this->assert(isset($view_link), 'The message area contains a link to a node'); + $view_link = $this->xpath('//div[contains(@class, "messages")]//a[contains(@href, :href)]', [':href' => 'node/']); + $this->assertTrue(!empty($view_link), 'The message area contains a link to a node'); $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->assertTrue($node, 'Node found in database.'); diff --git a/core/modules/filter/tests/src/Functional/FilterFormTest.php b/core/modules/filter/tests/src/Functional/FilterFormTest.php index ddfa727..c2b97c4 100644 --- a/core/modules/filter/tests/src/Functional/FilterFormTest.php +++ b/core/modules/filter/tests/src/Functional/FilterFormTest.php @@ -173,13 +173,10 @@ protected function doFilterFormTestAsNonAdmin() { * * @param string $id * The HTML ID of the select element. - * - * @return bool - * TRUE if the assertion passed; FALSE otherwise. */ protected function assertNoSelect($id) { $select = $this->xpath('//select[@id=:id]', [':id' => $id]); - return $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', [ + $this->assertTrue(empty($select), SafeMarkup::format('Field @id does not exist.', [ '@id' => $id, ])); } @@ -199,14 +196,13 @@ protected function assertNoSelect($id) { */ protected function assertOptions($id, array $expected_options, $selected) { $select = $this->xpath('//select[@id=:id]', [':id' => $id]); - $select = reset($select); - $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', [ + $this->assertTrue(!empty($select), SafeMarkup::format('Field @id exists.', [ '@id' => $id, ])); - - $found_options = $this->getAllOptions($select); + $select = reset($select); + $found_options = $select->findAll('css', 'option'); foreach ($found_options as $found_key => $found_option) { - $expected_key = array_search($found_option->attributes()->value, $expected_options); + $expected_key = array_search($found_option->getValue(), $expected_options); if ($expected_key !== FALSE) { $this->pass(SafeMarkup::format('Option @option for field @id exists.', [ '@option' => $expected_options[$expected_key], @@ -224,17 +220,15 @@ protected function assertOptions($id, array $expected_options, $selected) { '@option' => $expected_option, '@id' => $id, ])); - $passed = FALSE; } foreach ($found_options as $found_option) { $this->fail(SafeMarkup::format('Option @option for field @id does not exist.', [ - '@option' => $found_option->attributes()->value, + '@option' => $found_option->getValue(), '@id' => $id, ])); - $passed = FALSE; } - return $passed && $this->assertOptionSelected($id, $selected); + $this->assertOptionSelected($id, $selected); } /** @@ -253,14 +247,13 @@ protected function assertRequiredSelectAndOptions($id, array $options) { $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [ ':id' => $id, ]); - $select = reset($select); - $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @id exists.', [ + $this->assertTrue(!empty($select), SafeMarkup::format('Required field @id exists.', [ '@id' => $id, ])); // A required select element has a "- Select -" option whose key is an empty // string. $options[] = ''; - return $passed && $this->assertOptions($id, $options, ''); + $this->assertOptions($id, $options, ''); } /** @@ -276,8 +269,7 @@ protected function assertEnabledTextarea($id) { $textarea = $this->xpath('//textarea[@id=:id and not(contains(@disabled, "disabled"))]', [ ':id' => $id, ]); - $textarea = reset($textarea); - return $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Enabled field @id exists.', [ + $this->assertTrue(!empty($textarea), SafeMarkup::format('Enabled field @id exists.', [ '@id' => $id, ])); } @@ -295,17 +287,17 @@ protected function assertDisabledTextarea($id) { $textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [ ':id' => $id, ]); - $textarea = reset($textarea); - $passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', [ + $this->assertTrue(!empty($textarea), SafeMarkup::format('Disabled field @id exists.', [ '@id' => $id, ])); + $textarea = reset($textarea); $expected = 'This field has been disabled because you do not have sufficient permissions to edit it.'; - $passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [ + $this->assertEqual($textarea->getText(), $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [ '@id' => $id, ])); // Make sure the text format select is not shown. $select_id = str_replace('value', 'format--2', $id); - return $passed && $this->assertNoSelect($select_id); + $this->assertNoSelect($select_id); } } diff --git a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php index a3af3e9..c5a0cd8 100644 --- a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php +++ b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php @@ -151,7 +151,7 @@ public function testFormatPermissions() { ]); $options = []; foreach ($elements as $element) { - $options[(string) $element['value']] = $element; + $options[(string) $element->getValue()] = $element; } $this->assertTrue(isset($options[$this->allowedFormat->id()]), 'The allowed text format appears as an option when adding a new node.'); $this->assertFalse(isset($options[$this->disallowedFormat->id()]), 'The disallowed text format does not appear as an option when adding a new node.'); diff --git a/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php index b94e2ee..77a263c 100644 --- a/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php @@ -6,6 +6,7 @@ use Drupal\Core\StreamWrapper\PublicStream; use Drupal\filter\Entity\FilterFormat; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\TestFileCreationTrait; /** * Tests restriction of IMG tags in HTML input. @@ -15,6 +16,7 @@ class FilterHtmlImageSecureTest extends BrowserTestBase { use CommentTestTrait; + use TestFileCreationTrait; /** * Modules to enable. @@ -90,7 +92,7 @@ public function testImageSource() { $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.'); // Put a test image in the files directory. - $test_images = $this->drupalGetTestFiles('image'); + $test_images = $this->getTestFiles('image'); $test_image = $test_images[0]->filename; // Put a test image in the files directory with special filename. @@ -141,14 +143,14 @@ public function testImageSource() { foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) { $found = TRUE; if ($converted == $red_x_image) { - $this->assertEqual((string) $element['src'], $red_x_image); - $this->assertEqual((string) $element['alt'], $alt_text); - $this->assertEqual((string) $element['title'], $title_text); - $this->assertEqual((string) $element['height'], '16'); - $this->assertEqual((string) $element['width'], '16'); + $this->assertEqual((string) $element->getAttribute('src'), $red_x_image); + $this->assertEqual((string) $element->getAttribute('alt'), $alt_text); + $this->assertEqual((string) $element->getAttribute('title'), $title_text); + $this->assertEqual((string) $element->getAttribute('height'), '16'); + $this->assertEqual((string) $element->getAttribute('width'), '16'); } else { - $this->assertEqual((string) $element['src'], $converted); + $this->assertEqual((string) $element->getAttribute('src'), $converted); } } $this->assertTrue($found, format_string('@image was found.', ['@image' => $image]));