Unverified Commit 7ca36cfc authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3253715 by mondrake, longwave: Replace assertions involving calls to...

Issue #3253715 by mondrake, longwave: Replace assertions involving calls to isset() on xpath results in functional tests with WebAssert calls
parent bc964dc4
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -116,10 +116,7 @@ function ($langcode) use ($url_base, $languageManager) {
    foreach ($urls as $langcode => $url) {
      $this->drupalGet($url);
      foreach ($urls as $langcode_alternate => $url_alternate) {
        $args = [':href' => $url_alternate->toString(), ':hreflang' => $langcode_alternate];
        $links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', $args);
        $message = sprintf('The "%s" translation has the correct alternate hreflang link for "%s": %s.', $langcode, $langcode_alternate, $url->toString());
        $this->assertTrue(isset($links[0]), $message);
        $this->assertSession()->elementAttributeContains('xpath', "head/link[@rel='alternate' and @hreflang='$langcode_alternate']", 'href', $url_alternate->toString());
      }
    }

@@ -135,12 +132,7 @@ function ($langcode) use ($url_base, $languageManager) {
          'absolute' => TRUE,
          'language' => $language,
        ])->toString();
        $args = [
          ':href' => $frontpage_path,
          ':hreflang' => $language->getId(),
        ];
        $links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', $args);
        $this->assertArrayHasKey(0, $links);
        $this->assertSession()->elementAttributeContains('xpath', "head/link[@rel='alternate' and @hreflang='{$language->getId()}']", 'href', $frontpage_path);
      }
    }
  }
+2 −4
Original line number Diff line number Diff line
@@ -275,8 +275,7 @@ public function testFieldFormUnlimited() {
    $this->assertSession()->fieldNotExists("{$field_name}[1][value]");

    // Check if aria-describedby attribute is placed on multiple value widgets.
    $elements = $this->xpath('//table[@id="field-unlimited-values" and @aria-describedby="edit-field-unlimited--description"]');
    $this->assertTrue(isset($elements[0]), 'aria-describedby attribute is properly placed on multiple value widgets.');
    $this->assertSession()->elementAttributeContains('xpath', '//table[@id="field-unlimited-values"]', 'aria-describedby', 'edit-field-unlimited--description');

    // Press 'add more' button -> 2 widgets.
    $this->submitForm([], 'Add another item');
@@ -362,8 +361,7 @@ public function testFieldFormUnlimitedRequired() {
    // Display creation form -> 1 widget.
    $this->drupalGet('entity_test/add');
    // Check that the Required symbol is present for the multifield label.
    $element = $this->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', [':value' => $this->field['label']]);
    $this->assertTrue(isset($element[0]), 'Required symbol added field label.');
    $this->assertSession()->elementAttributeContains('xpath', "//h4[contains(@class, 'label') and contains(text(), '{$this->field['label']}')]", 'class', 'js-form-required');
    // Check that the label of the field input is visually hidden and contains
    // the field title and an indication of the delta for a11y.
    $this->assertSession()->elementExists('xpath', "//label[@for='edit-field-unlimited-0-value' and contains(@class, 'visually-hidden') and contains(text(), '{$this->field['label']} (value 1)')]");
+1 −2
Original line number Diff line number Diff line
@@ -124,9 +124,8 @@ public function testDeleteField() {
    $this->assertSession()->pageTextContains('The listed configuration will be updated.');
    $this->assertSession()->elementTextEquals('xpath', '//ul[@data-drupal-selector="edit-view"]', 'test_view_field_delete');

    $xml = $this->cssSelect('#edit-entity-deletes');
    // Test that nothing is scheduled for deletion.
    $this->assertFalse(isset($xml[0]), 'The field currently being deleted is not shown in the entity deletions.');
    $this->assertSession()->elementNotExists('css', '#edit-entity-deletes');

    // Delete the second field.
    $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$field_name", $field_label, $type_name2);
+1 −2
Original line number Diff line number Diff line
@@ -382,8 +382,7 @@ private function doAdminTests($user) {
    $this->drupalGet('admin/structure/taxonomy/manage/tags/add');
    $this->assertSession()->fieldExists('parent[]');
    // Test relations widget exists.
    $relations_widget = $this->xpath("//details[@id='edit-relations']");
    $this->assertTrue(isset($relations_widget[0]), 'Relations widget element found.');
    $this->assertSession()->elementExists('xpath', "//details[@id='edit-relations']");
  }

  /**
+4 −11
Original line number Diff line number Diff line
@@ -260,8 +260,6 @@ public function testLanguageLinkActiveClass() {
   * Check the path-admin class, as same as on default language.
   */
  public function testLanguageBodyClass() {
    $searched_class = 'path-admin';

    // Add language.
    $edit = [
      'predefined_langcode' => 'fr',
@@ -276,13 +274,11 @@ public function testLanguageBodyClass() {

    // Check if the default (English) admin/config page has the right class.
    $this->drupalGet('admin/config');
    $class = $this->xpath('//body[contains(@class, :class)]', [':class' => $searched_class]);
    $this->assertTrue(isset($class[0]), 'The path-admin class appears on default language.');
    $this->assertSession()->elementAttributeContains('xpath', '//body', 'class', 'path-admin');

    // Check if the French admin/config page has the right class.
    $this->drupalGet('fr/admin/config');
    $class = $this->xpath('//body[contains(@class, :class)]', [':class' => $searched_class]);
    $this->assertTrue(isset($class[0]), 'The path-admin class same as on default language.');
    $this->assertSession()->elementAttributeContains('xpath', '//body', 'class', 'path-admin');

    // The testing profile sets the user/login page as the frontpage. That
    // redirects authenticated users to their profile page, so check with an
@@ -291,14 +287,11 @@ public function testLanguageBodyClass() {

    // Check if the default (English) frontpage has the right class.
    $this->drupalGet('<front>');
    $class = $this->xpath('//body[contains(@class, :class)]', [':class' => 'path-frontpage']);
    $this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag');
    $this->assertSession()->elementAttributeContains('xpath', '//body', 'class', 'path-frontpage');

    // Check if the French frontpage has the right class.
    $this->drupalGet('fr');
    $class = $this->xpath('//body[contains(@class, :class)]', [':class' => 'path-frontpage']);
    $this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag with french as the active language');

    $this->assertSession()->elementAttributeContains('xpath', '//body', 'class', 'path-frontpage');
  }

  /**
Loading