public function FieldDropbuttonTest::testDropbuttonMarkupShouldNotLeakBetweenRows in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php \Drupal\Tests\views\Kernel\Handler\FieldDropbuttonTest::testDropbuttonMarkupShouldNotLeakBetweenRows()
Tests that dropbutton markup doesn't leak between rows.
File
- core/
modules/ views/ tests/ src/ Kernel/ Handler/ FieldDropbuttonTest.php, line 126
Class
- FieldDropbuttonTest
- Tests the core Drupal\views\Plugin\views\field\Dropbutton handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
public function testDropbuttonMarkupShouldNotLeakBetweenRows() {
$view = Views::getView('test_dropbutton');
$view
->setDisplay();
$view
->preExecute([]);
$view
->execute();
$renderer = $this->container
->get('renderer');
$dropbutton_output = [];
// Render each row and field in turn - the dropbutton plugin relies on
// output being set in previous versions.
foreach ($view->result as $index => $row) {
foreach (array_keys($view->field) as $field) {
$output = $renderer
->executeInRenderContext(new RenderContext(), function () use ($view, $row, $field) {
return $view->field[$field]
->advancedRender($row);
});
if ($field === 'dropbutton') {
$dropbutton_output[] = $output;
}
}
}
// The first row should contain edit links to node 3, as the user has
// access.
$this
->assertStringContainsString($this->node3
->toUrl('edit-form')
->toString(), (string) $dropbutton_output[0]);
$this
->assertStringContainsString($this->node3
->toUrl('delete-form')
->toString(), (string) $dropbutton_output[0]);
// Second row should be not contain links to edit/delete any content as user
// has no edit/delete permissions.
// It most certainly should not contain links to node 3, as node 2 is the
// entity that forms this row.
$this
->assertStringNotContainsString($this->node3
->toUrl('edit-form')
->toString(), (string) $dropbutton_output[1]);
$this
->assertStringNotContainsString($this->node3
->toUrl('delete-form')
->toString(), (string) $dropbutton_output[1]);
$this
->assertStringNotContainsString($this->node2
->toUrl('edit-form')
->toString(), (string) $dropbutton_output[1]);
$this
->assertStringNotContainsString($this->node2
->toUrl('delete-form')
->toString(), (string) $dropbutton_output[1]);
// Third row should contain links for node 1.
$this
->assertStringContainsString($this->node1
->toUrl('edit-form')
->toString(), (string) $dropbutton_output[2]);
$this
->assertStringContainsString($this->node1
->toUrl('delete-form')
->toString(), (string) $dropbutton_output[2]);
}