comparison core/modules/rdf/tests/src/Functional/CommentAttributesTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\rdf\Functional; 3 namespace Drupal\Tests\rdf\Functional;
4 4
5 use Drupal\Core\Url;
5 use Drupal\comment\CommentInterface; 6 use Drupal\comment\CommentInterface;
6 use Drupal\comment\CommentManagerInterface; 7 use Drupal\comment\CommentManagerInterface;
7 use Drupal\Tests\comment\Functional\CommentTestBase; 8 use Drupal\Tests\comment\Functional\CommentTestBase;
8 use Drupal\user\RoleInterface; 9 use Drupal\user\RoleInterface;
9 use Drupal\comment\Entity\Comment; 10 use Drupal\comment\Entity\Comment;
44 'access comments' => TRUE, 45 'access comments' => TRUE,
45 'post comments' => TRUE, 46 'post comments' => TRUE,
46 'skip comment approval' => TRUE, 47 'skip comment approval' => TRUE,
47 ]); 48 ]);
48 // Allows anonymous to leave their contact information. 49 // Allows anonymous to leave their contact information.
49 $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT); 50 $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);
50 $this->setCommentPreview(DRUPAL_OPTIONAL); 51 $this->setCommentPreview(DRUPAL_OPTIONAL);
51 $this->setCommentForm(TRUE); 52 $this->setCommentForm(TRUE);
52 $this->setCommentSubject(TRUE); 53 $this->setCommentSubject(TRUE);
53 $this->setCommentSettings('comment_default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.'); 54 $this->setCommentSettings('comment_default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
54 55
55 // Prepares commonly used URIs. 56 // Prepares commonly used URIs.
56 $this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]); 57 $this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
57 $this->nodeUri = $this->node->url('canonical', ['absolute' => TRUE]); 58 $this->nodeUri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString();
58 59
59 // Set relation between node and comment. 60 // Set relation between node and comment.
60 $article_mapping = rdf_get_mapping('node', 'article'); 61 $article_mapping = rdf_get_mapping('node', 'article');
61 $comment_count_mapping = [ 62 $comment_count_mapping = [
62 'properties' => ['sioc:num_replies'], 63 'properties' => ['sioc:num_replies'],
152 $this->drupalLogin($this->webUser); 153 $this->drupalLogin($this->webUser);
153 154
154 // Ensure that the author link still works properly after the author output 155 // Ensure that the author link still works properly after the author output
155 // is modified by the RDF module. 156 // is modified by the RDF module.
156 $this->drupalGet('node/' . $this->node->id()); 157 $this->drupalGet('node/' . $this->node->id());
157 $this->assertLink($this->webUser->getUsername()); 158 $this->assertLink($this->webUser->getAccountName());
158 $this->assertLinkByHref('user/' . $this->webUser->id()); 159 $this->assertLinkByHref('user/' . $this->webUser->id());
159 } 160 }
160 161
161 /** 162 /**
162 * Tests if RDFa markup for meta information is present in comments. 163 * Tests if RDFa markup for meta information is present in comments.
209 public function testCommentReplyOfRdfaMarkup() { 210 public function testCommentReplyOfRdfaMarkup() {
210 // Posts comment #1 on behalf of registered user. 211 // Posts comment #1 on behalf of registered user.
211 $this->drupalLogin($this->webUser); 212 $this->drupalLogin($this->webUser);
212 $comment_1 = $this->saveComment($this->node->id(), $this->webUser->id()); 213 $comment_1 = $this->saveComment($this->node->id(), $this->webUser->id());
213 214
214 $comment_1_uri = $comment_1->url('canonical', ['absolute' => TRUE]); 215 $comment_1_uri = $comment_1->toUrl('canonical', ['absolute' => TRUE])->toString();
215 216
216 // Posts a reply to the first comment. 217 // Posts a reply to the first comment.
217 $comment_2 = $this->saveComment($this->node->id(), $this->webUser->id(), NULL, $comment_1->id()); 218 $comment_2 = $this->saveComment($this->node->id(), $this->webUser->id(), NULL, $comment_1->id());
218 $comment_2_uri = $comment_2->url('canonical', ['absolute' => TRUE]); 219 $comment_2_uri = $comment_2->toUrl('canonical', ['absolute' => TRUE])->toString();
219 220
220 $parser = new \EasyRdf_Parser_Rdfa(); 221 $parser = new \EasyRdf_Parser_Rdfa();
221 $graph = new \EasyRdf_Graph(); 222 $graph = new \EasyRdf_Graph();
222 $parser->parse($graph, $this->drupalGet('node/' . $this->node->id()), 'rdfa', $this->baseUri); 223 $parser->parse($graph, $this->drupalGet('node/' . $this->node->id()), 'rdfa', $this->baseUri);
223 224
250 * Comment object. 251 * Comment object.
251 * @param $account 252 * @param $account
252 * An array containing information about an anonymous user. 253 * An array containing information about an anonymous user.
253 */ 254 */
254 public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $account = []) { 255 public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $account = []) {
255 $comment_uri = $comment->url('canonical', ['absolute' => TRUE]); 256 $comment_uri = $comment->toUrl('canonical', ['absolute' => TRUE])->toString();
256 257
257 // Comment type. 258 // Comment type.
258 $expected_value = [ 259 $expected_value = [
259 'type' => 'uri', 260 'type' => 'uri',
260 'value' => 'http://rdfs.org/sioc/types#Comment', 261 'value' => 'http://rdfs.org/sioc/types#Comment',
276 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Comment subject found in RDF output (dc:title).'); 277 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Comment subject found in RDF output (dc:title).');
277 278
278 // Comment date. 279 // Comment date.
279 $expected_value = [ 280 $expected_value = [
280 'type' => 'literal', 281 'type' => 'literal',
281 'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'), 282 'value' => $this->container->get('date.formatter')->format($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
282 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', 283 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
283 ]; 284 ];
284 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Comment date found in RDF output (dc:date).'); 285 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Comment date found in RDF output (dc:date).');
285 // Comment date. 286 // Comment date.
286 $expected_value = [ 287 $expected_value = [
287 'type' => 'literal', 288 'type' => 'literal',
288 'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'), 289 'value' => $this->container->get('date.formatter')->format($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
289 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime', 290 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
290 ]; 291 ];
291 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Comment date found in RDF output (dc:created).'); 292 $this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Comment date found in RDF output (dc:created).');
292 293
293 // Comment body. 294 // Comment body.
298 ]; 299 ];
299 $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).'); 300 $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).');
300 301
301 // The comment author can be a registered user or an anonymous user. 302 // The comment author can be a registered user or an anonymous user.
302 if ($comment->getOwnerId() > 0) { 303 if ($comment->getOwnerId() > 0) {
303 $author_uri = \Drupal::url('entity.user.canonical', ['user' => $comment->getOwnerId()], ['absolute' => TRUE]); 304 $author_uri = Url::fromRoute('entity.user.canonical', ['user' => $comment->getOwnerId()], ['absolute' => TRUE])->toString();
304 // Comment relation to author. 305 // Comment relation to author.
305 $expected_value = [ 306 $expected_value = [
306 'type' => 'uri', 307 'type' => 'uri',
307 'value' => $author_uri, 308 'value' => $author_uri,
308 ]; 309 ];
318 $this->fail('Comment relation to author found in RDF output (sioc:has_creator).'); 319 $this->fail('Comment relation to author found in RDF output (sioc:has_creator).');
319 } 320 }
320 } 321 }
321 322
322 // Author name. 323 // Author name.
323 $name = empty($account["name"]) ? $this->webUser->getUsername() : $account["name"] . " (not verified)"; 324 $name = empty($account["name"]) ? $this->webUser->getAccountName() : $account["name"] . " (not verified)";
324 $expected_value = [ 325 $expected_value = [
325 'type' => 'literal', 326 'type' => 'literal',
326 'value' => $name, 327 'value' => $name,
327 ]; 328 ];
328 $this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'Comment author name found in RDF output (foaf:name).'); 329 $this->assertTrue($graph->hasProperty($author_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'Comment author name found in RDF output (foaf:name).');