Merge pull request #4294 from tractorcow/pulls/4.0/make-validate-public

API make DataObject::validate public
This commit is contained in:
Ingo Schommer 2015-06-18 09:17:49 +12:00
commit 3e2fe2b751
9 changed files with 12 additions and 12 deletions

View File

@ -917,7 +917,7 @@ class File extends DataObject {
return $labels;
}
protected function validate() {
public function validate() {
if($this->config()->apply_restrictions_to_admin || !Permission::check('ADMIN')) {
// Extension validation
// TODO Merge this with Upload_Validator

View File

@ -326,7 +326,7 @@ class Folder extends File {
}
}
protected function validate() {
public function validate() {
return new ValidationResult(true);
}

View File

@ -919,7 +919,7 @@ class FormField extends RequestHandler {
* Validation method each {@link FormField} subclass should implement,
* determining whether the field is valid or not based on the value.
*
* @param Validator $validator
* @param Validator
* @return boolean
*/
public function validate($validator) {

View File

@ -1063,7 +1063,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @see {@link ValidationResult}
* @return ValidationResult
*/
protected function validate() {
public function validate() {
$result = ValidationResult::create();
$this->extend('validate', $result);
return $result;
@ -1075,7 +1075,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @return ValidationResult
*/
public function doValidate() {
// validate will be public in 4.0
Deprecation::notice('5.0', 'Use validate');
return $this->validate();
}

View File

@ -336,7 +336,7 @@ class Group extends DataObject {
$this->setField("Code", Convert::raw2url($val));
}
protected function validate() {
public function validate() {
$result = parent::validate();
// Check if the new group hierarchy would add certain "privileged permissions",

View File

@ -1487,7 +1487,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
/**
* Validate this member object.
*/
protected function validate() {
public function validate() {
$valid = parent::validate();
if(!$this->ID || $this->isChanged('Password')) {

View File

@ -20,7 +20,7 @@ class PermissionRoleCode extends DataObject {
"Role" => "PermissionRole",
);
protected function validate() {
public function validate() {
$result = parent::validate();
// Check that new code doesn't increase privileges, unless an admin is editing.

View File

@ -103,18 +103,18 @@ class FileTest extends SapphireTest {
// Invalid ext
$file->Name = 'asdf.php';
$v = $file->doValidate();
$v = $file->validate();
$this->assertFalse($v->valid());
$this->assertContains('Extension is not allowed', $v->message());
// Valid ext
$file->Name = 'asdf.txt';
$v = $file->doValidate();
$v = $file->validate();
$this->assertTrue($v->valid());
// Capital extension is valid as well
$file->Name = 'asdf.TXT';
$v = $file->doValidate();
$v = $file->validate();
$this->assertTrue($v->valid());
Config::inst()->remove('File', 'allowed_extensions');

View File

@ -1821,7 +1821,7 @@ class DataObjectTest_ValidatedObject extends DataObject implements TestOnly {
'Name' => 'Varchar(50)'
);
protected function validate() {
public function validate() {
if(!empty($this->Name)) {
return new ValidationResult();
} else {