function FieldCustomTest::testFieldCustom

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldCustomTest.php \Drupal\Tests\views\Kernel\Handler\FieldCustomTest::testFieldCustom()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldCustomTest.php \Drupal\Tests\views\Kernel\Handler\FieldCustomTest::testFieldCustom()
  3. 10 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 37

Class

FieldCustomTest
Tests the core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21Custom.php/class/Custom/11.x" title="A handler to provide a field that is completely custom by the administrator." class="local">Drupal\views\Plugin\views\field\Custom</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFieldCustom() : void {
    $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->assertSame($random, (string) $view->style_plugin
        ->getField(0, 'name'));
}

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