class StyleUITest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views_ui/tests/src/Functional/StyleUITest.php \Drupal\Tests\views_ui\Functional\StyleUITest
- 9 core/modules/views_ui/tests/src/Functional/StyleUITest.php \Drupal\Tests\views_ui\Functional\StyleUITest
Tests the UI of style plugins.
@group views_ui
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\views\Functional\ViewTestBase uses ViewResultAssertionTrait
- class \Drupal\Tests\views_ui\Functional\UITestBase
- class \Drupal\Tests\views_ui\Functional\StyleUITest
- class \Drupal\Tests\views_ui\Functional\UITestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses ViewResultAssertionTrait
Expanded class hierarchy of StyleUITest
See also
\Drupal\views_test_data\Plugin\views\style\StyleTest.
File
- core/
modules/ views_ui/ tests/ src/ Functional/ StyleUITest.php, line 13
Namespace
Drupal\Tests\views_ui\FunctionalView source
class StyleUITest extends UITestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_view',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests changing the style plugin and changing some options of a style.
*/
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.');
// Test that fields are working correctly in the UI for style plugins when
// a field row plugin is selected.
$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');
// If fields are being used this text will not be shown.
$this
->assertSession()
->pageTextNotContains('The selected style or row format does not use fields.');
}
}