Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeder committed Dec 2, 2024
1 parent f5d947f commit d8e7b69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private function getExpectedComplexArrayElement() {
'distribution' => [
0 => $this->getExpectedObject(),
],
'#required' => FALSE,
];
}

Expand Down
34 changes: 28 additions & 6 deletions modules/json_form_widget/tests/src/Unit/JsonFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,29 @@ public function testSchema() {
"#suffix" => '</div>',
"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.
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d8e7b69

Please sign in to comment.