Commit c3a97f59 authored by catch's avatar catch
Browse files

Issue #3220255 by Spokje, mondrake, longwave: Convert assertions involving use...

Issue #3220255 by Spokje, mondrake, longwave: Convert assertions involving use of xpath on links to WebAssert
parent 61e0890f
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -162,11 +162,14 @@ public function testAddBlockFromLibraryWithWeight() {
        'plugin_id' => $block_name,
        'theme' => $default_theme,
      ]);
      $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
      $this->assertCount(1, $links, 'Found one matching link.');
      $this->assertEquals(t('Place block'), $links[0]->getText(), 'Found the expected link text.');

      list($path, $query_string) = explode('?', $links[0]->getAttribute('href'), 2);
      // Verify that one link is found, with the the expected link text.
      $xpath = $this->assertSession()->buildXPathQuery('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
      $this->assertSession()->elementsCount('xpath', $xpath, 1);
      $this->assertSession()->elementTextEquals('xpath', $xpath, 'Place block');

      $link = $this->getSession()->getPage()->find('xpath', $xpath);
      list($path, $query_string) = explode('?', $link->getAttribute('href'), 2);
      parse_str($query_string, $query_parts);
      $this->assertEquals($weight, $query_parts['weight'], 'Found the expected weight query string.');

@@ -178,7 +181,7 @@ public function testAddBlockFromLibraryWithWeight() {
        'settings[label]' => $title,
      ];
      // Create the block using the link parsed from the library page.
      $this->drupalGet($this->getAbsoluteUrl($links[0]->getAttribute('href')));
      $this->drupalGet($this->getAbsoluteUrl($link->getAttribute('href')));
      $this->submitForm($edit, 'Save block');

      // Ensure that the block was created with the expected weight.
+12 −13
Original line number Diff line number Diff line
@@ -81,9 +81,6 @@ public function testBlockCategory() {
    $this->submitForm($edit, 'Save and edit');

    $pattern = '//tr[.//td[text()=:category] and .//td//a[contains(@href, :href)]]';

    // Test that the block was given a default category corresponding to its
    // base table.
    $arguments = [
      ':href' => Url::fromRoute('block.admin_add', [
        'plugin_id' => 'views_block:' . $edit['id'] . '-block_1',
@@ -91,10 +88,12 @@ public function testBlockCategory() {
      ])->toString(),
      ':category' => 'Lists (Views)',
    ];

    // Test that the block was given a default category corresponding to its
    // base table.
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Place block');
    $elements = $this->xpath($pattern, $arguments);
    $this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.');
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($pattern, $arguments));

    // Duplicate the block before changing the category.
    $this->drupalGet('admin/structure/views/view/' . $edit['id'] . '/edit/block_1');
@@ -103,8 +102,7 @@ public function testBlockCategory() {

    // Change the block category to a random string.
    $this->drupalGet('admin/structure/views/view/' . $edit['id'] . '/edit/block_1');
    $link = $this->xpath('//a[@id="views-block-1-block-category" and normalize-space(text())=:category]', $arguments);
    $this->assertTrue(!empty($link));
    $this->assertSession()->elementTextEquals('named', ['id', 'views-block-1-block-category'], 'Lists (Views)');
    $this->clickLink('Lists (Views)');
    $category = $this->randomString();
    $this->submitForm(['block_category' => $category], 'Apply');
@@ -119,9 +117,10 @@ public function testBlockCategory() {
    $arguments[':category'] = $category;
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Place block');
    $elements = $this->xpath($pattern, $arguments);
    $this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($pattern, $arguments));

    // Test that the first duplicated test block remains in the original
    // category.
    $arguments = [
      ':href' => Url::fromRoute('block.admin_add', [
        'plugin_id' => 'views_block:' . $edit['id'] . '-block_2',
@@ -129,9 +128,10 @@ public function testBlockCategory() {
      ])->toString(),
      ':category' => 'Lists (Views)',
    ];
    $elements = $this->xpath($pattern, $arguments);
    $this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($pattern, $arguments));

    // Test that the second duplicated test block appears in the custom
    // category.
    $arguments = [
      ':href' => Url::fromRoute('block.admin_add', [
        'plugin_id' => 'views_block:' . $edit['id'] . '-block_3',
@@ -139,8 +139,7 @@ public function testBlockCategory() {
      ])->toString(),
      ':category' => $category,
    ];
    $elements = $this->xpath($pattern, $arguments);
    $this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.');
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($pattern, $arguments));
  }

  /**
+7 −7
Original line number Diff line number Diff line
@@ -635,9 +635,11 @@ public function testAdminBookNodeListing() {
    $this->drupalGet('admin/structure/book/' . $this->book->id());
    $this->assertSession()->pageTextContains($this->book->label());

    $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
    $this->assertEquals('View', $elements[0]->getText(), 'View link is found from the list.');
    $this->assertSameSize($nodes, $elements, 'All the book pages are displayed on the book outline page.');
    // Test that the view link is found from the list.
    $this->assertSession()->elementTextEquals('xpath', '//table//ul[@class="dropbutton"]/li/a', 'View');

    // Test that all the book pages are displayed on the book outline page.
    $this->assertSession()->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));

    // Unpublish a book in the hierarchy.
    $nodes[0]->setUnPublished();
@@ -645,8 +647,7 @@ public function testAdminBookNodeListing() {

    // Node should still appear on the outline for admins.
    $this->drupalGet('admin/structure/book/' . $this->book->id());
    $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
    $this->assertSameSize($nodes, $elements, 'All the book pages are displayed on the book outline page.');
    $this->assertSession()->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));

    // Saving a book page not as the current version shouldn't effect the book.
    $old_title = $nodes[1]->getTitle();
@@ -656,8 +657,7 @@ public function testAdminBookNodeListing() {
    $nodes[1]->setTitle($new_title);
    $nodes[1]->save();
    $this->drupalGet('admin/structure/book/' . $this->book->id());
    $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
    $this->assertSameSize($nodes, $elements, 'All the book pages are displayed on the book outline page.');
    $this->assertSession()->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));
    $this->assertSession()->responseNotContains($new_title);
    $this->assertSession()->responseContains($old_title);
  }
+1 −2
Original line number Diff line number Diff line
@@ -125,8 +125,7 @@ public function testCommentPreviewDuplicateSubmission() {
    $submit_button = $this->assertSession()->buttonExists('Save');
    $submit_button->click();
    $this->assertSession()->pageTextContains('Your comment has been posted.');
    $elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article');
    $this->assertCount(2, $elements);
    $this->assertSession()->elementsCount('xpath', '//section[contains(@class, "comment-wrapper")]/article', 2);
  }

  /**
+14 −12
Original line number Diff line number Diff line
@@ -128,21 +128,23 @@ public function testApprovalAdminInterface() {
    $this->submitForm([], 'Apply to selected items');
    $this->assertSession()->pageTextContains('Select one or more comments to perform the update on.');

    $subject_link = $this->xpath('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
    // Test that comment listing shows the correct subject link.
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
      ':href' => $comments[0]->permalink()->toString(),
      ':title' => Unicode::truncate($comments[0]->get('comment_body')->value, 128),
      ':text' => $comments[0]->getSubject(),
    ]);
    $this->assertTrue(!empty($subject_link), 'Comment listing shows the correct subject link.');
    ]));

    // Verify that anonymous author name is displayed correctly.
    $this->assertSession()->pageTextContains($author_name . ' (not verified)');

    $subject_link = $this->xpath('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
    // Test that comment listing shows the correct subject link.
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr/td/a[contains(@href, :href) and contains(@title, :title) and text()=:text]', [
      ':href' => $anonymous_comment4->permalink()->toString(),
      ':title' => Unicode::truncate($body, 128),
      ':text' => $subject,
    ]);
    $this->assertTrue(!empty($subject_link), 'Comment listing shows the correct subject link.');
    ]));

    // Verify that anonymous author name is displayed correctly.
    $this->assertSession()->pageTextContains($author_name . ' (not verified)');

@@ -214,16 +216,16 @@ public function testCommentedEntityLabel() {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/content/comment');

    $comment_author_link = $this->xpath('//table/tbody/tr[1]/td/a[contains(@href, :href) and text()=:text]', [
    // Test that comment listing links to comment author.
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr[1]/td/a[contains(@href, :href) and text()=:text]', [
      ':href' => $this->webUser->toUrl()->toString(),
      ':text' => $this->webUser->label(),
    ]);
    $this->assertTrue(!empty($comment_author_link), 'Comment listing links to comment author.');
    $comment_author_link = $this->xpath('//table/tbody/tr[2]/td/a[contains(@href, :href) and text()=:text]', [
    ]));
    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr[2]/td/a[contains(@href, :href) and text()=:text]', [
      ':href' => $this->webUser->toUrl()->toString(),
      ':text' => $this->webUser->label(),
    ]);
    $this->assertTrue(!empty($comment_author_link), 'Comment listing links to comment author.');
    ]));

    // Admin page contains label of both entities.
    $this->assertSession()->pageTextContains(Html::escape($this->node->label()));
    $this->assertSession()->pageTextContains(Html::escape($block_content->label()));
Loading