Exemple #1
0
 /**
  * Checks current page for specified comment.
  *
  * @param \Drupal\comment\CommentInterface $comment
  *   The comment object.
  * @param bool $reply
  *   Boolean indicating whether the comment is a reply to another comment.
  *
  * @return bool
  *   Boolean indicating whether the comment was found.
  */
 function commentExists(CommentInterface $comment = NULL, $reply = FALSE)
 {
     if ($comment) {
         $comment_element = $this->cssSelect('.comment-wrapper ' . ($reply ? '.indented ' : '') . '#comment-' . $comment->id() . ' ~ article');
         if (empty($comment_element)) {
             return FALSE;
         }
         $comment_title = $comment_element[0]->xpath('div/h3/a');
         if (empty($comment_title) || (string) $comment_title[0] !== $comment->getSubject()) {
             return FALSE;
         }
         $comment_body = $comment_element[0]->xpath('div/div/p');
         if (empty($comment_body) || (string) $comment_body[0] !== $comment->comment_body->value) {
             return FALSE;
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Checks current page for specified comment.
  *
  * @param \Drupal\comment\CommentInterface $comment
  *   The comment object.
  * @param bool $reply
  *   Boolean indicating whether the comment is a reply to another comment.
  *
  * @return bool
  *   Boolean indicating whether the comment was found.
  */
 function commentExists(CommentInterface $comment = NULL, $reply = FALSE)
 {
     if ($comment) {
         $regex = '!' . ($reply ? '<div class="indented">(.*?)' : '');
         $regex .= '<a id="comment-' . $comment->id() . '"(.*?)';
         $regex .= $comment->getSubject() . '(.*?)';
         $regex .= $comment->comment_body->value . '(.*?)';
         $regex .= $reply ? '</article>\\s</div>(.*?)' : '';
         $regex .= '!s';
         return (bool) preg_match($regex, $this->getRawContent());
     } else {
         return FALSE;
     }
 }
 /**
  * Helper function for testCommentRdfaMarkup().
  *
  * Tests the current page for basic comment RDFa markup.
  *
  * @param $comment
  *   Comment object.
  * @param $account
  *   An array containing information about an anonymous user.
  */
 function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $account = array())
 {
     $comment_uri = $comment->url('canonical', array('absolute' => TRUE));
     // Comment type.
     $expected_value = array('type' => 'uri', 'value' => 'http://rdfs.org/sioc/types#Comment');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioct:Comment).');
     // Comment type.
     $expected_value = array('type' => 'uri', 'value' => 'http://rdfs.org/sioc/ns#Post');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Comment type found in RDF output (sioc:Post).');
     // Comment title.
     $expected_value = array('type' => 'literal', 'value' => $comment->getSubject(), 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Comment subject found in RDF output (dc:title).');
     // Comment date.
     $expected_value = array('type' => 'literal', 'value' => date('c', $comment->getCreatedTime()), 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Comment date found in RDF output (dc:date).');
     // Comment date.
     $expected_value = array('type' => 'literal', 'value' => date('c', $comment->getCreatedTime()), 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Comment date found in RDF output (dc:created).');
     // Comment body.
     $expected_value = array('type' => 'literal', 'value' => $comment->comment_body->value . "\n", 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/rss/1.0/modules/content/encoded', $expected_value), 'Comment body found in RDF output (content:encoded).');
     // The comment author can be a registered user or an anonymous user.
     if ($comment->getOwnerId() > 0) {
         $author_uri = url('user/' . $comment->getOwnerId(), array('absolute' => TRUE));
         // Comment relation to author.
         $expected_value = array('type' => 'uri', 'value' => $author_uri);
         $this->assertTrue($graph->hasProperty($comment_uri, 'http://rdfs.org/sioc/ns#has_creator', $expected_value), 'Comment relation to author found in RDF output (sioc:has_creator).');
     } else {
         // The author is expected to be a blank node.
         $author_uri = $graph->get($comment_uri, '<http://rdfs.org/sioc/ns#has_creator>');
         if ($author_uri instanceof \EasyRdf_Resource) {
             $this->assertTrue($author_uri->isBnode(), 'Comment relation to author found in RDF output (sioc:has_creator) and author is blank node.');
         } else {
             $this->fail('Comment relation to author found in RDF output (sioc:has_creator).');
         }
     }
     // Author name.
     $name = empty($account["name"]) ? $this->web_user->getUsername() : $account["name"] . " (not verified)";
     $expected_value = array('type' => 'literal', 'value' => $name);
     $this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'Comment author name found in RDF output (foaf:name).');
     // Comment author homepage (only for anonymous authors).
     if ($comment->getOwnerId() == 0) {
         $expected_value = array('type' => 'uri', 'value' => 'http://example.org/');
         $this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/page', $expected_value), 'Comment author link found in RDF output (foaf:page).');
     }
 }