Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation exception can be rendered only if a form field exists #1888

Merged
merged 5 commits into from
Oct 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
mvorisek committed Oct 6, 2022
commit 29e2902ad0f7716cf7db7c625203258d11d40793
23 changes: 17 additions & 6 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
use Atk4\Ui\App;
use Atk4\Ui\Callback;
use Atk4\Ui\Exception;
use Atk4\Ui\Exception\UnhandledCallbackExceptionError;
use Atk4\Ui\Form;
use Mvorisek\Atk4\Hintable\Phpstan\PhpstanUtil;

@@ -115,11 +116,6 @@ public function testTextarea(): void
});
}

public function assertSubmitError(array $post, \Closure $checkExpectedErrorsFx): void
{
$this->assertSubmit($post, null, $checkExpectedErrorsFx);
}

public function assertFormControlError(string $field, string $error): void
{
$n = preg_match_all('~form\("add prompt", "([^"]*)", "([^"]*)"\)~', $this->formError, $matchesAll, \PREG_SET_ORDER);
@@ -162,7 +158,7 @@ public function testSubmitError(): void
$m = $m->createEntity();
$this->form->setModel($m);

$this->assertSubmitError(['opt1' => '2', 'opt3_z' => '0', 'opt4' => '', 'opt4_z' => '0'], function (string $formError) {
$this->assertSubmit(['opt1' => '2', 'opt3_z' => '0', 'opt4' => '', 'opt4_z' => '0'], null, function (string $formError) {
// dropdown validates to make sure option is proper
$this->assertFormControlError('opt1', 'not one of the allowed values');

@@ -176,6 +172,21 @@ public function testSubmitError(): void
$this->assertFormControlError('opt4_z', 'Must not be empty');
});
}

public function testSubmitNonFormFieldError(): void
{
$m = new Model();
$m->addField('foo', ['nullable' => false]);
$m->addField('bar', ['nullable' => false]);

$m = $m->createEntity();
$this->form->setModel($m, ['foo']);

$this->expectException(UnhandledCallbackExceptionError::class);
$this->assertSubmit(['foo' => 'x'], function (Model $model) {
$model->set('bar', null);
});
}
}

class AppFormTestMock extends App