You are here

function FileFieldDisplayTest::testDefaultFileFieldDisplay in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/FileFieldDisplayTest.php \Drupal\file\Tests\FileFieldDisplayTest::testDefaultFileFieldDisplay()

Tests default display of File Field.

File

core/modules/file/src/Tests/FileFieldDisplayTest.php, line 110
Contains \Drupal\file\Tests\FileFieldDisplayTest.

Class

FileFieldDisplayTest
Tests the display of file fields in node and views.

Namespace

Drupal\file\Tests

Code

function testDefaultFileFieldDisplay() {
  $field_name = strtolower($this
    ->randomMachineName());
  $type_name = 'article';
  $field_storage_settings = array(
    'display_field' => '1',
    'display_default' => '0',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  );
  $field_settings = array(
    'description_field' => '1',
  );
  $widget_settings = array();
  $this
    ->createFileField($field_name, 'node', $type_name, $field_storage_settings, $field_settings, $widget_settings);
  $test_file = $this
    ->getTestFile('text');

  // Create a new node with the uploaded file.
  $nid = $this
    ->uploadNodeFile($test_file, $field_name, $type_name);
  $this
    ->drupalGet('node/' . $nid . '/edit');
  $this
    ->assertFieldByXPath('//input[@type="checkbox" and @name="' . $field_name . '[0][display]"]', NULL, 'Default file display checkbox field exists.');
  $this
    ->assertFieldByXPath('//input[@type="checkbox" and @name="' . $field_name . '[0][display]" and not(@checked)]', NULL, 'Default file display is off.');
}