You are here

protected function StandardProfileTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rdf/src/Tests/StandardProfileTest.php \Drupal\rdf\Tests\StandardProfileTest::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 WebTestBase::setUp

File

core/modules/rdf/src/Tests/StandardProfileTest.php, line 107
Contains \Drupal\rdf\Tests\StandardProfileTest.

Class

StandardProfileTest
Tests the RDF mappings and RDFa markup of the standard profile.

Namespace

Drupal\rdf\Tests

Code

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

  // Use Classy theme for testing markup output.
  \Drupal::service('theme_handler')
    ->install([
    'classy',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'classy')
    ->save();
  $this->baseUri = \Drupal::url('<front>', [], [
    'absolute' => TRUE,
  ]);

  // Create two test users.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer comments',
    'access comments',
    'access content',
  ));
  $this->webUser = $this
    ->drupalCreateUser(array(
    'access comments',
    'post comments',
    'skip comment approval',
    'access content',
  ));
  $this
    ->drupalLogin($this->adminUser);

  // Create term.
  $this->term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomMachineName(),
    'description' => $this
      ->randomMachineName(),
    'vid' => 'tags',
  ));
  $this->term
    ->save();

  // Create image.
  file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
  $this->image = entity_create('file', array(
    'uri' => 'public://example.jpg',
  ));
  $this->image
    ->save();

  // Create article.
  $article_settings = array(
    'type' => 'article',
    'promote' => NODE_PROMOTED,
    'field_image' => array(
      array(
        'target_id' => $this->image
          ->id(),
      ),
    ),
    'field_tags' => array(
      array(
        'target_id' => $this->term
          ->id(),
      ),
    ),
  );
  $this->article = $this
    ->drupalCreateNode($article_settings);

  // Create second article to test teaser list.
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => NODE_PROMOTED,
  ));

  // Create article comment.
  $this->articleComment = $this
    ->saveComment($this->article
    ->id(), $this->webUser
    ->id(), NULL, 0);

  // Create page.
  $this->page = $this
    ->drupalCreateNode(array(
    'type' => 'page',
  ));

  // Set URIs.
  // Image.
  $image_file = $this->article
    ->get('field_image')->entity;
  $this->imageUri = ImageStyle::load('large')
    ->buildUrl($image_file
    ->getFileUri());

  // Term.
  $this->termUri = $this->term
    ->url('canonical', array(
    'absolute' => TRUE,
  ));

  // Article.
  $this->articleUri = $this->article
    ->url('canonical', array(
    'absolute' => TRUE,
  ));

  // Page.
  $this->pageUri = $this->page
    ->url('canonical', array(
    'absolute' => TRUE,
  ));

  // Author.
  $this->authorUri = $this->adminUser
    ->url('canonical', array(
    'absolute' => TRUE,
  ));

  // Comment.
  $this->articleCommentUri = $this->articleComment
    ->url('canonical', array(
    'absolute' => TRUE,
  ));

  // Commenter.
  $this->commenterUri = $this->webUser
    ->url('canonical', array(
    'absolute' => TRUE,
  ));
  $this
    ->drupalLogout();
}