function DisplayModeBundleSelectionTest::testBundleSelection
Same name and namespace in other branches
- 11.x core/modules/field_ui/tests/src/FunctionalJavascript/DisplayModeBundleSelectionTest.php \Drupal\Tests\field_ui\FunctionalJavascript\DisplayModeBundleSelectionTest::testBundleSelection()
- 10 core/modules/field_ui/tests/src/FunctionalJavascript/DisplayModeBundleSelectionTest.php \Drupal\Tests\field_ui\FunctionalJavascript\DisplayModeBundleSelectionTest::testBundleSelection()
Tests the bundle selection.
Attributes
#[DataProvider('providerBundleSelection')]
Parameters
string $display_mode: View or Form display mode.
string $path: Display mode path.
string $custom_mode: Custom mode to test.
File
-
core/
modules/ field_ui/ tests/ src/ FunctionalJavascript/ DisplayModeBundleSelectionTest.php, line 73
Class
- DisplayModeBundleSelectionTest
- Tests the bundle selection for view & form display modes.
Namespace
Drupal\Tests\field_ui\FunctionalJavascriptCode
public function testBundleSelection(string $display_mode, string $path, string $custom_mode) : void {
$page = $this->getSession()
->getPage();
$assert_session = $this->assertSession();
// Add new display mode for content.
$this->drupalGet("/admin/structure/display-modes/{$display_mode}");
$this->assertNotEmpty($assert_session->waitForText("Add {$display_mode} mode"));
$this->clickLink("Add {$display_mode} mode for Content");
$this->assertNotEmpty($assert_session->waitForText("Add new Content {$display_mode} mode"));
$page->find('css', '[data-drupal-selector="edit-label"]')
->setValue('test');
$page->find('css', '[data-drupal-selector="edit-bundles-by-entity-article"]')
->check();
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Save');
// Verify that test display mode is selected for article content type.
$this->drupalGet("/admin/structure/types/manage/article/{$path}");
if ($display_mode === 'view') {
$assert_session->elementExists('css', '#enabled-display-modes-wrapper #display-mode-node-article-test');
}
else {
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', '[data-drupal-selector="edit-display-modes-custom-test"]');
$this->assertTrue($checkbox->isChecked());
}
// Verify that test display mode is not selected for page content type.
$this->drupalGet("/admin/structure/types/manage/page/{$path}");
if ($display_mode === 'view') {
$enabled = $page->find('css', '#enabled-display-modes-wrapper #display-mode-node-page-test');
$this->assertNull($enabled, 'The "test" display mode should not be enabled for the page content type.');
}
else {
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', '[data-drupal-selector="edit-display-modes-custom-test"]');
$this->assertFalse($checkbox->isChecked());
}
// Click Add view/form display mode button.
$this->drupalGet("/admin/structure/display-modes/{$display_mode}");
$this->assertNotEmpty($assert_session->waitForText("Add {$display_mode} mode"));
$this->clickLink("Add {$display_mode} mode");
$this->assertNotEmpty($assert_session->waitForText("Choose {$display_mode} mode entity type"));
// Add new view/form display mode for content.
$this->clickLink('Content');
$this->assertNotEmpty($assert_session->waitForText("Add new Content {$display_mode} mode"));
$page->find('css', '[data-drupal-selector="edit-label"]')
->setValue('test2');
$page->find('css', '[data-drupal-selector="edit-bundles-by-entity-article"]')
->check();
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Save');
// Verify that test2 display mode is selected for article content type.
$this->drupalGet("/admin/structure/types/manage/article/{$path}");
if ($display_mode === 'view') {
$assert_session->waitForElement('css', '#display-mode-node-article-test2', 10000);
$enabled_element = $page->find('css', '#enabled-display-modes-wrapper #display-mode-node-article-test2');
$this->assertNotNull($enabled_element, 'The "test2" display mode should be in the enabled table.');
}
else {
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', '[data-drupal-selector="edit-display-modes-custom-test2"]');
$this->assertTrue($checkbox->isChecked());
}
// Verify that test2 display mode is not selected for page content type.
if ($display_mode === 'view') {
$this->drupalGet("/admin/structure/types/manage/page/{$path}");
$enabled = $page->find('css', '#enabled-display-modes-wrapper #display-mode-node-page-test2');
$this->assertNull($enabled, 'The "test2" display mode should not be enabled for the page content type.');
}
else {
$this->drupalGet("/admin/structure/types/manage/page/{$path}/default");
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', '[data-drupal-selector="edit-display-modes-custom-test2"]');
$this->assertFalse($checkbox->isChecked());
}
// Verify that display mode is not selected on article content type.
if ($display_mode === 'view') {
$this->drupalGet("/admin/structure/types/manage/article/{$path}");
$enabled = $page->find('css', "#enabled-display-modes-wrapper #display-mode-node-article-{$custom_mode}");
$this->assertNull($enabled, "The \"{$custom_mode}\" display mode should not be enabled for the article content type.");
}
else {
$this->drupalGet("/admin/structure/types/manage/article/{$path}/default");
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', "[data-drupal-selector='edit-display-modes-custom-{$custom_mode}']");
$this->assertFalse($checkbox->isChecked());
}
// Edit existing display mode and enable it for article content type.
$this->drupalGet("/admin/structure/display-modes/{$display_mode}");
$this->assertNotEmpty($assert_session->waitForText("Add {$display_mode} mode"));
$page->find('xpath', '//ul[@class = "dropbutton"]/li[1]/a')
->click();
$this->assertNotEmpty($assert_session->waitForText("This {$display_mode} mode will still be available for the rest of the Content types if not checked here, but it will not be enabled by default."));
$page->find('css', '[data-drupal-selector="edit-bundles-by-entity-article"]')
->check();
$page->find('css', '.ui-dialog-buttonset')
->pressButton('Save');
// Verify that display mode is selected on article content type.
if ($display_mode === 'view') {
$this->drupalGet("/admin/structure/types/manage/article/{$path}");
$enabled = $page->find('css', "#enabled-display-modes-wrapper #display-mode-node-article-{$custom_mode}");
$this->assertNotNull($enabled, "The \"{$custom_mode}\" display mode should be enabled for the article content type.");
}
else {
$this->drupalGet("/admin/structure/types/manage/article/{$path}/default");
$details = $page->find('css', 'details[data-drupal-selector="edit-modes"]');
if ($details && !$details->hasAttribute('open')) {
$summary = $details->find('css', 'summary');
if ($summary) {
$summary->click();
}
}
$checkbox = $page->find('css', "[data-drupal-selector='edit-display-modes-custom-{$custom_mode}']");
$this->assertTrue($checkbox->isChecked());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.