annotate core/modules/rdf/tests/src/Functional/StandardProfileTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\rdf\Functional;
Chris@0 4
Chris@0 5 use Drupal\Core\Url;
Chris@0 6 use Drupal\file\Entity\File;
Chris@0 7 use Drupal\image\Entity\ImageStyle;
Chris@0 8 use Drupal\node\Entity\NodeType;
Chris@0 9 use Drupal\node\NodeInterface;
Chris@0 10 use Drupal\Tests\BrowserTestBase;
Chris@0 11 use Drupal\comment\Entity\Comment;
Chris@0 12 use Drupal\taxonomy\Entity\Term;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Tests the RDF mappings and RDFa markup of the standard profile.
Chris@0 16 *
Chris@0 17 * @group rdf
Chris@0 18 */
Chris@0 19 class StandardProfileTest extends BrowserTestBase {
Chris@0 20
Chris@0 21 /**
Chris@0 22 * The profile used during tests.
Chris@0 23 *
Chris@0 24 * This purposefully uses the standard profile.
Chris@0 25 *
Chris@0 26 * @var string
Chris@0 27 */
Chris@0 28 public $profile = 'standard';
Chris@0 29
Chris@0 30 /**
Chris@0 31 * @var string
Chris@0 32 */
Chris@0 33 protected $baseUri;
Chris@0 34
Chris@0 35 /**
Chris@0 36 * @var \Drupal\user\UserInterface
Chris@0 37 */
Chris@0 38 protected $adminUser;
Chris@0 39
Chris@0 40 /**
Chris@0 41 * @var \Drupal\user\UserInterface
Chris@0 42 */
Chris@0 43 protected $webUser;
Chris@0 44
Chris@0 45 /**
Chris@0 46 * @var \Drupal\taxonomy\TermInterface
Chris@0 47 */
Chris@0 48 protected $term;
Chris@0 49
Chris@0 50 /**
Chris@0 51 * @var \Drupal\file\FileInterface
Chris@0 52 */
Chris@0 53 protected $image;
Chris@0 54
Chris@0 55 /**
Chris@0 56 * @var \Drupal\node\NodeInterface
Chris@0 57 */
Chris@0 58 protected $article;
Chris@0 59
Chris@0 60 /**
Chris@0 61 * @var \Drupal\comment\CommentInterface
Chris@0 62 */
Chris@0 63 protected $articleComment;
Chris@0 64
Chris@0 65 /**
Chris@0 66 * @var \Drupal\node\NodeInterface
Chris@0 67 */
Chris@0 68 protected $page;
Chris@0 69
Chris@0 70 /**
Chris@0 71 * @var string
Chris@0 72 */
Chris@0 73 protected $imageUri;
Chris@0 74
Chris@0 75 /**
Chris@0 76 * @var string
Chris@0 77 */
Chris@0 78 protected $termUri;
Chris@0 79
Chris@0 80 /**
Chris@0 81 * @var string
Chris@0 82 */
Chris@0 83 protected $articleUri;
Chris@0 84
Chris@0 85 /**
Chris@0 86 * @var string
Chris@0 87 */
Chris@0 88 protected $pageUri;
Chris@0 89
Chris@0 90 /**
Chris@0 91 * @var string
Chris@0 92 */
Chris@0 93 protected $authorUri;
Chris@0 94
Chris@0 95 /**
Chris@0 96 * @var string
Chris@0 97 */
Chris@0 98 protected $articleCommentUri;
Chris@0 99
Chris@0 100 /**
Chris@0 101 * @var string
Chris@0 102 */
Chris@0 103 protected $commenterUri;
Chris@0 104
Chris@0 105 protected function setUp() {
Chris@0 106 parent::setUp();
Chris@0 107
Chris@0 108 // Use Classy theme for testing markup output.
Chris@0 109 \Drupal::service('theme_handler')->install(['classy']);
Chris@0 110 $this->config('system.theme')->set('default', 'classy')->save();
Chris@0 111
Chris@18 112 $this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
Chris@0 113
Chris@0 114 // Create two test users.
Chris@0 115 $this->adminUser = $this->drupalCreateUser([
Chris@0 116 'administer content types',
Chris@0 117 'administer comments',
Chris@0 118 'access comments',
Chris@0 119 'access content',
Chris@0 120 ]);
Chris@0 121 $this->webUser = $this->drupalCreateUser([
Chris@0 122 'access comments',
Chris@0 123 'post comments',
Chris@0 124 'skip comment approval',
Chris@0 125 'access content',
Chris@0 126 ]);
Chris@0 127
Chris@0 128 $this->drupalLogin($this->adminUser);
Chris@0 129
Chris@0 130 // Create term.
Chris@0 131 $this->term = Term::create([
Chris@0 132 'name' => $this->randomMachineName(),
Chris@0 133 'description' => $this->randomMachineName(),
Chris@0 134 'vid' => 'tags',
Chris@0 135 ]);
Chris@0 136 $this->term->save();
Chris@0 137
Chris@0 138 // Create image.
Chris@18 139 \Drupal::service('file_system')->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
Chris@0 140 $this->image = File::create(['uri' => 'public://example.jpg']);
Chris@0 141 $this->image->save();
Chris@0 142
Chris@0 143 // Create article.
Chris@0 144 $article_settings = [
Chris@0 145 'type' => 'article',
Chris@0 146 'promote' => NodeInterface::PROMOTED,
Chris@0 147 'field_image' => [
Chris@0 148 [
Chris@0 149 'target_id' => $this->image->id(),
Chris@0 150 ],
Chris@0 151 ],
Chris@0 152 'field_tags' => [
Chris@0 153 [
Chris@0 154 'target_id' => $this->term->id(),
Chris@0 155 ],
Chris@0 156 ],
Chris@0 157 ];
Chris@0 158 $this->article = $this->drupalCreateNode($article_settings);
Chris@0 159 // Create second article to test teaser list.
Chris@0 160 $this->drupalCreateNode(['type' => 'article', 'promote' => NodeInterface::PROMOTED]);
Chris@0 161
Chris@0 162 // Create article comment.
Chris@0 163 $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
Chris@0 164
Chris@0 165 // Create page.
Chris@0 166 $this->page = $this->drupalCreateNode(['type' => 'page']);
Chris@0 167
Chris@0 168 // Set URIs.
Chris@0 169 // Image.
Chris@0 170 $image_file = $this->article->get('field_image')->entity;
Chris@0 171 $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri());
Chris@0 172 // Term.
Chris@18 173 $this->termUri = $this->term->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 174 // Article.
Chris@18 175 $this->articleUri = $this->article->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 176 // Page.
Chris@18 177 $this->pageUri = $this->page->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 178 // Author.
Chris@18 179 $this->authorUri = $this->adminUser->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 180 // Comment.
Chris@18 181 $this->articleCommentUri = $this->articleComment->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 182 // Commenter.
Chris@18 183 $this->commenterUri = $this->webUser->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 184
Chris@0 185 $this->drupalLogout();
Chris@0 186 }
Chris@0 187
Chris@0 188 /**
Chris@0 189 * Tests that data is exposed correctly when using standard profile.
Chris@0 190 *
Chris@0 191 * Because tests using standard profile take a very long time to run, and
Chris@0 192 * because there is no manipulation of config or data within the test, simply
Chris@0 193 * run all the tests from within this function.
Chris@0 194 */
Chris@0 195 public function testRdfaOutput() {
Chris@0 196 $this->doFrontPageRdfaTests();
Chris@0 197 $this->doArticleRdfaTests();
Chris@0 198 $this->doPageRdfaTests();
Chris@0 199 $this->doUserRdfaTests();
Chris@0 200 $this->doTermRdfaTests();
Chris@0 201 }
Chris@0 202
Chris@0 203 /**
Chris@0 204 * Tests that data is exposed in the front page teasers.
Chris@0 205 */
Chris@0 206 protected function doFrontPageRdfaTests() {
Chris@0 207 // Feed the HTML into the parser.
Chris@0 208 $graph = $this->getRdfGraph(Url::fromRoute('<front>'));
Chris@0 209
Chris@0 210 // Ensure that both articles are listed.
Chris@0 211 $this->assertEqual(2, count($graph->allOfType('http://schema.org/Article')), 'Two articles found on front page.');
Chris@0 212
Chris@0 213 // Test interaction count.
Chris@0 214 $expected_value = [
Chris@0 215 'type' => 'literal',
Chris@0 216 'value' => 'UserComments:1',
Chris@0 217 'lang' => 'en',
Chris@0 218 ];
Chris@0 219 $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/interactionCount', $expected_value), "Teaser comment count was found (schema:interactionCount).");
Chris@0 220
Chris@0 221 // Test the properties that are common between pages and articles and are
Chris@0 222 // displayed in full and teaser mode.
Chris@0 223 $this->assertRdfaCommonNodeProperties($graph, $this->article, "Teaser");
Chris@0 224 // Test properties that are displayed in both teaser and full mode.
Chris@0 225 $this->assertRdfaArticleProperties($graph, "Teaser");
Chris@0 226
Chris@0 227 // @todo Once the image points to the original instead of the processed
Chris@0 228 // image, move this to testArticleProperties().
Chris@0 229 $image_file = $this->article->get('field_image')->entity;
Chris@0 230 $image_uri = ImageStyle::load('medium')->buildUrl($image_file->getFileUri());
Chris@0 231 $expected_value = [
Chris@0 232 'type' => 'uri',
Chris@0 233 'value' => $image_uri,
Chris@0 234 ];
Chris@0 235 $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/image', $expected_value), "Teaser image was found (schema:image).");
Chris@0 236 }
Chris@0 237
Chris@0 238 /**
Chris@0 239 * Tests that article data is exposed using RDFa.
Chris@0 240 *
Chris@0 241 * Two fields are not tested for output here. Changed date is not displayed
Chris@0 242 * on the page, so there is no test for output in node view. Comment count is
Chris@0 243 * displayed in teaser view, so it is tested in the front article tests.
Chris@0 244 */
Chris@0 245 protected function doArticleRdfaTests() {
Chris@0 246 // Feed the HTML into the parser.
Chris@18 247 $graph = $this->getRdfGraph($this->article->toUrl());
Chris@0 248
Chris@0 249 // Type.
Chris@0 250 $this->assertEqual($graph->type($this->articleUri), 'schema:Article', 'Article type was found (schema:Article).');
Chris@0 251
Chris@0 252 // Test the properties that are common between pages and articles.
Chris@0 253 $this->assertRdfaCommonNodeProperties($graph, $this->article, "Article");
Chris@0 254 // Test properties that are displayed in both teaser and full mode.
Chris@0 255 $this->assertRdfaArticleProperties($graph, "Article");
Chris@0 256 // Test the comment properties displayed on articles.
Chris@0 257 $this->assertRdfaNodeCommentProperties($graph);
Chris@0 258
Chris@0 259 // @todo Once the image points to the original instead of the processed
Chris@0 260 // image, move this to testArticleProperties().
Chris@0 261 $expected_value = [
Chris@0 262 'type' => 'uri',
Chris@0 263 'value' => $this->imageUri,
Chris@0 264 ];
Chris@0 265 $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/image', $expected_value), "Article image was found (schema:image).");
Chris@0 266 }
Chris@0 267
Chris@0 268 /**
Chris@0 269 * Tests that page data is exposed using RDFa.
Chris@0 270 *
Chris@0 271 * Two fields are not tested for output here. Changed date is not displayed
Chris@0 272 * on the page, so there is no test for output in node view. Comment count is
Chris@0 273 * displayed in teaser view, so it is tested in the front page tests.
Chris@0 274 */
Chris@0 275 protected function doPageRdfaTests() {
Chris@0 276 // The standard profile hides the created date on pages. Revert display to
Chris@0 277 // true for testing.
Chris@0 278 // @todo Clean-up standard profile defaults.
Chris@0 279 $node_type = NodeType::load('page');
Chris@0 280 $node_type->setDisplaySubmitted(TRUE);
Chris@0 281 $node_type->save();
Chris@0 282
Chris@0 283 // Feed the HTML into the parser.
Chris@18 284 $graph = $this->getRdfGraph($this->page->toUrl());
Chris@0 285
Chris@0 286 // Type.
Chris@0 287 $this->assertEqual($graph->type($this->pageUri), 'schema:WebPage', 'Page type was found (schema:WebPage).');
Chris@0 288
Chris@0 289 // Test the properties that are common between pages and articles.
Chris@0 290 $this->assertRdfaCommonNodeProperties($graph, $this->page, "Page");
Chris@0 291 }
Chris@0 292
Chris@0 293 /**
Chris@0 294 * Tests that user data is exposed on user page.
Chris@0 295 */
Chris@0 296 protected function doUserRdfaTests() {
Chris@0 297 $this->drupalLogin($this->rootUser);
Chris@0 298
Chris@0 299 // Feed the HTML into the parser.
Chris@18 300 $graph = $this->getRdfGraph($this->adminUser->toUrl());
Chris@0 301
Chris@0 302 // User type.
Chris@0 303 $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "User type was found (schema:Person) on user page.");
Chris@0 304
Chris@0 305 // User name.
Chris@0 306 $expected_value = [
Chris@0 307 'type' => 'literal',
Chris@0 308 'value' => $this->adminUser->label(),
Chris@0 309 ];
Chris@0 310 $this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "User name was found (schema:name) on user page.");
Chris@0 311
Chris@0 312 $this->drupalLogout();
Chris@0 313 }
Chris@0 314
Chris@0 315 /**
Chris@0 316 * Tests that term data is exposed on term page.
Chris@0 317 */
Chris@0 318 protected function doTermRdfaTests() {
Chris@0 319 // Feed the HTML into the parser.
Chris@18 320 $graph = $this->getRdfGraph($this->term->toUrl());
Chris@0 321
Chris@0 322 // Term type.
Chris@0 323 $this->assertEqual($graph->type($this->termUri), 'schema:Thing', "Term type was found (schema:Thing) on term page.");
Chris@0 324
Chris@0 325 // Term name.
Chris@0 326 $expected_value = [
Chris@0 327 'type' => 'literal',
Chris@0 328 'value' => $this->term->getName(),
Chris@0 329 'lang' => 'en',
Chris@0 330 ];
Chris@0 331 $this->assertTrue($graph->hasProperty($this->termUri, 'http://schema.org/name', $expected_value), "Term name was found (schema:name) on term page.");
Chris@0 332
Chris@0 333 // @todo Add test for term description once it is a field:
Chris@0 334 // https://www.drupal.org/node/569434.
Chris@0 335 }
Chris@0 336
Chris@0 337 /**
Chris@0 338 * Tests output for properties held in common between articles and pages.
Chris@0 339 *
Chris@0 340 * @param \EasyRdf_Graph $graph
Chris@0 341 * The EasyRDF graph object.
Chris@0 342 * @param \Drupal\node\NodeInterface $node
Chris@0 343 * The node being displayed.
Chris@0 344 * @param string $message_prefix
Chris@0 345 * The word to use in the test assertion message.
Chris@0 346 */
Chris@0 347 protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix) {
Chris@18 348 $uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString();
Chris@0 349
Chris@0 350 // Title.
Chris@0 351 $expected_value = [
Chris@0 352 'type' => 'literal',
Chris@0 353 'value' => $node->get('title')->value,
Chris@0 354 'lang' => 'en',
Chris@0 355 ];
Chris@0 356 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "$message_prefix title was found (schema:name).");
Chris@0 357
Chris@0 358 // Created date.
Chris@0 359 $expected_value = [
Chris@0 360 'type' => 'literal',
Chris@18 361 'value' => $this->container->get('date.formatter')->format($node->get('created')->value, 'custom', 'c', 'UTC'),
Chris@0 362 'lang' => 'en',
Chris@0 363 ];
Chris@0 364 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "$message_prefix created date was found (schema:dateCreated) in teaser.");
Chris@0 365
Chris@0 366 // Body.
Chris@0 367 $expected_value = [
Chris@0 368 'type' => 'literal',
Chris@0 369 'value' => $node->get('body')->value,
Chris@0 370 'lang' => 'en',
Chris@0 371 ];
Chris@0 372 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/text', $expected_value), "$message_prefix body was found (schema:text) in teaser.");
Chris@0 373
Chris@0 374 // Author.
Chris@0 375 $expected_value = [
Chris@0 376 'type' => 'uri',
Chris@0 377 'value' => $this->authorUri,
Chris@0 378 ];
Chris@0 379 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/author', $expected_value), "$message_prefix author was found (schema:author) in teaser.");
Chris@0 380
Chris@0 381 // Author type.
Chris@0 382 $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "$message_prefix author type was found (schema:Person).");
Chris@0 383
Chris@0 384 // Author name.
Chris@0 385 $expected_value = [
Chris@0 386 'type' => 'literal',
Chris@0 387 'value' => $this->adminUser->label(),
Chris@0 388 ];
Chris@0 389 $this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "$message_prefix author name was found (schema:name).");
Chris@0 390 }
Chris@0 391
Chris@0 392 /**
Chris@0 393 * Tests output for article properties displayed in both view modes.
Chris@0 394 *
Chris@0 395 * @param \EasyRdf_Graph $graph
Chris@0 396 * The EasyRDF graph object.
Chris@0 397 * @param string $message_prefix
Chris@0 398 * The word to use in the test assertion message.
Chris@0 399 */
Chris@0 400 protected function assertRdfaArticleProperties($graph, $message_prefix) {
Chris@0 401 // Tags.
Chris@0 402 $expected_value = [
Chris@0 403 'type' => 'uri',
Chris@0 404 'value' => $this->termUri,
Chris@0 405 ];
Chris@0 406 $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/about', $expected_value), "$message_prefix tag was found (schema:about).");
Chris@0 407
Chris@0 408 // Tag type.
Chris@0 409 // @todo Enable with https://www.drupal.org/node/2072791.
Chris@0 410 // $this->assertEqual($graph->type($this->termUri), 'schema:Thing', 'Tag type was found (schema:Thing).');
Chris@0 411
Chris@0 412 // Tag name.
Chris@0 413 $expected_value = [
Chris@0 414 'type' => 'literal',
Chris@0 415 'value' => $this->term->getName(),
Chris@0 416 'lang' => 'en',
Chris@0 417 ];
Chris@0 418 // @todo Enable with https://www.drupal.org/node/2072791.
Chris@0 419 // $this->assertTrue($graph->hasProperty($this->termUri, 'http://schema.org/name', $expected_value), "$message_prefix name was found (schema:name).");
Chris@0 420 }
Chris@0 421
Chris@0 422 /**
Chris@0 423 * Tests output for comment properties on nodes in full page view mode.
Chris@0 424 *
Chris@0 425 * @param \EasyRdf_Graph $graph
Chris@0 426 * The EasyRDF graph object.
Chris@0 427 */
Chris@0 428 protected function assertRdfaNodeCommentProperties($graph) {
Chris@0 429 // Relationship between node and comment.
Chris@0 430 $expected_value = [
Chris@0 431 'type' => 'uri',
Chris@0 432 'value' => $this->articleCommentUri,
Chris@0 433 ];
Chris@0 434 $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/comment', $expected_value), 'Relationship between node and comment found (schema:comment).');
Chris@0 435
Chris@0 436 // Comment type.
Chris@0 437 $this->assertEqual($graph->type($this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).');
Chris@0 438
Chris@0 439 // Comment title.
Chris@0 440 $expected_value = [
Chris@0 441 'type' => 'literal',
Chris@0 442 'value' => $this->articleComment->get('subject')->value,
Chris@0 443 'lang' => 'en',
Chris@0 444 ];
Chris@0 445 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/name', $expected_value), 'Article comment title was found (schema:name).');
Chris@0 446
Chris@0 447 // Comment created date.
Chris@0 448 $expected_value = [
Chris@0 449 'type' => 'literal',
Chris@18 450 'value' => $this->container->get('date.formatter')->format($this->articleComment->get('created')->value, 'custom', 'c', 'UTC'),
Chris@0 451 'lang' => 'en',
Chris@0 452 ];
Chris@0 453 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).');
Chris@0 454
Chris@0 455 // Comment body.
Chris@0 456 $text = $this->articleComment->get('comment_body')->value;
Chris@0 457 $expected_value = [
Chris@0 458 'type' => 'literal',
Chris@0 459 // There is an extra carriage return in the when parsing comments as
Chris@0 460 // output by Bartik, so it must be added to the expected value.
Chris@0 461 'value' => "$text
Chris@0 462 ",
Chris@0 463 'lang' => 'en',
Chris@0 464 ];
Chris@0 465 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/text', $expected_value), 'Article comment body was found (schema:text).');
Chris@0 466
Chris@0 467 // Comment uid.
Chris@0 468 $expected_value = [
Chris@0 469 'type' => 'uri',
Chris@0 470 'value' => $this->commenterUri,
Chris@0 471 ];
Chris@0 472 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/author', $expected_value), 'Article comment author was found (schema:author).');
Chris@0 473
Chris@0 474 // Comment author type.
Chris@0 475 $this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');
Chris@0 476
Chris@0 477 // Comment author name.
Chris@0 478 $expected_value = [
Chris@0 479 'type' => 'literal',
Chris@18 480 'value' => $this->webUser->getAccountName(),
Chris@0 481 ];
Chris@0 482 $this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).');
Chris@0 483 }
Chris@0 484
Chris@0 485 /**
Chris@0 486 * Creates a comment entity.
Chris@0 487 *
Chris@0 488 * @param int $nid
Chris@0 489 * Node id which will hold the comment.
Chris@0 490 * @param int $uid
Chris@0 491 * User id of the author of the comment. Can be NULL if $contact provided.
Chris@0 492 * @param mixed $contact
Chris@0 493 * Set to NULL for no contact info, TRUE to ignore success checking, and
Chris@0 494 * array of values to set contact info.
Chris@0 495 * @param int $pid
Chris@0 496 * Comment id of the parent comment in a thread.
Chris@0 497 *
Chris@0 498 * @return \Drupal\comment\Entity\Comment
Chris@0 499 * The saved comment.
Chris@0 500 */
Chris@0 501 protected function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
Chris@0 502 $values = [
Chris@0 503 'entity_id' => $nid,
Chris@0 504 'entity_type' => 'node',
Chris@0 505 'field_name' => 'comment',
Chris@0 506 'uid' => $uid,
Chris@0 507 'pid' => $pid,
Chris@0 508 'subject' => $this->randomMachineName(),
Chris@0 509 'comment_body' => $this->randomMachineName(),
Chris@0 510 'status' => 1,
Chris@0 511 ];
Chris@0 512 if ($contact) {
Chris@0 513 $values += $contact;
Chris@0 514 }
Chris@0 515
Chris@0 516 $comment = Comment::create($values);
Chris@0 517 $comment->save();
Chris@0 518 return $comment;
Chris@0 519 }
Chris@0 520
Chris@0 521 /**
Chris@0 522 * Get the EasyRdf_Graph object for a page.
Chris@0 523 *
Chris@0 524 * @param \Drupal\Core\Url $url
Chris@0 525 * The URL object for the page.
Chris@0 526 *
Chris@0 527 * @return \EasyRdf_Graph
Chris@0 528 * The RDF graph object.
Chris@0 529 */
Chris@0 530 protected function getRdfGraph(Url $url) {
Chris@0 531 $parser = new \EasyRdf_Parser_Rdfa();
Chris@0 532 $graph = new \EasyRdf_Graph();
Chris@0 533 $parser->parse($graph, $this->drupalGet($url), 'rdfa', $this->baseUri);
Chris@0 534 return $graph;
Chris@0 535 }
Chris@0 536
Chris@0 537 }