You are here

protected function CommentAttributesTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rdf/src/Tests/CommentAttributesTest.php \Drupal\rdf\Tests\CommentAttributesTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides CommentTestBase::setUp

File

core/modules/rdf/src/Tests/CommentAttributesTest.php, line 43
Contains \Drupal\rdf\Tests\CommentAttributesTest.

Class

CommentAttributesTest
Tests the RDFa markup of comments.

Namespace

Drupal\rdf\Tests

Code

protected function setUp() {
  parent::setUp();

  // Enables anonymous user comments.
  user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array(
    'access comments' => TRUE,
    'post comments' => TRUE,
    'skip comment approval' => TRUE,
  ));

  // Allows anonymous to leave their contact information.
  $this
    ->setCommentAnonymous(COMMENT_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 = \Drupal::url('<front>', [], [
    'absolute' => TRUE,
  ]);
  $this->nodeUri = $this->node
    ->url('canonical', [
    'absolute' => TRUE,
  ]);

  // Set relation between node and comment.
  $article_mapping = rdf_get_mapping('node', 'article');
  $comment_count_mapping = array(
    'properties' => array(
      'sioc:num_replies',
    ),
    'datatype' => 'xsd:integer',
    'datatype_callback' => array(
      '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 = array(
    'properties' => array(
      'foaf:name',
    ),
  );
  $user_mapping
    ->setFieldMapping('name', $username_mapping)
    ->save();
  $user_mapping
    ->setFieldMapping('homepage', array(
    'properties' => array(
      'foaf:page',
    ),
    'mapping_type' => 'rel',
  ))
    ->save();

  // Save comment mapping.
  $mapping = rdf_get_mapping('comment', 'comment');
  $mapping
    ->setBundleMapping(array(
    'types' => array(
      'sioc:Post',
      'sioct:Comment',
    ),
  ))
    ->save();
  $field_mappings = array(
    'subject' => array(
      'properties' => array(
        'dc:title',
      ),
    ),
    'created' => array(
      'properties' => array(
        'dc:date',
        'dc:created',
      ),
      'datatype' => 'xsd:dateTime',
      'datatype_callback' => array(
        'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
      ),
    ),
    'changed' => array(
      'properties' => array(
        'dc:modified',
      ),
      'datatype' => 'xsd:dateTime',
      'datatype_callback' => array(
        'callable' => 'Drupal\\rdf\\CommonDataConverter::dateIso8601Value',
      ),
    ),
    'comment_body' => array(
      'properties' => array(
        'content:encoded',
      ),
    ),
    'pid' => array(
      'properties' => array(
        'sioc:reply_of',
      ),
      'mapping_type' => 'rel',
    ),
    'uid' => array(
      'properties' => array(
        'sioc:has_creator',
      ),
      'mapping_type' => 'rel',
    ),
    'name' => array(
      'properties' => array(
        'foaf:name',
      ),
    ),
  );

  // Iterate over shared field mappings and save.
  foreach ($field_mappings as $field_name => $field_mapping) {
    $mapping
      ->setFieldMapping($field_name, $field_mapping)
      ->save();
  }
}