View source
<?php
namespace Drupal\Tests\rdf\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
class UserAttributesTest extends BrowserTestBase {
use RdfParsingTrait;
public static $modules = [
'rdf',
'node',
'user_hooks_test',
];
protected $defaultTheme = 'stark';
protected $baseUri;
protected function setUp() {
parent::setUp();
rdf_get_mapping('user', 'user')
->setBundleMapping([
'types' => [
'sioc:UserAccount',
],
])
->setFieldMapping('name', [
'properties' => [
'foaf:name',
],
])
->save();
$this->baseUri = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString();
\Drupal::state()
->set('user_hooks_test_user_format_name_alter', TRUE);
}
public function testUserAttributesInMarkup() {
$user1 = $this
->drupalCreateUser([
'access user profiles',
]);
$authors = [
$this
->drupalCreateUser([], $this
->randomMachineName(30)),
$this
->drupalCreateUser([], $this
->randomMachineName(20)),
$this
->drupalCreateUser([], $this
->randomMachineName(5)),
];
$this
->drupalLogin($user1);
$this
->drupalCreateContentType([
'type' => 'article',
]);
foreach ($authors as $author) {
$account_uri = $author
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
$this
->drupalGet('user/' . $author
->id());
$expected_value = [
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
$expected_value = [
'type' => 'literal',
'value' => $author
->getDisplayName(),
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
$this
->drupalLogin($author);
$node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
]);
$this
->drupalLogin($user1);
$this
->drupalGet('node/' . $node
->id());
$expected_value = [
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
$expected_value = [
'type' => 'literal',
'value' => $author
->getDisplayName(),
];
$this
->assertTrue($this
->hasRdfProperty($this
->getSession()
->getPage()
->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
}
}
}