Changeset 1030

Show
Ignore:
Timestamp:
11/12/07 14:56:59 (1 year ago)
Author:
mikey
Message:

implemented enhancement #96 for net.stubbles.ipo.request.filters.stubMailFilter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubMailFilter.php

    r678 r1030  
    1818{ 
    1919    /** 
     20     * error id for incorrect mail address 
     21     */ 
     22    const MAILADDRESS_INCORRECT = 'MAILADDRESS_INCORRECT'; 
     23    /** 
    2024     * validator to use for checking the mail address 
    2125     * 
     
    2327     */ 
    2428    protected $mailValidator; 
     29    /** 
     30     * list of error ids to be used by this filter 
     31     * 
     32     * @var  array<string,string> 
     33     */ 
     34    protected $errorIds         = array(self::MAILADDRESS_INCORRECT => self::MAILADDRESS_INCORRECT); 
    2535 
    2636    /** 
     
    3747 
    3848    /** 
     49     * sets the error id to be used in case the filter finds an error in the value 
     50     * 
     51     * @param  string  $type     type of error, one of the stubHTTPURLFilter::URL_* constants 
     52     * @param  string  $errorId  the id of the error object to use 
     53     */ 
     54    public function setErrorId($type, $errorId) 
     55    { 
     56        if (isset($this->errorIds[$type]) === false) { 
     57            throw new stubIllegalArgumentException('Illegal type ' . $type . ' given. Allowed types are ' . join(', ', array_keys($this->errorIds)) . '.'); 
     58        } 
     59         
     60        $this->errorIds[$type] = $errorId; 
     61    } 
     62 
     63    /** 
    3964     * check if entered passwords fulfill password conditions 
    4065     * 
     
    4570    public function execute($value) 
    4671    { 
    47         if ($this->mailValidator->validate($value) == false) { 
    48             throw new stubFilterException($this->rveFactory->create('MAILADDRESS_INCORRECT')); 
     72        if ($this->mailValidator->validate($value) === false) { 
     73            throw new stubFilterException($this->rveFactory->create($this->errorIds[self::MAILADDRESS_INCORRECT])); 
    4974        } 
    5075 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubMailFilterTestCase.php

    r696 r1030  
    6464    { 
    6565        $this->mockStubMailValidator->setReturnValue('validate', false); 
    66         $this->mockStubRequestValueErrorFactory->expect('MAILADDRESS_INCORRECT'); 
     66        $this->mockStubRequestValueErrorFactory->expect('create', array('MAILADDRESS_INCORRECT')); 
     67        $this->expectException('stubFilterException'); 
     68        $this->mailFilter->execute(null); 
     69    } 
     70 
     71    /** 
     72     * assure that an exceptiom is thrown when a wrong value is passed 
     73     */ 
     74    public function testWrongValueWithDifferentErrorId() 
     75    { 
     76        $this->mockStubMailValidator->setReturnValue('validate', false); 
     77        $this->mailFilter->setErrorId(stubMailFilter::MAILADDRESS_INCORRECT, 'MAILADDRESS_INCORRECT_TEST'); 
     78        $this->mockStubRequestValueErrorFactory->expect('create', array('MAILADDRESS_INCORRECT_TEST')); 
    6779        $this->expectException('stubFilterException'); 
    6880        $this->mailFilter->execute(null);