Skip to content

Commit

Permalink
unit test for collection alterFieldValues
Browse files Browse the repository at this point in the history
  • Loading branch information
rudiedirkx committed Mar 11, 2022
1 parent 8f978ff commit 735c258
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tests/FormBuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function buildForm()
->add('body', 'textarea');
}

public function alterFieldValues(array &$values)
{
$values['body'] = strtoupper($values['body']);
}

public function alterValid(Form $mainForm, &$isValid)
{
$values = $this->getFieldValues();
Expand All @@ -88,6 +93,15 @@ public function buildForm()
$this->add('subcustom', 'form', [
'class' => CustomDummyForm::class,
]);

$this->add('subcustom_collection', 'collection', [
'type' => 'form',
'empty_row' => true,
'prefer_input' => true,
'options' => [
'class' => CustomDummyForm::class,
],
]);
}

public function alterFieldValues(array &$values)
Expand Down
14 changes: 11 additions & 3 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,24 @@ public function it_returns_field_values()
/** @test */
public function it_returns_altered_field_values()
{
$customForm = $this->formBuilder->create('CustomNesterDummyForm');

$this->request['name'] = 'lower case';
$this->request['subcustom'] = ['title' => 'Bar foo', 'body' => 'Foo bar'];
$this->request['subcustom_collection'] = [
['title' => 'Item 1 title', 'body' => 'Item 1 body'],
['title' => 'Item 2 title', 'body' => 'Item 2 body'],
];

$customForm = $this->formBuilder->create('CustomNesterDummyForm');

$this->assertEquals(
[
'name' => 'LOWER CASE',
'options' => ['x'],
'subcustom' => ['title' => 'Bar foo', 'body' => 'Foo bar'],
'subcustom' => ['title' => 'Bar foo', 'body' => 'FOO BAR'],
'subcustom_collection' => [
['title' => 'Item 1 title', 'body' => 'ITEM 1 BODY'],
['title' => 'Item 2 title', 'body' => 'ITEM 2 BODY'],
],
],
$customForm->getFieldValues()
);
Expand Down

0 comments on commit 735c258

Please sign in to comment.