function ComputedBundleFieldTest::testComputedFieldHandler

Same name in other branches
  1. 11.x core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php \Drupal\Tests\views\Kernel\Handler\ComputedBundleFieldTest::testComputedFieldHandler()

Tests the computed field handler.

File

core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php, line 77

Class

ComputedBundleFieldTest
Provides some integration tests for computed bundle fields.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testComputedFieldHandler() : void {
    \Drupal::state()->set('entity_test_computed_field_item_list_value', [
        'computed string',
    ]);
    \Drupal::state()->set('entity_test_comp_bund_fld_item_list_value', [
        'some other string that is also computed',
    ]);
    $view = Views::getView('computed_bundle_field_view');
    $this->executeView($view);
    $this->assertCount(3, $view->result, 'The number of returned rows match.');
    // Entities 1 and 2 should have the computed bundle field. But entity 3
    // should not.
    $this->assertStringContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']
        ->render($view->result[0]));
    $this->assertStringContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']
        ->render($view->result[1]));
    $this->assertStringNotContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']
        ->render($view->result[2]));
    $view->destroy();
}

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