Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit b7b1531

Browse files
committed
Test validating collection - custom error message
1 parent 0583947 commit b7b1531

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/CollectionInputFilterTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,4 +552,54 @@ public function testValidateCollection()
552552
$this->assertContains('The input appears to be a local network name but local network names are not allowed', $messages[1]['email']);
553553
// @codingStandardsIgnoreEnd
554554
}
555+
556+
public function testValidateCollectionWithCustomErrorMessage()
557+
{
558+
$inputFilter = new InputFilter();
559+
$inputFilter->add([
560+
'name' => 'email',
561+
'required' => true,
562+
'validators' => [
563+
['name' => EmailAddress::class],
564+
['name' => NotEmpty::class],
565+
],
566+
'error_message' => 'CUSTOM ERROR MESSAGE',
567+
]);
568+
$inputFilter->add([
569+
'name' => 'name',
570+
'required' => true,
571+
'validators' => [
572+
['name' => NotEmpty::class],
573+
],
574+
]);
575+
576+
$collectionInputFilter = $this->inputFilter;
577+
$collectionInputFilter->setInputFilter($inputFilter);
578+
579+
$collectionInputFilter->setData([
580+
[
581+
'name' => 'Tom',
582+
],
583+
[
584+
'email' => 'tom@tom',
585+
'name' => 'Tom',
586+
],
587+
]);
588+
589+
$isValid = $collectionInputFilter->isValid();
590+
$messages = $collectionInputFilter->getMessages();
591+
592+
593+
$this->assertFalse($isValid);
594+
$this->assertCount(2, $messages);
595+
596+
$this->assertArrayHasKey('email', $messages[0]);
597+
$this->assertCount(1, $messages[0]['email']);
598+
$this->assertContains('CUSTOM ERROR MESSAGE', $messages[0]['email']);
599+
$this->assertNotContains('Value is required and can\'t be empty', $messages[0]['email']);
600+
601+
$this->assertArrayHasKey('email', $messages[1]);
602+
$this->assertCount(1, $messages[1]['email']);
603+
$this->assertContains('CUSTOM ERROR MESSAGE', $messages[1]['email']);
604+
}
555605
}

0 commit comments

Comments
 (0)