diff --git a/core/Form/Form.class.php b/core/Form/Form.class.php index f94abc892e..bafb549ab9 100644 --- a/core/Form/Form.class.php +++ b/core/Form/Form.class.php @@ -1,12 +1,12 @@ errors, $this->violated); + $errors = array(); + foreach($this->primitives as $name => $prm) { + if (null !== $prm->getError()) + $errors[$name] = $prm->getError(); + } + + return $errors; } public function hasError($name) { - return array_key_exists($name, $this->errors) - || array_key_exists($name, $this->violated); + return $this->get($name)->getError() !== null; } public function getError($name) { - if (array_key_exists($name, $this->errors)) { - return $this->errors[$name]; - } elseif (array_key_exists($name, $this->violated)) { - return $this->violated[$name]; - } - return null; + return $this->get($name)->getError(); } public function getInnerErrors() @@ -65,17 +61,11 @@ public function getInnerErrors() foreach ($this->primitives as $name => $prm) { if ( - ( - ($prm instanceof PrimitiveFormsList) - || ($prm instanceof PrimitiveForm) - ) - && $prm->getValue() + $prm instanceof PrimitiveFormsList + || $prm instanceof PrimitiveForm ) { - if ($errors = $prm->getInnerErrors()) { + if ($errors = $prm->getInnerErrors()) $result[$name] = $errors; - } else { - unset($result[$name]); - } } } @@ -87,9 +77,10 @@ public function getInnerErrors() **/ public function dropAllErrors() { - $this->errors = array(); - $this->violated = array(); - + foreach($this->primitives as $name => $prm) { + $prm->dropError(); + } + return $this; } @@ -122,7 +113,7 @@ public function disableImportFiltering() **/ public function markMissing($primitiveName, $label = null) { - return $this->markCustom($primitiveName, Form::MISSING, $label); + return $this->markCustom($primitiveName, BasePrimitive::MISSING, $label); } /** @@ -132,17 +123,11 @@ public function markMissing($primitiveName, $label = null) **/ public function markWrong($name, $label = null) { - if (isset($this->primitives[$name])) - $this->errors[$name] = self::WRONG; - elseif (isset($this->rules[$name])) - $this->violated[$name] = self::WRONG; - else - throw new MissingElementException( - $name.' does not match known primitives or rules' - ); + $prm = $this->get($name); + $prm->markWrong(); if ($label !== null) - $this->addWrongLabel($name, $label); + $prm->setWrongLabel($label); return $this; } @@ -152,14 +137,7 @@ public function markWrong($name, $label = null) **/ public function markGood($primitiveName) { - if (isset($this->primitives[$primitiveName])) - unset($this->errors[$primitiveName]); - elseif (isset($this->rules[$primitiveName])) - unset($this->violated[$primitiveName]); - else - throw new MissingElementException( - $primitiveName.' does not match known primitives or rules' - ); + $this->get($primitiveName)->markGood(); return $this; } @@ -171,12 +149,7 @@ public function markGood($primitiveName) **/ public function markCustom($primitiveName, $customMark, $label = null) { - Assert::isInteger($customMark); - - $this->errors[$this->get($primitiveName)->getName()] = $customMark; - - if ($label !== null) - $this->addCustomLabel($primitiveName, $customMark, $label); + $this->get($primitiveName)->setErrorLabel($customMark, $label); return $this; } @@ -189,9 +162,9 @@ public function getTextualErrors() { $list = array(); - foreach (array_keys($this->labels) as $name) { + foreach ($this->primitives as $name => $prm) { if ($label = $this->getTextualErrorFor($name)) - $list[] = $label; + $list[$name] = $label; } return $list; @@ -199,42 +172,12 @@ public function getTextualErrors() public function getTextualErrorFor($name) { - if ( - isset( - $this->violated[$name], - $this->labels[$name][$this->violated[$name]] - ) - ) - return $this->labels[$name][$this->violated[$name]]; - elseif ( - isset( - $this->errors[$name], - $this->labels[$name][$this->errors[$name]] - ) - ) - return $this->labels[$name][$this->errors[$name]]; - else - return null; + return $this->get($name)->getActualErrorLabel(); } public function getErrorDescriptionFor($name) { - if ( - isset( - $this->violated[$name], - $this->describedLabels[$name][$this->violated[$name]] - ) - ) - return $this->describedLabels[$name][$this->violated[$name]]; - elseif ( - isset( - $this->errors[$name], - $this->describedLabels[$name][$this->errors[$name]] - ) - ) - return $this->describedLabels[$name][$this->errors[$name]]; - else - return null; + return $this->get($name)->getActualErrorDescription(); } /** @@ -242,17 +185,8 @@ public function getErrorDescriptionFor($name) **/ public function addErrorDescription($name, $errorType, $description) { - - if ( - !isset($this->rules[$name]) - && !$this->get($name)->getName() - ) - throw new MissingElementException( - "knows nothing about '{$name}'" - ); - - $this->describedLabels[$name][$errorType] = $description; - + $this->get($name)->setErrorDescription($errorType, $description); + return $this; } @@ -261,7 +195,7 @@ public function addErrorDescription($name, $errorType, $description) **/ public function addWrongLabel($primitiveName, $label) { - return $this->addErrorLabel($primitiveName, Form::WRONG, $label); + return $this->addErrorLabel($primitiveName, BasePrimitive::WRONG, $label); } /** @@ -269,7 +203,7 @@ public function addWrongLabel($primitiveName, $label) **/ public function addMissingLabel($primitiveName, $label) { - return $this->addErrorLabel($primitiveName, Form::MISSING, $label); + return $this->addErrorLabel($primitiveName, BasePrimitive::MISSING, $label); } /** @@ -282,12 +216,12 @@ public function addCustomLabel($primitiveName, $customMark, $label) public function getWrongLabel($primitiveName) { - return $this->getErrorLabel($primitiveName, Form::WRONG); + return $this->getErrorLabel($primitiveName, BasePrimitive::WRONG); } public function getMissingLabel($primitiveName) { - return $this->getErrorLabel($primitiveName, Form::MISSING); + return $this->getErrorLabel($primitiveName, BasePrimitive::MISSING); } /** @@ -327,9 +261,9 @@ public function importOne($primitiveName, $scope) **/ public function importValue($primitiveName, $value) { - $prm = $this->get($primitiveName); - - return $this->checkImportResult($prm, $prm->importValue($value)); + $this->get($primitiveName)->importValue($value); + + return $this; } /** @@ -395,60 +329,8 @@ public function getProto() **/ private function importPrimitive($scope, BasePrimitive $prm) { - if (!$this->importFiltering) { - if ($prm instanceof FiltrablePrimitive) { - - $chain = $prm->getImportFilter(); - - $prm->dropImportFilters(); - - $result = $this->checkImportResult( - $prm, - $prm->import($scope) - ); - - $prm->setImportFilter($chain); - - return $result; - - } elseif ($prm instanceof PrimitiveForm) { - return $this->checkImportResult( - $prm, - $prm->unfilteredImport($scope) - ); - } - } - - return $this->checkImportResult($prm, $prm->import($scope)); - } - - /** - * @return Form - **/ - private function checkImportResult(BasePrimitive $prm, $result) - { - if ( - $prm instanceof PrimitiveAlias - && $result !== null - ) - $this->markGood($prm->getInner()->getName()); - - $name = $prm->getName(); - - if (null === $result) { - if ($prm->isRequired()) - $this->errors[$name] = self::MISSING; - - } elseif (true === $result) { - unset($this->errors[$name]); - - } elseif ($error = $prm->getCustomError()) { - - $this->errors[$name] = $error; - - } else - $this->errors[$name] = self::WRONG; - + $prm->import($scope); + return $this; } @@ -464,28 +346,14 @@ private function checkImportResult(BasePrimitive $prm, $result) **/ private function addErrorLabel($name, $errorType, $label) { - if ( - !isset($this->rules[$name]) - && !$this->get($name)->getName() - ) - throw new MissingElementException( - "knows nothing about '{$name}'" - ); - - $this->labels[$name][$errorType] = $label; + $this->get($name)->setErrorLabel($errorType, $label); return $this; } private function getErrorLabel($name, $errorType) { - // checks for primitive's existence - $this->get($name); - - if (isset($this->labels[$name][$errorType])) - return $this->labels[$name][$errorType]; - - return null; + return $this->get($name)->getErrorLabel($errorType); } } ?> \ No newline at end of file diff --git a/core/Form/Primitive.class.php b/core/Form/Primitive.class.php index 41f6fab878..dfdee82738 100644 --- a/core/Form/Primitive.class.php +++ b/core/Form/Primitive.class.php @@ -394,5 +394,13 @@ public static function enumList($name) { return new PrimitiveEnumList($name); } + + /** + * @return PrimitiveRule + **/ + public static function rule($name) + { + return new PrimitiveRule($name); + } } ?> \ No newline at end of file diff --git a/core/Form/Primitives/BasePrimitive.class.php b/core/Form/Primitives/BasePrimitive.class.php index 20af7b8b2e..1a389bf7fa 100644 --- a/core/Form/Primitives/BasePrimitive.class.php +++ b/core/Form/Primitives/BasePrimitive.class.php @@ -1,12 +1,12 @@ 'label') + */ + protected $errorLabels = array(); + + /** + * Error description for each error type + * @var array of ('errorType' => 'description') + */ + protected $errorDescriptions = array(); + + /** + * @deprecated by error + */ + protected $customError = null; public function __construct($name) { @@ -183,6 +215,7 @@ public function clean() $this->raw = null; $this->value = null; $this->imported = false; + $this->dropError(); return $this; } @@ -196,29 +229,224 @@ public function exportValue() { return $this->value; } - + + public function getError() + { + return $this->error | $this->customError; + } + + /** + * @return BasePrimitive + **/ + public function setError($error) + { + Assert::isPositiveInteger($error); + + $this->error = $error; + $this->customError = $error; + + return $this; + } + + /** + * @return BasePrimitive + **/ + public function dropError() + { + $this->error = null; + $this->customError = null; + + return $this; + } + + /** + * @alias dropError + * @return BasePrimitive + */ + public function markGood() + { + return $this->dropError(); + } + + /** + * @alias setError + * @return BasePrimitive + */ + public function markWrong() + { + return $this->setError(static::WRONG); + } + + /** + * @alias setError + * @return BasePrimitive + */ + public function markMissing() + { + return $this->setError(static::MISSING); + } + + /** + * @deprecated by getError + */ public function getCustomError() { - return $this->customError; + return $this->getError(); } - - protected function import($scope) + + /** + * @param null $val + * @return BasePrimitive + */ + public function setLabel($val=null) { - if ( - !empty($scope[$this->name]) - || ( - isset($scope[$this->name]) - && $scope[$this->name] !== '' - ) + $this->label = $val; + + return $this; + } + + /** + * @return null|string + */ + public function getLabel() + { + return $this->label; + } + + public function setDescription($val) + { + $this->description = $val; + + return $this; + } + + /** + * @return null|string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param $type + * @param $val + * @return BasePrimitive + */ + public function setErrorLabel($type, $val) + { + $this->errorLabels[$type] = $val; + + return $this; + } + + /** + * @param $val + * @return BasePrimitive + */ + public function setWrongLabel($val) + { + return $this->setErrorLabel(BasePrimitive::WRONG, $val); + } + + public function setMissingLabel($val) + { + return $this->setErrorLabel(BasePrimitive::MISSING, $val); + } + + /** + * @param integer $type + * @return null|string + */ + public function getErrorLabel($type) + { + return (isset($this->errorLabels[$type])) + ? $this->errorLabels[$type] + : null; + } + + /** + * @return null|string + */ + public function getActualErrorLabel() + { + if( + ($error = $this->getError()) + && $error !==null ) { - $this->raw = $scope[$this->name]; - - return $this->imported = true; + return $this->getErrorLabel($error); } - - $this->clean(); - + + return null; } + + /** + * @return array + */ + public function getErrorLabels() + { + return $this->errorLabels; + } + + /** + * @param $type + * @param $val + * @return BasePrimitive + */ + public function setErrorDescription($type, $val) + { + $this->errorDescriptions[$type] = $val; + + return $this; + } + + /** + * @param integer $type + * @return null|string + */ + public function getErrorDescription($type) + { + return (isset($this->errorDescriptions[$type])) + ? $this->errorDescriptions[$type] + : null; + } + + /** + * @return null|string + */ + public function getActualErrorDescription() + { + if( + ($error = $this->getError()) + && $error !==null + ) { + return $this->getErrorDescription($error); + } + + return null; + } + + /** + * @return array + */ + public function getErrorDescriptions() + { + return $this->errorDescriptions; + } + + + public function import($scope) + { + if (isset($scope[$this->name])) + { + $this->setRawValue( + $scope[$this->name] + ); + $this->imported = true; + } + + return $this; + } } ?> \ No newline at end of file diff --git a/core/Form/Primitives/PrimitiveAlias.class.php b/core/Form/Primitives/PrimitiveAlias.class.php index 927a61c1a4..92a80eff78 100644 --- a/core/Form/Primitives/PrimitiveAlias.class.php +++ b/core/Form/Primitives/PrimitiveAlias.class.php @@ -142,20 +142,30 @@ public function exportValue() { return $this->primitive->exportValue(); } - - public function getCustomError() - { - return $this->primitive->getCustomError(); - } - + public function import($scope) { if (array_key_exists($this->name, $scope)) - return + { + $result = $this->primitive->import( - array($this->primitive->getName() => $scope[$this->name]) + array( + $this->primitive->getName() => $scope[$this->name] + ) ); + if( + ($error = $this->primitive->getError()) + && $error !== null + ) { + $this->setError($error); + } + + + return $result; + } + + return null; } } diff --git a/core/Form/Primitives/PrimitiveRule.class.php b/core/Form/Primitives/PrimitiveRule.class.php new file mode 100644 index 0000000000..400172d663 --- /dev/null +++ b/core/Form/Primitives/PrimitiveRule.class.php @@ -0,0 +1,67 @@ +form = clone $this->form; + $this->expression = clone $this->expression; + } + + /** + * @return PrimitiveRule + **/ + public function setForm(Form $form) + { + $this->form = $form; + + return $this; + } + + /** + * @return PrimitiveRule + **/ + public function setExpression(LogicalObject $exp) + { + $this->expression = $exp; + + return $this; + } + + public function import($scope) + { + Assert::isNotNull($this->form); + Assert::isNotNull($this->expression); + + if( + !($result = $this->expression->toBoolean($this->form)) + ) { + $this->markWrong(); + } + + return $result; + } + } +?> \ No newline at end of file diff --git a/core/Form/RegulatedForm.class.php b/core/Form/RegulatedForm.class.php index dcf3ac9052..05e49995bd 100644 --- a/core/Form/RegulatedForm.class.php +++ b/core/Form/RegulatedForm.class.php @@ -17,20 +17,17 @@ **/ abstract class RegulatedForm extends PlainForm { - protected $rules = array(); // forever - protected $violated = array(); // rules - /** * @throws WrongArgumentException * @return Form **/ public function addRule($name, LogicalObject $rule) { - Assert::isString($name); - - $this->rules[$name] = $rule; - - return $this; + return $this->add( + Primitive::rule($name)-> + setExpression($rule)-> + setForm($this) + ); } /** @@ -39,19 +36,21 @@ public function addRule($name, LogicalObject $rule) **/ public function dropRuleByName($name) { - if (isset($this->rules[$name])) { - unset($this->rules[$name]); - return $this; - } - - throw new MissingElementException( - "no such rule with '{$name}' name" + $rule = $this->get($name); + + Assert::isInstance($rule, 'PrimitiveRule', + 'primitive by "'.$name.'" must be instanceof PrimitiveRule! gived, "'.get_class($rule).'"' ); + + return $this->drop($name); } public function ruleExists($name) { - return isset($this->rules[$name]); + return ( + $this->exists($name) + && ($this->get($name) instanceof PrimitiveRule) + ); } /** @@ -59,9 +58,15 @@ public function ruleExists($name) **/ public function checkRules() { - foreach ($this->rules as $name => $logicalObject) { - if (!$logicalObject->toBoolean($this)) - $this->violated[$name] = Form::WRONG; + $primitives = $this->getPrimitiveList(); + foreach($primitives as $prm) { + if( + $prm instanceof PrimitiveRule + && !$prm->import(null) + ) { + $prm->markWrong(); + } + } return $this; diff --git a/main/Base/LightMetaProperty.class.php b/main/Base/LightMetaProperty.class.php index e7f5b06998..372ec8ce5f 100644 --- a/main/Base/LightMetaProperty.class.php +++ b/main/Base/LightMetaProperty.class.php @@ -46,32 +46,35 @@ class LightMetaProperty implements Stringable ) ); - private $name = null; - private $columnName = null; + private $name = null; + private $columnName = null; - private $type = null; - private $className = null; + private $type = null; + private $className = null; - private $size = null; + private $size = null; - private $min = null; - private $max = null; + private $min = null; + private $max = null; - private $required = false; - private $generic = false; - private $inner = false; + private $required = false; + private $generic = false; + private $inner = false; /// @see MetaRelation - private $relationId = null; + private $relationId = null; /// @see FetchStrategy - private $strategyId = null; + private $strategyId = null; - private $getter = null; - private $setter = null; - private $dropper = null; + private $getter = null; + private $setter = null; + private $dropper = null; - private $identifier = null; + private $identifier = null; + + private $label = null; + private $description = null; /** * @return LightMetaProperty @@ -89,10 +92,13 @@ public static function create() public static function fill( LightMetaProperty $property, $name, $columnName, $type, $className, $size, - $required, $generic, $inner, $relationId, $strategyId + $required, $generic, $inner, $relationId, $strategyId, $label=null, $description=null ) { $property->name = $name; + + $property->label = $label; + $property->description = $description; $methodSuffix = ucfirst($name); $property->getter = 'get'.$methodSuffix; @@ -309,6 +315,12 @@ public function makePrimitive($name) if ($this->required) $prm->required(); + + if($this->label) + $prm->setLabel($this->label); + + if($this->description) + $prm->setDescription($this->description); return $prm; } @@ -526,6 +538,18 @@ final public function toString() ? $this->strategyId : 'null' ) + .', ' + .( + $this->label + ? '\''.$this->label.'\'' + : 'null' + ) + .', ' + .( + $this->description + ? '\''.$this->description.'\'' + : 'null' + ) .')'; } diff --git a/meta/classes/MetaClassProperty.class.php b/meta/classes/MetaClassProperty.class.php index b8572961ca..a99f106ebd 100644 --- a/meta/classes/MetaClassProperty.class.php +++ b/meta/classes/MetaClassProperty.class.php @@ -14,20 +14,23 @@ **/ class MetaClassProperty { - private $class = null; + private $class = null; - private $name = null; - private $columnName = null; + private $name = null; + private $columnName = null; - private $type = null; - private $size = null; + private $type = null; + private $size = null; - private $required = false; - private $identifier = false; + private $required = false; + private $identifier = false; - private $relation = null; + private $relation = null; - private $strategy = null; + private $strategy = null; + + private $label = null; + private $description = null; public function __construct( $name, @@ -250,6 +253,44 @@ public function getFetchStrategyId() return null; } + + /** + * @param $label + * @return MetaClassProperty + */ + public function setLabel($label) + { + $this->label = $label; + + return $this; + } + + /** + * @return null|string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @param $description + * @return MetaClassProperty + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return null|string + */ + public function getDescription() + { + return $this->description; + } public function toMethods( MetaClass $class, @@ -423,7 +464,9 @@ public function toLightProperty(MetaClass $holder) $this->getType()->isGeneric(), $inner, $this->getRelationId(), - $this->getFetchStrategyId() + $this->getFetchStrategyId(), + $this->getLabel(), + $this->getDescription() ) ); } diff --git a/meta/classes/MetaConfiguration.class.php b/meta/classes/MetaConfiguration.class.php index ce5f7fe414..a2b944d9e2 100644 --- a/meta/classes/MetaConfiguration.class.php +++ b/meta/classes/MetaConfiguration.class.php @@ -786,7 +786,7 @@ private function addSource(SimpleXMLElement $source) /** * @return MetaClassProperty **/ - private function makeProperty($name, $type, MetaClass $class, $size) + private function makeProperty($name, $type, MetaClass $class, $size, $label=null, $description=null) { Assert::isFalse( strpos($name, '_'), @@ -823,6 +823,9 @@ private function makeProperty($name, $type, MetaClass $class, $size) 'size is required for "'.$property->getName().'"' ); } + + $property->setLabel($label); + $property->setDescription($description); return $property; } @@ -1120,7 +1123,9 @@ private function processClasses(SimpleXMLElement $xml, $metafile, $generate) (string) $xmlProperty['name'], (string) $xmlProperty['type'], $class, - (string) $xmlProperty['size'] + (string) $xmlProperty['size'], + (string) $xmlProperty['label'], + (string) $xmlProperty['description'] ); if (isset($xmlProperty['column'])) { diff --git a/meta/dtd/meta.dtd b/meta/dtd/meta.dtd index 0eaa67897f..1306495fee 100644 --- a/meta/dtd/meta.dtd +++ b/meta/dtd/meta.dtd @@ -38,6 +38,8 @@ required (true|false) "false" relation (OneToOne|OneToMany|ManyToMany) #IMPLIED fetch (lazy|cascade) #IMPLIED + label CDATA #IMPLIED + description CDATA #IMPLIED > diff --git a/meta/types/BasePropertyType.class.php b/meta/types/BasePropertyType.class.php index 04049505a9..8f3bfd79c8 100644 --- a/meta/types/BasePropertyType.class.php +++ b/meta/types/BasePropertyType.class.php @@ -66,9 +66,29 @@ public function toGetter( $name = $property->getName(); $methodName = 'get'.ucfirst($property->getName()); - + + $doc = '/**'."\n"; + $doced = null; + + if($label = $property->getLabel()) { + $doc .= ' * '.$label."\n"; + $doced = true; + } + + if($desc = $property->getDescription()) { + $doc.=" *\n"; + $doc.=' * '.$desc."\n"; + $doced = true; + } + + $doc .= "**/"; + + if($doced===null) + $doc = ''; + return <<{$name}; @@ -85,13 +105,31 @@ public function toSetter( { $name = $property->getName(); $methodName = 'set'.ucfirst($name); - + + $doc = '/**'."\n"; + $doced = false; + + if($label = $property->getLabel()) { + $doc .= ' * '.$label."\n"; + } + + if($desc = $property->getDescription()) { + $doc.=" *\n"; + $doc.=' * '.$desc."\n"; + } + + if($holder) { + $doc .= ' * @return '.$holder->getClass()->getName()."\n"; + } else { + $doc .= ' * @return '.$class->getName()."\n"; + } + + $doc .= "**/"; + if ($holder) { return <<getClass()->getName()} -**/ +{$doc} public function {$methodName}(\${$name}) { \$this->{$holder->getName()}->{$methodName}(\${$name}); @@ -103,9 +141,7 @@ public function {$methodName}(\${$name}) } else { return <<getName()} -**/ +{$doc} public function {$methodName}(\${$name}) { \$this->{$name} = \${$name}; diff --git a/test/config.inc.php.tpl b/test/config.inc.php.tpl index 683dee0bf6..cae04e0213 100644 --- a/test/config.inc.php.tpl +++ b/test/config.inc.php.tpl @@ -2,22 +2,22 @@ $dbs = array( 'PgSQL' => array( - 'user' => 'onphp', - 'pass' => 'onphp', + 'user' => 'postgres', + 'pass' => '', 'host' => '127.0.0.1', 'base' => 'onphp' ), 'MySQL' => array( - 'user' => 'onphp', - 'pass' => 'onphp', + 'user' => 'root', + 'pass' => '', 'host' => '127.0.0.1', 'base' => 'onphp' ), 'SQLitePDO' => array( - 'user' => 'onphp', - 'pass' => 'onphp', - 'host' => '127.0.0.1', - 'base' => 'onphp' + 'user' => '', + 'pass' => '', + 'host' => '', + 'base' => ':memory:' ), ); diff --git a/test/core/FormPrimitivesDateTest.class.php b/test/core/FormPrimitivesDateTest.class.php index 81646578e2..748adb85f5 100644 --- a/test/core/FormPrimitivesDateTest.class.php +++ b/test/core/FormPrimitivesDateTest.class.php @@ -123,25 +123,25 @@ protected function processInvalidBy($scope, $data) import($scope); $this->assertEquals( - $form->getValue('test'), - null + null, + $form->getValue('test') ); $this->assertEquals( - $form->getRawValue('test'), - $data + $data, + $form->getRawValue('test') ); $this->assertEquals( - $form->get('test')->isImported(), - true + true, + $form->get('test')->isImported() ); $this->assertEquals( - $form->getErrors(), array( 'test' => Form::WRONG, - ) + ), + $form->getErrors() ); } diff --git a/test/core/PrimitiveLabelsTest.class.php b/test/core/PrimitiveLabelsTest.class.php new file mode 100644 index 0000000000..9b2b453191 --- /dev/null +++ b/test/core/PrimitiveLabelsTest.class.php @@ -0,0 +1,51 @@ +setMax(3); + + $label = 'Some string label'; + $prm->setLabel($label); + $this->assertEquals($label, $prm->getLabel()); + + $description = 'Some string description'; + $prm->setDescription($description); + $this->assertEquals($description, $prm->getDescription()); + + $missingLabel = 'You must complete this field'; + $prm->setMissingLabel($missingLabel); + $prm->markMissing(); + $this->assertEquals($missingLabel, $prm->getActualErrorLabel()); + + $prm->clean(); + + $this->assertNull($prm->getActualErrorLabel()); + + $wrongLabel = 'The error in the field'; + $prm->setWrongLabel($wrongLabel); + $prm->markWrong(); + $this->assertEquals($wrongLabel, $prm->getActualErrorLabel()); + + $prm->clean(); + + $customErrorLabel = 'The custom error in the field'; + $customError = 25; + $prm->setErrorLabel($customError, $customErrorLabel); + $prm->setError($customError); + $this->assertEquals($customErrorLabel, $prm->getActualErrorLabel()); + + + } + + } \ No newline at end of file diff --git a/test/core/PrimitiveRuleTest.class.php b/test/core/PrimitiveRuleTest.class.php new file mode 100644 index 0000000000..8d3f7c9c97 --- /dev/null +++ b/test/core/PrimitiveRuleTest.class.php @@ -0,0 +1,72 @@ +add( + Primitive::string('pass') + )->add( + Primitive::string('repass') + ); + + $form->add( + Primitive::rule('correctPass')->setForm( + $form + )->setExpression( + Expression::eq( + FormField::create('pass'), + FormField::create('repass') + ) + ) + ); + + $scope = array( + 'pass' => '12345', + 'repass' => '1234', + ); + + $form->import($scope); + + $this->assertEmpty( + $form->getErrors() + ); + + $form->checkRules(); + + $this->assertNotNull($form->getError('correctPass')); + + $errors = $form->getErrors(); + + $this->assertTrue(isset($errors['correctPass'])); + $this->assertEquals(BasePrimitive::WRONG, $errors['correctPass']); + + $form->clean(); + + $this->assertEmpty($form->getErrors()); + + $scope = array( + 'pass' => '12345', + 'repass' => '12345', + ); + + $form->import($scope); + + $this->assertEmpty($form->getErrors()); + + $form->checkRules(); + + $this->assertEmpty($form->getErrors()); + + } + } +?> \ No newline at end of file diff --git a/test/main/ProtoTest.class.php b/test/main/ProtoTest.class.php new file mode 100644 index 0000000000..a07856f74b --- /dev/null +++ b/test/main/ProtoTest.class.php @@ -0,0 +1,59 @@ +makePrimitive($name); + + $this->assertEquals( + $size, + $prm->getMax() + ); + + $this->assertEquals( + $label, + $prm->getLabel() + ); + + $this->assertEquals( + $description, + $prm->getDescription() + ); + + $this->assertEquals( + $name, + $prm->getName() + ); + } + + } diff --git a/test/meta/config.meta.xml b/test/meta/config.meta.xml index ba98dc7840..0c09935ea4 100644 --- a/test/meta/config.meta.xml +++ b/test/meta/config.meta.xml @@ -7,7 +7,7 @@ - +