From ce4e065b17f7d51bbc2ad8c38c3ad068b6041772 Mon Sep 17 00:00:00 2001
From: M Parker <mparker17@536298.no-reply.drupal.org>
Date: Fri, 4 Sep 2015 16:35:59 -0400
Subject: [PATCH] 2563339-6

---
 .../src/Tests/Form/ElementsVerticalTabsTest.php    | 11 ++++
 .../tests/modules/form_test/form_test.routing.yml  |  8 +++
 .../src/Form/FormTestVerticalTabs4Form.php         | 65 ++++++++++++++++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabs4Form.php

diff --git a/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php b/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php
index d4b16e4..66c14da 100644
--- a/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php
+++ b/core/modules/system/src/Tests/Form/ElementsVerticalTabsTest.php
@@ -90,4 +90,15 @@ function testDefaultTabCleaned() {
     $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
     $this->assertFalse(isset($values['vertical_tabs__active_tab']), SafeMarkup::format('%element was removed.', ['%element' => 'vertical_tabs__active_tab']));
   }
+
+  /**
+   * Test that tabs show for child elements with groups but without weights.
+   */
+  function testTabsShowForChildAndGroupWithoutWeight() {
+    // Tests that we can see fieldsets which are BOTH child elements of the
+    // vertical_tabs form element AND have a #group set, but not a #weight.
+    $this->drupalGet('form_test/vertical-tabs-4');
+    $tab2 = $this->xpath("//div[@class='vertical-tabs-panes']/fieldset[@id='edit-tab2']");
+    $this->assertTrue(isset($tab2[0]), 'Child with #group found.');
+  }
 }
diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml
index 82243fa..936236e 100644
--- a/core/modules/system/tests/modules/form_test/form_test.routing.yml
+++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml
@@ -164,6 +164,14 @@ form_test.vertical_tabs:
   requirements:
     _access: 'TRUE'
 
+form_test.vertical_tabs_4:
+  path: '/form_test/vertical-tabs-4'
+  defaults:
+    _form: '\Drupal\form_test\Form\FormTestVerticalTabs4Form'
+    _title: 'Vertical tabs tests'
+  requirements:
+    _access: 'TRUE'
+
 form_test.storage:
   path: '/form_test/form-storage'
   defaults:
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabs4Form.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabs4Form.php
new file mode 100644
index 0000000..3249270
--- /dev/null
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabs4Form.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\form_test\Form\FormTestVerticalTabsForm.
+ */
+
+namespace Drupal\form_test\Form;
+
+use Drupal\Core\Form\FormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+class FormTestVerticalTabs4Form extends FormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return '_form_test_vertical_tabs_4_form';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form['vertical_tabs'] = array(
+      '#type' => 'vertical_tabs',
+    );
+
+    $form['vertical_tabs']['tab1'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Tab 1'),
+      '#group' => 'vertical_tabs',
+      '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'),
+    );
+    $form['vertical_tabs']['tab1']['field1'] = array(
+      '#title' => t('Field 1'),
+      '#type' => 'textfield',
+    );
+
+    $form['vertical_tabs']['tab2'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Tab 1'),
+      '#group' => 'vertical_tabs',
+      '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'),
+    );
+    $form['vertical_tabs']['tab2']['field2'] = array(
+      '#title' => t('Field 1'),
+      '#type' => 'textfield',
+    );
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $form_state->cleanValues();
+    // This won't have a proper JSON header, but Drupal doesn't check for that
+    // anyway so this is fine until it's replaced with a JsonResponse.
+    print Json::encode($form_state->getValues());
+    exit;
+  }
+}
-- 
2.5.0

