Commit 0b271376 authored by Tyler Struyk's avatar Tyler Struyk
Browse files

ISTWCMS-4101: Add layout builder EC module along with test for the layout...

ISTWCMS-4101: Add layout builder EC module along with test for the layout builder section configuration form
parent 06da1516
......@@ -58,6 +58,7 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->createUsers();
$this->layoutSectionConfigurationFormTest();
$this->webformTests();
$this->createContent();
$this->taxonomies();
......@@ -1247,4 +1248,170 @@ class UwWcmsBasicTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Profile ' . $profile_name . ' has been created.');
}
/**
* Tests for Layout Section Configuration Form and their Settings.
*/
private function layoutSectionConfigurationFormTest() {
// Step 3A is in a bigger loop and only need to do it once.
$step3AComplete = FALSE;
$locator = '';
// Plan:
// Add 6 sections. One of each layout type.
// Each section will be a little bit different so we can test things.
// From Bottom to Top
// One column: Group1, Admin Label 1 Column, Section ID 1 Column.
// Two columns: Group1, Admin Label none, Section ID none.
// Three columns: Group2, Admin Label none.
// Four columns: no group, Admin Label none. Section ID 4 Column.
// Inverted "L" - right: no group. Admin Label Inverted "L" - right.
// Inverted "L" - left: Group2. Admin Label Inverted "L" - left.
$listLayout = [
[
'name' => 'One column',
'admin-label' => '1 Column',
'section-id' => '1 Column',
'ec-setting' => 1,
'ec-group-title' => 'One Column Tab Title',
'group' => 'group1',
'group-sections-total' => 1,
],
[
'name' => 'Two columns',
'admin-label' => '',
'section-id' => '',
'ec-setting' => 1,
'ec-group-title' => 'Two Column Tab Title',
'group' => 'group1',
'group-sections-total' => 2,
],
[
'name' => 'Three columns',
'admin-label' => '',
'section-id' => '',
'ec-setting' => 1,
'ec-group-title' => 'Third Column Tab Title',
'group' => 'group2',
'group-sections-total' => 1,
],
[
'name' => 'Four columns',
'admin-label' => '',
'section-id' => '4 Column',
'ec-setting' => 0,
'group' => '',
],
[
'name' => 'Inverted "L" - right',
'admin-label' => 'Inverted "L" - right',
'section-id' => '',
'ec-setting' => 0,
'group' => '',
],
[
'name' => 'Inverted "L" - left',
'admin-label' => 'Inverted "L" - left',
'section-id' => '',
'ec-setting' => 1,
'ec-group-title' => 'Inverted "L" - left Tab Title',
'group' => 'group2',
'group-sections-total' => 2,
],
];
$this->drupalLogin($this->drupalUsers['administrator']);
// Test step 1: Visit the home page layout.
$this->drupalGet('node/1/layout');
$this->assertSession()->statusCodeEquals(200);
foreach ($listLayout as $section) {
// Test step 2: Look on the layout edit page to click 'Add section'.
$this->clickLink('Add section');
$this->assertSession()->statusCodeEquals(200);
// Test step 3: Loop and add 6 sections. Testing along the way.
// Test step 3A: Verify all the columns. Do this only once.
if ($step3AComplete == FALSE) {
foreach ($listLayout as $layout) {
$this->assertSession()->linkExists($layout['name']);
}
$step3AComplete = TRUE;
}
// Test step 3B: Goto section configuration form.
$this->clickLink($section['name']);
// Test step 3C: Verify all configuration form elements.
// Note: Javascription is off so no conditional form elements are hidden.
$this->assertSession()->pageTextContains('Administrative label');
$this->assertSession()->pageTextContains('Section ID');
$this->assertSession()
->pageTextContains('Make Section Expand/Collapsible');
$this->assertSession()
->pageTextContains('Title of Expand/Collapse Group');
$this->assertSession()->pageTextContains('Heading Selector');
$this->assertSession()->pageTextContains('Grouping');
$this->assertSession()->pageTextContains('other');
$this->assertSession()->pageTextContains('Create new grouping');
$this->assertSession()->pageTextContains('Extra-wide contained width');
// No column widths on one column.
if ($section['name'] != 'One column') {
$this->assertSession()->pageTextContains('Column widths');
}
$locator = "//*[@id='edit-expand-collapse-group-" . $section['group'] . "']";
// Step 3D: Submit the form.
if ($this->getSession()->getPage()->find('xpath', $locator)) {
$this->submitForm([
'layout_settings[label]' => $section['admin-label'],
'layout_settings[layout_builder_id]' => $section['section-id'],
'expand_collapse[setting]' => $section['ec-setting'],
'expand_collapse[heading_selector]' => $section['heading-selector'] ?? 'h2',
'expand_collapse[group_title]' => $section['ec-group-title'] ?? '',
'expand_collapse[group]' => $section['group'],
], 'Add section');
}
else {
$this->submitForm([
'layout_settings[label]' => $section['admin-label'],
'layout_settings[layout_builder_id]' => $section['section-id'],
'expand_collapse[setting]' => $section['ec-setting'],
'expand_collapse[heading_selector]' => $section['heading-selector'] ?? 'h2',
'expand_collapse[group_title]' => $section['ec-group-title'] ?? '',
'expand_collapse[group]' => 'other',
'expand_collapse[new_grouping]' => $section['group'],
], 'Add section');
}
// Test step 3E: Check if page contains the correct link wordage.
$this->assertSession()->statusCodeEquals(200);
$msg = $this->t('Expand/Collapse Grouping of');
// Text is based on the label and group.
$labelCheck = [
'label' => "Configure " . $section['admin-label'],
'group' => "Configure [$msg: " . $section['group'] . "]",
'label-group' => "Configure " . $section['admin-label'] . " [$msg: " . $section['group'] . "]",
];
if (!empty($section['admin-label']) && !empty($section['group'])) {
// Configure {ADMIN LABEL} [Expand/Collapse Grouping of: {GROUP}].
$this->assertSession()->linkExists($labelCheck['label-group']);
}
elseif (!empty($section['admin-label']) && empty($section['group'])) {
// Configure {ADMIN LABEL}.
$this->assertSession()->linkExists($labelCheck['label']);
}
elseif (empty($section['admin-label']) && !empty($section['group'])) {
// Configure [Expand/Collapse Grouping of: {GROUP}].
$this->assertSession()->linkExists($labelCheck['group']);
}
// Step 3F: Assert the class and custom data property.
if (!empty($section['group'])) {
$locator = "//section[@data-expand-collapse-group='" . $section['group'] . "']";
$dataGroupCount = $this->getSession()->getPage()->findAll('xpath', $locator);
$this->assertCount($section['group-sections-total'], $dataGroupCount);
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment