From 0b0af86264107a9c95ff37a1b3fdc845aa7a27b2 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 6 Jan 2022 00:56:41 +0100 Subject: Test single page validation --- tests/Test.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Test.php b/tests/Test.php index abb4749..37e5f65 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -38,7 +38,7 @@ class Test extends TestCase keys = ["1234"] [api.cors] - origins = [] + origins = ["http://localhost:8081"] EOF); # formname config @@ -209,6 +209,7 @@ class Test extends TestCase public function testValidation() { + // valid response $response = $this->request('POST', 'customername/pagedform/submit?key=' . $this->apiKey, [ 'form_params' => [ 'name' => 'NAME', @@ -228,6 +229,7 @@ class Test extends TestCase $this->assertEquals(true, $body['second']['date']['is_valid']); $this->assertEquals(true, $body['second']['text']['is_valid']); + // invalid response $response = $this->request('POST', 'customername/pagedform/submit?key=' . $this->apiKey, [ 'form_params' => [ 'name' => 'NAME', @@ -241,6 +243,36 @@ class Test extends TestCase $this->assertEquals(false, $body['one']['email']['is_valid']); $this->assertEquals(true, $body['second']['date']['is_valid']); $this->assertEquals(false, $body['second']['text']['is_valid']); + + // valid response "one" page + $response = $this->request('POST', 'customername/pagedform/validate?page=one&key=' . $this->apiKey, [ + 'form_params' => [ + 'name' => 'NAME', + 'email' => 'EMAIL', + ], + ]); + $body = json_decode((string)$response->getBody(), true); + $this->assertArrayNotHasKey('error', $body); + $body = $body['data']; + $this->assertArrayNotHasKey('one', $body); + $this->assertArrayNotHasKey('second', $body); + $this->assertEquals(true, $body['name']['is_valid']); + $this->assertEquals(true, $body['email']['is_valid']); + + // valid response "second" page + $response = $this->request('POST', 'customername/pagedform/validate?page=second&key=' . $this->apiKey, [ + 'form_params' => [ + 'date' => 'DATE', + 'text' => '123', + ], + ]); + $body = json_decode((string)$response->getBody(), true); + $this->assertArrayNotHasKey('error', $body); + $body = $body['data']; + $this->assertArrayNotHasKey('one', $body); + $this->assertArrayNotHasKey('second', $body); + $this->assertEquals(true, $body['date']['is_valid']); + $this->assertEquals(true, $body['text']['is_valid']); } } -- cgit v1.2.3