function FileFieldAttributesTest::setUp

Same name in other branches
  1. 9 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() {
    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();
}

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