Phalcon\Test\Unit\Validation\Validator\ExclusionInTest::testMultipleFieldSingleDomain PHP Method

testMultipleFieldSingleDomain() public method

Tests exclusion in validator with multiple field and single domain
Since: 2016-06-05
Author: Wojciech Ĺšlawski ([email protected])
    public function testMultipleFieldSingleDomain()
    {
        $this->specify('Test exclusion in validator with multiple field and single domain.', function () {
            $validation = new Validation();
            $validationMessages = ['type' => 'Type cant be mechanic or cyborg.', 'anotherType' => 'AnotherType cant by mechanic or cyborg.'];
            $validation->add(['type', 'anotherType'], new ExclusionIn(['domain' => ['mechanic', 'cyborg'], 'message' => $validationMessages]));
            $messages = $validation->validate(['type' => 'hydraulic', 'anotherType' => 'hydraulic']);
            expect($messages->count())->equals(0);
            $messages = $validation->validate(['type' => 'cyborg', 'anotherType' => 'hydraulic']);
            expect($messages->count())->equals(1);
            expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['type']);
            $messages = $validation->validate(['type' => 'cyborg', 'anotherType' => 'mechanic']);
            expect($messages->count())->equals(2);
            expect($messages->offsetGet(0)->getMessage())->equals($validationMessages['type']);
            expect($messages->offsetGet(1)->getMessage())->equals($validationMessages['anotherType']);
        });
    }