function DisplayModeBundleSelectionTest::testBundleSelection

Same name in other branches
  1. 11.x core/modules/field_ui/tests/src/FunctionalJavascript/DisplayModeBundleSelectionTest.php \Drupal\Tests\field_ui\FunctionalJavascript\DisplayModeBundleSelectionTest::testBundleSelection()

Tests the bundle selection.

@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 72

Class

DisplayModeBundleSelectionTest
Tests the bundle selection for view & form display modes.

Namespace

Drupal\Tests\field_ui\FunctionalJavascript

Code

public function testBundleSelection($display_mode, $path, $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}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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.
    $this->drupalGet("/admin/structure/types/manage/page/{$path}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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.
    $this->drupalGet("/admin/structure/types/manage/article/{$path}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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.
    $this->drupalGet("/admin/structure/types/manage/article/{$path}");
    $page->find('css', '[data-drupal-selector="edit-modes"]')
        ->pressButton('Custom display settings');
    $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.