3 namespace Drupal\Tests\rdf\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the RDFa markup of Users.
12 class UserAttributesTest extends BrowserTestBase {
19 public static $modules = ['rdf', 'node'];
21 protected function setUp() {
23 rdf_get_mapping('user', 'user')
25 'types' => ['sioc:UserAccount'],
27 ->setFieldMapping('name', [
28 'properties' => ['foaf:name'],
34 * Tests if default mapping for user is being used.
36 * Creates a random user and ensures the default mapping for the user is
39 public function testUserAttributesInMarkup() {
40 // Creates users that should and should not be truncated
41 // by template_preprocess_username (20 characters)
42 // one of these users tests right on the cusp (20).
43 $user1 = $this->drupalCreateUser(['access user profiles']);
46 $this->drupalCreateUser([], $this->randomMachineName(30)),
47 $this->drupalCreateUser([], $this->randomMachineName(20)),
48 $this->drupalCreateUser([], $this->randomMachineName(5))
51 $this->drupalLogin($user1);
53 $this->drupalCreateContentType(['type' => 'article']);
55 /** @var \Drupal\user\UserInterface[] $authors */
56 foreach ($authors as $author) {
57 $account_uri = $author->url('canonical', ['absolute' => TRUE]);
59 // Parses the user profile page where the default bundle mapping for user
61 $parser = new \EasyRdf_Parser_Rdfa();
62 $graph = new \EasyRdf_Graph();
63 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
64 $parser->parse($graph, $this->drupalGet('user/' . $author->id()), 'rdfa', $base_uri);
66 // Inspects RDF graph output.
70 'value' => 'http://rdfs.org/sioc/ns#UserAccount',
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).');
76 'value' => $author->getUsername(),
78 $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
80 // User creates a node.
81 $this->drupalLogin($author);
82 $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
83 $this->drupalLogin($user1);
85 // Parses the node created by the user.
86 $parser = new \EasyRdf_Parser_Rdfa();
87 $graph = new \EasyRdf_Graph();
88 $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
89 $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
91 // Ensures the default bundle mapping for user is used on the Authored By
92 // information on the node.
95 'value' => 'http://rdfs.org/sioc/ns#UserAccount',
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).');
101 'value' => $author->getUsername(),
103 $this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');