function StandardProfileTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/modules/rdf/tests/src/Functional/StandardProfileTest.php \Drupal\Tests\rdf\Functional\StandardProfileTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/rdf/tests/src/Functional/StandardProfileTest.php, line 152

Class

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

Namespace

Drupal\Tests\rdf\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this->baseUri = Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])->toString();
  // Create two test users.
  $this->adminUser = $this->drupalCreateUser([
    'administer content types',
    'administer comments',
    'access comments',
    'access content',
  ]);
  $this->webUser = $this->drupalCreateUser([
    'access comments',
    'post comments',
    'skip comment approval',
    'access content',
  ]);
  $this->drupalLogin($this->adminUser);
  // Create term.
  $this->term = Term::create([
    'name' => $this->randomMachineName(),
    'description' => $this->randomMachineName(),
    'vid' => 'tags',
  ]);
  $this->term
    ->save();
  // Create image.
  \Drupal::service('file_system')->copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
  $this->image = File::create([
    'uri' => 'public://example.jpg',
  ]);
  $this->image
    ->save();
  // Create article.
  $article_settings = [
    'type' => 'article',
    'promote' => NodeInterface::PROMOTED,
    'field_image' => [
      [
        'target_id' => $this->image
          ->id(),
      ],
    ],
    'field_tags' => [
      [
        'target_id' => $this->term
          ->id(),
      ],
    ],
  ];
  $this->article = $this->drupalCreateNode($article_settings);
  // Create second article to test teaser list.
  $this->drupalCreateNode([
    'type' => 'article',
    'promote' => NodeInterface::PROMOTED,
  ]);
  // Create article comment.
  $this->articleComment = $this->saveComment($this->article
    ->id(), $this->webUser
    ->id(), NULL, 0);
  // Create page.
  $this->page = $this->drupalCreateNode([
    'type' => 'page',
  ]);
  // Set URIs.
  // Image.
  $image_file = $this->article
    ->get('field_image')->entity;
  $this->imageUri = ImageStyle::load('wide')->buildUrl($image_file->getFileUri());
  // Term.
  $this->termUri = $this->term
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Article.
  $this->articleUri = $this->article
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Page.
  $this->pageUri = $this->page
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Author.
  $this->authorUri = $this->adminUser
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Comment.
  $this->articleCommentUri = $this->articleComment
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  // Commenter.
  $this->commenterUri = $this->webUser
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  $this->drupalLogout();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.