diff --git a/src/Core/Validation/ValidationResult.php b/src/Core/Validation/ValidationResult.php index e767be85d9e..9cc0147ebb6 100644 --- a/src/Core/Validation/ValidationResult.php +++ b/src/Core/Validation/ValidationResult.php @@ -50,91 +50,52 @@ class ValidationResult /** * Is the result valid or not. * Note that there can be non-error messages in the list. - * - * @var bool */ - protected $isValid = true; + protected bool $isValid = true; /** * List of messages - * - * @var array */ - protected $messages = []; + protected array $messages = []; /** * Record an error against this validation result, * - * @param string $message The message string. - * @param string $messageType Passed as a CSS class to the form, so other values can be used if desired. + * @param $message The message string. + * @param $messageType Passed as a CSS class to the form, so other values can be used if desired. * Standard types are defined by the TYPE_ constant definitions. - * @param string $code A codename for this error. Only one message per codename will be added. + * @param $code A codename for this error. Only one message per codename will be added. * This can be usedful for ensuring no duplicate messages - * @param string|bool $cast Cast type; One of the CAST_ constant definitions. - * Bool values will be treated as plain text flag. + * @param $cast Cast type; One of the CAST_ constant definitions. * @return $this */ public function addError( - $message, - $messageType = ValidationResult::TYPE_ERROR, - $code = null, - $cast = ValidationResult::CAST_TEXT - ) { - if ($code === null) { - Deprecation::notice( - '5.4.0', - 'Passing $code as null is deprecated. Pass a blank string instead.', - Deprecation::SCOPE_GLOBAL - ); - $code = ''; - } - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } + string $message, + string $messageType = ValidationResult::TYPE_ERROR, + string $code = '', + string $cast = ValidationResult::CAST_TEXT, + ): static { return $this->addFieldError('', $message, $messageType, $code, $cast); } /** * Record an error against this validation result, * - * @param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed. - * @param string $message The message string. - * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS + * @param $fieldName The field to link the message to. If omitted; a form-wide message is assumed. + * @param $message The message string. + * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS * class to the form, so other values can be used if desired. - * @param string $code A codename for this error. Only one message per codename will be added. + * @param $code A codename for this error. Only one message per codename will be added. * This can be usedful for ensuring no duplicate messages - * @param string|bool $cast Cast type; One of the CAST_ constant definitions. - * Bool values will be treated as plain text flag. - * @return $this + * @param $cast Cast type; One of the CAST_ constant definitions. */ public function addFieldError( - $fieldName, - $message, - $messageType = ValidationResult::TYPE_ERROR, - $code = null, - $cast = ValidationResult::CAST_TEXT, - ) { - if ($code === null) { - Deprecation::notice( - '5.4.0', - 'Passing $code as null is deprecated. Pass a blank string instead.', - Deprecation::SCOPE_GLOBAL - ); - $code = ''; - } - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } + string $fieldName, + string $message, + string $messageType = ValidationResult::TYPE_ERROR, + string $code = '', + string $cast = ValidationResult::CAST_TEXT, + ): static { $this->isValid = false; return $this->addFieldMessage($fieldName, $message, $messageType, $code, $cast); } @@ -142,81 +103,42 @@ public function addFieldError( /** * Add a message to this ValidationResult without necessarily marking it as an error * - * @param string $message The message string. - * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS + * @param $message The message string. + * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS * class to the form, so other values can be used if desired. - * @param string $code A codename for this error. Only one message per codename will be added. + * @param $code A codename for this error. Only one message per codename will be added. * This can be usedful for ensuring no duplicate messages - * @param string|bool $cast Cast type; One of the CAST_ constant definitions. - * Bool values will be treated as plain text flag. - * @return $this + * @param $cast Cast type; One of the CAST_ constant definitions. */ public function addMessage( - $message, - $messageType = ValidationResult::TYPE_ERROR, - $code = null, - $cast = ValidationResult::CAST_TEXT, - ) { - if ($code === null) { - Deprecation::notice( - '5.4.0', - 'Passing $code as null is deprecated. Pass a blank string instead.', - Deprecation::SCOPE_GLOBAL - ); - $code = ''; - } - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } - return $this->addFieldMessage(null, $message, $messageType, $code, $cast); + string $message, + string $messageType = ValidationResult::TYPE_ERROR, + string $code = '', + string $cast = ValidationResult::CAST_TEXT, + ): static { + return $this->addFieldMessage('', $message, $messageType, $code, $cast); } /** * Add a message to this ValidationResult without necessarily marking it as an error * - * @param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed. - * @param string $message The message string. - * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS + * @param $fieldName The field to link the message to. If omitted; a form-wide message is assumed. + * @param $message The message string. + * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS * class to the form, so other values can be used if desired. - * @param string $code A codename for this error. Only one message per codename will be added. + * @param $code A codename for this error. Only one message per codename will be added. * This can be usedful for ensuring no duplicate messages - * @param string|bool $cast Cast type; One of the CAST_ constant definitions. - * Bool values will be treated as plain text flag. - * @return $this + * @param $cast Cast type; One of the CAST_ constant definitions. */ public function addFieldMessage( - $fieldName, - $message, - $messageType = ValidationResult::TYPE_ERROR, - $code = null, - $cast = ValidationResult::CAST_TEXT, - ) { - if ($code === null) { - Deprecation::notice( - '5.4.0', - 'Passing $code as null is deprecated. Pass a blank string instead.', - Deprecation::SCOPE_GLOBAL - ); - $code = ''; - } - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } + string $fieldName, + string $message, + string $messageType = ValidationResult::TYPE_ERROR, + string $code = '', + string $cast = ValidationResult::CAST_TEXT, + ): static { if ($code && is_numeric($code)) { - throw new InvalidArgumentException("Don't use a numeric code '$code'. Use a string."); - } - if (is_bool($cast)) { - $cast = $cast ? ValidationResult::CAST_TEXT : ValidationResult::CAST_HTML; + throw new InvalidArgumentException("Don't use a numeric code '$code'. Use a non-numeric code instead."); } $metadata = [ 'message' => $message, @@ -229,15 +151,13 @@ public function addFieldMessage( } else { $this->messages[] = $metadata; } - return $this; } /** * Returns true if the result is valid. - * @return boolean */ - public function isValid() + public function isValid(): bool { return $this->isValid; } @@ -245,9 +165,9 @@ public function isValid() /** * Return the full error meta-data, suitable for combining with another ValidationResult. * - * @return array Array of messages, where each item is an array of data for that message. + * @return Array of messages, where each item is an array of data for that message. */ - public function getMessages() + public function getMessages(): array { return $this->messages; } @@ -257,10 +177,9 @@ public function getMessages() * It will be valid if both this and the other result are valid. * This object will be modified to contain the new validation information. * - * @param ValidationResult $other the validation result object to combine - * @return $this + * @param $other the validation result object to combine */ - public function combineAnd(ValidationResult $other) + public function combineAnd(ValidationResult $other): static { $this->isValid = $this->isValid && $other->isValid(); $this->messages = array_merge($this->messages, $other->getMessages()); diff --git a/src/Forms/CheckboxField.php b/src/Forms/CheckboxField.php index 48f1c652e87..90a742e8feb 100644 --- a/src/Forms/CheckboxField.php +++ b/src/Forms/CheckboxField.php @@ -21,7 +21,7 @@ public function dataValue() return ($this->value) ? 1 : null; } - public function Value() + public function getValue(): mixed { return ($this->value) ? 1 : 0; } @@ -39,7 +39,7 @@ public function getAttributes() return array_merge( $attributes, [ - 'checked' => ($this->Value()) ? 'checked' : null, + 'checked' => ($this->getValue()) ? 'checked' : null, 'type' => 'checkbox', ] ); diff --git a/src/Forms/CheckboxField_Readonly.php b/src/Forms/CheckboxField_Readonly.php index f161a66c746..b611d17c311 100644 --- a/src/Forms/CheckboxField_Readonly.php +++ b/src/Forms/CheckboxField_Readonly.php @@ -13,7 +13,7 @@ public function performReadonlyTransformation() return clone $this; } - public function Value() + public function getFormattedValue(): mixed { return $this->value ? _t('SilverStripe\\Forms\\CheckboxField.YESANSWER', 'Yes') : diff --git a/src/Forms/ConfirmedPasswordField.php b/src/Forms/ConfirmedPasswordField.php index 34a084be5a8..e9e594240ef 100644 --- a/src/Forms/ConfirmedPasswordField.php +++ b/src/Forms/ConfirmedPasswordField.php @@ -204,7 +204,7 @@ public function Field($properties = []) } // Check if the field should be visible up front - $visible = $this->hiddenField->Value(); + $visible = $this->hiddenField->getValue(); $classes = $visible ? 'showOnClickContainer' : 'showOnClickContainer d-none'; @@ -418,7 +418,7 @@ public function setName($name) public function isSaveable() { return !$this->showOnClick - || ($this->showOnClick && $this->hiddenField && $this->hiddenField->Value()); + || ($this->showOnClick && $this->hiddenField && $this->hiddenField->getValue()); } public function validate(): ValidationResult @@ -432,10 +432,10 @@ public function validate(): ValidationResult $this->getPasswordField()->setValue($this->value); $this->getConfirmPasswordField()->setValue($this->confirmValue); - $value = $this->getPasswordField()->Value(); + $value = $this->getPasswordField()->getValue(); // both password-fields should be the same - if ($value != $this->getConfirmPasswordField()->Value()) { + if ($value != $this->getConfirmPasswordField()->getValue()) { $result->addFieldError( $name, _t('SilverStripe\\Forms\\Form.VALIDATIONPASSWORDSDONTMATCH', "Passwords don't match"), @@ -446,7 +446,7 @@ public function validate(): ValidationResult if (!$this->canBeEmpty) { // both password-fields shouldn't be empty - if (!$value || !$this->getConfirmPasswordField()->Value()) { + if (!$value || !$this->getConfirmPasswordField()->getValue()) { $result->addFieldError( $name, _t('SilverStripe\\Forms\\Form.VALIDATIONPASSWORDSNOTEMPTY', "Passwords can't be empty"), diff --git a/src/Forms/DateField.php b/src/Forms/DateField.php index 914b20f72ea..15efbaf42f4 100644 --- a/src/Forms/DateField.php +++ b/src/Forms/DateField.php @@ -343,7 +343,7 @@ public function setValue($value, $data = null) return $this; } - public function Value() + public function getFormattedValue(): mixed { return $this->internalToFrontend($this->value); } diff --git a/src/Forms/DateField_Disabled.php b/src/Forms/DateField_Disabled.php index be56d92ea5a..bb68af5fd48 100644 --- a/src/Forms/DateField_Disabled.php +++ b/src/Forms/DateField_Disabled.php @@ -39,7 +39,7 @@ public function Field($properties = []) // Render the display value with some complement of info $displayValue = Convert::raw2xml(sprintf( $format ?? '', - $this->Value(), + $this->getFormattedValue(), $infoComplement )); } diff --git a/src/Forms/DatetimeField.php b/src/Forms/DatetimeField.php index cfa1beb012c..e0769ae7470 100644 --- a/src/Forms/DatetimeField.php +++ b/src/Forms/DatetimeField.php @@ -362,7 +362,7 @@ public function setValue($value, $data = null) * * @return string */ - public function Value() + public function getFormattedValue(): mixed { return $this->internalToFrontend($this->value); } diff --git a/src/Forms/DropdownField.php b/src/Forms/DropdownField.php index 9e31245250f..e0e1ef6067b 100644 --- a/src/Forms/DropdownField.php +++ b/src/Forms/DropdownField.php @@ -97,7 +97,7 @@ class DropdownField extends SingleSelectField protected function getFieldOption($value, $title) { // Check selection - $selected = $this->isSelectedValue($value, $this->Value()); + $selected = $this->isSelectedValue($value, $this->getValue()); // Check disabled $disabled = false; diff --git a/src/Forms/FileField.php b/src/Forms/FileField.php index fdeed0a59d7..6760ab03de0 100644 --- a/src/Forms/FileField.php +++ b/src/Forms/FileField.php @@ -172,7 +172,7 @@ public function saveInto(DataObjectInterface $record) } } - public function Value() + public function getValue(): mixed { return isset($_FILES[$this->getName()]) ? $_FILES[$this->getName()] : null; } diff --git a/src/Forms/FileUploadReceiver.php b/src/Forms/FileUploadReceiver.php index 3aaa42ff323..90fc6722ada 100644 --- a/src/Forms/FileUploadReceiver.php +++ b/src/Forms/FileUploadReceiver.php @@ -237,11 +237,11 @@ public function getItems() */ public function getItemIDs() { - $value = $this->Value(); + $value = $this->getValue(); return empty($value['Files']) ? [] : $value['Files']; } - public function Value() + public function getValue(): mixed { // Re-override FileField Value to use data value return $this->dataValue(); diff --git a/src/Forms/Form.php b/src/Forms/Form.php index fbcf2425034..0a0eb3c0aa9 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -1186,17 +1186,9 @@ public function FieldMap() */ public function sessionMessage($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); - $result->addMessage($message, $type, null, $cast); + $result->addMessage($message, $type, '', $cast); $this->setSessionValidationResult($result); } @@ -1210,17 +1202,9 @@ public function sessionMessage($message, $type = ValidationResult::TYPE_ERROR, $ */ public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); - $result->addError($message, $type, null, $cast); + $result->addError($message, $type, '', $cast); $this->setSessionValidationResult($result); } @@ -1235,17 +1219,9 @@ public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $ca */ public function sessionFieldError($message, $fieldName, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { - if ($cast === null) { - Deprecation::notice( - '5.4.0', - 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', - Deprecation::SCOPE_GLOBAL - ); - $cast = ValidationResult::CAST_TEXT; - } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); - $result->addFieldMessage($fieldName, $message, $type, null, $cast); + $result->addFieldMessage($fieldName, $message, $type, '', $cast); $this->setSessionValidationResult($result); } diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php index 08301ecb54d..92c2ef4c24e 100644 --- a/src/Forms/FormField.php +++ b/src/Forms/FormField.php @@ -269,7 +269,8 @@ class FormField extends RequestHandler implements FieldValidationInterface 'Field' => 'HTMLFragment', 'AttributesHTML' => 'HTMLFragment', // property $AttributesHTML version 'getAttributesHTML' => 'HTMLFragment', // method $getAttributesHTML($arg) version - 'Value' => 'Text', + 'FormattedValue' => 'Text', + 'getFormattedValue' => 'Text', 'extraClass' => 'Text', 'ID' => 'Text', 'isReadOnly' => 'Boolean', @@ -457,14 +458,10 @@ public function getValue(): mixed /** * Returns the value of the field which may be modified for display purposes * for instance to add localisation or formatting. - * - * @return mixed - * @deprecated 5.4.0 Will be replaced by getFormattedValue() and getValue() */ - public function Value() + public function getFormattedValue(): mixed { - Deprecation::notice('5.4.0', 'Will be replaced by getFormattedValue() and getValue()'); - return $this->value; + return $this->getValue(); } /** @@ -670,7 +667,7 @@ protected function getDefaultAttributes(): array $attributes = [ 'type' => $this->getInputType(), 'name' => $this->getName(), - 'value' => $this->Value(), + 'value' => $this->getFormattedValue(), 'class' => $this->extraClass(), 'id' => $this->ID(), 'disabled' => $this->isDisabled(), @@ -950,16 +947,12 @@ public function Field($properties = []) $context = $context->customise($properties); } - $result = $context->renderWith($context->getTemplates()); + $dbHtmlText = $context->renderWith($context->getTemplates()); - // Trim whitespace from the result, so that trailing newlines are suppressed. Works for strings and HTMLText values - if (is_string($result)) { - $result = trim($result ?? ''); - } elseif ($result instanceof DBField) { - $result->setValue(trim($result->getValue() ?? '')); - } + // Trim whitespace from the result, so that trailing newlines are suppressed. + $dbHtmlText->setValue(trim($dbHtmlText->getValue() ?? '')); - return $result; + return $dbHtmlText; } /** @@ -1556,7 +1549,7 @@ public function getSchemaStateDefaults() $state = [ 'name' => $this->getName(), 'id' => $this->ID(), - 'value' => $this->Value(), + 'value' => $this->getFormattedValue(), 'message' => $this->getSchemaMessage(), 'data' => [], ]; diff --git a/src/Forms/GridField/GridField.php b/src/Forms/GridField/GridField.php index 05c204b6dbb..ef7e94d7262 100644 --- a/src/Forms/GridField/GridField.php +++ b/src/Forms/GridField/GridField.php @@ -485,7 +485,7 @@ private function addStateFromRequest(): void // Create a dummy state so that we can merge the current state with the request state. $newState = new GridState($this, $stateStr); // Put the current state on top of the request state. - $newState->setValue($oldState->Value()); + $newState->setValue($oldState->getValue()); $this->state = $newState; } } diff --git a/src/Forms/GridField/GridFieldStateManager.php b/src/Forms/GridField/GridFieldStateManager.php index 727077737a3..53ac56b3e05 100644 --- a/src/Forms/GridField/GridFieldStateManager.php +++ b/src/Forms/GridField/GridFieldStateManager.php @@ -39,7 +39,7 @@ public function getStateKey(GridField $gridField): string public function addStateToURL(GridField $gridField, string $url): string { $key = $this->getStateKey($gridField); - $value = $gridField->getState(false)->Value(); + $value = $gridField->getState(false)->getValue(); // Using a JSON-encoded empty array as the blank value, to avoid changing Value() semantics in a minor release if ($value === '{}') { diff --git a/src/Forms/GridField/GridState.php b/src/Forms/GridField/GridState.php index a5f5725970a..7e97f9f878e 100644 --- a/src/Forms/GridField/GridState.php +++ b/src/Forms/GridField/GridState.php @@ -101,10 +101,8 @@ public function getList() /** * Returns a json encoded string representation of this state. - * - * @return string */ - public function Value() + public function getValue(): string { $data = $this->data ? $this->data->getChangesArray() : []; return json_encode($data, JSON_FORCE_OBJECT); @@ -117,7 +115,7 @@ public function Value() */ public function dataValue() { - return $this->Value(); + return $this->getValue(); } /** @@ -126,11 +124,11 @@ public function dataValue() */ public function attrValue() { - return Convert::raw2att($this->Value()); + return Convert::raw2att($this->getValue()); } public function __toString() { - return $this->Value(); + return $this->getValue(); } } diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php index 4527dd1de6a..72e1de842e4 100644 --- a/src/Forms/HTMLEditor/HTMLEditorField.php +++ b/src/Forms/HTMLEditor/HTMLEditorField.php @@ -23,7 +23,8 @@ class HTMLEditorField extends TextareaField { private static $casting = [ - 'Value' => 'HTMLText', + 'FormattedValue' => 'HTMLText', + 'getFormattedValue' => 'HTMLText', ]; protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_HTML; @@ -134,7 +135,7 @@ public function saveInto(DataObjectInterface $record) } // Sanitise if requested - $htmlValue = HTMLValue::create($this->Value()); + $htmlValue = HTMLValue::create($this->getValue()); if (HTMLEditorField::config()->sanitise_server_side) { $config = $this->getEditorConfig(); $santiser = HTMLEditorSanitiser::create($config); @@ -184,11 +185,9 @@ public function getSchemaStateDefaults() } /** - * Return value with all values encoded in html entities - * - * @return string Raw HTML + * Return formatted value with all values encoded in html entities */ - public function ValueEntities() + public function getFormattedValueEntities(): string { $entities = get_html_translation_table(HTML_ENTITIES); @@ -196,13 +195,13 @@ public function ValueEntities() $entities[$key] = "/" . $value . "/"; } - $value = preg_replace_callback($entities, function ($matches) { + $formattedValue = preg_replace_callback($entities, function ($matches) { // Don't apply double encoding to ampersand $doubleEncoding = $matches[0] != '&'; return htmlentities($matches[0], ENT_COMPAT, 'UTF-8', $doubleEncoding); - }, $this->Value() ?? ''); + }, $this->getFormattedValue() ?? ''); - return $value; + return $formattedValue; } /** @@ -231,7 +230,7 @@ private function usesXmlFriendlyField(DataObjectInterface $record): bool } $castingService = CastingService::singleton(); - $castValue = $castingService->cast($this->Value(), $record, $this->getName()); + $castValue = $castingService->cast($this->getFormattedValue(), $record, $this->getName()); return $castValue instanceof DBField && $castValue::config()->get('escape_type') === 'xml'; } } diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php b/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php index 2f02b71ac67..00b48c3e6e3 100644 --- a/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php +++ b/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php @@ -10,7 +10,8 @@ class HTMLEditorField_Readonly extends HTMLReadonlyField { private static $casting = [ - 'Value' => 'HTMLText', + 'FormattedValue' => 'HTMLText', + 'getFormattedValue' => 'HTMLText', ]; public function Type() diff --git a/src/Forms/HTMLReadonlyField.php b/src/Forms/HTMLReadonlyField.php index 64bb339e30f..280fca6a51b 100644 --- a/src/Forms/HTMLReadonlyField.php +++ b/src/Forms/HTMLReadonlyField.php @@ -10,8 +10,10 @@ class HTMLReadonlyField extends ReadonlyField { private static $casting = [ - 'Value' => 'HTMLFragment', - 'ValueEntities' => 'HTMLFragment', + 'FormattedValue' => 'HTMLFragment', + 'getFormattedValue' => 'HTMLFragment', + 'FormattedValueEntities' => 'HTMLFragment', + 'getFormattedValueEntities' => 'HTMLFragment', ]; protected $schemaDataType = HTMLReadonlyField::SCHEMA_DATA_TYPE_STRUCTURAL; @@ -27,12 +29,12 @@ public function Field($properties = []) } /** - * Return value with all values encoded in html entities + * Return formatted value with all values encoded in html entities * * @return string Raw HTML */ - public function ValueEntities() + public function getFormattedValueEntities() { - return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8'); + return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8'); } } diff --git a/src/Forms/ListboxField.php b/src/Forms/ListboxField.php index 0a2112cae08..ac8d90b040c 100644 --- a/src/Forms/ListboxField.php +++ b/src/Forms/ListboxField.php @@ -4,6 +4,8 @@ use SilverStripe\Model\List\ArrayList; use SilverStripe\Model\ArrayData; +use SilverStripe\ORM\DB; +use SilverStripe\ORM\FieldType\DBHTMLText; /** * Multi-line listbox field, created from a select tag. @@ -68,9 +70,6 @@ public function __construct($name, $title = '', $source = [], $value = null, $si /** * Returns a select tag containing all the appropriate option tags - * - * @param array $properties - * @return string */ public function Field($properties = []) { @@ -252,7 +251,7 @@ protected function getOptionsArray($term) public function getValueArray() { - $value = $this->Value(); + $value = $this->getFormattedValue(); $validValues = $this->getValidValues(); if (empty($validValues)) { return []; diff --git a/src/Forms/LiteralField.php b/src/Forms/LiteralField.php index 0dda550c0c3..82d926bc897 100644 --- a/src/Forms/LiteralField.php +++ b/src/Forms/LiteralField.php @@ -18,7 +18,8 @@ class LiteralField extends DatalessField { private static $casting = [ - 'Value' => 'HTMLFragment', + 'FormattedValue' => 'HTMLFragment', + 'getFormattedValue' => 'HTMLFragment', ]; /** diff --git a/src/Forms/MoneyField.php b/src/Forms/MoneyField.php index 75e70d61f6a..eb072e2937b 100644 --- a/src/Forms/MoneyField.php +++ b/src/Forms/MoneyField.php @@ -219,7 +219,7 @@ public function dataValue() return $this->getDBMoney()->getValue(); } - public function Value() + public function getFormattedValue(): mixed { // Localised money return $this->getDBMoney()->Nice(); diff --git a/src/Forms/MultiSelectField.php b/src/Forms/MultiSelectField.php index e3adb61c32e..626689dbf90 100644 --- a/src/Forms/MultiSelectField.php +++ b/src/Forms/MultiSelectField.php @@ -39,7 +39,7 @@ abstract class MultiSelectField extends SelectField */ public function getValueArray() { - return $this->getListValues($this->Value()); + return $this->getListValues($this->getFormattedValue()); } /** diff --git a/src/Forms/NullableField.php b/src/Forms/NullableField.php index 99669cd0ab8..954a8a45365 100644 --- a/src/Forms/NullableField.php +++ b/src/Forms/NullableField.php @@ -17,7 +17,7 @@ * When a form is submitted the field tests the value of the "is null" checkbox and sets its value * accordingly. You can retrieve the value of the wrapped field from the NullableField as follows: * - * $field->Value() or $field->dataValue() + * $field->getValue() or $field->dataValue() * * You can specify the label to use for the "is null" checkbox. If you want to use i18n for this * label then specify it like this: @@ -61,7 +61,7 @@ public function __construct(FormField $valueField, $isNullLabel = null) parent::__construct( $valueField->getName(), $valueField->Title(), - $valueField->Value() + $valueField->getValue() ); $this->setForm($valueField->getForm()); diff --git a/src/Forms/NumericField.php b/src/Forms/NumericField.php index cc36e9509dc..320f4def8c8 100644 --- a/src/Forms/NumericField.php +++ b/src/Forms/NumericField.php @@ -169,7 +169,7 @@ public function setSubmittedValue($value, $data = null) * * @return string */ - public function Value() + public function getFormattedValue(): mixed { // Show invalid value back to user in case of error if ($this->value === null || $this->value === false) { diff --git a/src/Forms/OptionsetField.php b/src/Forms/OptionsetField.php index a966aebe375..53eddd68262 100644 --- a/src/Forms/OptionsetField.php +++ b/src/Forms/OptionsetField.php @@ -75,7 +75,7 @@ protected function getFieldOption($value, $title, $odd) 'Name' => $this->getOptionName(), 'Value' => $value, 'Title' => $title, - 'isChecked' => $this->isSelectedValue($value, $this->Value()), + 'isChecked' => $this->isSelectedValue($value, $this->getValue()), 'isDisabled' => $this->isDisabledValue($value) ]); } diff --git a/src/Forms/ReadonlyField.php b/src/Forms/ReadonlyField.php index 68a496a5d61..f8e6badecc4 100644 --- a/src/Forms/ReadonlyField.php +++ b/src/Forms/ReadonlyField.php @@ -70,7 +70,7 @@ public function castingHelper(string $field, bool $useFallback = true): ?string public function getSchemaStateDefaults() { $state = parent::getSchemaStateDefaults(); - $state['value'] = $this->dataValue(); + $state['value'] = $this->getFormattedValue(); return $state; } @@ -79,7 +79,7 @@ public function getSchemaStateDefaults() /** * @return mixed|string */ - public function Value() + public function getFormattedValue(): mixed { // Get raw value $value = $this->dataValue(); diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php index b5d794726db..a844baa13b6 100644 --- a/src/Forms/SearchableDropdownTrait.php +++ b/src/Forms/SearchableDropdownTrait.php @@ -319,7 +319,7 @@ public function getAttributes(): array */ public function getValueArray(): array { - $value = $this->Value(); + $value = $this->getValue(); if (empty($value)) { return []; } @@ -474,7 +474,7 @@ private function getDefaultSchemaValue() if (!$this->getIsLazyLoaded() && $this->hasMethod('getDefaultValue')) { return $this->getDefaultValue(); } - return $this->Value(); + return $this->getValue(); } private function getOptionsForSearchRequest(string $term): array diff --git a/src/Forms/SingleLookupField.php b/src/Forms/SingleLookupField.php index 1bf54b8f24e..bb79eab5133 100644 --- a/src/Forms/SingleLookupField.php +++ b/src/Forms/SingleLookupField.php @@ -83,14 +83,13 @@ public function Type() * * @return mixed */ - public function Value() + public function getFormattedValue(): mixed { $label = $this->valueToLabel(); if (!is_null($label)) { return $label; } - - return parent::Value(); + return parent::getFormattedValue(); } /** diff --git a/src/Forms/SingleSelectField.php b/src/Forms/SingleSelectField.php index b2488c369cf..f8a0126cd78 100644 --- a/src/Forms/SingleSelectField.php +++ b/src/Forms/SingleSelectField.php @@ -58,7 +58,7 @@ public function getValueForValidation(): mixed public function getDefaultValue() { - $value = $this->Value(); + $value = $this->getValue(); $validValues = $this->getValidValues(); // assign value to field, such as first option available if ($value === null || !in_array($value, $validValues)) { diff --git a/src/Forms/TextareaField.php b/src/Forms/TextareaField.php index 713faf9a1a2..d1c54b94175 100644 --- a/src/Forms/TextareaField.php +++ b/src/Forms/TextareaField.php @@ -34,8 +34,10 @@ class TextareaField extends FormField * @var array */ private static $casting = [ - 'Value' => 'Text', - 'ValueEntities' => 'HTMLFragment([\'shortcodes\' => false])', + 'FormattedValue' => 'Text', + 'getFormattedValue' => 'Text', + 'FormattedValueEntities' => 'HTMLFragment([\'shortcodes\' => false])', + 'getFormattedValueEntities' => 'HTMLFragment([\'shortcodes\' => false])', ]; protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT; @@ -192,9 +194,8 @@ public function getSchemaValidation() * @return string Raw HTML * @deprecated 5.4.0 Use getFormattedValueEntities() instead */ - public function ValueEntities() + public function getFormattedValueEntities(): string { - Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced by getFormattedValueEntities()'); - return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8'); + return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8'); } } diff --git a/src/Forms/TimeField.php b/src/Forms/TimeField.php index 082e11aee8e..1c64bd6828a 100644 --- a/src/Forms/TimeField.php +++ b/src/Forms/TimeField.php @@ -280,7 +280,7 @@ public function setValue($value, $data = null) return $this; } - public function Value() + public function getFormattedValue(): mixed { $localised = $this->internalToFrontend($this->value); if ($localised) { diff --git a/src/Forms/TreeDropdownField.php b/src/Forms/TreeDropdownField.php index 7a8889dafca..69d5c994ba7 100644 --- a/src/Forms/TreeDropdownField.php +++ b/src/Forms/TreeDropdownField.php @@ -865,7 +865,7 @@ public function getSchemaStateDefaults() { $data = parent::getSchemaStateDefaults(); /** @var Hierarchy|DataObject $record */ - $record = $this->Value() ? $this->objectForKey($this->Value()) : null; + $record = $this->getValue() ? $this->objectForKey($this->getValue()) : null; $data['data']['cacheKey'] = $this->getCacheKey(); $data['data']['showSelectedPath'] = $this->getShowSelectedPath(); diff --git a/src/Forms/TreeMultiselectField.php b/src/Forms/TreeMultiselectField.php index 449a275fe45..48e8c8b9aad 100644 --- a/src/Forms/TreeMultiselectField.php +++ b/src/Forms/TreeMultiselectField.php @@ -121,7 +121,7 @@ public function getSchemaStateDefaults() */ public function getItems() { - $value = $this->Value(); + $value = $this->getValue(); // If unchanged, load from record if ($value === 'unchanged') { diff --git a/src/Forms/Validation/Validator.php b/src/Forms/Validation/Validator.php index 04df3d263cb..e36a85b80da 100644 --- a/src/Forms/Validation/Validator.php +++ b/src/Forms/Validation/Validator.php @@ -83,7 +83,7 @@ public function validationError( $messageType = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT ) { - $this->result->addFieldError($fieldName, $message, $messageType, null, $cast); + $this->result->addFieldError($fieldName, $message, $messageType, '', $cast); return $this; } diff --git a/templates/SilverStripe/Forms/GridField/GridField_Item.ss b/templates/SilverStripe/Forms/GridField/GridField_Item.ss index c57cd94df2f..d14aabc5e1b 100644 --- a/templates/SilverStripe/Forms/GridField/GridField_Item.ss +++ b/templates/SilverStripe/Forms/GridField/GridField_Item.ss @@ -1,12 +1,12 @@ <% if $GridField.ExtraColumnsCount %> <% loop $Fields %> - $Value + $FormattedValue <% end_loop %> <% else %> <% loop $Fields %> - class="ss-gridfield-{$FirstLast}"<% end_if %>>$Value + class="ss-gridfield-{$FirstLast}"<% end_if %>>$FormattedValue <% end_loop %> <% end_if %> diff --git a/templates/SilverStripe/Forms/HTMLReadonlyField.ss b/templates/SilverStripe/Forms/HTMLReadonlyField.ss index 971bf6c3e2d..04e221d7f41 100644 --- a/templates/SilverStripe/Forms/HTMLReadonlyField.ss +++ b/templates/SilverStripe/Forms/HTMLReadonlyField.ss @@ -1,6 +1,6 @@ - <% if $Value %>$Value<% else %>(not set)<% end_if %> + <% if $FormattedValue %>$FormattedValue<% else %>(not set)<% end_if %> <% if $IncludeHiddenField %> - + <% end_if %> diff --git a/templates/SilverStripe/Forms/ReadonlyField.ss b/templates/SilverStripe/Forms/ReadonlyField.ss index a306debe5d2..e447aa41cfa 100644 --- a/templates/SilverStripe/Forms/ReadonlyField.ss +++ b/templates/SilverStripe/Forms/ReadonlyField.ss @@ -1,5 +1,5 @@ class="$extraClass"<% end_if %>> - $Value + $FormattedValue <% if $IncludeHiddenField %> diff --git a/templates/SilverStripe/Forms/TextareaField.ss b/templates/SilverStripe/Forms/TextareaField.ss index 3d0342ca30d..e58bc84cac3 100644 --- a/templates/SilverStripe/Forms/TextareaField.ss +++ b/templates/SilverStripe/Forms/TextareaField.ss @@ -1 +1 @@ - + diff --git a/templates/SilverStripe/Forms/TreeDropdownField.ss b/templates/SilverStripe/Forms/TreeDropdownField.ss index c17e1582d2b..a8b70bc1115 100644 --- a/templates/SilverStripe/Forms/TreeDropdownField.ss +++ b/templates/SilverStripe/Forms/TreeDropdownField.ss @@ -3,5 +3,5 @@ $AttributesHTML('class') $SchemaAttributesHtml <% if $Metadata %>data-metadata="$Metadata.ATT"<% end_if %> > - + diff --git a/tests/php/Core/Validation/ValidationResultTest.php b/tests/php/Core/Validation/ValidationResultTest.php index ac725919928..353d372d8d7 100644 --- a/tests/php/Core/Validation/ValidationResultTest.php +++ b/tests/php/Core/Validation/ValidationResultTest.php @@ -11,28 +11,26 @@ class ValidationResultTest extends SapphireTest public function testSerialise() { $result = new ValidationResult(); - $result->addError("Error", ValidationResult::TYPE_ERROR, null, ValidationResult::CAST_HTML); + $result->addError("Error", ValidationResult::TYPE_ERROR, '', ValidationResult::CAST_HTML); $result->addMessage("Message", ValidationResult::TYPE_GOOD); $serialised = serialize($result); - /** - * @var ValidationResult $result2 -*/ + /** @var ValidationResult $result2 */ $result2 = unserialize($serialised ?? ''); $this->assertEquals( [ - [ - 'message' => 'Error', - 'fieldName' => null, - 'messageCast' => ValidationResult::CAST_HTML, - 'messageType' => ValidationResult::TYPE_ERROR, - ], - [ - 'message' => 'Message', - 'fieldName' => null, - 'messageCast' => ValidationResult::CAST_TEXT, - 'messageType' => ValidationResult::TYPE_GOOD, - ] + [ + 'message' => 'Error', + 'fieldName' => '', + 'messageCast' => ValidationResult::CAST_HTML, + 'messageType' => ValidationResult::TYPE_ERROR, + ], + [ + 'message' => 'Message', + 'fieldName' => '', + 'messageCast' => ValidationResult::CAST_TEXT, + 'messageType' => ValidationResult::TYPE_GOOD, + ] ], $result2->getMessages() ); diff --git a/tests/php/Forms/CheckboxFieldTest.php b/tests/php/Forms/CheckboxFieldTest.php index 574106976f0..435b48cfdac 100644 --- a/tests/php/Forms/CheckboxFieldTest.php +++ b/tests/php/Forms/CheckboxFieldTest.php @@ -30,7 +30,7 @@ public function testFieldValueTrue() $this->assertEquals($field->dataValue(), 1, 'dataValue() returns a 1'); /* Value() returns 1 as well */ - $this->assertEquals($field->Value(), 1, 'Value() returns a 1'); + $this->assertEquals($field->getValue(), 1, 'getValue() returns a 1'); } public function testFieldValueString() @@ -43,7 +43,7 @@ public function testFieldValueString() $this->assertEquals($field->dataValue(), 1, 'dataValue() returns a 1'); /* Value() returns 1 as well */ - $this->assertEquals($field->Value(), 1, 'Value() returns a 1'); + $this->assertEquals($field->getValue(), 1, 'getValue() returns a 1'); } public function testFieldValueSettingNull() @@ -56,7 +56,7 @@ public function testFieldValueSettingNull() $this->assertEquals($field->dataValue(), null, 'dataValue() returns a 0'); /* Value() returns 0 as well */ - $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + $this->assertEquals($field->getValue(), 0, 'getValue() returns a 0'); } public function testFieldValueSettingFalse() @@ -69,7 +69,7 @@ public function testFieldValueSettingFalse() $this->assertEquals($field->dataValue(), null, 'dataValue() returns a 0'); /* Value() returns 0 as well */ - $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + $this->assertEquals($field->getValue(), 0, 'getValue() returns a 0'); } public function testFieldValueWithoutSettingValue() @@ -81,7 +81,7 @@ public function testFieldValueWithoutSettingValue() $this->assertEquals($field->dataValue(), null, 'dataValue() returns a 0'); /* Value() returns 0 as well */ - $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + $this->assertEquals($field->getValue(), 0, 'getValue() returns a 0'); } public function testSavingChecked() diff --git a/tests/php/Forms/CheckboxSetFieldMultiEnumTest.php b/tests/php/Forms/CheckboxSetFieldMultiEnumTest.php index 47095982b54..29bef59b3d5 100644 --- a/tests/php/Forms/CheckboxSetFieldMultiEnumTest.php +++ b/tests/php/Forms/CheckboxSetFieldMultiEnumTest.php @@ -65,7 +65,7 @@ public function testLoadDataFromMultiEnum() new FieldList() ); $form->loadDataFrom($article); - $value = $field->Value(); + $value = $field->getValue(); $this->assertEquals(['Red', 'Green'], $value); } diff --git a/tests/php/Forms/CheckboxSetFieldTest.php b/tests/php/Forms/CheckboxSetFieldTest.php index 2c7e75a3775..6767c01cbb9 100644 --- a/tests/php/Forms/CheckboxSetFieldTest.php +++ b/tests/php/Forms/CheckboxSetFieldTest.php @@ -181,7 +181,7 @@ public function testLoadDataFromObject() new FieldList() ); $form->loadDataFrom($articleWithTags); - $value = $field->Value(); + $value = $field->getValue(); sort($value); $this->assertEquals( [ diff --git a/tests/php/Forms/ConfirmedPasswordFieldTest.php b/tests/php/Forms/ConfirmedPasswordFieldTest.php index 6c8cee8cf66..78d9e282e17 100644 --- a/tests/php/Forms/ConfirmedPasswordFieldTest.php +++ b/tests/php/Forms/ConfirmedPasswordFieldTest.php @@ -29,13 +29,13 @@ protected function setUp(): void public function testSetValue() { $field = new ConfirmedPasswordField('Test', 'Testing', 'valueA'); - $this->assertEquals('valueA', $field->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('valueA', $field->getValue()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->getValue()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->getValue()); $field->setValue('valueB'); - $this->assertEquals('valueB', $field->Value()); - $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); - $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('valueB', $field->getValue()); + $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_Password]')->getValue()); + $this->assertEquals('valueB', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->getValue()); } /** @@ -46,9 +46,9 @@ public function testHashHidden() $field = new ConfirmedPasswordField('Password', 'Password', 'valueA'); $field->setCanBeEmpty(true); - $this->assertEquals('valueA', $field->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); - $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('valueA', $field->getValue()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_Password]')->getValue()); + $this->assertEquals('valueA', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->getValue()); $member = new Member(); $member->Password = "valueB"; @@ -57,9 +57,9 @@ public function testHashHidden() $form = new Form(Controller::curr(), 'Form', new FieldList($field), new FieldList()); $form->loadDataFrom($member); - $this->assertEquals('', $field->Value()); - $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_Password]')->Value()); - $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->Value()); + $this->assertEquals('', $field->getValue()); + $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_Password]')->getValue()); + $this->assertEquals('', $field->children->fieldByName($field->getName() . '[_ConfirmPassword]')->getValue()); } public function testSetShowOnClick() @@ -149,8 +149,8 @@ public function testFormValidation() '_ConfirmPassword' => '', ], ]); - $this->assertSame('123', $field->children->first()->Value()); - $this->assertSame('', $field->children->last()->Value()); + $this->assertSame('123', $field->children->first()->getValue()); + $this->assertSame('', $field->children->last()->getValue()); $form->loadDataFrom([ 'Password' => [ @@ -158,8 +158,8 @@ public function testFormValidation() '_ConfirmPassword' => 'abc', ], ]); - $this->assertSame('123', $field->children->first()->Value()); - $this->assertSame('abc', $field->children->last()->Value()); + $this->assertSame('123', $field->children->first()->getValue()); + $this->assertSame('abc', $field->children->last()->getValue()); $form->loadDataFrom([ 'Password' => [ @@ -167,8 +167,8 @@ public function testFormValidation() '_ConfirmPassword' => 'abc', ], ]); - $this->assertSame('', $field->children->first()->Value()); - $this->assertSame('abc', $field->children->last()->Value()); + $this->assertSame('', $field->children->first()->getValue()); + $this->assertSame('abc', $field->children->last()->getValue()); } /** @@ -328,7 +328,7 @@ public function testPerformReadonlyTransformation() $this->assertInstanceOf(ReadonlyField::class, $result); $this->assertSame('Change it', $result->Title()); - $this->assertStringContainsString('***', $result->Value()); + $this->assertStringContainsString('***', $result->getValue()); } public function testPerformDisabledTransformation() @@ -365,10 +365,10 @@ public function testSetCanBeEmptySaveInto(bool $generateRandomPasswordOnEmpty, ? return 'R4ndom-P4ssw0rd$LOREM^ipsum#12345'; })); } - $this->assertEmpty($field->Value()); + $this->assertEmpty($field->getValue()); $member = new Member(); $field->saveInto($member); - $this->assertSame($expected, $field->Value()); + $this->assertSame($expected, $field->getValue()); } public static function provideSetCanBeEmptySaveInto(): array diff --git a/tests/php/Forms/CurrencyFieldTest.php b/tests/php/Forms/CurrencyFieldTest.php index 13543e65751..fc4c52579fa 100644 --- a/tests/php/Forms/CurrencyFieldTest.php +++ b/tests/php/Forms/CurrencyFieldTest.php @@ -124,56 +124,56 @@ public function testSetValue() //tests with default currency symbol setting $f->setValue('123.45'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$123.45', 'Prepends dollar sign to positive decimal' ); $f->setValue('-123.45'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$-123.45', 'Prepends dollar sign to negative decimal' ); $f->setValue('$1'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$1.00', 'Formats small value' ); $f->setValue('$2.5'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$2.50', 'Formats small value' ); $f->setValue('$2500000.13'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$2,500,000.13', 'Formats large value' ); $f->setValue('$2.50000013'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$2.50', 'Truncates long decimal portions' ); $f->setValue('test123.00test'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$123.00', 'Strips alpha values' ); $f->setValue('test'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '$0.00', 'Does not set alpha values' ); @@ -183,56 +183,56 @@ public function testSetValue() $f->setValue('123.45'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€123.45', 'Prepends dollar sign to positive decimal' ); $f->setValue('-123.45'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€-123.45', 'Prepends dollar sign to negative decimal' ); $f->setValue('€1'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€1.00', 'Formats small value' ); $f->setValue('€2.5'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€2.50', 'Formats small value' ); $f->setValue('€2500000.13'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€2,500,000.13', 'Formats large value' ); $f->setValue('€2.50000013'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€2.50', 'Truncates long decimal portions' ); $f->setValue('test123.00test'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€123.00', 'Strips alpha values' ); $f->setValue('test'); $this->assertEquals( - $f->Value(), + $f->getFormattedValue(), '€0.00', 'Does not set alpha values' ); diff --git a/tests/php/Forms/DateFieldTest.php b/tests/php/Forms/DateFieldTest.php index 7f60339a177..67ae67d1585 100644 --- a/tests/php/Forms/DateFieldTest.php +++ b/tests/php/Forms/DateFieldTest.php @@ -115,22 +115,22 @@ public function testConstructorWithDateString() $this->assertEquals('2003-03-29', $f->dataValue()); } - public function testSetValue() + public function testGetFormattedValue() { $f = (new DateField('Date', 'Date'))->setValue('notadate'); - $this->assertNull($f->Value(), 'Invalid input ignored'); + $this->assertNull($f->getFormattedValue()); $f = (new DateField('Date', 'Date'))->setValue('-1 day'); - $this->assertEquals($f->Value(), '2011-01-31', 'Relative dates accepted'); + $this->assertSame('2011-01-31', $f->getFormattedValue()); $f = (new DateField('Date', 'Date'))->setValue('2011-01-31'); - $this->assertEquals($f->Value(), '2011-01-31', 'ISO format accepted'); + $this->assertSame('2011-01-31', $f->getFormattedValue()); $f = (new DateField('Date', 'Date'))->setValue('2011-01-31 23:59:59'); - $this->assertEquals($f->Value(), '2011-01-31', 'ISO format with time accepted'); + $this->assertSame('2011-01-31', $f->getFormattedValue()); $f->setValue(null); - $this->assertNull($f->Value()); + $this->assertNull($f->getFormattedValue()); } public function testSetValueWithLocalisedDateString() @@ -220,7 +220,7 @@ public function testHtml5WithCustomFormatThrowsException() $dateField = new DateField('Date', 'Date'); $dateField->setValue('2010-03-31'); $dateField->setDateFormat('d/M/y'); - $dateField->Value(); + $dateField->getFormattedValue(); } public function testHtml5WithCustomDateLengthThrowsException() @@ -230,7 +230,7 @@ public function testHtml5WithCustomDateLengthThrowsException() $dateField = new DateField('Date', 'Date'); $dateField->setValue('2010-03-31'); $dateField->setDateLength(IntlDateFormatter::MEDIUM); - $dateField->Value(); + $dateField->getFormattedValue(); } public function testHtml5WithCustomLocaleThrowsException() @@ -240,7 +240,7 @@ public function testHtml5WithCustomLocaleThrowsException() $dateField = new DateField('Date', 'Date'); $dateField->setValue('2010-03-31'); $dateField->setLocale('de_DE'); - $dateField->Value(); + $dateField->getFormattedValue(); } public function testGetDateFormatHTML5() @@ -275,7 +275,7 @@ public function testSetSubmittedValueNull() { $field = new DateField('Date'); $field->setSubmittedValue(false); - $this->assertNull($field->Value()); + $this->assertNull($field->getFormattedValue()); } public function testPerformReadonlyTransformation() diff --git a/tests/php/Forms/DatetimeFieldTest.php b/tests/php/Forms/DatetimeFieldTest.php index 4dc5da9e8b4..f0fe0255fe9 100644 --- a/tests/php/Forms/DatetimeFieldTest.php +++ b/tests/php/Forms/DatetimeFieldTest.php @@ -70,10 +70,9 @@ public function testFormSaveIntoLocalised() public function testDataValue() { $f = new DatetimeField('Datetime'); - $this->assertEquals(null, $f->dataValue(), 'Empty field'); - + $this->assertEquals(null, $f->dataValue()); $f = new DatetimeField('Datetime', null, '2003-03-29 23:59:38'); - $this->assertEquals('2003-03-29 23:59:38', $f->dataValue(), 'From date/time string'); + $this->assertEquals('2003-03-29 23:59:38', $f->dataValue()); } public function testDataValueWithTimezone() @@ -84,14 +83,14 @@ public function testDataValueWithTimezone() $f = new DatetimeField('Datetime'); $f->setTimezone('Pacific/Auckland'); $f->setSubmittedValue('2003-01-30T23:59:38'); // frontend timezone (Auckland) - $this->assertEquals('2003-01-30 11:59:38', $f->dataValue()); // server timezone (Berlin) + $this->assertEquals('2003-01-30 11:59:38', $f->getValue()); // server timezone (Berlin) } public function testSetSubmittedValueNull() { $field = new DatetimeField('Datetime'); $field->setSubmittedValue(false); - $this->assertNull($field->Value()); + $this->assertNull($field->getFormattedValue()); } public function testConstructorWithoutArgs() @@ -100,43 +99,55 @@ public function testConstructorWithoutArgs() $this->assertEquals($f->dataValue(), null); } - public function testConstructorWithLocalizedDateSetsNullValue() + public function testConstructorWithLocalizedDate() { $f = new DatetimeField('Datetime', 'Datetime', '29/03/2003 23:59:38'); - $this->assertNull($f->Value()); + $this->assertSame('29/03/2003 23:59:38', $f->getValue()); + $this->assertNull($f->getFormattedValue()); } public function testConstructorWithIsoDate() { // used by Form->loadDataFrom() $f = new DatetimeField('Datetime', 'Datetime', '2003-03-29 23:59:38'); - $this->assertEquals($f->dataValue(), '2003-03-29 23:59:38'); + $this->assertSame('2003-03-29 23:59:38', $f->getValue()); + $this->assertSame('2003-03-29T23:59:38', $f->getFormattedValue()); } public function testSetValueWithDateTimeString() { + // ISO $f = new DatetimeField('Datetime', 'Datetime'); $f->setValue('2003-03-29 23:59:38'); - $this->assertEquals('2003-03-29 23:59:38', $f->dataValue(), 'Accepts ISO'); + $this->assertEquals('2003-03-29 23:59:38', $f->getValue()); + $this->assertEquals('2003-03-29T23:59:38', $f->getFormattedValue()); + // Normalised ISO $f = new DatetimeField('Datetime', 'Datetime'); $f->setValue('2003-03-29T23:59:38'); - $this->assertEquals('2003-03-29 23:59:38', $f->dataValue(), 'Accepts normalised ISO'); + $this->assertEquals('2003-03-29 23:59:38', $f->getValue()); + $this->assertEquals('2003-03-29T23:59:38', $f->getFormattedValue()); + // Null $f = new DatetimeField('Datetime', 'Datetime'); $f->setValue(null); - $this->assertEquals(null, $f->dataValue()); + $this->assertEquals(null, $f->getValue()); + $this->assertEquals('', $f->getFormattedValue()); } public function testSubmittedValue() { + // ISO $datetimeField = new DatetimeField('Datetime', 'Datetime'); $datetimeField->setSubmittedValue('2003-03-29 23:00:00'); - $this->assertEquals($datetimeField->dataValue(), '2003-03-29 23:00:00'); + $this->assertEquals('2003-03-29 23:00:00', $datetimeField->getValue()); + $this->assertEquals('2003-03-29T23:00:00', $datetimeField->getFormattedValue()); + // Normalised ISO $datetimeField = new DatetimeField('Datetime', 'Datetime'); $datetimeField->setSubmittedValue('2003-03-29T23:00:00'); - $this->assertEquals($datetimeField->dataValue(), '2003-03-29 23:00:00', 'Normalised ISO'); + $this->assertEquals('2003-03-29 23:00:00', $datetimeField->getValue()); + $this->assertEquals('2003-03-29T23:00:00', $datetimeField->getFormattedValue()); } public function testSetValueWithLocalised() @@ -153,7 +164,7 @@ public function testSetValueWithLocalised() // Some localisation packages exclude the ',' in default medium format $this->assertMatchesRegularExpression( '#29.03.2003(,)? 23:00:00#', - $datetimeField->Value(), + $datetimeField->getFormattedValue(), 'User value is formatted, and in user timezone' ); } @@ -353,7 +364,7 @@ public function testTimezoneSetValueLocalised() $datetimeField->setValue('2003-12-24 23:59:59'); $this->assertEquals( '25/12/2003 11:59:59', - $datetimeField->Value(), + $datetimeField->getFormattedValue(), 'User value is formatted, and in user timezone' ); @@ -374,7 +385,7 @@ public function testTimezoneSetValueWithHtml5() $datetimeField->setValue('2003-12-24 23:59:59'); $this->assertEquals( '2003-12-25T11:59:59', - $datetimeField->Value(), + $datetimeField->getFormattedValue(), 'User value is in normalised ISO format and in user timezone' ); diff --git a/tests/php/Forms/DropdownFieldTest.php b/tests/php/Forms/DropdownFieldTest.php index 321546be928..f8a9f3cb3de 100644 --- a/tests/php/Forms/DropdownFieldTest.php +++ b/tests/php/Forms/DropdownFieldTest.php @@ -418,7 +418,7 @@ public function testDropdownWithArrayValues($value) $field = $this->createDropdownField(); $field->setValue($value); $this->assertInstanceOf('SilverStripe\\ORM\\FieldType\\DBHTMLText', $field->Field()); - $this->assertSame($value, $field->Value()); + $this->assertSame($value, $field->getValue()); } /** diff --git a/tests/php/Forms/FormTest.php b/tests/php/Forms/FormTest.php index abf45e2605d..e66e48e789a 100644 --- a/tests/php/Forms/FormTest.php +++ b/tests/php/Forms/FormTest.php @@ -183,11 +183,11 @@ public function testLoadDataFromRequest() $form->loadDataFrom($requestData); $fields = $form->Fields(); - $this->assertEquals('val1', $fields->fieldByName('key1')->Value()); - $this->assertEquals('val2', $fields->fieldByName('namespace[key2]')->Value()); - $this->assertEquals('val4', $fields->fieldByName('namespace[key3][key4]')->Value()); - $this->assertEquals('val7', $fields->fieldByName('othernamespace[key5][key6][key7]')->Value()); - $this->assertEquals('dot.field val', $fields->fieldByName('dot.field')->Value()); + $this->assertEquals('val1', $fields->fieldByName('key1')->getValue()); + $this->assertEquals('val2', $fields->fieldByName('namespace[key2]')->getValue()); + $this->assertEquals('val4', $fields->fieldByName('namespace[key3][key4]')->getValue()); + $this->assertEquals('val7', $fields->fieldByName('othernamespace[key5][key6][key7]')->getValue()); + $this->assertEquals('dot.field val', $fields->fieldByName('dot.field')->getValue()); } public function testSubmitReadonlyFields() @@ -469,7 +469,7 @@ public function testFormMethodOverride() $form = $this->getStubForm(); $form->setFormMethod('PUT'); $this->assertEquals( - $form->Fields()->dataFieldByName('_method')->Value(), + $form->Fields()->dataFieldByName('_method')->getValue(), 'PUT', 'PUT override in forms has PUT in hiddenfield' ); @@ -482,7 +482,7 @@ public function testFormMethodOverride() $form = $this->getStubForm(); $form->setFormMethod('DELETE'); $this->assertEquals( - $form->Fields()->dataFieldByName('_method')->Value(), + $form->Fields()->dataFieldByName('_method')->getValue(), 'DELETE', 'PUT override in forms has PUT in hiddenfield' ); diff --git a/tests/php/Forms/GridField/GridFieldStateManagerTest.php b/tests/php/Forms/GridField/GridFieldStateManagerTest.php index c17929bd99e..9c8f9ede8a0 100644 --- a/tests/php/Forms/GridField/GridFieldStateManagerTest.php +++ b/tests/php/Forms/GridField/GridFieldStateManagerTest.php @@ -44,14 +44,14 @@ public function testAddStateToURL() $grid = new GridField('TestGrid'); $grid->getState()->testValue = 'foo'; $link = '/link-to/something'; - $state = $grid->getState(false)->Value(); + $state = $grid->getState(false)->getValue(); $this->assertEquals( '/link-to/something?gridState-TestGrid-0=' . urlencode($state ?? ''), $manager->addStateToURL($grid, $link) ); $link = '/link-to/something-else?someParam=somevalue'; - $state = $grid->getState(false)->Value(); + $state = $grid->getState(false)->getValue(); $this->assertEquals( '/link-to/something-else?someParam=somevalue&gridState-TestGrid-0=' . urlencode($state ?? ''), $manager->addStateToURL($grid, $link) @@ -67,7 +67,7 @@ public function testGetStateFromRequest() $grid->setForm($form); $grid->getState()->testValue = 'foo'; - $state = urlencode($grid->getState(false)->Value() ?? ''); + $state = urlencode($grid->getState(false)->getValue() ?? ''); $request = new HTTPRequest( 'GET', '/link-to/something', @@ -87,7 +87,7 @@ public function testDefaultStateLeavesURLUnchanged() $grid->getState()->initDefaults(['testValue' => 'foo']); $link = '/link-to/something'; - $this->assertEquals('{}', $grid->getState(false)->Value()); + $this->assertEquals('{}', $grid->getState(false)->getValue()); $this->assertEquals( '/link-to/something', diff --git a/tests/php/Forms/GridField/GridStateTest.php b/tests/php/Forms/GridField/GridStateTest.php index 8598c978043..3053de80d89 100644 --- a/tests/php/Forms/GridField/GridStateTest.php +++ b/tests/php/Forms/GridField/GridStateTest.php @@ -14,18 +14,18 @@ public function testValue() $gridfield = new GridField('Test'); $state = new GridState($gridfield); - $this->assertEquals('{}', $state->Value(), 'GridState without any data has empty JSON object for Value'); + $this->assertEquals('{}', $state->getValue(), 'GridState without any data has empty JSON object for Value'); $data = $state->getData(); $data->initDefaults(['Foo' => 'Bar']); - $this->assertEquals('{}', $state->Value(), 'GridState without change has empty JSON object for Value'); + $this->assertEquals('{}', $state->getValue(), 'GridState without change has empty JSON object for Value'); $data->Foo = 'Barrr'; $this->assertEquals( '{"Foo":"Barrr"}', - $state->Value(), + $state->getValue(), 'GridState with changes returns has a JSON object string for Value.' ); } diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php index d9f69cfe49c..e87ec9428d7 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php @@ -216,7 +216,7 @@ public function testReadonlyField() ); } - public static function provideTestValueEntities() + public static function provideTestFormattedValueEntities() { return [ "ampersand" => [ @@ -234,15 +234,15 @@ public static function provideTestValueEntities() ]; } - #[DataProvider('provideTestValueEntities')] - public function testValueEntities(string $input, string $result) + #[DataProvider('provideTestFormattedValueEntities')] + public function testFormattedValueEntities(string $input, string $result) { $field = new HTMLEditorField("Content"); $field->setValue($input); $this->assertEquals( $result, - $field->obj('ValueEntities')->forTemplate() + $field->obj('FormattedValueEntities')->forTemplate() ); } diff --git a/tests/php/Forms/ListboxFieldTest.php b/tests/php/Forms/ListboxFieldTest.php index 5ef0a1b3832..29c5bfb2069 100644 --- a/tests/php/Forms/ListboxFieldTest.php +++ b/tests/php/Forms/ListboxFieldTest.php @@ -31,7 +31,6 @@ public function testFieldWithManyManyRelationship() $tag3 = $this->objFromFixture(Tag::class, 'tag3'); $field = new ListboxField("Tags", "Test field", DataObject::get(Tag::class)->map()->toArray()); $field->setValue(null, $articleWithTags); - $p = new CSSContentParser($field->Field()); $tag1xml = $p->getByXpath('//option[@value=' . $tag1->ID . ']'); $tag2xml = $p->getByXpath('//option[@value=' . $tag2->ID . ']'); @@ -115,7 +114,7 @@ public function testSaveIntoMultiple() $obj2 = new TestObject(); $obj2->Choices = '["a","c"]'; $field->setValue(null, $obj2); - $this->assertEquals(['a', 'c'], $field->Value()); + $this->assertEquals(['a', 'c'], $field->getValue()); $field->saveInto($obj2); $this->assertEquals('["a","c"]', $obj2->Choices); } diff --git a/tests/php/Forms/MoneyFieldTest.php b/tests/php/Forms/MoneyFieldTest.php index ea136e8be69..9b598e29e5d 100644 --- a/tests/php/Forms/MoneyFieldTest.php +++ b/tests/php/Forms/MoneyFieldTest.php @@ -51,7 +51,7 @@ public function testSetValueAsMoney() $this->assertEquals(123456.78, $testObject->MyMoney->getAmount()); $this->assertEquals('EUR', $testObject->MyMoney->getCurrency()); $this->assertEquals('123456.78 EUR', $field->dataValue()); - $this->assertEquals('€123,456.78', $field->Value()); + $this->assertEquals('€123,456.78', $field->getFormattedValue()); } public function testSetValueAsArray() @@ -78,7 +78,7 @@ public function testSetValueAsString() $this->assertEquals(1.01, $testObject->MyMoney->getAmount()); $this->assertEquals('USD', $testObject->MyMoney->getCurrency()); $this->assertEquals('1.01 USD', $field->dataValue()); - $this->assertEquals('US$1.01', $field->Value()); + $this->assertEquals('US$1.01', $field->getFormattedValue()); $testObject = new TestObject(); $field = new MoneyField('MyMoney'); @@ -88,7 +88,7 @@ public function testSetValueAsString() $this->assertEquals(1.01, $testObject->MyMoney->getAmount()); $this->assertNull($testObject->MyMoney->getCurrency()); $this->assertEquals('1.01', $field->dataValue()); - $this->assertEquals('$1.01', $field->Value()); + $this->assertEquals('$1.01', $field->getFormattedValue()); } /** diff --git a/tests/php/Forms/NullableFieldTests.php b/tests/php/Forms/NullableFieldTests.php index 8cb1dd8ef4c..ee34a852ead 100644 --- a/tests/php/Forms/NullableFieldTests.php +++ b/tests/php/Forms/NullableFieldTests.php @@ -22,7 +22,7 @@ public function testWithContent() $a = new NullableField(new TextField("Field1", "Field 1", "abc")); $this->assertEquals("Field1", $a->getName()); $this->assertEquals("Field 1", $a->Title()); - $this->assertSame("abc", $a->Value()); + $this->assertSame("abc", $a->getValue()); $this->assertSame("abc", $a->dataValue()); $field = $a->Field(); $this->assertTag( @@ -50,7 +50,7 @@ public function testWithEmpty() $a = new NullableField(new TextField("Field1", "Field 1", "")); $this->assertEquals("Field1", $a->getName()); $this->assertEquals("Field 1", $a->Title()); - $this->assertSame("", $a->Value()); + $this->assertSame("", $a->getValue()); $this->assertSame("", $a->dataValue()); $field = $a->Field(); $this->assertTag( @@ -78,7 +78,7 @@ public function testWithNull() $a = new NullableField(new TextField("Field1", "Field 1", null)); $this->assertEquals("Field1", $a->getName()); $this->assertEquals("Field 1", $a->Title()); - $this->assertSame(null, $a->Value()); + $this->assertSame(null, $a->getValue()); $this->assertSame(null, $a->dataValue()); $field = $a->Field(); $this->assertTag( diff --git a/tests/php/Forms/NumericFieldTest.php b/tests/php/Forms/NumericFieldTest.php index 641a8153703..919cf95df3a 100644 --- a/tests/php/Forms/NumericFieldTest.php +++ b/tests/php/Forms/NumericFieldTest.php @@ -216,9 +216,9 @@ public function testSetValue( } $field->setScale($scale); $field->setValue($input); - $this->assertSame($expDataValue, $field->dataValue(), 'dataValue()'); - $this->assertSame($expValue, $field->Value(), 'Value()'); - $this->assertTrue($field->validate()->isValid(), 'isValid()'); + $this->assertSame($expDataValue, $field->dataValue()); + $this->assertSame($expValue, $field->getFormattedValue()); + $this->assertTrue($field->validate()->isValid()); } public function testReadonly() @@ -244,13 +244,13 @@ public function testNullSet() { $field = new NumericField('Number'); $field->setValue(''); - $this->assertEquals('', $field->Value()); + $this->assertEquals('', $field->getFormattedValue()); $this->assertNull($field->dataValue()); $field->setValue(null); - $this->assertNull($field->Value()); + $this->assertNull($field->getFormattedValue()); $this->assertNull($field->dataValue()); $field->setValue(0); - $this->assertEquals(0, $field->Value()); + $this->assertEquals(0, $field->getFormattedValue()); $this->assertEquals(0, $field->dataValue()); } @@ -615,7 +615,7 @@ public function testSetSubmittedValue( if (!$cleanedInput) { $cleanedInput = $submittedValue; } - $this->assertSame($cleanedInput, $field->Value(), 'Value()'); + $this->assertSame($cleanedInput, $field->getFormattedValue(), 'getFormattedValue()'); } public static function provideDataType(): array @@ -625,6 +625,7 @@ public static function provideDataType(): array 'value' => 3, 'scale' => 0, 'expValue' => '3', + 'expFormattedValue' => '3', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -632,6 +633,7 @@ public static function provideDataType(): array 'value' => 3, 'scale' => 1, 'expValue' => '3', + 'expFormattedValue' => '3.0', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -639,6 +641,7 @@ public static function provideDataType(): array 'value' => 3.4, 'scale' => 0, 'expValue' => '3', + 'expFormattedValue' => '3', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -646,6 +649,7 @@ public static function provideDataType(): array 'value' => 3.4, 'scale' => 1, 'expValue' => '3.4', + 'expFormattedValue' => '3.4', 'expValueForValidation' => '3.4', 'expDataValue' => '3.4', ], @@ -653,6 +657,8 @@ public static function provideDataType(): array 'value' => '3', 'scale' => 0, 'expValue' => '3', + 'expValue' => '3', + 'expFormattedValue' => '3', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -660,6 +666,7 @@ public static function provideDataType(): array 'value' => '3', 'scale' => 1, 'expValue' => '3', + 'expFormattedValue' => '3.0', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -667,6 +674,7 @@ public static function provideDataType(): array 'value' => '3.4', 'scale' => 0, 'expValue' => '3', + 'expFormattedValue' => '3', 'expValueForValidation' => '3', 'expDataValue' => '3', ], @@ -674,6 +682,7 @@ public static function provideDataType(): array 'value' => '3.4', 'scale' => 1, 'expValue' => '3.4', + 'expFormattedValue' => '3.4', 'expValueForValidation' => '3.4', 'expDataValue' => '3.4', ], @@ -681,6 +690,7 @@ public static function provideDataType(): array 'value' => null, 'scale' => 0, 'expValue' => null, + 'expFormattedValue' => null, 'expValueForValidation' => null, 'expDataValue' => null, ], @@ -688,6 +698,7 @@ public static function provideDataType(): array 'value' => true, 'scale' => 0, 'expValue' => true, + 'expFormattedValue' => '1', 'expValueForValidation' => true, 'expDataValue' => true, ], @@ -699,6 +710,7 @@ public function testDataType( mixed $value, int $scale, mixed $expValue, + mixed $expFormattedValue, mixed $expValueForValidation, mixed $expDataValue ): void { @@ -706,6 +718,7 @@ public function testDataType( $field->setScale($scale); $field->setValue($value); $this->assertSame($expValue, $field->getValue(), 'getValue()'); + $this->assertSame($expFormattedValue, $field->getFormattedValue(), 'getFormattedValue()'); $this->assertSame($expValueForValidation, $field->getValueForValidation(), 'getValueForValidation()'); $this->assertSame($expDataValue, $field->dataValue(), 'dataValue()'); } diff --git a/tests/php/Forms/TextareaFieldTest.php b/tests/php/Forms/TextareaFieldTest.php index 32ee7724aab..3edc63cee58 100644 --- a/tests/php/Forms/TextareaFieldTest.php +++ b/tests/php/Forms/TextareaFieldTest.php @@ -74,22 +74,22 @@ public function testMaxLengthValidationSuccess() $this->assertTrue($field->validate()->isValid()); } - public function testValueEntities() + public function testFormattedValueEntities() { $inputText = "These are some unicodes: äöü"; $field = new TextareaField("Test", "Test"); $field->setValue($inputText); - // Value should be safe-encoding only, but ValueEntities should be more aggressive + // Value should be safe-encoding only, but FormattedValueEntities should be more aggressive $this->assertEquals( "These <b>are</b> some unicodes: äöü", - $field->obj('ValueEntities')->forTemplate() + $field->obj('FormattedValueEntities')->forTemplate() ); // Shortcodes are disabled $this->assertEquals( false, - $field->obj('ValueEntities')->getProcessShortcodes() + $field->obj('FormattedValueEntities')->getProcessShortcodes() ); } diff --git a/tests/php/Forms/TimeFieldTest.php b/tests/php/Forms/TimeFieldTest.php index ea915cceb6f..b75ad50ecbb 100644 --- a/tests/php/Forms/TimeFieldTest.php +++ b/tests/php/Forms/TimeFieldTest.php @@ -23,13 +23,17 @@ protected function setUp(): void public function testConstructorWithoutArgs() { $f = new TimeField('Time'); - $this->assertEquals($f->dataValue(), null); + $this->assertSame('', $f->dataValue()); + $this->assertSame('00:00:00', $f->getFormattedValue()); } public function testConstructorWithString() { $f = new TimeField('Time', 'Time', '23:00:00'); - $this->assertEquals($f->dataValue(), '23:00:00'); + $this->assertSame('23:00:00', $f->dataValue()); + $f->setLocale('de_DE'); + $f->setHTML5(false); + $this->assertSame('23:00:00', $f->getFormattedValue()); } public function testValidate() @@ -65,39 +69,36 @@ public function testSetLocale() $f->setHTML5(false); $f->setLocale('fr_FR'); $f->setValue('23:59'); - $this->assertEquals($f->dataValue(), '23:59:00'); + $this->assertSame('23:59:00', $f->dataValue()); } public function testSetValueWithUseStrToTime() { $f = new TimeField('Time', 'Time'); $f->setValue('11pm'); - $this->assertEquals( - $f->dataValue(), - '23:00:00', - 'Setting value to "11pm" parses with strtotime enabled' - ); + // Setting value to "11pm" parses with strtotime enabled + $this->assertSame('23:00:00', $f->dataValue()); $this->assertTrue($f->validate()->isValid()); $f = new TimeField('Time', 'Time'); $f->setValue('11:59pm'); - $this->assertEquals('23:59:00', $f->dataValue()); + $this->assertSame('23:59:00', $f->dataValue()); $f = new TimeField('Time', 'Time'); $f->setValue('11:59 pm'); - $this->assertEquals('23:59:00', $f->dataValue()); + $this->assertSame('23:59:00', $f->dataValue()); $f = new TimeField('Time', 'Time'); $f->setValue('23:59'); - $this->assertEquals('23:59:00', $f->dataValue()); + $this->assertSame('23:59:00', $f->dataValue()); $f = new TimeField('Time', 'Time'); $f->setValue('23:59:38'); - $this->assertEquals('23:59:38', $f->dataValue()); + $this->assertSame('23:59:38', $f->dataValue()); $f = new TimeField('Time', 'Time'); $f->setValue('12:00 am'); - $this->assertEquals($f->dataValue(), '00:00:00'); + $this->assertSame('00:00:00', $f->dataValue()); } public function testOverrideWithNull() @@ -105,7 +106,7 @@ public function testOverrideWithNull() $field = new TimeField('Time', 'Time'); $field->setValue('11:00:00'); $field->setValue(''); - $this->assertEquals($field->dataValue(), ''); + $this->assertSame('', $field->dataValue()); } /** @@ -113,7 +114,6 @@ public function testOverrideWithNull() */ public function testSetTimeFormat() { - // Test with timeformat that includes hour // Check pm @@ -121,35 +121,35 @@ public function testSetTimeFormat() $f->setHTML5(false); $f->setTimeFormat('h:mm:ss a'); $f->setValue('3:59 pm'); - $this->assertEquals($f->dataValue(), '15:59:00'); + $this->assertSame('15:59:00', $f->dataValue()); // Check am $f = new TimeField('Time', 'Time'); $f->setHTML5(false); $f->setTimeFormat('h:mm:ss a'); $f->setValue('3:59 am'); - $this->assertEquals($f->dataValue(), '03:59:00'); + $this->assertSame('03:59:00', $f->dataValue()); // Check with ISO date/time $f = new TimeField('Time', 'Time'); $f->setHTML5(false); $f->setTimeFormat('h:mm:ss a'); $f->setValue('15:59:00'); - $this->assertEquals($f->dataValue(), '15:59:00'); + $this->assertSame('15:59:00', $f->dataValue()); // ISO am $f = new TimeField('Time', 'Time'); $f->setHTML5(false); $f->setTimeFormat('h:mm:ss a'); $f->setValue('03:59:00'); - $this->assertEquals($f->dataValue(), '03:59:00'); + $this->assertSame('03:59:00', $f->dataValue()); } public function testLenientSubmissionParseWithoutSecondsOnHtml5() { $f = new TimeField('Time', 'Time'); $f->setSubmittedValue('23:59'); - $this->assertEquals($f->Value(), '23:59:00'); + $this->assertSame('23:59:00', $f->getFormattedValue()); } public function testHtml5WithCustomFormatThrowsException() @@ -159,7 +159,7 @@ public function testHtml5WithCustomFormatThrowsException() $f = new TimeField('Time', 'Time'); $f->setValue('15:59:00'); $f->setTimeFormat('mm:HH'); - $f->Value(); + $f->getFormattedValue(); } public function testHtml5WithCustomDateLengthThrowsException() @@ -169,7 +169,7 @@ public function testHtml5WithCustomDateLengthThrowsException() $f = new TimeField('Time', 'Time'); $f->setValue('15:59:00'); $f->setTimeLength(IntlDateFormatter::MEDIUM); - $f->Value(); + $f->getFormattedValue(); } public function testHtml5WithCustomLocaleThrowsException() @@ -179,7 +179,7 @@ public function testHtml5WithCustomLocaleThrowsException() $f = new TimeField('Time', 'Time'); $f->setValue('15:59:00'); $f->setLocale('de_DE'); - $f->Value(); + $f->getFormattedValue(); } public static function provideTidyInternal(): array @@ -225,6 +225,6 @@ public function testTidyInternal(?string $time, bool $returnNullOnFailure, ?stri $method = new ReflectionMethod($field, 'tidyInternal'); $method->setAccessible(true); $actual = $method->invoke($field, $time, $returnNullOnFailure); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } } diff --git a/tests/php/ORM/DecimalTest.php b/tests/php/ORM/DecimalTest.php index 0fab0a8adc9..24006a341b3 100644 --- a/tests/php/ORM/DecimalTest.php +++ b/tests/php/ORM/DecimalTest.php @@ -97,6 +97,6 @@ public function testScaffoldFormField() $this->assertEquals(3, $field->getScale()); $field->setValue(1.9999); $this->assertEquals(1.9999, $field->dataValue()); - $this->assertEquals('2.000', $field->Value()); + $this->assertEquals('2.000', $field->getFormattedValue()); } } diff --git a/tests/php/ORM/MySQLiConnectorTest.php b/tests/php/ORM/MySQLiConnectorTest.php index 274eb8b21ec..8781934ada1 100644 --- a/tests/php/ORM/MySQLiConnectorTest.php +++ b/tests/php/ORM/MySQLiConnectorTest.php @@ -237,9 +237,7 @@ public function testPreparedQueryThrowsDuplicateEntryException(int $reportMode): $connector->preparedQuery('INSERT INTO duplicate_entry_table (Title, Name) VALUES (?, ?);', ['My Title', 'My Name']); } - /** - * @dataProvider provideQueryThrowsException - */ + #[DataProvider('provideQueryThrowsException')] public function testPrepareStatementThrowsDatabaseError(int $reportMode): void { $connector = $this->getConnector(); diff --git a/tests/php/Security/SecurityTokenTest.php b/tests/php/Security/SecurityTokenTest.php index eb01bc3b915..316d46f0518 100644 --- a/tests/php/Security/SecurityTokenTest.php +++ b/tests/php/Security/SecurityTokenTest.php @@ -147,7 +147,7 @@ public function testUpdateFieldSet() $this->assertInstanceOf(HiddenField::class, $f); $this->assertEquals($f->getName(), $t->getName(), 'Name matches'); - $this->assertEquals($f->Value(), $t->getValue(), 'Value matches'); + $this->assertEquals($f->getValue(), $t->getValue(), 'Value matches'); } public function testUpdateFieldSetDoesntAddTwice()