From 1c0a7fcc68fda108486050081455495d41a46eef Mon Sep 17 00:00:00 2001 From: GoZ Date: Tue, 21 Mar 2017 17:31:23 +0100 Subject: [PATCH] Issue #2757023 by claudiu.cristea, jibran, Jo Fitzgerald: Convert all aggregator web tests to BrowserTestBase --- .../Tests => tests/src/Functional}/AddFeedTest.php | 8 +++- .../src/Functional}/AggregatorAdminTest.php | 15 ++++--- .../src/Functional}/AggregatorCronTest.php | 7 +++- .../src/Functional}/AggregatorRenderingTest.php | 14 ++++--- .../src/Functional}/FeedAdminDisplayTest.php | 2 +- .../src/Functional}/FeedLanguageTest.php | 5 ++- .../src/Functional}/UpdateFeedItemTest.php | 3 +- .../src/Functional}/UpdateFeedTest.php | 2 +- .../Drupal/Tests/Traits/Core/MetaRefreshTrait.php | 48 ++++++++++++++++++++++ 9 files changed, 86 insertions(+), 18 deletions(-) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/AddFeedTest.php (92%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/AggregatorAdminTest.php (83%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/AggregatorCronTest.php (93%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/AggregatorRenderingTest.php (91%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/FeedAdminDisplayTest.php (98%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/FeedLanguageTest.php (95%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/UpdateFeedItemTest.php (98%) rename core/modules/aggregator/{src/Tests => tests/src/Functional}/UpdateFeedTest.php (97%) create mode 100644 core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php diff --git a/core/modules/aggregator/src/Tests/AddFeedTest.php b/core/modules/aggregator/tests/src/Functional/AddFeedTest.php similarity index 92% rename from core/modules/aggregator/src/Tests/AddFeedTest.php rename to core/modules/aggregator/tests/src/Functional/AddFeedTest.php index 4dfeb95..426aeab 100644 --- a/core/modules/aggregator/src/Tests/AddFeedTest.php +++ b/core/modules/aggregator/tests/src/Functional/AddFeedTest.php @@ -1,6 +1,8 @@ assertNoRaw('Test feed title '); // Ensure the feed icon title is escaped. - $this->assertTrue(strpos(str_replace(["\n", "\r"], '', $this->getRawContent()), 'class="feed-icon"> Subscribe to Test feed title <script>alert(123);</script> feed') !== FALSE); + $this->assertTrue(strpos(str_replace(["\n", "\r"], '', $this->getSession()->getPage()->getContent()), 'class="feed-icon"> Subscribe to Test feed title <script>alert(123);</script> feed') !== FALSE); } /** diff --git a/core/modules/aggregator/src/Tests/AggregatorAdminTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php similarity index 83% rename from core/modules/aggregator/src/Tests/AggregatorAdminTest.php rename to core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php index 01898b6..00dece1 100644 --- a/core/modules/aggregator/src/Tests/AggregatorAdminTest.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php @@ -1,6 +1,6 @@ assertEqual(1, count($result), 'Created feed is found in the overview'); // Check if the fields in the table match with what's expected. - $this->assertEqual($feed->label(), (string) $result[0]->td[0]->a); + $link = $this->xpath('//table/tbody/tr//td[1]/a'); + $this->assertEquals($feed->label(), $link[0]->getText()); $count = $this->container->get('entity.manager')->getStorage('aggregator_item')->getItemCount($feed); - $this->assertEqual(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), (string) $result[0]->td[1]); + $td = $this->xpath('//table/tbody/tr//td[2]'); + $this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText()); // Update the items of the first feed. $feed->refreshItems(); $this->drupalGet('admin/config/services/aggregator'); - $result = $this->xpath('//table/tbody/tr'); // Check if the fields in the table match with what's expected. - $this->assertEqual($feed->label(), (string) $result[0]->td[0]->a); + $link = $this->xpath('//table/tbody/tr//td[1]/a'); + $this->assertEquals($feed->label(), $link[0]->getText()); $count = $this->container->get('entity.manager')->getStorage('aggregator_item')->getItemCount($feed); - $this->assertEqual(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), (string) $result[0]->td[1]); + $td = $this->xpath('//table/tbody/tr//td[2]'); + $this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText()); } } diff --git a/core/modules/aggregator/src/Tests/AggregatorCronTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php similarity index 93% rename from core/modules/aggregator/src/Tests/AggregatorCronTest.php rename to core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php index 9ebb2d2..bb7c90a 100644 --- a/core/modules/aggregator/src/Tests/AggregatorCronTest.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php @@ -1,6 +1,8 @@ drupalGet('aggregator/opml'); - $outline = $this->xpath('//outline[1]'); - $this->assertEqual($outline[0]['type'], 'rss', 'The correct type attribute is used for rss OPML.'); - $this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for rss OPML.'); - $this->assertEqual($outline[0]['xmlurl'], $feed->getUrl(), 'The correct xmlUrl attribute is used for rss OPML.'); + $content = $this->getSession()->getPage()->getContent(); + // We can't use Mink xpath queries here because it only supports HTML pages, + // but we are dealing with XML here. + $xml = simplexml_load_string($content); + $attributes = $xml->xpath('//outline[1]')[0]->attributes(); + $this->assertEquals('rss', $attributes->type); + $this->assertEquals($feed->label(), $attributes->text); + $this->assertEquals($feed->getUrl(), $attributes->xmlUrl); // Check for the presence of a pager. $this->drupalGet('aggregator/sources/' . $feed->id()); diff --git a/core/modules/aggregator/src/Tests/FeedAdminDisplayTest.php b/core/modules/aggregator/tests/src/Functional/FeedAdminDisplayTest.php similarity index 98% rename from core/modules/aggregator/src/Tests/FeedAdminDisplayTest.php rename to core/modules/aggregator/tests/src/Functional/FeedAdminDisplayTest.php index 0dbb872..b6be97b 100644 --- a/core/modules/aggregator/src/Tests/FeedAdminDisplayTest.php +++ b/core/modules/aggregator/tests/src/Functional/FeedAdminDisplayTest.php @@ -1,6 +1,6 @@ cssSelect('meta[http-equiv="Refresh"]'); + if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) { + // Parse the content attribute of the meta tag for the format: + // "[delay]: URL=[page_to_redirect_to]". + if (preg_match('/\d+;\s*URL=(?.*)/i', $refresh[0]->getAttribute('content'), $match)) { + $this->metaRefreshCount++; + return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url']))); + } + } + return FALSE; + } + +} -- 2.8.1