RowEntityTest.php in Drupal 10
File
core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\Core\Form\FormState;
use Drupal\views\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
class RowEntityTest extends ViewsKernelTestBase {
protected static $modules = [
'taxonomy',
'text',
'filter',
'field',
'system',
'node',
'user',
];
public static $testViews = [
'test_entity_row',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp();
$this
->installEntitySchema('taxonomy_term');
$this
->installConfig([
'taxonomy',
]);
}
public function testEntityRow() {
$vocab = Vocabulary::create([
'name' => $this
->randomMachineName(),
'vid' => strtolower($this
->randomMachineName()),
]);
$vocab
->save();
$term = Term::create([
'name' => $this
->randomMachineName(),
'vid' => $vocab
->id(),
]);
$term
->save();
$view = Views::getView('test_entity_row');
$build = $view
->preview();
$this
->render($build);
$this
->assertText($term
->getName(), 'The rendered entity appears as row in the view.');
$form = [];
$form_state = new FormState();
$form_state
->set('view', $view->storage);
$view->rowPlugin
->buildOptionsForm($form, $form_state);
$this
->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');
}
}