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

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
107 107
108 // Use Classy theme for testing markup output. 108 // Use Classy theme for testing markup output.
109 \Drupal::service('theme_handler')->install(['classy']); 109 \Drupal::service('theme_handler')->install(['classy']);
110 $this->config('system.theme')->set('default', 'classy')->save(); 110 $this->config('system.theme')->set('default', 'classy')->save();
111 111
112 $this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]); 112 $this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
113 113
114 // Create two test users. 114 // Create two test users.
115 $this->adminUser = $this->drupalCreateUser([ 115 $this->adminUser = $this->drupalCreateUser([
116 'administer content types', 116 'administer content types',
117 'administer comments', 117 'administer comments',
134 'vid' => 'tags', 134 'vid' => 'tags',
135 ]); 135 ]);
136 $this->term->save(); 136 $this->term->save();
137 137
138 // Create image. 138 // Create image.
139 file_unmanaged_copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg'); 139 \Drupal::service('file_system')->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
140 $this->image = File::create(['uri' => 'public://example.jpg']); 140 $this->image = File::create(['uri' => 'public://example.jpg']);
141 $this->image->save(); 141 $this->image->save();
142 142
143 // Create article. 143 // Create article.
144 $article_settings = [ 144 $article_settings = [
168 // Set URIs. 168 // Set URIs.
169 // Image. 169 // Image.
170 $image_file = $this->article->get('field_image')->entity; 170 $image_file = $this->article->get('field_image')->entity;
171 $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri()); 171 $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri());
172 // Term. 172 // Term.
173 $this->termUri = $this->term->url('canonical', ['absolute' => TRUE]); 173 $this->termUri = $this->term->toUrl('canonical', ['absolute' => TRUE])->toString();
174 // Article. 174 // Article.
175 $this->articleUri = $this->article->url('canonical', ['absolute' => TRUE]); 175 $this->articleUri = $this->article->toUrl('canonical', ['absolute' => TRUE])->toString();
176 // Page. 176 // Page.
177 $this->pageUri = $this->page->url('canonical', ['absolute' => TRUE]); 177 $this->pageUri = $this->page->toUrl('canonical', ['absolute' => TRUE])->toString();
178 // Author. 178 // Author.
179 $this->authorUri = $this->adminUser->url('canonical', ['absolute' => TRUE]); 179 $this->authorUri = $this->adminUser->toUrl('canonical', ['absolute' => TRUE])->toString();
180 // Comment. 180 // Comment.
181 $this->articleCommentUri = $this->articleComment->url('canonical', ['absolute' => TRUE]); 181 $this->articleCommentUri = $this->articleComment->toUrl('canonical', ['absolute' => TRUE])->toString();
182 // Commenter. 182 // Commenter.
183 $this->commenterUri = $this->webUser->url('canonical', ['absolute' => TRUE]); 183 $this->commenterUri = $this->webUser->toUrl('canonical', ['absolute' => TRUE])->toString();
184 184
185 $this->drupalLogout(); 185 $this->drupalLogout();
186 } 186 }
187 187
188 /** 188 /**
242 * on the page, so there is no test for output in node view. Comment count is 242 * on the page, so there is no test for output in node view. Comment count is
243 * displayed in teaser view, so it is tested in the front article tests. 243 * displayed in teaser view, so it is tested in the front article tests.
244 */ 244 */
245 protected function doArticleRdfaTests() { 245 protected function doArticleRdfaTests() {
246 // Feed the HTML into the parser. 246 // Feed the HTML into the parser.
247 $graph = $this->getRdfGraph($this->article->urlInfo()); 247 $graph = $this->getRdfGraph($this->article->toUrl());
248 248
249 // Type. 249 // Type.
250 $this->assertEqual($graph->type($this->articleUri), 'schema:Article', 'Article type was found (schema:Article).'); 250 $this->assertEqual($graph->type($this->articleUri), 'schema:Article', 'Article type was found (schema:Article).');
251 251
252 // Test the properties that are common between pages and articles. 252 // Test the properties that are common between pages and articles.
279 $node_type = NodeType::load('page'); 279 $node_type = NodeType::load('page');
280 $node_type->setDisplaySubmitted(TRUE); 280 $node_type->setDisplaySubmitted(TRUE);
281 $node_type->save(); 281 $node_type->save();
282 282
283 // Feed the HTML into the parser. 283 // Feed the HTML into the parser.
284 $graph = $this->getRdfGraph($this->page->urlInfo()); 284 $graph = $this->getRdfGraph($this->page->toUrl());
285 285
286 // Type. 286 // Type.
287 $this->assertEqual($graph->type($this->pageUri), 'schema:WebPage', 'Page type was found (schema:WebPage).'); 287 $this->assertEqual($graph->type($this->pageUri), 'schema:WebPage', 'Page type was found (schema:WebPage).');
288 288
289 // Test the properties that are common between pages and articles. 289 // Test the properties that are common between pages and articles.
295 */ 295 */
296 protected function doUserRdfaTests() { 296 protected function doUserRdfaTests() {
297 $this->drupalLogin($this->rootUser); 297 $this->drupalLogin($this->rootUser);
298 298
299 // Feed the HTML into the parser. 299 // Feed the HTML into the parser.
300 $graph = $this->getRdfGraph($this->adminUser->urlInfo()); 300 $graph = $this->getRdfGraph($this->adminUser->toUrl());
301 301
302 // User type. 302 // User type.
303 $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "User type was found (schema:Person) on user page."); 303 $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "User type was found (schema:Person) on user page.");
304 304
305 // User name. 305 // User name.
315 /** 315 /**
316 * Tests that term data is exposed on term page. 316 * Tests that term data is exposed on term page.
317 */ 317 */
318 protected function doTermRdfaTests() { 318 protected function doTermRdfaTests() {
319 // Feed the HTML into the parser. 319 // Feed the HTML into the parser.
320 $graph = $this->getRdfGraph($this->term->urlInfo()); 320 $graph = $this->getRdfGraph($this->term->toUrl());
321 321
322 // Term type. 322 // Term type.
323 $this->assertEqual($graph->type($this->termUri), 'schema:Thing', "Term type was found (schema:Thing) on term page."); 323 $this->assertEqual($graph->type($this->termUri), 'schema:Thing', "Term type was found (schema:Thing) on term page.");
324 324
325 // Term name. 325 // Term name.
343 * The node being displayed. 343 * The node being displayed.
344 * @param string $message_prefix 344 * @param string $message_prefix
345 * The word to use in the test assertion message. 345 * The word to use in the test assertion message.
346 */ 346 */
347 protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix) { 347 protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix) {
348 $uri = $node->url('canonical', ['absolute' => TRUE]); 348 $uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString();
349 349
350 // Title. 350 // Title.
351 $expected_value = [ 351 $expected_value = [
352 'type' => 'literal', 352 'type' => 'literal',
353 'value' => $node->get('title')->value, 353 'value' => $node->get('title')->value,
356 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "$message_prefix title was found (schema:name)."); 356 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "$message_prefix title was found (schema:name).");
357 357
358 // Created date. 358 // Created date.
359 $expected_value = [ 359 $expected_value = [
360 'type' => 'literal', 360 'type' => 'literal',
361 'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'), 361 'value' => $this->container->get('date.formatter')->format($node->get('created')->value, 'custom', 'c', 'UTC'),
362 'lang' => 'en', 362 'lang' => 'en',
363 ]; 363 ];
364 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "$message_prefix created date was found (schema:dateCreated) in teaser."); 364 $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "$message_prefix created date was found (schema:dateCreated) in teaser.");
365 365
366 // Body. 366 // Body.
445 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/name', $expected_value), 'Article comment title was found (schema:name).'); 445 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/name', $expected_value), 'Article comment title was found (schema:name).');
446 446
447 // Comment created date. 447 // Comment created date.
448 $expected_value = [ 448 $expected_value = [
449 'type' => 'literal', 449 'type' => 'literal',
450 'value' => format_date($this->articleComment->get('created')->value, 'custom', 'c', 'UTC'), 450 'value' => $this->container->get('date.formatter')->format($this->articleComment->get('created')->value, 'custom', 'c', 'UTC'),
451 'lang' => 'en', 451 'lang' => 'en',
452 ]; 452 ];
453 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).'); 453 $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).');
454 454
455 // Comment body. 455 // Comment body.
475 $this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).'); 475 $this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).');
476 476
477 // Comment author name. 477 // Comment author name.
478 $expected_value = [ 478 $expected_value = [
479 'type' => 'literal', 479 'type' => 'literal',
480 'value' => $this->webUser->getUsername(), 480 'value' => $this->webUser->getAccountName(),
481 ]; 481 ];
482 $this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).'); 482 $this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).');
483 } 483 }
484 484
485 /** 485 /**