Verified Commit 5551334f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3265574 by mondrake: Convert remaining assertions involving use of...

Issue #3265574 by mondrake: Convert remaining assertions involving use of xpath to WebAssert, where possible
parent b70a8a15
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -376,13 +376,13 @@ protected function assertBigPipePlaceholders(array $expected_big_pipe_placeholde
      $placeholder_positions[$pos] = $big_pipe_placeholder_id;
      // Verify expected placeholder replacement.
      $expected_placeholder_replacement = '<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="' . $big_pipe_placeholder_id . '">';
      $result = $this->xpath('//script[@data-big-pipe-replacement-for-placeholder-with-id=:id]', [':id' => Html::decodeEntities($big_pipe_placeholder_id)]);
      $xpath = '//script[@data-big-pipe-replacement-for-placeholder-with-id="' . Html::decodeEntities($big_pipe_placeholder_id) . '"]';
      if ($expected_ajax_response === NULL) {
        $this->assertCount(0, $result);
        $this->assertSession()->elementNotExists('xpath', $xpath);
        $this->assertSession()->responseNotContains($expected_placeholder_replacement);
        continue;
      }
      $this->assertEquals($expected_ajax_response, trim($result[0]->getText()));
      $this->assertSession()->elementTextContains('xpath', $xpath, $expected_ajax_response);
      $this->assertSession()->responseContains($expected_placeholder_replacement);
      $pos = strpos($this->getSession()->getPage()->getContent(), $expected_placeholder_replacement);
      $placeholder_replacement_positions[$pos] = $big_pipe_placeholder_id;
+2 −4
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ trait AssertBlockAppearsTrait {
   *   The block entity to find on the page.
   */
  protected function assertBlockAppears(Block $block) {
    $result = $this->findBlockInstance($block);
    $this->assertNotEmpty($result, sprintf('The block %s should appear on the page.', $block->id()));
    $this->assertSession()->elementExists('xpath', "//div[@id = 'block-{$block->id()}']");
  }

  /**
@@ -29,8 +28,7 @@ protected function assertBlockAppears(Block $block) {
   *   The block entity to find on the page.
   */
  protected function assertNoBlockAppears(Block $block) {
    $result = $this->findBlockInstance($block);
    $this->assertEmpty($result, sprintf('The block %s should not appear on the page.', $block->id()));
    $this->assertSession()->elementNotExists('xpath', "//div[@id = 'block-{$block->id()}']");
  }

  /**
+1 −2
Original line number Diff line number Diff line
@@ -48,8 +48,7 @@ public function testHtml() {
    $this->assertSession()->elementExists('xpath', '//div[@id="block-test-html-block" and @data-custom-attribute="foo"]');

    // Ensure expected markup for a menu block.
    $elements = $this->xpath('//nav[@id="block-test-menu-block"]/ul/li');
    $this->assertNotEmpty($elements, 'The proper block markup was found.');
    $this->assertSession()->elementExists('xpath', '//nav[@id="block-test-menu-block"]/ul/li');
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -135,8 +135,7 @@ public function testLanguageBlockVisibilityLanguageDelete() {
    // Ensure that the block visibility for language is gone from the UI.
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Configure');
    $elements = $this->xpath('//details[@id="edit-visibility-language"]');
    $this->assertEmpty($elements);
    $this->assertSession()->elementNotExists('xpath', '//details[@id="edit-visibility-language"]');
  }

  /**
+17 −21
Original line number Diff line number Diff line
@@ -44,12 +44,11 @@ public function testSystemBrandingSettings() {

    // Set default block settings.
    $this->drupalGet('');
    $site_logo_element = $this->xpath($site_logo_xpath);
    $site_name_element = $this->xpath($site_name_xpath);

    // Test that all branding elements are displayed.
    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
    $this->assertSession()->elementExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementExists('xpath', $site_name_xpath);
    $this->assertSession()->elementExists('xpath', $site_slogan_xpath);
    $this->assertSession()->elementTextContains('xpath', $site_slogan_xpath, 'Community plumbing');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
    // Just this once, assert that the img src of the logo is as expected.
@@ -61,18 +60,18 @@ public function testSystemBrandingSettings() {
      ->set('slogan', '<script>alert("Community carpentry");</script>')
      ->save();
    $this->drupalGet('');
    $this->assertSession()->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->elementTextEquals('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->responseNotContains('<script>alert("Community carpentry");</script>');

    // Turn just the logo off.
    $this->config('block.block.site-branding')
      ->set('settings.use_site_logo', 0)
      ->save();
    $this->drupalGet('');
    $site_logo_element = $this->xpath($site_logo_xpath);
    $site_name_element = $this->xpath($site_name_xpath);

    // Re-test all branding elements.
    $this->assertEmpty($site_logo_element, 'The branding block logo was disabled.');
    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
    $this->assertSession()->elementNotExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementExists('xpath', $site_name_xpath);
    $this->assertSession()->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->responseNotContains('<script>alert("Community carpentry");</script>');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
@@ -83,11 +82,10 @@ public function testSystemBrandingSettings() {
      ->set('settings.use_site_name', 0)
      ->save();
    $this->drupalGet('');
    $site_logo_element = $this->xpath($site_logo_xpath);
    $site_name_element = $this->xpath($site_name_xpath);

    // Re-test all branding elements.
    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
    $this->assertEmpty($site_name_element, 'The branding block site name was disabled.');
    $this->assertSession()->elementExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementNotExists('xpath', $site_name_xpath);
    $this->assertSession()->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->responseNotContains('<script>alert("Community carpentry");</script>');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
@@ -98,11 +96,10 @@ public function testSystemBrandingSettings() {
      ->set('settings.use_site_slogan', 0)
      ->save();
    $this->drupalGet('');
    $site_logo_element = $this->xpath($site_logo_xpath);
    $site_name_element = $this->xpath($site_name_xpath);

    // Re-test all branding elements.
    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
    $this->assertSession()->elementExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementExists('xpath', $site_name_xpath);
    $this->assertSession()->elementTextNotContains('xpath', $site_slogan_xpath, 'Community carpentry');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');

@@ -112,11 +109,10 @@ public function testSystemBrandingSettings() {
      ->set('settings.use_site_slogan', 0)
      ->save();
    $this->drupalGet('');
    $site_logo_element = $this->xpath($site_logo_xpath);
    $site_name_element = $this->xpath($site_name_xpath);

    // Re-test all branding elements.
    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
    $this->assertEmpty($site_name_element, 'The branding block site name was disabled.');
    $this->assertSession()->elementExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementNotExists('xpath', $site_name_xpath);
    $this->assertSession()->elementTextNotContains('xpath', $site_slogan_xpath, 'Community carpentry');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
  }
Loading