You are here

protected function FileFieldAttributesTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php \Drupal\Tests\rdf\Functional\FileFieldAttributesTest::setUp()
  2. 10 core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php \Drupal\Tests\rdf\Functional\FileFieldAttributesTest::setUp()

Overrides FileFieldTestBase::setUp

File

core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php, line 59

Class

FileFieldAttributesTest
Tests the RDFa markup of filefields.

Namespace

Drupal\Tests\rdf\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $node_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $this->fieldName = strtolower($this
    ->randomMachineName());
  $type_name = 'article';
  $this
    ->createFileField($this->fieldName, 'node', $type_name);

  // Set the teaser display to show this field.
  \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'article', 'teaser')
    ->setComponent($this->fieldName, [
    'type' => 'file_default',
  ])
    ->save();

  // Set the RDF mapping for the new field.
  $mapping = rdf_get_mapping('node', 'article');
  $mapping
    ->setFieldMapping($this->fieldName, [
    'properties' => [
      'rdfs:seeAlso',
    ],
    'mapping_type' => 'rel',
  ])
    ->save();
  $test_file = $this
    ->getTestFile('text');

  // Create a new node with the uploaded file.
  $nid = $this
    ->uploadNodeFile($test_file, $this->fieldName, $type_name);
  $node_storage
    ->resetCache([
    $nid,
  ]);
  $this->node = $node_storage
    ->load($nid);
  $this->file = File::load($this->node->{$this->fieldName}->target_id);

  // Prepares commonly used URIs.
  $this->baseUri = Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])
    ->toString();
}