Skip to content

Commit 1fb9339

Browse files
committed
tests: Add extra tests for #68
Though they are currently broken by something else so marking them as ignored.
1 parent 8fede17 commit 1fb9339

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

tests/Unit/CreateButtonTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,54 @@ public function testNoOrphanFieldsets()
170170
$this->assertCount(2, $dom->find('fieldset'), 'After adding a container, there should be two fieldsets.');
171171
}
172172

173+
/**
174+
* Ensure filters (e.g. integer) work on submit,
175+
* since they are dependent on properly set validation scope.
176+
*/
177+
public function testSendCreateFilter()
178+
{
179+
$this->markTestIncomplete(
180+
'`getValues()` omits `num` field, even though it works '
181+
. 'just fine when sending without the button.'
182+
);
183+
184+
$response = $this->services->form->createRequest(
185+
MultiplierBuilder::create()
186+
->fields([])
187+
->beforeFormModifier(function (Form $form) {
188+
$form->addInteger('num');
189+
})
190+
->multiplierModifier(function (Multiplier $multiplier) {
191+
$multiplier->onCreate[] = function (Container $container) {
192+
$container->addInteger('mnum')->setDefaultValue(47);
193+
};
194+
})
195+
->addCreateButton()
196+
->createForm()
197+
)
198+
->setPost([
199+
'num' => '11',
200+
'm' => [
201+
['mnum' => '49'],
202+
'multiplier_creator' => '',
203+
],
204+
])->send();
205+
206+
$this->assertTrue($response->isSuccess());
207+
$this->assertSame([
208+
'num' => 11,
209+
'm' => [
210+
['mnum' => 49],
211+
// TODO: not sure if this is correct
212+
['mnum' => null],
213+
],
214+
], $response->getValues());
215+
216+
$dom = $response->toDomQuery();
217+
218+
$this->assertDomHas($dom, 'input[name="m[0][mnum]"][value="49"]');
219+
$this->assertDomHas($dom, 'input[name="m[1][mnum]"][value="47"]');
220+
$this->assertDomNotHas($dom, 'input[name="m[2][mnum]"]');
221+
}
222+
173223
}

tests/Unit/RemoveButtonTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,63 @@ public function testOnRemoveEvent()
257257
$this->assertDomNotHas($dom, 'input[name="m[0][bar]"]');
258258
}
259259

260+
/**
261+
* Ensure filters (e.g. integer) work on submit,
262+
* since they are dependent on properly set validation scope.
263+
*/
264+
public function testSendRemoveFilter()
265+
{
266+
$this->markTestIncomplete(
267+
'`getValues()` returns array `["m" => [], "m2" => []]`, '
268+
. 'even though it works just fine when sending without the button.'
269+
);
270+
271+
$response = $this->services->form->createRequest(
272+
MultiplierBuilder::create(2)
273+
->setMinCopies(1)
274+
->fields([])
275+
->beforeFormModifier(function (Form $form) {
276+
$form->addInteger('num');
277+
})
278+
->multiplierModifier(function (Multiplier $multiplier) {
279+
$multiplier->onCreate[] = function (Container $container) {
280+
$container->addInteger('mnum')->setDefaultValue(47);
281+
};
282+
$multiplier->addRemoveButton();
283+
})
284+
->formModifier(function (Form $form) {
285+
$form['m2'] = new Multiplier(function (Container $container) {
286+
$container->addInteger('m2num')->setDefaultValue(72);
287+
});
288+
})
289+
->createForm()
290+
)
291+
->setPost([
292+
'num' => '11',
293+
'm' => [
294+
['mnum' => '49'],
295+
['mnum' => '47', 'multiplier_remover' => ''],
296+
],
297+
'm2' => [
298+
['m2num' => '72'],
299+
],
300+
])->send();
301+
302+
$this->assertTrue($response->isSuccess());
303+
$this->assertSame([
304+
'num' => 11,
305+
'm' => [
306+
['mnum' => 49],
307+
],
308+
'm2' => [
309+
['m2num' => 72],
310+
],
311+
], $response->getValues());
312+
313+
$dom = $response->toDomQuery();
314+
315+
$this->assertDomHas($dom, 'input[name="m[0][mnum]"][value="49"]');
316+
$this->assertDomNotHas($dom, 'input[name="m[1][mnum]"]');
317+
}
318+
260319
}

0 commit comments

Comments
 (0)