diff --git a/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php b/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php index 2f88b400d8..8634e4d302 100644 --- a/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php +++ b/modules/json_form_widget/tests/src/Unit/ArrayHelperTest.php @@ -207,6 +207,7 @@ private function getExpectedComplexArrayElement() { 'distribution' => [ 0 => $this->getExpectedObject(), ], + '#required' => FALSE, ]; } diff --git a/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php b/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php index 7ee6b13a54..a32f92be48 100644 --- a/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php +++ b/modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php @@ -306,17 +306,29 @@ public function testSchema() { "#suffix" => '', "keyword" => [ 0 => [ - "#type" => "textfield", - "#title" => "Tag", + "#type" => "fieldset", "#required" => FALSE, + '#attributes' => [ + 'class' => ['json-form-widget-array-item'], + 'data-parent' => 'keyword', + ], + "field" => [ + '#type' => 'textfield', + '#title' => 'Tag', + ], ], ], + '#required' => FALSE, ], ]; $form_state = new FormState(); $form_state->set(ArrayHelper::buildCountProperty('keyword'), 1); $result = $form_builder->getJsonForm([], $form_state); - unset($result['keyword']['actions']); + // The actions are too complex to deal with in the $expected array, we just + // assert the count is correct then remove them. + $this->assertCount(1, $result['keyword']['keyword']); + $this->assertCount(1, $result['keyword']['keyword']); + unset($result['keyword']['actions'], $result['keyword']['keyword'][0]['actions']); $this->assertEquals($expected, $result); // Test array required. @@ -355,16 +367,26 @@ public function testSchema() { '#description_display' => 'before', "keyword" => [ 0 => [ - "#type" => "textfield", - "#title" => "Tag", + "#type" => "fieldset", "#required" => TRUE, + 'field' => [ + '#type' => 'textfield', + '#title' => 'Tag', + ], + '#attributes' => [ + 'class' => ['json-form-widget-array-item'], + 'data-parent' => 'keyword', + ], ], ], + '#required' => TRUE, ], ]; $form_state = new FormState(); $result = $form_builder->getJsonForm([], $form_state); - unset($result['keyword']['actions']); + $this->assertCount(1, $result['keyword']['keyword']); + $this->assertCount(1, $result['keyword']['keyword']); + unset($result['keyword']['actions'], $result['keyword']['keyword'][0]['actions']); $this->assertEquals($expected, $result); }