/** * Combine this Validation Result with the ValidationResult given in other. * It will be valid if both this and the other result are valid. * This object will be modified to contain the new validation information. */ function combineAnd(ValidationResult $other) { $this->isValid = $this->isValid && $other->valid(); $this->errorList = array_merge($this->errorList, $other->messageList()); }
/** * Test combining validation results together */ public function testCombineResults() { $result = new ValidationResult(); $anotherresult = new ValidationResult(); $yetanotherresult = new ValidationResult(); $anotherresult->error("Eat with your mouth closed", "EATING101"); $yetanotherresult->error("You didn't wash your hands", "BECLEAN"); $this->assertTrue($result->valid()); $this->assertFalse($anotherresult->valid()); $this->assertFalse($yetanotherresult->valid()); $result->combineAnd($anotherresult)->combineAnd($yetanotherresult); $this->assertFalse($result->valid()); $this->assertEquals(array("EATING101" => "Eat with your mouth closed", "BECLEAN" => "You didn't wash your hands"), $result->messageList()); }