public function testValidateValueInteger() { $inputValue = 0; $expectedResult = ['"Test" is a required value.']; $result = $this->_model->validateValue($inputValue); $this->assertEquals($expectedResult, [(string) $result[0]]); }
/** * @param string $value * @return true|string[] */ public function validateValue($value) { $countryId = $this->getExtractedData('country_id'); $optionalZip = $this->_directoryData->getCountriesWithOptionalZip(); if (!in_array($countryId, $optionalZip)) { return parent::validateValue($value); } return true; }
/** * Validate data * Return true or array of errors * * @param array|string $value * @return bool|array */ public function validateValue($value) { $errors = array(); $attribute = $this->getAttribute(); if ($value === false) { // try to load original value and validate it $value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode()); if (!is_array($value)) { $value = explode("\n", $value); } } if (!is_array($value)) { $value = array($value); } for ($i = 0; $i < $attribute->getMultilineCount(); $i++) { if (!isset($value[$i])) { $value[$i] = null; } // validate first line if ($i == 0) { $result = parent::validateValue($value[$i]); if ($result !== true) { $errors = $result; } } else { if (!empty($value[$i])) { $result = parent::validateValue($value[$i]); if ($result !== true) { $errors = array_merge($errors, $result); } } } } if (count($errors) == 0) { return true; } return $errors; }
/** * Validate data * Return true or array of errors * * @param array|string $value * @return bool|array */ public function validateValue($value) { $errors = []; $lines = $this->processValue($value); $attribute = $this->getAttribute(); $attributeLabel = __($attribute->getStoreLabel()); if ($attribute->getIsRequired() && empty($lines)) { $errors[] = __('"%1" is a required value.', $attributeLabel); } $maxAllowedLineCount = $attribute->getMultilineCount(); if (count($lines) > $maxAllowedLineCount) { $errors[] = __('"%1" cannot contain more than %2 lines.', $attributeLabel, $maxAllowedLineCount); } foreach ($lines as $lineIndex => $line) { // First line must be always validated if ($lineIndex == 0 || !empty($line)) { $result = parent::validateValue($line); if ($result !== true) { $errors = array_merge($errors, $result); } } } return count($errors) == 0 ? true : $errors; }