Chris@0: setBundleMapping([ Chris@0: 'types' => ['sioc:UserAccount'], Chris@0: ]) Chris@0: ->setFieldMapping('name', [ Chris@0: 'properties' => ['foaf:name'], Chris@0: ]) Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests if default mapping for user is being used. Chris@0: * Chris@0: * Creates a random user and ensures the default mapping for the user is Chris@0: * being used. Chris@0: */ Chris@0: public function testUserAttributesInMarkup() { Chris@0: // Creates users that should and should not be truncated Chris@0: // by template_preprocess_username (20 characters) Chris@0: // one of these users tests right on the cusp (20). Chris@0: $user1 = $this->drupalCreateUser(['access user profiles']); Chris@0: Chris@0: $authors = [ Chris@0: $this->drupalCreateUser([], $this->randomMachineName(30)), Chris@0: $this->drupalCreateUser([], $this->randomMachineName(20)), Chris@17: $this->drupalCreateUser([], $this->randomMachineName(5)), Chris@0: ]; Chris@0: Chris@0: $this->drupalLogin($user1); Chris@0: Chris@0: $this->drupalCreateContentType(['type' => 'article']); Chris@0: Chris@0: /** @var \Drupal\user\UserInterface[] $authors */ Chris@0: foreach ($authors as $author) { Chris@18: $account_uri = $author->toUrl('canonical', ['absolute' => TRUE])->toString(); Chris@0: Chris@0: // Parses the user profile page where the default bundle mapping for user Chris@0: // should be used. Chris@0: $parser = new \EasyRdf_Parser_Rdfa(); Chris@0: $graph = new \EasyRdf_Graph(); Chris@18: $base_uri = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); Chris@0: $parser->parse($graph, $this->drupalGet('user/' . $author->id()), 'rdfa', $base_uri); Chris@0: Chris@0: // Inspects RDF graph output. Chris@0: // User type. Chris@0: $expected_value = [ Chris@0: 'type' => 'uri', Chris@0: 'value' => 'http://rdfs.org/sioc/ns#UserAccount', Chris@0: ]; Chris@0: $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: // User name. Chris@0: $expected_value = [ Chris@0: 'type' => 'literal', Chris@18: 'value' => $author->getAccountName(), Chris@0: ]; Chris@0: $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: Chris@0: // User creates a node. Chris@0: $this->drupalLogin($author); Chris@0: $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]); Chris@0: $this->drupalLogin($user1); Chris@0: Chris@0: // Parses the node created by the user. Chris@0: $parser = new \EasyRdf_Parser_Rdfa(); Chris@0: $graph = new \EasyRdf_Graph(); Chris@18: $base_uri = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); Chris@0: $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri); Chris@0: Chris@0: // Ensures the default bundle mapping for user is used on the Authored By Chris@0: // information on the node. Chris@0: $expected_value = [ Chris@0: 'type' => 'uri', Chris@0: 'value' => 'http://rdfs.org/sioc/ns#UserAccount', Chris@0: ]; Chris@0: $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: // User name. Chris@0: $expected_value = [ Chris@0: 'type' => 'literal', Chris@18: 'value' => $author->getAccountName(), Chris@0: ]; Chris@0: $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: Chris@0: } Chris@0: } Chris@0: Chris@0: }