/** * Make sure that the type is valid. */ public function valid_field(Validation $v, $field) { switch ($field) { case "mime_type": if ($this->is_movie()) { $legal_values = legal_file::get_movie_types(); } else { if ($this->is_photo()) { $legal_values = legal_file::get_photo_types(); } } break; case "sort_column": if (!array_key_exists($this->sort_column, $this->object)) { $v->add_error($field, "invalid"); } break; case "sort_order": $legal_values = array("ASC", "DESC", "asc", "desc"); break; case "type": $legal_values = array("album", "photo", "movie"); break; default: $v->add_error($field, "unvalidated_field"); break; } if (isset($legal_values) && !in_array($this->{$field}, $legal_values)) { $v->add_error($field, "invalid"); } }
public function get_movie_types_test() { // Note that this is one *more* than movie extensions since video/flv is added. $this->assert_equal(6, count(legal_file::get_movie_types())); }