From 55170a0b746e09c59fc6a0d78f2461bfea5f835c Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 17 Jun 2015 15:51:30 +1200 Subject: [PATCH] API make DataObject::validate public --- filesystem/File.php | 2 +- filesystem/Folder.php | 2 +- forms/FormField.php | 2 +- model/DataObject.php | 4 ++-- security/Group.php | 2 +- security/Member.php | 2 +- security/PermissionRoleCode.php | 2 +- tests/filesystem/FileTest.php | 6 +++--- tests/model/DataObjectTest.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/filesystem/File.php b/filesystem/File.php index 35bd2da18..5dfcf5783 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -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 diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 630128493..5d34a9511 100644 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -326,7 +326,7 @@ class Folder extends File { } } - protected function validate() { + public function validate() { return new ValidationResult(true); } diff --git a/forms/FormField.php b/forms/FormField.php index 718a9c50b..448f5b393 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -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) { diff --git a/model/DataObject.php b/model/DataObject.php index d59e2cb66..044347a9d 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -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(); } diff --git a/security/Group.php b/security/Group.php index 27ce75829..d7bddcae9 100755 --- a/security/Group.php +++ b/security/Group.php @@ -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", diff --git a/security/Member.php b/security/Member.php index 4b1dd7aed..a83a2c62a 100644 --- a/security/Member.php +++ b/security/Member.php @@ -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')) { diff --git a/security/PermissionRoleCode.php b/security/PermissionRoleCode.php index f954c6fd4..0982b96bd 100644 --- a/security/PermissionRoleCode.php +++ b/security/PermissionRoleCode.php @@ -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. diff --git a/tests/filesystem/FileTest.php b/tests/filesystem/FileTest.php index 0fd26f237..0c6f11da8 100644 --- a/tests/filesystem/FileTest.php +++ b/tests/filesystem/FileTest.php @@ -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'); diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index 58d5f9c70..26444ccb1 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -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 {