function HandlerFieldFieldTest::testFieldRender

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. 8.9.x core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::testFieldRender()
  3. 11.x 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 69

Class

HandlerFieldFieldTest
Tests the field rendering in views.

Namespace

Drupal\Tests\field\Kernel\Views

Code

public function testFieldRender() : void {
  $this->installConfig([
    'filter',
  ]);
  $this->installEntitySchema('user');
  $this->installEntitySchema('node');
  NodeType::create([
    'type' => 'page',
    'name' => '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();
}

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