You are here

protected function FileFieldAttributesTest::setUp in Zircon Profile 8

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

File

core/modules/rdf/src/Tests/FileFieldAttributesTest.php, line 48
Contains \Drupal\rdf\Tests\FileFieldAttributesTest.

Class

FileFieldAttributesTest
Tests the RDFa markup of filefields.

Namespace

Drupal\rdf\Tests

Code

protected function setUp() {
  parent::setUp();
  $node_storage = $this->container
    ->get('entity.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.
  entity_get_display('node', 'article', 'teaser')
    ->setComponent($this->fieldName, array(
    'type' => 'file_default',
  ))
    ->save();

  // Set the RDF mapping for the new field.
  $mapping = rdf_get_mapping('node', 'article');
  $mapping
    ->setFieldMapping($this->fieldName, array(
    'properties' => array(
      '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(array(
    $nid,
  ));
  $this->node = $node_storage
    ->load($nid);
  $this->file = File::load($this->node->{$this->fieldName}->target_id);
}