From d6c5c7735e3207ead7759375e444bc6b72045e49 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 5 Jan 2022 23:12:23 +0100 Subject: Validate fields by pattern and add more example fields --- tests/Test.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/Test.php b/tests/Test.php index 798a74d..abb4749 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -96,6 +96,20 @@ class Test extends TestCase file_put_contents($contentRoot . '/customername/pagedform/fields/second.toml', <<client->request($method, $path, ['http_errors' => false]); + $response = $this->client->request($method, $path, ['http_errors' => false] + $options); } catch (\Exception $e) {} return $response; @@ -150,7 +164,8 @@ class Test extends TestCase $this->assertEquals(Response::HTTP_OK, $pagedformResponse->getStatusCode()); } - public function testFields() { + public function testFields() + { $formnameResponse = $this->request('GET', 'customername/formname/fields?key=' . $this->apiKey); $formnameBody = json_decode((string)$formnameResponse->getBody(), true)['data']; $this->assertArrayHasKey('name', $formnameBody); @@ -162,7 +177,8 @@ class Test extends TestCase $this->assertArrayHasKey('required', $formnameBody['email']); } - public function testFieldsPaged() { + public function testFieldsPaged() + { // all pages $pagedformResponse = $this->request('GET', 'customername/pagedform/fields?key=' . $this->apiKey); $pagedformBody = json_decode((string)$pagedformResponse->getBody(), true)['data']; @@ -187,6 +203,44 @@ class Test extends TestCase $this->assertArrayNotHasKey('second', $pagedformBody); $this->assertArrayHasKey('date', $pagedformBody); $this->assertArrayHasKey('text', $pagedformBody); + $this->assertArrayHasKey('first', $pagedformBody['manythings']['options']); + $this->assertEquals('thing-2', $pagedformBody['multiplethings']['options'][1]); + } + + public function testValidation() + { + $response = $this->request('POST', 'customername/pagedform/submit?key=' . $this->apiKey, [ + 'form_params' => [ + 'name' => 'NAME', + 'email' => 'EMAIL', + 'date' => 'DATE', + 'text' => '123', + 'manythings' => 'second', + 'multiplethings' => [ + 'thing-1', 'thing-3', + ], + ], + ]); + $body = json_decode((string)$response->getBody(), true); + $this->assertArrayNotHasKey('error', $body); + $body = $body['data']; + $this->assertEquals(true, $body['one']['email']['is_valid']); + $this->assertEquals(true, $body['second']['date']['is_valid']); + $this->assertEquals(true, $body['second']['text']['is_valid']); + + $response = $this->request('POST', 'customername/pagedform/submit?key=' . $this->apiKey, [ + 'form_params' => [ + 'name' => 'NAME', + 'date' => 'DATE', + 'text' => 'einszweidrei', + ], + ]); + $body = json_decode((string)$response->getBody(), true); + $this->assertArrayHasKey('error', $body); + $body = $body['data']; + $this->assertEquals(false, $body['one']['email']['is_valid']); + $this->assertEquals(true, $body['second']['date']['is_valid']); + $this->assertEquals(false, $body['second']['text']['is_valid']); } } -- cgit v1.2.3