function TestMultiWidthLayoutsTest::testWidthChange

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\TestMultiWidthLayoutsTest::testWidthChange()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\TestMultiWidthLayoutsTest::testWidthChange()
  3. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\TestMultiWidthLayoutsTest::testWidthChange()

Tests changing the columns widths of a multi-width section.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/TestMultiWidthLayoutsTest.php, line 54

Class

TestMultiWidthLayoutsTest
Test the multi-width layout plugins.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testWidthChange() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalGet('node/1/layout');
    $width_options = [
        [
            'label' => 'Two column',
            'default_width' => '50-50',
            'additional_widths' => [
                '33-67',
                '67-33',
                '25-75',
                '75-25',
            ],
            'class' => 'layout--twocol-section--',
        ],
        [
            'label' => 'Three column',
            'default_width' => '33-34-33',
            'additional_widths' => [
                '25-50-25',
                '25-25-50',
                '50-25-25',
            ],
            'class' => 'layout--threecol-section--',
        ],
    ];
    foreach ($width_options as $width_option) {
        $width = $width_option['default_width'];
        $assert_session->linkExists('Add section');
        $page->clickLink('Add section');
        $this->assertNotEmpty($assert_session->waitForElementVisible('css', "#drupal-off-canvas a:contains(\"{$width_option['label']}\")"));
        $page->clickLink($width_option['label']);
        $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Add section"]'));
        $page->pressButton("Add section");
        $this->assertWidthClassApplied($width_option['class'] . $width);
        foreach ($width_option['additional_widths'] as $width) {
            $width_class = $width_option['class'] . $width;
            $assert_session->linkExists('Configure Section 1');
            $page->clickLink('Configure Section 1');
            $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Update"]'));
            $page->findField('layout_settings[column_widths]')
                ->setValue($width);
            $page->pressButton("Update");
            $this->assertWidthClassApplied($width_class);
        }
        $assert_session->linkExists('Remove Section 1');
        $this->clickLink('Remove Section 1');
        $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Remove"]'));
        $page->pressButton('Remove');
        $assert_session->assertNoElementAfterWait('css', ".{$width_class}");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.