function FieldKernelTest::testExclude

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testExclude()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testExclude()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php \Drupal\Tests\views\Kernel\Handler\FieldKernelTest::testExclude()

Tests the exclude setting.

File

core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php, line 364

Class

FieldKernelTest
Tests the generic field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testExclude() : void {
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container
        ->get('renderer');
    $view = Views::getView('test_field_output');
    $view->initHandlers();
    // Hide the field and see whether it's rendered.
    $view->field['name']->options['exclude'] = TRUE;
    $output = $view->preview();
    $output = (string) $renderer->renderRoot($output);
    foreach ($this->dataSet() as $entry) {
        $this->assertNotSubString($output, $entry['name']);
    }
    // Show and check the field.
    $view->field['name']->options['exclude'] = FALSE;
    $output = $view->preview();
    $output = (string) $renderer->renderRoot($output);
    foreach ($this->dataSet() as $entry) {
        $this->assertSubString($output, $entry['name']);
    }
}

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