installEntitySchema('taxonomy_term'); $this->installEntitySchema('user'); $this->installConfig(['filter']); /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */ $vocabulary = $this->createVocabulary(); $this->term1 = $this->createTerm($vocabulary); // Create user 1 and set is as the logged in user, so that the logged in // user has the correct permissions to view the vocabulary name. $this->adminUser = User::create(['name' => $this->randomString()]); $this->adminUser->save(); $this->container->get('current_user')->setAccount($this->adminUser); ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']); } /** * Tests the field handling for the Vocabulary ID. */ public function testViewsHandlerVidField() { /** @var \Drupal\Core\Render\RendererInterface $renderer */ $renderer = \Drupal::service('renderer'); $view = Views::getView('test_taxonomy_vid_field'); $this->executeView($view); $actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) { return $view->field['vid']->advancedRender($view->result[0]); }); $vocabulary = Vocabulary::load($this->term1->bundle()); $expected = $vocabulary->get('name'); $this->assertEquals($expected, $actual); } }