diff options
Diffstat (limited to 'tests/Test.php')
-rw-r--r-- | tests/Test.php | 62 |
1 files changed, 58 insertions, 4 deletions
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', <<<EOF [field.text] placeholder = "Text placeholder" + + [field.text.validation] + pattern = "\\\d+" + + [field.manythings] + type = "select" + + [field.manythings.options] + first = "First level" + second = "Second level" + + [field.multiplethings] + type = "checkbox" + options = ["thing-1", "thing-2", "thing-3"] EOF); file_put_contents($contentRoot . '/customername/pagedform/fields/email.toml', <<<EOF type = "email" @@ -114,11 +128,11 @@ class Test extends TestCase EOF); } - public function request($method, $path): GuzzleHttpResponse + public function request($method, $path, $options = []): GuzzleHttpResponse { $response = null; try { - $response = $this->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']); } } |