You are here

public function HandlerFieldFieldTest::testFieldRender in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::testFieldRender()
  2. 10 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::testFieldRender()

Tests fields rendering in views.

File

core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php, line 67

Class

HandlerFieldFieldTest
Tests the field rendering in views.

Namespace

Drupal\Tests\field\Kernel\Views

Code

public function testFieldRender() {
  $this
    ->installConfig([
    'filter',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('node');
  NodeType::create([
    'type' => 'page',
  ])
    ->save();
  ViewTestData::createTestViews(static::class, [
    'field_test_views',
  ]);

  // Setup basic fields.
  $this
    ->createFields();

  // Create some nodes.
  $this->nodes = [];
  for ($i = 0; $i < 3; $i++) {
    $values = [
      'type' => 'page',
    ];
    foreach ([
      0,
      1,
      2,
      5,
    ] as $key) {
      $field_storage = $this->fieldStorages[$key];
      $values[$field_storage
        ->getName()][0]['value'] = $this
        ->randomMachineName(8);
    }

    // Add a hidden value for the no-view field.
    $values[$this->fieldStorages[6]
      ->getName()][0]['value'] = 'ssh secret squirrel';
    for ($j = 0; $j < 5; $j++) {
      $values[$this->fieldStorages[3]
        ->getName()][$j]['value'] = $this
        ->randomMachineName(8);
    }

    // Set this field to be empty.
    $values[$this->fieldStorages[4]
      ->getName()] = [
      [
        'value' => NULL,
      ],
    ];
    $this->nodes[$i] = $this
      ->createNode($values);
  }

  // Perform actual tests.
  $this
    ->doTestSimpleFieldRender();
  $this
    ->doTestInaccessibleFieldRender();
  $this
    ->doTestFormatterSimpleFieldRender();
  $this
    ->doTestMultipleFieldRender();
}