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