You are here

public function FieldCustomTest::testFieldCustom in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FieldCustomTest.php \Drupal\Tests\views\Kernel\Handler\FieldCustomTest::testFieldCustom()

Ensure that custom fields work and doesn't escape unnecessary markup.

File

core/modules/views/tests/src/Kernel/Handler/FieldCustomTest.php, line 35

Class

FieldCustomTest
Tests the core Drupal\views\Plugin\views\field\Custom handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFieldCustom() {
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Alter the text of the field to a random string.
  $random = '<div>' . $this
    ->randomMachineName() . '</div>';
  $view->displayHandlers
    ->get('default')
    ->overrideOption('fields', [
    'name' => [
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'relationship' => 'none',
      'alter' => [
        'text' => $random,
      ],
    ],
  ]);
  $this
    ->executeView($view);
  $this
    ->assertEquals($random, $view->style_plugin
    ->getField(0, 'name'));
}