#933856: Make xpath() return value consistent.

From: Damien Tournoud <damien@commerceguys.com>


---
 rdf/rdf.test                        |    9 +++++----
 simpletest/drupal_web_test_case.php |    6 +++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git modules/rdf/rdf.test modules/rdf/rdf.test
index f0b83a5..797b5b9 100644
--- modules/rdf/rdf.test
+++ modules/rdf/rdf.test
@@ -511,9 +511,9 @@ class RdfCommentAttributesTestCase extends CommentHelperCase {
     $comments[] = $this->postComment($this->node1, $this->randomName(), $this->randomName());
 
     // Tests the reply_of relationship of a first level comment.
-    $result = $this->xpath("id('comments')//div[@class='comment' and position()=0]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
+    $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
     $this->assertEqual(1, count($result), t('RDFa markup referring to the node is present.'));
-    $result = $this->xpath("id('comments')//div[@class='comment' and position()=0]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
+    $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
     $this->assertFalse($result, t('No RDFa markup referring to the comment itself is present.'));
 
     // Posts a reply to the first comment.
@@ -521,10 +521,11 @@ class RdfCommentAttributesTestCase extends CommentHelperCase {
     $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
 
     // Tests the reply_of relationship of a second level comment.
-    $result = $this->xpath("id('comments')//div[@class='comment' and position()=1]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
+    $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
     $this->assertEqual(1, count($result), t('RDFa markup referring to the node is present.'));
-    $result = $this->xpath("id('comments')//div[@class='comment' and position()=1]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
+    $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1', array('fragment' => 'comment-1'))));
     $this->assertEqual(1, count($result), t('RDFa markup referring to the parent comment is present.'));
+    $comments = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]");
   }
 
   /**
diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php
index 3355fc2..8f4164c 100644
--- modules/simpletest/drupal_web_test_case.php
+++ modules/simpletest/drupal_web_test_case.php
@@ -2180,7 +2180,11 @@ class DrupalWebTestCase extends DrupalTestCase {
   protected function xpath($xpath, array $arguments = array()) {
     if ($this->parse()) {
       $xpath = $this->buildXPathQuery($xpath, $arguments);
-      return $this->elements->xpath($xpath);
+      $result = $this->elements->xpath($xpath);
+      // Some combinaisons of PHP / libxml versions return an empty array
+      // instead of the documented FALSE. Forcefully convert any falsish values
+      // to an empty array to allow foreach(...) constructions.
+      return $result ? $result : array();
     }
     else {
       return FALSE;
