StyleUITest.php in Drupal 10
File
core/modules/views_ui/tests/src/Functional/StyleUITest.php
View source
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\views\Views;
class StyleUITest extends UITestBase {
public static $testViews = [
'test_view',
];
protected $defaultTheme = 'stark';
public function testStyleUI() {
$view_name = 'test_view';
$view_edit_url = "admin/structure/views/view/{$view_name}/edit";
$style_plugin_url = "admin/structure/views/nojs/display/{$view_name}/default/style";
$style_options_url = "admin/structure/views/nojs/display/{$view_name}/default/style_options";
$this
->drupalGet($style_plugin_url);
$this
->assertSession()
->fieldValueEquals('style[type]', 'default');
$edit = [
'style[type]' => 'test_style',
];
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->fieldExists('style_options[test_option]');
$random_name = $this
->randomMachineName();
$edit = [
'style_options[test_option]' => $random_name,
];
$this
->submitForm($edit, 'Apply');
$this
->drupalGet($style_options_url);
$this
->assertSession()
->fieldValueEquals('style_options[test_option]', $random_name);
$this
->drupalGet($view_edit_url);
$this
->submitForm([], 'Save');
$this
->assertSession()
->linkExists('Test style plugin', 0, 'Make sure the test style plugin is shown in the UI');
$view = Views::getView($view_name);
$view
->initDisplay();
$style = $view->display_handler
->getOption('style');
$this
->assertEquals('test_style', $style['type'], 'Make sure that the test_style got saved as used style plugin.');
$this
->assertEquals($random_name, $style['options']['test_option'], 'Make sure that the custom settings field got saved as expected.');
$this
->drupalGet("admin/structure/views/view/{$view_name}/edit");
$this
->submitForm([], 'Add Page');
$this
->drupalGet("admin/structure/views/nojs/display/{$view_name}/page_1/row");
$this
->submitForm([
'row[type]' => 'fields',
], 'Apply');
$this
->assertSession()
->pageTextNotContains('The selected style or row format does not use fields.');
}
}