Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Handler / ComputedFieldTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Handler;
4
5 use Drupal\entity_test\Entity\EntityTestComputedField;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views\Views;
8
9 /**
10  * Provides some integration tests for the Field handler.
11  *
12  * @see \Drupal\views\Plugin\views\field\EntityField
13  * @group views
14  */
15 class ComputedFieldTest extends ViewsKernelTestBase {
16
17   /**
18    * Views to be enabled.
19    *
20    * @var array
21    */
22   public static $testViews = ['computed_field_view'];
23
24   /**
25    * Modules to enable.
26    *
27    * @var array
28    */
29   public static $modules = ['entity_test'];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp($import_test_views = TRUE) {
35     parent::setUp($import_test_views);
36
37     $this->installEntitySchema('entity_test_computed_field');
38   }
39
40   /**
41    * Test the computed field handler.
42    */
43   public function testComputedFieldHandler() {
44     \Drupal::state()->set('entity_test_computed_field_item_list_value', ['computed string']);
45
46     $entity = EntityTestComputedField::create([]);
47     $entity->save();
48
49     $view = Views::getView('computed_field_view');
50
51     $rendered_view = $view->preview();
52     $output = $this->container->get('renderer')->renderRoot($rendered_view);
53     $this->assertContains('computed string', (string) $output);
54   }
55
56 }