Changeset 1338
- Timestamp:
- 02/11/08 17:31:58 (5 months ago)
- Files:
-
- trunk/experiments/people/mikey/filterAPI/filterAPI.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotation.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/provider (added)
- trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubFilterProvider.php (moved) (moved from trunk/experiments/people/mikey/filterAPI/stubFilterProvider.php)
- trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubMailFilterProvider.php (moved) (moved from trunk/experiments/people/mikey/filterAPI/stubMailFilterProvider.php) (4 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubSimpleFilterProvider.php (moved) (moved from trunk/experiments/people/mikey/filterAPI/stubSimpleFilterProvider.php) (4 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubFilterFactory.php (moved) (moved from trunk/experiments/people/mikey/filterAPI/stubFilterFactory.php) (12 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubMailFilter.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php (modified) (8 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecorator.php (modified) (1 diff)
- trunk/src/main/php/org/stubbles/test/FilterWithConstArgs.php (added)
- trunk/src/main/php/org/stubbles/test/FilterWithoutConstArgs.php (added)
- trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/filters/provider (added)
- trunk/src/test/php/net/stubbles/ipo/request/filters/provider/stubMailFilterProviderTestCase.php (added)
- trunk/src/test/php/net/stubbles/ipo/request/filters/provider/stubSimpleFilterProviderTestCase.php (added)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubFilterFactoryTestCase.php (added)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubMailFilterTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecoratorTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/experiments/people/mikey/filterAPI/filterAPI.php
r1334 r1338 1 1 <?php 2 /**3 * @todo make PasswordFilter more fluent4 * @todo remove min length from PasswordFilter constructor (use LengthFilterDecorator instead?)5 * @todo remove encoding feature from PasswordFilter, use EncodingFilterDecorator instead6 */7 8 2 $filter = stubFilterFactory::forType('integer')->inRange(1, 4)->asRequired(); 9 3 $filter = stubFilterFactory::forType('integer')->using(new MyRVEFactory())->inRange(1, 4)->asRequired(); … … 13 7 $filter = stubFilterFactory::forType('string')->length(2, 5)->validatedBy(new stubRegexValidator($regex))->defaultsTo('foo'); 14 8 15 $password = stubFilterFactory::forType('password', array($rveFactory))-> minLength(5)->minDiffChars(3)->nonAllowedValues(array(1, 2, 3))->encodedWith(new stubMd5Encoder());9 $password = stubFilterFactory::forType('password', array($rveFactory))->length(5, null)->minDiffChars(3)->nonAllowedValues(array(1, 2, 3))->encodedWith(new stubMd5Encoder()); 16 10 17 11 $http = stubFilterFactory::forType('http', array($rveFactory))->checkDNS(true); trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotation.php
r1301 r1338 7 7 * @subpackage ipo_request_broker_annotations 8 8 */ 9 stubClassLoader::load('net::stubbles::reflection::annotations::stubAnnotation', 9 stubClassLoader::load('net::stubbles::ipo::request::broker::annotations::stubAbstractFilterAnnotation', 10 'net::stubbles::ipo::request::filters::stubEncodingFilterDecorator', 11 'net::stubbles::ipo::request::filters::stubLengthFilterDecorator', 10 12 'net::stubbles::ipo::request::filters::stubPasswordFilter', 11 'net::stubbles:: ipo::request::broker::annotations::stubAbstractFilterAnnotation',13 'net::stubbles::reflection::annotations::stubAnnotation', 12 14 'net::stubbles::util::validators::stubMinLengthValidator' 13 15 ); … … 59 61 * returns the filter defined by the annotation 60 62 * 61 * @return stubPasswordFilter 62 * @throws stubRequestBrokerException 63 * @return stubFilter 63 64 */ 64 65 protected function doGetFilter() 65 66 { 66 $passwordFilter = new stubPasswordFilter($this->createRVEFactory(), new stubMinLengthValidator($this->minLength)); 67 $rveFactory = $this->createRVEFactory(); 68 $filter = new stubLengthFilterDecorator(new stubPasswordFilter($rveFactory), $rveFactory); 69 $filter->setMinLengthValidator(new stubMinLengthValidator($this->minLength)); 67 70 if (null !== $this->encoderClass) { 68 $ passwordFilter->setEncoder($this->encoderClass->newInstance());71 $filter = new stubEncodingFilterDecorator($filter, $this->encoderClass->newInstance(), stubStringEncoder::MODE_ENCODE); 69 72 } 70 73 71 return $ passwordFilter;74 return $filter; 72 75 } 73 76 } trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubMailFilterProvider.php
r1334 r1338 1 1 <?php 2 2 /** 3 * Interface for filter providers.3 * Filter provider for the mail filter. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage ipo_request_filters_provider 8 8 */ 9 stubClassLoader::load('net::stubbles::ipo::request::stubRequestValueErrorFactory', 10 'net::stubbles::ipo::request::filters::provider::stubFilterProvider' 11 ); 9 12 /** 10 * Interface for filter providers.13 * Filter provider for the mail filter. 11 14 * 12 15 * @package stubbles … … 29 32 * returns a filter instance 30 33 * 34 * The mail filter requires a stubRequestValueErrorFactory as constructor 35 * argument. The $args array must have such an instance under its key 0 36 * despite the fact that the $args param is declared as optional, which is 37 * due to method declaration inheritence. If no stubRequestValueErrorFactory 38 * is given under the named key a stubIllegalArgumentException will be 39 * thrown. 40 * 31 41 * @param array $args optional constructor arguments 32 42 * @return stubFilter … … 35 45 public function getFilter(array $args = null) 36 46 { 37 if (isset($args[0]) === false || ($args instanceof stubRequestErrorValueFactory) === false) {38 throw new stubIllegalArgumentException('Requested filter requires a stubRequestErrorValueFactory.');47 if (isset($args[0]) === false || ($args[0] instanceof stubRequestValueErrorFactory) === false) { 48 throw new stubIllegalArgumentException('Requested filter requires an instance of net::stubbles::ipo::request::stubRequestValueErrorFactory.'); 39 49 } 40 50 trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubSimpleFilterProvider.php
r1334 r1338 1 1 <?php 2 2 /** 3 * Interface for filter providers.3 * Filter provider simple filters. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 9 9 stubClassLoader::load('net::stubbles::reflection::stubReflectionClass'); 10 10 /** 11 * Interface for filter providers.11 * Filter provider simple filters. 12 12 * 13 13 * @package stubbles … … 57 57 * @param array $args optional constructor arguments 58 58 * @return stubFilter 59 * @throws stubIllegalArgumentException60 59 */ 61 60 public function getFilter(array $args = null) … … 63 62 if (null !== $args) { 64 63 $refClass = new stubReflectionClass($this->classname); 65 try { 66 return $refClass->newInstanceArgs($args); 67 } catch (ReflectionException $re) { 68 throw new stubIllegalArgumentException('Missing constructor arguments for filter ' . $this->classname . ': ' . $re->getMessage()); 69 } 64 return $refClass->newInstanceArgs($args); 70 65 } 71 66 trunk/src/main/php/net/stubbles/ipo/request/filters/stubFilterFactory.php
r1334 r1338 7 7 * @subpackage ipo_request_filters 8 8 */ 9 stubClassLoader::load('net::stubbles::ipo::request::stubRequestErrorValueFactory', 10 'net::stubbles::ipo::request::stubRequestValueErrorXJConfFactory', 9 stubClassLoader::load('net::stubbles::ipo::request::stubRequestValueErrorFactory', 11 10 'net::stubbles::ipo::request::filters::stubAbstractFilterDecorator', 12 'net::stubbles::ipo::request::filters::stubEncodingFilterDecorator',13 'net::stubbles::ipo::request::filters::stubDefaultValueFilterDecorator',14 'net::stubbles::ipo::request::filters::stubLengthFilterDecorator',15 'net::stubbles::ipo::request::filters::stubRangeFilterDecorator',16 'net::stubbles::ipo::request::filters::stubRequiredFilterDecorator',17 11 'net::stubbles::ipo::request::filters::stubStrategyFilterDecorator', 18 'net::stubbles::ipo::request::filters::stubValidatorFilterDecorator',19 12 'net::stubbles::ipo::request::filters::provider::stubFilterProvider', 20 13 'net::stubbles::ipo::request::filters::provider::stubMailFilterProvider', 21 14 'net::stubbles::ipo::request::filters::provider::stubSimpleFilterProvider', 22 'net::stubbles::lang::exceptions::stubIllegalArgumentException' 15 'net::stubbles::lang::exceptions::stubIllegalArgumentException', 16 'net::stubbles::lang::exceptions::stubMethodNotSupportedException' 23 17 ); 24 18 /** … … 27 21 * @package stubbles 28 22 * @subpackage ipo_request_filters 29 * @todo allow to register user-defined base filters to be used in forType()30 23 */ 31 24 class stubFilterFactory extends stubAbstractFilterDecorator … … 84 77 * @param array $args optional constructor arguments for filter 85 78 * @return stubFilterFactory 79 * @throws stubIllegalArgumentException 86 80 */ 87 81 public static function forType($type, array $args = null) … … 99 93 100 94 $me = new self($filter); 101 if ( null !== $rveFactory) {102 $me->using($ rveFactory);95 if (isset($args[0]) === true && $args[0] instanceof stubRequestValueErrorFactory) { 96 $me->using($args[0]); 103 97 } 104 98 … … 109 103 * sets the request error value factory to be used by the filter 110 104 * 111 * @param stubRequest ErrorValueFactory $rveFactory112 * @return stubFilterFactory 113 */ 114 public function using(stubRequest ErrorValueFactory $rveFactory)105 * @param stubRequestValueErrorFactory $rveFactory 106 * @return stubFilterFactory 107 */ 108 public function using(stubRequestValueErrorFactory $rveFactory) 115 109 { 116 110 $this->rveFactory = $rveFactory; … … 119 113 120 114 /** 121 * helper method to retrieve the request error value factory122 * 123 * @return stubRequest ErrorValueFactory124 * @t odo make default class configurable125 */ 126 p rotectedfunction getRVEFactory()115 * returns the request error value factory to be used by the filter 116 * 117 * @return stubRequestValueErrorFactory 118 * @throws stubRuntimeException 119 */ 120 public function getRVEFactory() 127 121 { 128 122 if (null === $this->rveFactory) { 129 $this->rveFactory = new stubRequestValueErrorXJConfFactory(); 123 $class = stubRegistry::getConfig('net.stubbles.ipo.request.valueerrorfactory.class', 'net::stubbles::ipo::request::stubRequestValueErrorXJConfFactory'); 124 $classname = stubClassLoader::getNonQualifiedClassName($class); 125 if (class_exists($classname) === false) { 126 stubClassLoader::load($class); 127 } 128 129 $rveFactory = new $classname(); 130 if (($rveFactory instanceof stubRequestValueErrorFactory) === false) { 131 throw new stubRuntimeException('Configured net.stubbles.ipo.request.valueerrorfactory.class is not an instance of net::stubbles::ipo::request::stubRequestValueErrorFactory.'); 132 } 133 134 $this->rveFactory = $rveFactory; 130 135 } 131 136 … … 146 151 public function inRange($min, $max, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 147 152 { 148 if (null !== $min && null !== $max) { 153 if (null !== $min || null !== $max) { 154 stubClassLoader::load('net::stubbles::ipo::request::filters::stubRangeFilterDecorator', 155 'net::stubbles::util::validators::stubMinNumberValidator', 156 'net::stubbles::util::validators::stubMaxNumberValidator' 157 ); 149 158 $filter = new stubRangeFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 150 159 if (null !== $min) { … … 176 185 public function length($minLength, $maxLength, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 177 186 { 178 if (null !== $minLength && null !== $maxLength) { 187 if (null !== $minLength || null !== $maxLength) { 188 stubClassLoader::load('net::stubbles::ipo::request::filters::stubLengthFilterDecorator', 189 'net::stubbles::util::validators::stubMinLengthValidator', 190 'net::stubbles::util::validators::stubMaxLengthValidator' 191 ); 179 192 $filter = new stubLengthFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 180 193 if (null !== $minLength) { … … 201 214 public function asRequired($strategy = stubStrategyFilterDecorator::STRATEGY_BEFORE) 202 215 { 216 stubClassLoader::load('net::stubbles::ipo::request::filters::stubRequiredFilterDecorator'); 203 217 $filter = new stubRequiredFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 204 218 $filter->setStrategy($strategy); … … 216 230 public function defaultsTo($defaultValue, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 217 231 { 232 stubClassLoader::load('net::stubbles::ipo::request::filters::stubDefaultValueFilterDecorator'); 218 233 $filter = new stubDefaultValueFilterDecorator($this->getDecoratedFilter(), $defaultValue); 219 234 $filter->setStrategy($strategy); … … 232 247 public function validatedBy(stubValidator $validator, $errorId = null, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 233 248 { 249 stubClassLoader::load('net::stubbles::ipo::request::filters::stubValidatorFilterDecorator'); 234 250 $filter = new stubValidatorFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory(), $validator); 235 251 if (null != $errorId) { … … 252 268 public function encodedWith(stubStringEncoder $encoder, $encoderMode = stubStringEncoder::MODE_DECODE, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 253 269 { 270 stubClassLoader::load('net::stubbles::ipo::request::filters::stubEncodingFilterDecorator'); 254 271 $filter = new stubEncodingFilterDecorator($this->getDecoratedFilter(), $encoder, $encoderMode); 255 272 $filter->setStrategy($strategy); trunk/src/main/php/net/stubbles/ipo/request/filters/stubMailFilter.php
r1323 r1338 45 45 46 46 /** 47 * returns the used mail validator 48 * 49 * @return stubValidator 50 */ 51 public function getMailValidator() 52 { 53 return $this->mailValidator; 54 } 55 56 /** 47 57 * check if entered passwords fulfill password conditions 48 58 * trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php
r1323 r1338 38 38 protected $rveFactory; 39 39 /** 40 * validator to use for checking the minimum length of the password41 *42 * @var stubValidator43 */44 protected $minLength;45 /**46 40 * minimum amount of different characters in the password 47 41 * … … 55 49 */ 56 50 protected $nonAllowedValues = array(); 57 /**58 * the encoder to be used for encoding the password59 *60 * @var stubStringEncoder61 */62 protected $encoder;63 51 64 52 /** … … 66 54 * 67 55 * @param stubRequestValueErrorFactory $rveFactory factory to create stubRequestValueErrors 68 * @param stubValidator $minLength validator to checking the minimum length69 56 */ 70 public function __construct(stubRequestValueErrorFactory $rveFactory , stubValidator $minLength)57 public function __construct(stubRequestValueErrorFactory $rveFactory) 71 58 { 72 59 $this->rveFactory = $rveFactory; 73 $this->minLength = $minLength;74 }75 76 /**77 * returns the validator for checking the minimum length of the password78 *79 * @return stubValidator80 */81 public function getMinLengthValidator()82 {83 return $this->minLength;84 60 } 85 61 … … 89 65 * @param array $values list of values that are not allowed as password 90 66 */ 91 public function setNonAllowedValues(array $values)67 public function nonAllowedValues(array $values) 92 68 { 93 69 $this->nonAllowedValues = $values; 70 } 71 72 /** 73 * returns a list of values that are not allowed as password 74 * 75 * @return array 76 */ 77 public function getNonAllowedValues() 78 { 79 return $this->nonAllowedValues; 94 80 } 95 81 … … 101 87 * @param int $minDiffChars 102 88 */ 103 public function setMinDiffChars($minDiffChars)89 public function minDiffChars($minDiffChars) 104 90 { 105 91 $this->minDiffChars = $minDiffChars; … … 114 100 { 115 101 return $this->minDiffChars; 116 }117 118 /**119 * sets the encoder to be used to encode the password120 *121 * @param stubStringEncoder $encoder122 */123 public function setEncoder($encoder)124 {125 $this->encoder = $encoder;126 }127 128 /**129 * returns the encoder to be used to encode the password130 *131 * @return stubStringEncoder132 */133 public function getEncoder()134 {135 return $this->encoder;136 102 } 137 103 … … 153 119 } 154 120 155 if ($this->minLength->validate($value) === false) {156 throw new stubFilterException($this->rveFactory->create('STRING_TOO_SHORT')->setValues($this->minLength->getCriteria()));157 }158 159 121 if (in_array($value, $this->nonAllowedValues) === true) { 160 122 throw new stubFilterException($this->rveFactory->create('PASSWORD_INVALID')); … … 168 130 169 131 if (strlen($value) > 0) { 170 return $ this->secure($value);132 return $value; 171 133 } 172 134 173 135 return null; 174 136 } 175 176 /**177 * turns input into a secure value178 *179 * @param string $password password to secure180 * @return string secure password181 */182 protected function secure($password)183 {184 if (null !== $this->encoder) {185 return $this->encoder->encode($password);186 }187 188 return md5($password);189 }190 137 } 191 138 ?> trunk/src/main/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecorator.php
r1324 r1338 67 67 68 68 /** 69 * returns the error id to be used 70 * 71 * @return string 72 */ 73 public function getErrorId() 74 { 75 return $this->errorId; 76 } 77 78 /** 69 79 * execute the filter 70 80 * trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php
r1329 r1338 42 42 $suite->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 43 43 44 $suite->addTestFile($dir . '/request/filters/stubFilterFactoryTestCase.php'); 44 45 $suite->addTestFile($dir . '/request/filters/stubAbstractFilterDecoratorTestCase.php'); 45 46 $suite->addTestFile($dir . '/request/filters/stubDefaultValueFilterDecoratorTestCase.php'); … … 59 60 $suite->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 60 61 $suite->addTestFile($dir . '/request/filters/stubValidatorFilterDecoratorTestCase.php'); 62 63 $suite->addTestFile($dir . '/request/filters/provider/stubMailFilterProviderTestCase.php'); 64 $suite->addTestFile($dir . '/request/filters/provider/stubSimpleFilterProviderTestCase.php'); 61 65 62 66 $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php
r1323 r1338 40 40 { 41 41 $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 42 $this->assertType('stubPasswordFilter', $passwordFilter); 42 $this->assertType('stubLengthFilterDecorator', $passwordFilter); 43 $this->assertType('stubPasswordFilter', $passwordFilter->getDecoratedFilter()); 43 44 $this->assertType('stubMinLengthValidator', $passwordFilter->getMinLengthValidator()); 44 45 $this->assertEquals(6, $passwordFilter->getMinLengthValidator()->getValue()); 45 $this->assertNull($passwordFilter->getEncoder());46 46 } 47 47 … … 55 55 $this->passwordFilterAnnotation->setMinLength(8); 56 56 $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 57 $this->assertType('stubPasswordFilter', $passwordFilter); 57 $this->assertType('stubLengthFilterDecorator', $passwordFilter); 58 $this->assertType('stubPasswordFilter', $passwordFilter->getDecoratedFilter()); 58 59 $this->assertType('stubMinLengthValidator', $passwordFilter->getMinLengthValidator()); 59 60 $this->assertEquals(8, $passwordFilter->getMinLengthValidator()->getValue()); 60 $this->assertNull($passwordFilter->getEncoder());61 61 } 62 62 … … 70 70 $this->passwordFilterAnnotation->setEncoder(new stubReflectionClass('net::stubbles::php::string::stubMd5Encoder')); 71 71 $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 72 $this->assertType('stubPasswordFilter', $passwordFilter); 72 $this->assertType('stubEncodingFilterDecorator', $passwordFilter); 73 $this->assertType('stubLengthFilterDecorator', $passwordFilter->getDecoratedFilter()); 74 $this->assertType('stubPasswordFilter', $passwordFilter->getDecoratedFilter()->getDecoratedFilter()); 73 75 $this->assertType('stubMd5Encoder', $passwordFilter->getEncoder()); 74 76 } trunk/src/test/php/net/stubbles/ipo/request/filters/stubMailFilterTestCase.php
r1274 r1338 53 53 public function value() 54 54 { 55 $this->assertSame($this->mockMailValidator, $this->mailFilter->getMailValidator()); 55 56 $this->mockMailValidator->expects($this->once())->method('validate')->will($this->returnValue(true)); 56 57 $this->assertEquals('example@example.org', $this->mailFilter->execute('example@example.org')); trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php
r1323 r1338 23 23 protected $mockRequestValueErrorFactory; 24 24 /** 25 * a mock to be used for the minimum validator26 *27 * @var PHPUnit_Framework_MockObject_MockObject28 */29 protected $mockMinLengthValidator;30 /**31 25 * the instance to test 32 26 * … … 42 36 { 43 37 $this->mockRequestValueErrorFactory = $this->getMock('stubRequestValueErrorFactory'); 44 $this->mockMinLengthValidator = $this->getMock('stubValidator'); 45 $this->passwordFilter = new stubPasswordFilter($this->mockRequestValueErrorFactory, $this->mockMinLengthValidator); 46 $this->passwordFilter->setMinDiffChars(null); 38 $this->passwordFilter = new stubPasswordFilter($this->mockRequestValueErrorFactory); 39 $this->passwordFilter->minDiffChars(null); 47 40 } 48 41 … … 54 47 public function value() 55 48 { 56 $this->mockMinLengthValidator->expects($this->exactly(2)) 57 ->method('validate') 58 ->will($this->returnValue(true)); 59 $this->assertSame($this->mockMinLengthValidator, $this->passwordFilter->getMinLengthValidator()); 60 $this->assertEquals(md5('foo'), $this->passwordFilter->execute('foo')); 61 $this->assertEquals(md5('425%$%"§$%t 32'), $this->passwordFilter->execute('425%$%"§$%t 32')); 62 } 63 64 /** 65 * assure that values are returned the expected way 66 * 67 * @test 68 * @expectedException stubFilterException 69 */ 70 public function valueFails() 71 { 72 $this->mockMinLengthValidator->expects($this->once()) 73 ->method('validate') 74 ->will($this->returnValue(false)); 75 $this->mockMinLengthValidator->expects($this->once()) 76 ->method('getCriteria') 77 ->will($this->returnValue(array('minLength' => 'foo'))); 78 $this->mockRequestValueErrorFactory->expects($this->once()) 79 ->method('create') 80 ->with($this->equalTo('STRING_TOO_SHORT')) 81 ->will($this->returnValue(new stubRequestValueError('foo', array('en_EN' => 'Something wrent wrong.')))); 82 $this->passwordFilter->execute('anything'); 49 $this->assertEquals('foo', $this->passwordFilter->execute('foo')); 50 $this->assertEquals('425%$%"§$%t 32', $this->passwordFilter->execute('425%$%"§$%t 32')); 83 51 } 84 52 … … 102 70 public function arrayValue() 103 71 { 104 $this->mockMinLengthValidator->expects($this->once()) 105 ->method('validate') 106 ->will($this->returnValue(true)); 107 $this->assertEquals(md5('foo'), $this->passwordFilter->execute(array('foo', 'foo'))); 72 $this->assertEquals('foo', $this->passwordFilter->execute(array('foo', 'foo'))); 108 73 } 109 74 … … 131 96 public function unexpectedValue() 132 97 { 133 $this->passwordFilter->setNonAllowedValues(array('bar')); 98 $this->passwordFilter->nonAllowedValues(array('bar')); 99 $this->assertEquals(array('bar'), $this->passwordFilter->getNonAllowedValues()); 134 100 $this->mockRequestValueErrorFactory->expects($this->once()) 135 101 ->method('create') … … 146 112 public function minDiffChars() 147 113 { 148 $this->passwordFilter-> setMinDiffChars(5);114 $this->passwordFilter->minDiffChars(5); 149 115 $this->assertEquals(5, $this->passwordFilter->getMinDiffChars()); 150 $this->mockMinLengthValidator->expects($this->once()) 151 ->method('validate') 152 ->will($this->returnValue(true)); 153 $this->assertEquals(md5('abcde'), $this->passwordFilter->execute(array('abcde', 'abcde'))); 116 $this->assertEquals('abcde', $this->passwordFilter->execute(array('abcde', 'abcde'))); 154 117 } 155 118 … … 162 125 public function minDiffCharsFails() 163 126 { 164 $this->passwordFilter-> setMinDiffChars(5);127 $this->passwordFilter->minDiffChars(5); 165 128 $this->assertEquals(5, $this->passwordFilter->getMinDiffChars()); 166 $this->mockMinLengthValidator->expects($this->once())167 ->method('validate')168 ->will($this->returnValue(true));169 129 $this->mockRequestValueErrorFactory->expects($this->once()) 170 130 ->method('create') … … 173 133 $this->passwordFilter->execute(array('abcdd', 'abcdd')); 174 134 } 175 176 /**177 * test that the encoder is used if set178 *179 * @test180 */181 public function withEncoder()182 {183 $this->mockMinLengthValidator->expects($this->once())184 ->method('validate')185 ->will($this->returnValue(true));186 $mockEncoder = $this->getMock('stubStringEncoder');187 $mockEncoder->expects($this->once())188 ->method('encode')189 ->will($this->returnValue('encodedValue'));190 $this->passwordFilter->setEncoder($mockEncoder);191 $this->assertSame($mockEncoder, $this->passwordFilter->getEncoder());192 $this->assertEquals('encodedValue', $this->passwordFilter->execute('foo'));193 }194 135 } 195 136 ?> trunk/src/test/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecoratorTestCase.php
r1324 r1338 97 97 public function validationFails() 98 98 { 99 $this->assertEquals('FIELD_WRONG_VALUE', $this->validatorFilterDecorator->getErrorId()); 99 100 $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 100 101 $this->mockRequestValueErrorFactory->expects($this->once()) … … 114 115 { 115 116 $this->validatorFilterDecorator->setErrorId('foo'); 117 $this->assertEquals('foo', $this->validatorFilterDecorator->getErrorId()); 116 118 $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 117 119 $this->mockRequestValueErrorFactory->expects($this->once())
