Follow up to #2863267: Convert web tests of views

Convert \Drupal\views\Tests\Plugin\StyleOpmlTest and \Drupal\views\Tests\Plugin\DisplayFeedTest to PHPUnit tests. Both these tests use a non-HTML page, so special steps need to be taken to account for that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude created an issue. See original summary.

Lendude’s picture

Lendude’s picture

Status: Active » Needs review
FileSize
8.19 KB

$this->getSession()->getDriver()->getAttribute() / $this->getSession()->getDriver()->getText() seems like the way forward here.

dawehner’s picture

I'm wondering whether really relying on these methods is the right idea. Maybe parsing the XML explicit is the right way to go.

michielnugter’s picture

Status: Needs review » Needs work

I actually think this is ok (at least for now). If we decide this is not the way to test XML responses we should do a follow-up, we should ask the rest maintainers I think as they deal with non-HTML responses I can imagine.

For this issue: This is about converting it as directly as possible and currently this is the only method to use Mink to get to a non-//html element (that I know of).

Review:

+++ b/core/modules/views/tests/src/Functional/Plugin/StyleOpmlTest.php
@@ -52,10 +54,9 @@ public function testOpmlOutput() {
-    $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.');
+    $this->assertEquals('rss', $this->getSession()->getDriver()->getAttribute('//outline[1]', 'type'));
+    $this->assertEquals($feed->label(), $this->getSession()->getDriver()->getAttribute('//outline[1]', 'text'));
+    $this->assertEquals($feed->getUrl(), $this->getSession()->getDriver()->getAttribute('//outline[1]', 'xmlUrl'));

@@ -66,12 +67,11 @@ public function testOpmlOutput() {
-    $outline = $this->xpath('//outline[1]');
-    $this->assertEqual($outline[0]['type'], 'link', 'The correct type attribute is used for link OPML.');
-    $this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for link OPML.');
-    $this->assertEqual($outline[0]['url'], $feed->getUrl(), 'The correct URL attribute is used for link OPML.');
+    $this->assertEquals('link', $this->getSession()->getDriver()->getAttribute('//outline[1]', 'type'));
+    $this->assertEquals($feed->label(), $this->getSession()->getDriver()->getAttribute('//outline[1]', 'text'));
+    $this->assertEquals($feed->getUrl(), $this->getSession()->getDriver()->getAttribute('//outline[1]', 'url'));

Could we use:
$element = $this->getSession()->getDriver()->find('xpath');

here and getAttribute on the returned NodeElement? Would make it a little more efficient and more similar to what it was.

dawehner’s picture

In general I prefer explicitness over implicitness, so parsing XML explicit rather than relying that it sort of works, feels better.

michielnugter’s picture

Discussed with @lendude offline and we agreed that finding out the proper way of testing an XML response is in scope for this issue as it's already a follow-up.

Let's figure it out. Maybe we should talk/borrow from the rest team.

dawehner’s picture

Discussed with @lendude offline and we agreed that finding out the proper way of testing an XML response is in scope for this issue as it's already a follow-up.

Sure, you know, we can always iterate later.

michielnugter’s picture

Might this issue be an interesting way to go forward for this?

#2812967: API test base: Provide a test helper to test REST and similar APIs

dawehner’s picture

Might this issue be an interesting way to go forward for this?

You are right, it would be probably a potential usage for it.

Lendude’s picture

Status: Needs work » Postponed
Related issues: +#2812967: API test base: Provide a test helper to test REST and similar APIs

Ok lets postpone on #2812967: API test base: Provide a test helper to test REST and similar APIs for now, using something like that would certainly be the best way to go.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Lendude’s picture

Status: Postponed » Needs review
FileSize
7.41 KB

Reroll.

If we ever get an API to better test XML stuff, we can always refactor this test to use then, lets not wait for that. Until then, this works, right?

Implemented feedback from #5 (better late then never :D)

Status: Needs review » Needs work

The last submitted patch, 15: 2876211-15.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Needs review
FileSize
449 bytes
7.48 KB

Whoops

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/tests/src/Functional/Plugin/StyleOpmlTest.php
@@ -66,12 +68,12 @@ public function testOpmlOutput() {
-    $this->assertEqual($outline[0]['url'], $feed->getUrl(), 'The correct URL attribute is used for link OPML.');
...
+    $this->assertEquals($feed->getUrl(), $outline->getAttribute('url'));

I really like the better API

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 5f2605fe4c to 8.7.x and 6ddb9ed89b to 8.6.x. Thanks!

+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
@@ -136,8 +134,8 @@ public function testDisabledFeed() {
+    $this->assertTrue(strpos($feed_header[0]->getAttribute('href'), 'test-attached-disabled.xml'), 'Page display contains the correct feed URL.');

FYI This is better written as assertContains() but let's not delay on such improvements.

  • alexpott committed 5f2605f on 8.7.x
    Issue #2876211 by Lendude, dawehner, michielnugter: Convert \Drupal\...

  • alexpott committed 6ddb9ed on 8.6.x
    Issue #2876211 by Lendude, dawehner, michielnugter: Convert \Drupal\...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.