You are here

protected function EntityReferenceFileUploadTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php \Drupal\field\Tests\EntityReference\EntityReferenceFileUploadTest::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/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php, line 43
Contains \Drupal\field\Tests\EntityReference\EntityReferenceFileUploadTest.

Class

EntityReferenceFileUploadTest
Tests an autocomplete widget with file upload.

Namespace

Drupal\field\Tests\EntityReference

Code

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

  // Create "referencing" and "referenced" node types.
  $referencing = $this
    ->drupalCreateContentType();
  $this->referencingType = $referencing
    ->id();
  $referenced = $this
    ->drupalCreateContentType();
  $this->referencedType = $referenced
    ->id();
  $this->nodeId = $this
    ->drupalCreateNode(array(
    'type' => $referenced
      ->id(),
  ))
    ->id();
  entity_create('field_storage_config', array(
    'field_name' => 'test_field',
    'entity_type' => 'node',
    'translatable' => FALSE,
    'entity_types' => array(),
    'settings' => array(
      'target_type' => 'node',
    ),
    'type' => 'entity_reference',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ))
    ->save();
  entity_create('field_config', array(
    'label' => 'Entity reference field',
    'field_name' => 'test_field',
    'entity_type' => 'node',
    'required' => TRUE,
    'bundle' => $referencing
      ->id(),
    'settings' => array(
      'handler' => 'default',
      'handler_settings' => array(
        // Reference a single vocabulary.
        'target_bundles' => array(
          $referenced
            ->id(),
        ),
      ),
    ),
  ))
    ->save();

  // Create a file field.
  $file_field_name = 'file_field';
  $field_storage = entity_create('field_storage_config', array(
    'field_name' => $file_field_name,
    'entity_type' => 'node',
    'type' => 'file',
  ));
  $field_storage
    ->save();
  entity_create('field_config', array(
    'entity_type' => 'node',
    'field_storage' => $field_storage,
    'bundle' => $referencing
      ->id(),
    'label' => $this
      ->randomMachineName() . '_label',
  ))
    ->save();
  entity_get_display('node', $referencing
    ->id(), 'default')
    ->setComponent('test_field')
    ->setComponent($file_field_name)
    ->save();
  entity_get_form_display('node', $referencing
    ->id(), 'default')
    ->setComponent('test_field', array(
    'type' => 'entity_reference_autocomplete',
  ))
    ->setComponent($file_field_name, array(
    'type' => 'file_generic',
  ))
    ->save();
}