Phalcon\Test\Unit\Validation\Validator\InclusionInTest::testMultipleFieldMultipleDomain PHP Method

testMultipleFieldMultipleDomain() public method

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