function CommentAttributesTest::setUp
Same name in other branches
- 8.9.x core/modules/rdf/tests/src/Functional/CommentAttributesTest.php \Drupal\Tests\rdf\Functional\CommentAttributesTest::setUp()
Overrides CommentTestBase::setUp
File
-
core/
modules/ rdf/ tests/ src/ Functional/ CommentAttributesTest.php, line 59
Class
- CommentAttributesTest
- Tests the RDFa markup of comments.
Namespace
Drupal\Tests\rdf\FunctionalCode
protected function setUp() : void {
parent::setUp();
// Enables anonymous user comments.
user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
]);
// Allows anonymous to leave their contact information.
$this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);
$this->setCommentPreview(DRUPAL_OPTIONAL);
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('comment_default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])->toString();
$this->nodeUri = $this->node
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
// Set relation between node and comment.
$article_mapping = rdf_get_mapping('node', 'article');
$comment_count_mapping = [
'properties' => [
'sioc:num_replies',
],
'datatype' => 'xsd:integer',
'datatype_callback' => [
'callable' => 'Drupal\\rdf\\CommonDataConverter::rawValue',
],
];
$article_mapping->setFieldMapping('comment_count', $comment_count_mapping)
->save();
// Save user mapping.
$user_mapping = rdf_get_mapping('user', 'user');
$username_mapping = [
'properties' => [
'foaf:name',
],
];
$user_mapping->setFieldMapping('name', $username_mapping)
->save();
$user_mapping->setFieldMapping('homepage', [
'properties' => [
'foaf:page',
],
'mapping_type' => 'rel',
])
->save();
// Save comment mapping.
$mapping = rdf_get_mapping('comment', 'comment');
$mapping->setBundleMapping([
'types' => [
'sioc:Post',
'sioct:Comment',
],
])
->save();
$field_mappings = [
'subject' => [
'properties' => [
'dc:title',
],
],
'created' => [
'properties' => [
'dc:date',
'dc:created',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
],
],
'changed' => [
'properties' => [
'dc:modified',
],
'datatype' => 'xsd:dateTime',
'datatype_callback' => [
'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
],
],
'comment_body' => [
'properties' => [
'content:encoded',
],
],
'pid' => [
'properties' => [
'sioc:reply_of',
],
'mapping_type' => 'rel',
],
'uid' => [
'properties' => [
'sioc:has_creator',
],
'mapping_type' => 'rel',
],
'name' => [
'properties' => [
'foaf:name',
],
],
];
// Iterate over shared field mappings and save.
foreach ($field_mappings as $field_name => $field_mapping) {
$mapping->setFieldMapping($field_name, $field_mapping)
->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.