Issue #3168788 by mondrake, longwave: Convert assertions involving use of xpath to WebAssert, aggregator module
parent
7e524d3b57
commit
f2845ab67d
|
@ -69,26 +69,23 @@ class AggregatorAdminTest extends AggregatorTestBase {
|
|||
$feed = $this->createFeed($this->getRSS091Sample());
|
||||
$this->drupalGet('admin/config/services/aggregator');
|
||||
|
||||
$result = $this->xpath('//table/tbody/tr');
|
||||
// Check if the amount of feeds in the overview matches the amount created.
|
||||
$this->assertCount(1, $result, 'Created feed is found in the overview');
|
||||
$this->assertSession()->elementsCount('xpath', '//table/tbody/tr', 1);
|
||||
|
||||
// Check if the fields in the table match with what's expected.
|
||||
$link = $this->xpath('//table/tbody/tr//td[1]/a');
|
||||
$this->assertEquals($feed->label(), $link[0]->getText());
|
||||
$this->assertSession()->elementTextContains('xpath', '//table/tbody/tr//td[1]/a', $feed->label());
|
||||
$count = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->getItemCount($feed);
|
||||
$td = $this->xpath('//table/tbody/tr//td[2]');
|
||||
$this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText());
|
||||
$this->assertSession()->elementTextContains('xpath', '//table/tbody/tr//td[2]', \Drupal::translation()->formatPlural($count, '1 item', '@count items'));
|
||||
|
||||
// Update the items of the first feed.
|
||||
$feed->refreshItems();
|
||||
$this->drupalGet('admin/config/services/aggregator');
|
||||
$result = $this->xpath('//table/tbody/tr');
|
||||
$this->assertSession()->elementsCount('xpath', '//table/tbody/tr', 1);
|
||||
|
||||
// Check if the fields in the table match with what's expected.
|
||||
$link = $this->xpath('//table/tbody/tr//td[1]/a');
|
||||
$this->assertEquals($feed->label(), $link[0]->getText());
|
||||
$this->assertSession()->elementTextContains('xpath', '//table/tbody/tr//td[1]/a', $feed->label());
|
||||
$count = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->getItemCount($feed);
|
||||
$td = $this->xpath('//table/tbody/tr//td[2]');
|
||||
$this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText());
|
||||
$this->assertSession()->elementTextContains('xpath', '//table/tbody/tr//td[2]', \Drupal::translation()->formatPlural($count, '1 item', '@count items'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\aggregator\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\views\Entity\View;
|
||||
|
||||
/**
|
||||
|
@ -69,8 +68,8 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Visit that page.
|
||||
$this->drupalGet($feed->toUrl()->getInternalPath());
|
||||
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => $feed->label()]);
|
||||
$this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
|
||||
// Verify that aggregator feed page is available and has the correct title.
|
||||
$this->assertSession()->elementTextContains('xpath', '//h1', $feed->label());
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
|
||||
|
@ -102,18 +101,15 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Check for presence of an aggregator pager.
|
||||
$this->drupalGet('aggregator');
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
|
||||
$this->assertSession()->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
|
||||
|
||||
// Check for sources page title.
|
||||
$this->drupalGet('aggregator/sources');
|
||||
$titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => 'Sources']);
|
||||
$this->assertTrue(!empty($titles), 'Source page contains correct title.');
|
||||
$this->assertSession()->elementTextContains('xpath', '//h1', 'Sources');
|
||||
|
||||
// Find the expected read_more link on the sources page.
|
||||
$href = $feed->toUrl()->toString();
|
||||
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
|
||||
$this->assertTrue(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href]));
|
||||
$this->assertSession()->linkByHrefExists($href);
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
|
||||
|
||||
// Check the rss aggregator page as anonymous user.
|
||||
|
@ -140,8 +136,7 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Check for the presence of a pager.
|
||||
$this->drupalGet('aggregator/sources/' . $feed->id());
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
|
||||
$this->assertSession()->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
|
||||
|
|
Loading…
Reference in New Issue