Changeset 1377

Show
Ignore:
Timestamp:
02/26/08 17:29:53 (6 months ago)
Author:
mikey
Message:

more flexibility with error ids

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubAbstractStringFilterAnnotation.php

    r1325 r1377  
    3030    protected $minLength; 
    3131    /** 
     32     * the error id to use in case min length validation fails 
     33     * 
     34     * @var  string 
     35     */ 
     36    protected $minLengthErrorId; 
     37    /** 
    3238     * maximum length of the string 
    3339     * 
     
    3541     */ 
    3642    protected $maxLength; 
     43    /** 
     44     * the error id to use in case max length validation fails 
     45     * 
     46     * @var  string 
     47     */ 
     48    protected $maxLengthErrorId; 
    3749    /** 
    3850     * the encoder class to be used 
     
    7183 
    7284    /** 
     85     * sets the error id to use in case min length validation fails 
     86     * 
     87     * @param  string  $minLengthErrorId 
     88     */ 
     89    public function setMinLengthErrorId($minLengthErrorId) 
     90    { 
     91        $this->minLengthErrorId = $minLengthErrorId; 
     92    } 
     93 
     94    /** 
    7395     * sets the maximum length of the string 
    7496     * 
     
    78100    { 
    79101        $this->maxLength = $maxLength; 
     102    } 
     103 
     104    /** 
     105     * sets the error id to use in case max length validation fails 
     106     * 
     107     * @param  string  $maxLengthErrorId 
     108     */ 
     109    public function setMaxLengthErrorId($maxLengthErrorId) 
     110    { 
     111        $this->maxLengthErrorId = $maxLengthErrorId; 
    80112    } 
    81113 
     
    111143            $filter = new stubLengthFilterDecorator($filter, $this->createRVEFactory()); 
    112144            if (null !== $this->minLength) { 
    113                 $filter->setMinLengthValidator(new stubMinLengthValidator($this->minLength)); 
     145                $filter->setMinLengthValidator(new stubMinLengthValidator($this->minLength), $this->minLengthErrorId); 
    114146            } 
    115147             
    116148            if (null !== $this->maxLength) { 
    117                 $filter->setMaxLengthValidator(new stubMaxLengthValidator($this->maxLength)); 
     149                $filter->setMaxLengthValidator(new stubMaxLengthValidator($this->maxLength), $this->maxLengthErrorId); 
    118150            } 
    119151        } 
  • trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubFloatFilterAnnotation.php

    r1329 r1377  
    2929    protected $minValue; 
    3030    /** 
     31     * the error id to use in case min validation fails 
     32     * 
     33     * @var  string 
     34     */ 
     35    protected $minErrorId; 
     36    /** 
    3137     * maximum value of the float 
    3238     * 
     
    3440     */ 
    3541    protected $maxValue; 
     42    /** 
     43     * the error id to use in case max validation fails 
     44     * 
     45     * @var  string 
     46     */ 
     47    protected $maxErrorId; 
    3648 
    3749    /** 
     
    4355    { 
    4456        $this->minValue = $minValue; 
     57    } 
     58 
     59    /** 
     60     * sets the error id to use in case max validation fails 
     61     * 
     62     * @param  string  $minErrorId 
     63     */ 
     64    public function setMinErrorId($minErrorId) 
     65    { 
     66        $this->minErrorId = $minErrorId; 
    4567    } 
    4668 
     
    5678 
    5779    /** 
     80     * sets the error id to use in case max validation fails 
     81     * 
     82     * @param  string  $maxErrorId 
     83     */ 
     84    public function setMaxErrorId($maxErrorId) 
     85    { 
     86        $this->maxErrorId = $maxErrorId; 
     87    } 
     88 
     89    /** 
    5890     * returns the filter defined by the annotation 
    5991     * 
     
    6698            $filter = new stubRangeFilterDecorator($filter, $this->createRVEFactory()); 
    6799            if (null !== $this->minValue) { 
    68                 $filter->setMinValidator(new stubMinNumberValidator($this->minValue)); 
     100                $filter->setMinValidator(new stubMinNumberValidator($this->minValue), $this->minErrorId); 
    69101            } 
    70102             
    71103            if (null !== $this->maxValue) { 
    72                 $filter->setMaxValidator(new stubMaxNumberValidator($this->maxValue)); 
     104                $filter->setMaxValidator(new stubMaxNumberValidator($this->maxValue), $this->maxErrorId); 
    73105            } 
    74106        } 
  • trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubIntegerFilterAnnotation.php

    r1329 r1377  
    2929    protected $minValue; 
    3030    /** 
     31     * the error id to use in case min validation fails 
     32     * 
     33     * @var  string 
     34     */ 
     35    protected $minErrorId; 
     36    /** 
    3137     * maximum value of the integer 
    3238     * 
     
    3440     */ 
    3541    protected $maxValue; 
     42    /** 
     43     * the error id to use in case max validation fails 
     44     * 
     45     * @var  string 
     46     */ 
     47    protected $maxErrorId; 
    3648 
    3749    /** 
     
    4355    { 
    4456        $this->minValue = $minValue; 
     57    } 
     58 
     59    /** 
     60     * sets the error id to use in case max validation fails 
     61     * 
     62     * @param  string  $minErrorId 
     63     */ 
     64    public function setMinErrorId($minErrorId) 
     65    { 
     66        $this->minErrorId = $minErrorId; 
    4567    } 
    4668 
     
    5678 
    5779    /** 
     80     * sets the error id to use in case max validation fails 
     81     * 
     82     * @param  string  $maxErrorId 
     83     */ 
     84    public function setMaxErrorId($maxErrorId) 
     85    { 
     86        $this->maxErrorId = $maxErrorId; 
     87    } 
     88 
     89    /** 
    5890     * returns the filter defined by the annotation 
    5991     * 
     
    6698            $filter = new stubRangeFilterDecorator($filter, $this->createRVEFactory()); 
    6799            if (null !== $this->minValue) { 
    68                 $filter->setMinValidator(new stubMinNumberValidator($this->minValue)); 
     100                $filter->setMinValidator(new stubMinNumberValidator($this->minValue), $this->minErrorId); 
    69101            } 
    70102             
    71103            if (null !== $this->maxValue) { 
    72                 $filter->setMaxValidator(new stubMaxNumberValidator($this->maxValue)); 
     104                $filter->setMaxValidator(new stubMaxNumberValidator($this->maxValue), $this->maxErrorId); 
    73105            } 
    74106        } 
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubAbstractStringFilterAnnotationTestCase.php

    r1323 r1377  
    6969        $this->assertType('stubMaxLengthValidator', $filter->getMaxLengthValidator()); 
    7070        $this->assertEquals(1, $filter->getMinLengthValidator()->getValue()); 
     71        $this->assertEquals('STRING_TOO_SHORT', $filter->getMinLengthErrorId()); 
    7172        $this->assertEquals(2, $filter->getMaxLengthValidator()->getValue()); 
     73        $this->assertEquals('STRING_TOO_LONG', $filter->getMaxLengthErrorId()); 
     74        $this->assertSame($this->mockFilter, $filter->getDecoratedFilter()); 
     75        $this->abstractStringFilterAnnotation->finish(); 
     76    } 
     77 
     78    /** 
     79     * test that the correct filter is created 
     80     * 
     81     * @test 
     82     */ 
     83    public function withValidatorsAndDifferentErrorIds() 
     84    { 
     85        $this->abstractStringFilterAnnotation->setMinLength(1); 
     86        $this->abstractStringFilterAnnotation->setMinLengthErrorId('differentMin'); 
     87        $this->abstractStringFilterAnnotation->setMaxLength(2); 
     88        $this->abstractStringFilterAnnotation->setMaxLengthErrorId('differentMax'); 
     89        $filter = $this->abstractStringFilterAnnotation->getFilter(); 
     90        $this->assertType('stubLengthFilterDecorator', $filter); 
     91        $this->assertType('stubMinLengthValidator', $filter->getMinLengthValidator()); 
     92        $this->assertType('stubMaxLengthValidator', $filter->getMaxLengthValidator()); 
     93        $this->assertEquals(1, $filter->getMinLengthValidator()->getValue()); 
     94        $this->assertEquals('differentMin', $filter->getMinLengthErrorId()); 
     95        $this->assertEquals(2, $filter->getMaxLengthValidator()->getValue()); 
     96        $this->assertEquals('differentMax', $filter->getMaxLengthErrorId()); 
    7297        $this->assertSame($this->mockFilter, $filter->getDecoratedFilter()); 
    7398        $this->abstractStringFilterAnnotation->finish(); 
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubFloatFilterAnnotationTestCase.php

    r1329 r1377  
    8888        $this->assertType('stubMaxNumberValidator', $filter->getMaxValidator()); 
    8989        $this->assertEquals(1, $filter->getMinValidator()->getValue()); 
     90        $this->assertEquals('VALUE_TOO_SMALL', $filter->getMinErrorId()); 
    9091        $this->assertEquals(2, $filter->getMaxValidator()->getValue()); 
     92        $this->assertEquals('VALUE_TOO_GREAT', $filter->getMaxErrorId()); 
     93        $this->assertType('stubFloatFilter', $filter->getDecoratedFilter()); 
     94    } 
     95 
     96    /** 
     97     * test that the correct filter is created 
     98     * 
     99     * @test 
     100     */ 
     101    public function withBothValidatorsDifferentErrorIds() 
     102    { 
     103        $this->floatFilterAnnotation->setMinValue(1); 
     104        $this->floatFilterAnnotation->setMinErrorId('differentMin'); 
     105        $this->floatFilterAnnotation->setMaxValue(2); 
     106        $this->floatFilterAnnotation->setMaxErrorId('differentMax'); 
     107        $filter = $this->floatFilterAnnotation->getFilter(); 
     108        $this->assertType('stubRangeFilterDecorator', $filter); 
     109        $this->assertType('stubMinNumberValidator', $filter->getMinValidator()); 
     110        $this->assertType('stubMaxNumberValidator', $filter->getMaxValidator()); 
     111        $this->assertEquals(1, $filter->getMinValidator()->getValue()); 
     112        $this->assertEquals('differentMin', $filter->getMinErrorId()); 
     113        $this->assertEquals(2, $filter->getMaxValidator()->getValue()); 
     114        $this->assertEquals('differentMax', $filter->getMaxErrorId()); 
    91115        $this->assertType('stubFloatFilter', $filter->getDecoratedFilter()); 
    92116    } 
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubIntegerFilterAnnotationTestCase.php

    r1329 r1377  
    8888        $this->assertType('stubMaxNumberValidator', $filter->getMaxValidator()); 
    8989        $this->assertEquals(1, $filter->getMinValidator()->getValue()); 
     90        $this->assertEquals('VALUE_TOO_SMALL', $filter->getMinErrorId()); 
    9091        $this->assertEquals(2, $filter->getMaxValidator()->getValue()); 
     92        $this->assertEquals('VALUE_TOO_GREAT', $filter->getMaxErrorId()); 
     93        $this->assertType('stubIntegerFilter', $filter->getDecoratedFilter()); 
     94    } 
     95 
     96    /** 
     97     * test that the correct filter is created 
     98     * 
     99     * @test 
     100     */ 
     101    public function withBothValidatorsDifferentErrorIds() 
     102    { 
     103        $this->integerFilterAnnotation->setMinValue(1); 
     104        $this->integerFilterAnnotation->setMinErrorId('differentMin'); 
     105        $this->integerFilterAnnotation->setMaxValue(2); 
     106        $this->integerFilterAnnotation->setMaxErrorId('differentMax'); 
     107        $filter = $this->integerFilterAnnotation->getFilter(); 
     108        $this->assertType('stubRangeFilterDecorator', $filter); 
     109        $this->assertType('stubMinNumberValidator', $filter->getMinValidator()); 
     110        $this->assertType('stubMaxNumberValidator', $filter->getMaxValidator()); 
     111        $this->assertEquals(1, $filter->getMinValidator()->getValue()); 
     112        $this->assertEquals('differentMin', $filter->getMinErrorId()); 
     113        $this->assertEquals(2, $filter->getMaxValidator()->getValue()); 
     114        $this->assertEquals('differentMax', $filter->getMaxErrorId()); 
    91115        $this->assertType('stubIntegerFilter', $filter->getDecoratedFilter()); 
    92116    }