From 172e4b5acb4b2c6a0d725447b40466c545db01f1 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 15 Feb 2021 09:53:11 +0000 Subject: [PATCH] Issue #3189607 by Spokje, longwave, Pooja Ganjage, anmolgoyal74: Convert assertions involving use of xpath on checkboxes to WebAssert --- .../tests/src/Functional/CKEditorAdminTest.php | 6 ++---- .../tests/src/Functional/EditorAdminTest.php | 6 ++---- .../src/Functional/Module/DependencyTest.php | 15 +++++---------- .../Functional/Module/InstallUninstallTest.php | 7 ++----- .../tests/src/Functional/Module/VersionTest.php | 8 ++++++-- .../Plugin/ExposedFormCheckboxesTest.php | 6 ++---- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php index 0b4c220b6e5a..05097097ef0c 100644 --- a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php @@ -200,8 +200,7 @@ public function testExistingFormat() { $this->resetAll(); $this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions(); $this->drupalGet('admin/config/content/formats/manage/filtered_html'); - $ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and not(@checked)]'); - $this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is not checked.'); + $this->assertSession()->checkboxNotChecked('editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]'); $editor = Editor::load('filtered_html'); $this->assertInstanceOf(Editor::class, $editor); $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); @@ -213,8 +212,7 @@ public function testExistingFormat() { ]; $this->submitForm($edit, 'Save configuration'); $this->drupalGet('admin/config/content/formats/manage/filtered_html'); - $ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and @checked="checked"]'); - $this->assertCount(1, $ultra_llama_mode_checkbox, 'The "Ultra llama mode" checkbox exists and is checked.'); + $this->assertSession()->checkboxChecked('editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]'); $expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = TRUE; $editor = Editor::load('filtered_html'); $this->assertInstanceOf(Editor::class, $editor); diff --git a/core/modules/editor/tests/src/Functional/EditorAdminTest.php b/core/modules/editor/tests/src/Functional/EditorAdminTest.php index 2783a99a700c..be112b1279d1 100644 --- a/core/modules/editor/tests/src/Functional/EditorAdminTest.php +++ b/core/modules/editor/tests/src/Functional/EditorAdminTest.php @@ -92,8 +92,7 @@ public function testAddEditorToExistingFormat() { 'editor[editor]' => '', ]; $this->submitForm($edit, 'Configure'); - $unicorn_setting = $this->xpath('//input[@name="editor[settings][ponies_too]" and @type="checkbox" and @checked]'); - $this->assertCount(0, $unicorn_setting, "Unicorn Editor's settings form is no longer present."); + $this->assertSession()->fieldNotExists('editor[settings][ponies_too]'); } /** @@ -224,8 +223,7 @@ protected function selectUnicornEditor() { 'editor[editor]' => 'unicorn', ]; $this->submitForm($edit, 'Configure'); - $unicorn_setting = $this->xpath('//input[@name="editor[settings][ponies_too]" and @type="checkbox" and @checked]'); - $this->assertCount(1, $unicorn_setting, "Unicorn Editor's settings form is present."); + $this->assertSession()->checkboxChecked('editor[settings][ponies_too]'); return $edit; } diff --git a/core/modules/system/tests/src/Functional/Module/DependencyTest.php b/core/modules/system/tests/src/Functional/Module/DependencyTest.php index ef20e11c0e16..7e997be5679b 100644 --- a/core/modules/system/tests/src/Functional/Module/DependencyTest.php +++ b/core/modules/system/tests/src/Functional/Module/DependencyTest.php @@ -64,8 +64,7 @@ public function testMissingModules() { // as missing a dependency. $this->drupalGet('admin/modules'); $this->assertRaw(t('@module (<span class="admin-missing">missing</span>)', ['@module' => Unicode::ucfirst('_missing_dependency')])); - $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_dependencies_test][enable]"]'); - $this->assertCount(1, $checkbox, 'Checkbox for the module is disabled.'); + $this->assertSession()->checkboxNotChecked('modules[system_dependencies_test][enable]'); } /** @@ -79,8 +78,7 @@ public function testIncompatibleModuleVersionDependency() { '@module' => 'System incompatible module version test (>2.0)', '@version' => '1.0', ])); - $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_module_version_dependencies_test][enable]"]'); - $this->assertCount(1, $checkbox, 'Checkbox for the module is disabled.'); + $this->assertSession()->fieldDisabled('modules[system_incompatible_module_version_dependencies_test][enable]'); } /** @@ -93,8 +91,7 @@ public function testIncompatibleCoreVersionDependency() { $this->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [ '@module' => 'System core incompatible semver test', ])); - $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_core_version_dependencies_test][enable]"]'); - $this->assertCount(1, $checkbox, 'Checkbox for the module is disabled.'); + $this->assertSession()->fieldDisabled('modules[system_incompatible_core_version_dependencies_test][enable]'); } /** @@ -103,8 +100,7 @@ public function testIncompatibleCoreVersionDependency() { public function testIncompatiblePhpVersionDependency() { $this->drupalGet('admin/modules'); $this->assertRaw('This module requires PHP version 6502.* and is incompatible with PHP version ' . phpversion() . '.'); - $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_php_version_test][enable]"]'); - $this->assertCount(1, $checkbox, 'Checkbox for the module is disabled.'); + $this->assertSession()->fieldDisabled('modules[system_incompatible_php_version_test][enable]'); } /** @@ -201,8 +197,7 @@ public function testUninstallDependents() { // Check that the comment module cannot be uninstalled. $this->drupalGet('admin/modules/uninstall'); - $checkbox = $this->xpath('//input[@type="checkbox" and @name="uninstall[comment]" and @disabled="disabled"]'); - $this->assertCount(1, $checkbox, 'Checkbox for uninstalling the comment module is disabled.'); + $this->assertSession()->fieldDisabled('uninstall[comment]'); // Delete any forum terms. $vid = $this->config('forum.settings')->get('vocabulary'); diff --git a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php index 14ab885aaa2c..754b3b18ac21 100644 --- a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php @@ -174,11 +174,8 @@ public function testInstallUninstall() { // See if we can currently uninstall this module (if its dependencies // have been uninstalled), and do so if we can. $this->drupalGet('admin/modules/uninstall'); - $field_name = "uninstall[$to_uninstall]"; - $has_checkbox = $this->xpath('//input[@type="checkbox" and @name="' . $field_name . '"]'); - $disabled = $this->xpath('//input[@type="checkbox" and @name="' . $field_name . '" and @disabled="disabled"]'); - - if (!empty($has_checkbox) && empty($disabled)) { + $checkbox = $this->assertSession()->fieldExists("uninstall[$to_uninstall]"); + if (!$checkbox->hasAttribute('disabled')) { // This one is eligible for being uninstalled. $package = $all_modules[$to_uninstall]->info['package']; $this->assertSuccessfulUninstall($to_uninstall, $package); diff --git a/core/modules/system/tests/src/Functional/Module/VersionTest.php b/core/modules/system/tests/src/Functional/Module/VersionTest.php index 9b84f03c0c47..21262c51f934 100644 --- a/core/modules/system/tests/src/Functional/Module/VersionTest.php +++ b/core/modules/system/tests/src/Functional/Module/VersionTest.php @@ -53,8 +53,12 @@ public function testModuleVersions() { $n = count($dependencies); for ($i = 0; $i < $n; $i++) { $this->drupalGet('admin/modules'); - $checkbox = $this->xpath('//input[@id="edit-modules-module-test-enable"]'); - $this->assertEqual($i % 2, !empty($checkbox[0]->getAttribute('disabled')), $dependencies[$i]); + if ($i % 2 == 0) { + $this->assertSession()->fieldEnabled('edit-modules-module-test-enable'); + } + else { + $this->assertSession()->fieldDisabled('edit-modules-module-test-enable'); + } } } diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php index 9d83b02019ec..cd468fc3ffa1 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php @@ -97,10 +97,8 @@ public function testExposedFormRenderCheckboxes() { $view->save(); $this->drupalGet('test_exposed_form_checkboxes'); - $actual = $this->xpath('//form//input[@type="checkbox" and @name="type[article]"]'); - $this->assertCount(1, $actual, 'Article option renders as a checkbox.'); - $actual = $this->xpath('//form//input[@type="checkbox" and @name="type[page]"]'); - $this->assertCount(1, $actual, 'Page option renders as a checkbox'); + $this->assertSame('checkbox', $this->assertSession()->fieldExists('type[article]')->getAttribute('type')); + $this->assertSame('checkbox', $this->assertSession()->fieldExists('type[page]')->getAttribute('type')); // Ensure that all results are displayed. $rows = $this->xpath("//div[contains(@class, 'views-row')]"); -- GitLab