Changeset 1030
- Timestamp:
- 11/12/07 14:56:59 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/filters/stubMailFilter.php
r678 r1030 18 18 { 19 19 /** 20 * error id for incorrect mail address 21 */ 22 const MAILADDRESS_INCORRECT = 'MAILADDRESS_INCORRECT'; 23 /** 20 24 * validator to use for checking the mail address 21 25 * … … 23 27 */ 24 28 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); 25 35 26 36 /** … … 37 47 38 48 /** 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 /** 39 64 * check if entered passwords fulfill password conditions 40 65 * … … 45 70 public function execute($value) 46 71 { 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])); 49 74 } 50 75 trunk/src/test/php/net/stubbles/ipo/request/filters/stubMailFilterTestCase.php
r696 r1030 64 64 { 65 65 $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')); 67 79 $this->expectException('stubFilterException'); 68 80 $this->mailFilter->execute(null);
