public function testFieldIsRequired() { //get the validator $requiredFields = new RequiredFields($fieldNames = array('Title', 'Content', 'Image', 'AnotherField')); foreach ($fieldNames as $field) { $this->assertTrue($requiredFields->fieldIsRequired($field), sprintf("Failed to find '%s' field in required list", $field)); } //add a new field $requiredFields->addRequiredField('ExtraField1'); //check the new field is required $this->assertTrue($requiredFields->fieldIsRequired('ExtraField1'), "Failed to find 'ExtraField1' field in required list after adding it to the list"); //check a non-existant field returns false $this->assertFalse($requiredFields->fieldIsRequired('DoesntExist'), "Unexpectedly returned true for a non-existant field"); }