Changeset 1585

Show
Ignore:
Timestamp:
05/24/08 03:47:28 (3 months ago)
Author:
mikey
Message:

enabled different error id in case regular expression fails

Files:

Legend:

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

    r1547 r1585  
    2525     * @var  string 
    2626     */ 
    27     protected $regex = null; 
     27    protected $regex   = null; 
     28    /** 
     29     * error if to be used 
     30     * 
     31     * @var  string 
     32     */ 
     33    protected $errorId = null; 
    2834 
    2935    /** 
     
    3844 
    3945    /** 
     46     * set error id to be used in case regular expression fails 
     47     * 
     48     * @param  string  $errorId 
     49     */ 
     50    public function setRegexErrorId($errorId) 
     51    { 
     52        $this->errorId = $errorId; 
     53    } 
     54 
     55    /** 
    4056     * returns the filter defined by the annotation 
    4157     * 
     
    4763        if (null !== $this->regex) { 
    4864            $stringFilter = new stubValidatorFilterDecorator($stringFilter, $this->createRVEFactory(), new stubRegexValidator($this->regex)); 
     65            if (null !== $this->errorId) { 
     66                $stringFilter->setErrorId($this->errorId); 
     67            } 
    4968        } 
    5069         
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php

    r1324 r1585  
    5353        $filter = $this->stringFilterAnnotation->getFilter(); 
    5454        $this->assertType('stubValidatorFilterDecorator', $filter); 
     55        $this->assertEquals('FIELD_WRONG_VALUE', $filter->getErrorId()); 
     56        $this->assertType('stubRegexValidator', $filter->getValidator()); 
     57        $this->assertEquals('/foo/', $filter->getValidator()->getValue()); 
     58        $this->assertType('stubStringFilter', $filter->getDecoratedFilter()); 
     59    } 
     60 
     61    /** 
     62     * test that the correct filter is created 
     63     * 
     64     * @test 
     65     */ 
     66    public function withValidatorAndDifferentErrorId() 
     67    { 
     68        $this->stringFilterAnnotation->setRegex('/foo/'); 
     69        $this->stringFilterAnnotation->setRegexErrorId('foo'); 
     70        $filter = $this->stringFilterAnnotation->getFilter(); 
     71        $this->assertType('stubValidatorFilterDecorator', $filter); 
     72        $this->assertEquals('foo', $filter->getErrorId()); 
    5573        $this->assertType('stubRegexValidator', $filter->getValidator()); 
    5674        $this->assertEquals('/foo/', $filter->getValidator()->getValue());