Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\rdf\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the RDFa markup of Users.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group rdf
|
Chris@0
|
11 */
|
Chris@0
|
12 class UserAttributesTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['rdf', 'node'];
|
Chris@0
|
20
|
Chris@0
|
21 protected function setUp() {
|
Chris@0
|
22 parent::setUp();
|
Chris@0
|
23 rdf_get_mapping('user', 'user')
|
Chris@0
|
24 ->setBundleMapping([
|
Chris@0
|
25 'types' => ['sioc:UserAccount'],
|
Chris@0
|
26 ])
|
Chris@0
|
27 ->setFieldMapping('name', [
|
Chris@0
|
28 'properties' => ['foaf:name'],
|
Chris@0
|
29 ])
|
Chris@0
|
30 ->save();
|
Chris@0
|
31 }
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * Tests if default mapping for user is being used.
|
Chris@0
|
35 *
|
Chris@0
|
36 * Creates a random user and ensures the default mapping for the user is
|
Chris@0
|
37 * being used.
|
Chris@0
|
38 */
|
Chris@0
|
39 public function testUserAttributesInMarkup() {
|
Chris@0
|
40 // Creates users that should and should not be truncated
|
Chris@0
|
41 // by template_preprocess_username (20 characters)
|
Chris@0
|
42 // one of these users tests right on the cusp (20).
|
Chris@0
|
43 $user1 = $this->drupalCreateUser(['access user profiles']);
|
Chris@0
|
44
|
Chris@0
|
45 $authors = [
|
Chris@0
|
46 $this->drupalCreateUser([], $this->randomMachineName(30)),
|
Chris@0
|
47 $this->drupalCreateUser([], $this->randomMachineName(20)),
|
Chris@4
|
48 $this->drupalCreateUser([], $this->randomMachineName(5)),
|
Chris@0
|
49 ];
|
Chris@0
|
50
|
Chris@0
|
51 $this->drupalLogin($user1);
|
Chris@0
|
52
|
Chris@0
|
53 $this->drupalCreateContentType(['type' => 'article']);
|
Chris@0
|
54
|
Chris@0
|
55 /** @var \Drupal\user\UserInterface[] $authors */
|
Chris@0
|
56 foreach ($authors as $author) {
|
Chris@0
|
57 $account_uri = $author->url('canonical', ['absolute' => TRUE]);
|
Chris@0
|
58
|
Chris@0
|
59 // Parses the user profile page where the default bundle mapping for user
|
Chris@0
|
60 // should be used.
|
Chris@0
|
61 $parser = new \EasyRdf_Parser_Rdfa();
|
Chris@0
|
62 $graph = new \EasyRdf_Graph();
|
Chris@0
|
63 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
|
Chris@0
|
64 $parser->parse($graph, $this->drupalGet('user/' . $author->id()), 'rdfa', $base_uri);
|
Chris@0
|
65
|
Chris@0
|
66 // Inspects RDF graph output.
|
Chris@0
|
67 // User type.
|
Chris@0
|
68 $expected_value = [
|
Chris@0
|
69 'type' => 'uri',
|
Chris@0
|
70 'value' => 'http://rdfs.org/sioc/ns#UserAccount',
|
Chris@0
|
71 ];
|
Chris@0
|
72 $this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
|
Chris@0
|
73 // User name.
|
Chris@0
|
74 $expected_value = [
|
Chris@0
|
75 'type' => 'literal',
|
Chris@0
|
76 'value' => $author->getUsername(),
|
Chris@0
|
77 ];
|
Chris@0
|
78 $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
|
Chris@0
|
79
|
Chris@0
|
80 // User creates a node.
|
Chris@0
|
81 $this->drupalLogin($author);
|
Chris@0
|
82 $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
|
Chris@0
|
83 $this->drupalLogin($user1);
|
Chris@0
|
84
|
Chris@0
|
85 // Parses the node created by the user.
|
Chris@0
|
86 $parser = new \EasyRdf_Parser_Rdfa();
|
Chris@0
|
87 $graph = new \EasyRdf_Graph();
|
Chris@0
|
88 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
|
Chris@0
|
89 $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
|
Chris@0
|
90
|
Chris@0
|
91 // Ensures the default bundle mapping for user is used on the Authored By
|
Chris@0
|
92 // information on the node.
|
Chris@0
|
93 $expected_value = [
|
Chris@0
|
94 'type' => 'uri',
|
Chris@0
|
95 'value' => 'http://rdfs.org/sioc/ns#UserAccount',
|
Chris@0
|
96 ];
|
Chris@0
|
97 $this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
|
Chris@0
|
98 // User name.
|
Chris@0
|
99 $expected_value = [
|
Chris@0
|
100 'type' => 'literal',
|
Chris@0
|
101 'value' => $author->getUsername(),
|
Chris@0
|
102 ];
|
Chris@0
|
103 $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
|
Chris@0
|
104
|
Chris@0
|
105 }
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 }
|