Changeset 1029
- Timestamp:
- 11/12/07 14:49:11 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/filters/stubHTTPURLFilter.php
r731 r1029 19 19 { 20 20 /** 21 * default error id if URL is not correct 22 */ 23 const URL_INCORRECT = 'URL_INCORRECT'; 24 /** 25 * default error id if URL is not available 26 */ 27 const URL_NOT_AVAILABLE = 'URL_NOT_AVAILABLE'; 28 /** 21 29 * switch whether DNS should be checked or not 22 30 * 23 31 * @var bool 24 32 */ 25 protected $checkDNS = false; 33 protected $checkDNS = false; 34 /** 35 * list of error ids to be used by this filter 36 * 37 * @var array<string,string> 38 */ 39 protected $errorIds = array(self::URL_INCORRECT => self::URL_INCORRECT, 40 self::URL_NOT_AVAILABLE => self::URL_NOT_AVAILABLE 41 ); 26 42 27 43 /** … … 56 72 57 73 /** 74 * sets the error id to be used in case the filter finds an error in the value 75 * 76 * @param string $type type of error, one of the stubHTTPURLFilter::URL_* constants 77 * @param string $errorId the id of the error object to use 78 */ 79 public function setErrorId($type, $errorId) 80 { 81 if (isset($this->errorIds[$type]) === false) { 82 throw new stubIllegalArgumentException('Illegal type ' . $type . ' given. Allowed types are ' . join(', ', array_keys($this->errorIds)) . '.'); 83 } 84 85 $this->errorIds[$type] = $errorId; 86 } 87 88 /** 58 89 * check if value is a valid HTTP URL 59 90 * … … 67 98 $http = stubHTTPURL::fromString($value); 68 99 } catch (stubMalformedURLException $murle) { 69 throw new stubFilterException($this->rveFactory->create( 'URL_INCORRECT'));100 throw new stubFilterException($this->rveFactory->create($this->errorIds[self::URL_INCORRECT])); 70 101 } 71 102 72 103 if (null === $http) { 73 104 if (true === $this->isRequired) { 74 throw new stubFilterException($this->rveFactory->create( 'URL_INCORRECT'));105 throw new stubFilterException($this->rveFactory->create($this->errorIds[self::URL_INCORRECT])); 75 106 } 76 107 … … 79 110 80 111 if (true === $this->checkDNS && $http->checkDNS() == false) { 81 throw new stubFilterException($this->rveFactory->create( 'URL_NOT_AVAILABLE'));112 throw new stubFilterException($this->rveFactory->create($this->errorIds[self::URL_NOT_AVAILABLE])); 82 113 } 83 114 trunk/src/test/php/net/stubbles/ipo/request/filters/stubHTTPURLFilterTestCase.php
r719 r1029 58 58 $this->assertNull($this->httpURLFilter->execute(null)); 59 59 $this->httpURLFilter->setRequired(true); 60 $this->mockStubRequestValueErrorFactory->expect('URL_INCORRECT'); 60 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT')); 61 $this->expectException('stubFilterException'); 62 $this->httpURLFilter->execute(null); 63 } 64 65 /** 66 * assure correct behaviour when a null value is passed 67 */ 68 public function testNullValueWithDifferentErrorId() 69 { 70 $this->httpURLFilter->setErrorId(stubHTTPURLFilter::URL_INCORRECT, 'URL_INCORRECT_TEST'); 71 $this->httpURLFilter->setRequired(true); 72 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT_TEST')); 61 73 $this->expectException('stubFilterException'); 62 74 $this->httpURLFilter->execute(null); … … 71 83 $this->assertNull($this->httpURLFilter->execute('')); 72 84 $this->httpURLFilter->setRequired(true); 73 $this->mockStubRequestValueErrorFactory->expect(' URL_INCORRECT');85 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT')); 74 86 $this->expectException('stubFilterException'); 75 87 $this->httpURLFilter->execute(''); 88 } 89 90 /** 91 * assure correct behaviour when a null value is passed 92 */ 93 public function testEmptyValueWithDifferentErrorId() 94 { 95 $this->httpURLFilter->setErrorId(stubHTTPURLFilter::URL_INCORRECT, 'URL_INCORRECT_TEST'); 96 $this->httpURLFilter->setRequired(true); 97 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT_TEST')); 98 $this->expectException('stubFilterException'); 99 $this->httpURLFilter->execute(null); 76 100 } 77 101 … … 81 105 public function testWrongScheme() 82 106 { 83 $this->mockStubRequestValueErrorFactory->expect(' URL_INCORRECT');107 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT')); 84 108 $this->expectException('stubFilterException'); 85 109 $this->httpURLFilter->execute('ftp://foobar.de/'); … … 91 115 public function testWrongValue() 92 116 { 93 $this->mockStubRequestValueErrorFactory->expect(' URL_INCORRECT');117 $this->mockStubRequestValueErrorFactory->expect('create', array('URL_INCORRECT')); 94 118 $this->expectException('stubFilterException'); 95 119 $this->httpURLFilter->execute('http://wrong example!'); 96 120 } 121 122 /** 123 * assure that setting a wrong error type causes an exception 124 */ 125 public function testSetErrorIdWithWrongType() 126 { 127 $this->expectException('stubIllegalArgumentException'); 128 $this->httpURLFilter->setErrorId('blub', 'dummy'); 129 } 97 130 } 98 131 ?>
