Changeset 1338

Show
Ignore:
Timestamp:
02/11/08 17:31:58 (5 months ago)
Author:
mikey
Message:

enhanced filter api

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/experiments/people/mikey/filterAPI/filterAPI.php

    r1334 r1338  
    11<?php 
    2 /** 
    3  * @todo  make PasswordFilter more fluent 
    4  * @todo  remove min length from PasswordFilter constructor (use LengthFilterDecorator instead?) 
    5  * @todo  remove encoding feature from PasswordFilter, use EncodingFilterDecorator instead 
    6  */ 
    7  
    82$filter = stubFilterFactory::forType('integer')->inRange(1, 4)->asRequired(); 
    93$filter = stubFilterFactory::forType('integer')->using(new MyRVEFactory())->inRange(1, 4)->asRequired(); 
     
    137$filter = stubFilterFactory::forType('string')->length(2, 5)->validatedBy(new stubRegexValidator($regex))->defaultsTo('foo'); 
    148 
    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()); 
    1610 
    1711$http = stubFilterFactory::forType('http', array($rveFactory))->checkDNS(true); 
  • trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotation.php

    r1301 r1338  
    77 * @subpackage  ipo_request_broker_annotations 
    88 */ 
    9 stubClassLoader::load('net::stubbles::reflection::annotations::stubAnnotation', 
     9stubClassLoader::load('net::stubbles::ipo::request::broker::annotations::stubAbstractFilterAnnotation', 
     10                      'net::stubbles::ipo::request::filters::stubEncodingFilterDecorator', 
     11                      'net::stubbles::ipo::request::filters::stubLengthFilterDecorator', 
    1012                      'net::stubbles::ipo::request::filters::stubPasswordFilter', 
    11                       'net::stubbles::ipo::request::broker::annotations::stubAbstractFilterAnnotation', 
     13                      'net::stubbles::reflection::annotations::stubAnnotation', 
    1214                      'net::stubbles::util::validators::stubMinLengthValidator' 
    1315); 
     
    5961     * returns the filter defined by the annotation 
    6062     * 
    61      * @return  stubPasswordFilter 
    62      * @throws  stubRequestBrokerException 
     63     * @return  stubFilter 
    6364     */ 
    6465    protected function doGetFilter() 
    6566    { 
    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)); 
    6770        if (null !== $this->encoderClass) { 
    68             $passwordFilter->setEncoder($this->encoderClass->newInstance()); 
     71            $filter = new stubEncodingFilterDecorator($filter, $this->encoderClass->newInstance(), stubStringEncoder::MODE_ENCODE); 
    6972        } 
    7073         
    71         return $passwordFilter; 
     74        return $filter; 
    7275    } 
    7376} 
  • trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubMailFilterProvider.php

    r1334 r1338  
    11<?php 
    22/** 
    3  * Interface for filter providers
     3 * Filter provider for the mail filter
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  ipo_request_filters_provider 
    88 */ 
     9stubClassLoader::load('net::stubbles::ipo::request::stubRequestValueErrorFactory', 
     10                      'net::stubbles::ipo::request::filters::provider::stubFilterProvider' 
     11); 
    912/** 
    10  * Interface for filter providers
     13 * Filter provider for the mail filter
    1114 * 
    1215 * @package     stubbles 
     
    2932     * returns a filter instance 
    3033     * 
     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     * 
    3141     * @param   array       $args  optional  constructor arguments 
    3242     * @return  stubFilter 
     
    3545    public function getFilter(array $args = null) 
    3646    { 
    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.'); 
    3949        } 
    4050         
  • trunk/src/main/php/net/stubbles/ipo/request/filters/provider/stubSimpleFilterProvider.php

    r1334 r1338  
    11<?php 
    22/** 
    3  * Interface for filter providers. 
     3 * Filter provider simple filters. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    99stubClassLoader::load('net::stubbles::reflection::stubReflectionClass'); 
    1010/** 
    11  * Interface for filter providers. 
     11 * Filter provider simple filters. 
    1212 * 
    1313 * @package     stubbles 
     
    5757     * @param   array       $args  optional  constructor arguments 
    5858     * @return  stubFilter 
    59      * @throws  stubIllegalArgumentException 
    6059     */ 
    6160    public function getFilter(array $args = null) 
     
    6362        if (null !== $args) { 
    6463            $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); 
    7065        } 
    7166         
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubFilterFactory.php

    r1334 r1338  
    77 * @subpackage  ipo_request_filters 
    88 */ 
    9 stubClassLoader::load('net::stubbles::ipo::request::stubRequestErrorValueFactory', 
    10                       'net::stubbles::ipo::request::stubRequestValueErrorXJConfFactory', 
     9stubClassLoader::load('net::stubbles::ipo::request::stubRequestValueErrorFactory', 
    1110                      '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', 
    1711                      'net::stubbles::ipo::request::filters::stubStrategyFilterDecorator', 
    18                       'net::stubbles::ipo::request::filters::stubValidatorFilterDecorator', 
    1912                      'net::stubbles::ipo::request::filters::provider::stubFilterProvider', 
    2013                      'net::stubbles::ipo::request::filters::provider::stubMailFilterProvider', 
    2114                      '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' 
    2317); 
    2418/** 
     
    2721 * @package     stubbles 
    2822 * @subpackage  ipo_request_filters 
    29  * @todo        allow to register user-defined base filters to be used in forType() 
    3023 */ 
    3124class stubFilterFactory extends stubAbstractFilterDecorator 
     
    8477     * @param   array              $args  optional  constructor arguments for filter 
    8578     * @return  stubFilterFactory 
     79     * @throws  stubIllegalArgumentException 
    8680     */ 
    8781    public static function forType($type, array $args = null) 
     
    9993         
    10094        $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]); 
    10397        } 
    10498         
     
    109103     * sets the request error value factory to be used by the filter 
    110104     * 
    111      * @param   stubRequestErrorValueFactory  $rveFactory 
    112      * @return  stubFilterFactory 
    113      */ 
    114     public function using(stubRequestErrorValueFactory $rveFactory) 
     105     * @param   stubRequestValueErrorFactory  $rveFactory 
     106     * @return  stubFilterFactory 
     107     */ 
     108    public function using(stubRequestValueErrorFactory $rveFactory) 
    115109    { 
    116110        $this->rveFactory = $rveFactory; 
     
    119113 
    120114    /** 
    121      * helper method to retrieve the request error value factory 
    122      * 
    123      * @return  stubRequestErrorValueFactory 
    124      * @todo    make default class configurable 
    125      */ 
    126     protected function 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() 
    127121    { 
    128122        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; 
    130135        } 
    131136         
     
    146151    public function inRange($min, $max, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 
    147152    { 
    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            ); 
    149158            $filter = new stubRangeFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 
    150159            if (null !== $min) { 
     
    176185    public function length($minLength, $maxLength, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 
    177186    { 
    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            ); 
    179192            $filter = new stubLengthFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 
    180193            if (null !== $minLength) { 
     
    201214    public function asRequired($strategy = stubStrategyFilterDecorator::STRATEGY_BEFORE) 
    202215    { 
     216        stubClassLoader::load('net::stubbles::ipo::request::filters::stubRequiredFilterDecorator'); 
    203217        $filter = new stubRequiredFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory()); 
    204218        $filter->setStrategy($strategy); 
     
    216230    public function defaultsTo($defaultValue, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 
    217231    { 
     232        stubClassLoader::load('net::stubbles::ipo::request::filters::stubDefaultValueFilterDecorator'); 
    218233        $filter = new stubDefaultValueFilterDecorator($this->getDecoratedFilter(), $defaultValue); 
    219234        $filter->setStrategy($strategy); 
     
    232247    public function validatedBy(stubValidator $validator, $errorId = null, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 
    233248    { 
     249        stubClassLoader::load('net::stubbles::ipo::request::filters::stubValidatorFilterDecorator'); 
    234250        $filter = new stubValidatorFilterDecorator($this->getDecoratedFilter(), $this->getRVEFactory(), $validator); 
    235251        if (null != $errorId) { 
     
    252268    public function encodedWith(stubStringEncoder $encoder, $encoderMode = stubStringEncoder::MODE_DECODE, $strategy = stubStrategyFilterDecorator::STRATEGY_AFTER) 
    253269    { 
     270        stubClassLoader::load('net::stubbles::ipo::request::filters::stubEncodingFilterDecorator'); 
    254271        $filter = new stubEncodingFilterDecorator($this->getDecoratedFilter(), $encoder, $encoderMode); 
    255272        $filter->setStrategy($strategy); 
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubMailFilter.php

    r1323 r1338  
    4545 
    4646    /** 
     47     * returns the used mail validator 
     48     * 
     49     * @return  stubValidator 
     50     */ 
     51    public function getMailValidator() 
     52    { 
     53        return $this->mailValidator; 
     54    } 
     55 
     56    /** 
    4757     * check if entered passwords fulfill password conditions 
    4858     * 
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php

    r1323 r1338  
    3838    protected $rveFactory; 
    3939    /** 
    40      * validator to use for checking the minimum length of the password 
    41      * 
    42      * @var  stubValidator 
    43      */ 
    44     protected $minLength; 
    45     /** 
    4640     * minimum amount of different characters in the password 
    4741     * 
     
    5549     */ 
    5650    protected $nonAllowedValues = array(); 
    57     /** 
    58      * the encoder to be used for encoding the password 
    59      * 
    60      * @var  stubStringEncoder 
    61      */ 
    62     protected $encoder; 
    6351 
    6452    /** 
     
    6654     * 
    6755     * @param  stubRequestValueErrorFactory  $rveFactory  factory to create stubRequestValueErrors 
    68      * @param  stubValidator                 $minLength   validator to checking the minimum length 
    6956     */ 
    70     public function __construct(stubRequestValueErrorFactory $rveFactory, stubValidator $minLength
     57    public function __construct(stubRequestValueErrorFactory $rveFactory
    7158    { 
    7259        $this->rveFactory = $rveFactory; 
    73         $this->minLength  = $minLength; 
    74     } 
    75  
    76     /** 
    77      * returns the validator for checking the minimum length of the password 
    78      * 
    79      * @return  stubValidator 
    80      */ 
    81     public function getMinLengthValidator() 
    82     { 
    83         return $this->minLength; 
    8460    } 
    8561 
     
    8965     * @param  array  $values  list of values that are not allowed as password 
    9066     */ 
    91     public function setNonAllowedValues(array $values) 
     67    public function nonAllowedValues(array $values) 
    9268    { 
    9369        $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; 
    9480    } 
    9581 
     
    10187     * @param  int  $minDiffChars 
    10288     */ 
    103     public function setMinDiffChars($minDiffChars) 
     89    public function minDiffChars($minDiffChars) 
    10490    { 
    10591        $this->minDiffChars = $minDiffChars; 
     
    114100    { 
    115101        return $this->minDiffChars; 
    116     } 
    117  
    118     /** 
    119      * sets the encoder to be used to encode the password 
    120      * 
    121      * @param  stubStringEncoder  $encoder 
    122      */ 
    123     public function setEncoder($encoder) 
    124     { 
    125         $this->encoder = $encoder; 
    126     } 
    127  
    128     /** 
    129      * returns the encoder to be used to encode the password 
    130      * 
    131      * @return  stubStringEncoder 
    132      */ 
    133     public function getEncoder() 
    134     { 
    135         return $this->encoder; 
    136102    } 
    137103 
     
    153119        } 
    154120 
    155         if ($this->minLength->validate($value) === false) { 
    156             throw new stubFilterException($this->rveFactory->create('STRING_TOO_SHORT')->setValues($this->minLength->getCriteria())); 
    157         } 
    158  
    159121        if (in_array($value, $this->nonAllowedValues) === true) { 
    160122            throw new stubFilterException($this->rveFactory->create('PASSWORD_INVALID')); 
     
    168130 
    169131        if (strlen($value) > 0) { 
    170             return $this->secure($value)
     132            return $value
    171133        } 
    172134         
    173135        return null; 
    174136    } 
    175  
    176     /** 
    177      * turns input into a secure value 
    178      * 
    179      * @param   string  $password  password to secure 
    180      * @return  string  secure password 
    181      */ 
    182     protected function secure($password) 
    183     { 
    184         if (null !== $this->encoder) { 
    185             return $this->encoder->encode($password); 
    186         } 
    187          
    188         return md5($password); 
    189     } 
    190137} 
    191138?> 
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecorator.php

    r1324 r1338  
    6767 
    6868    /** 
     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    /** 
    6979     * execute the filter 
    7080     * 
  • trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php

    r1329 r1338  
    4242        $suite->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 
    4343 
     44        $suite->addTestFile($dir . '/request/filters/stubFilterFactoryTestCase.php'); 
    4445        $suite->addTestFile($dir . '/request/filters/stubAbstractFilterDecoratorTestCase.php'); 
    4546        $suite->addTestFile($dir . '/request/filters/stubDefaultValueFilterDecoratorTestCase.php'); 
     
    5960        $suite->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 
    6061        $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'); 
    6165 
    6266        $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); 
  • trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php

    r1323 r1338  
    4040    { 
    4141        $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 
    42         $this->assertType('stubPasswordFilter', $passwordFilter); 
     42        $this->assertType('stubLengthFilterDecorator', $passwordFilter); 
     43        $this->assertType('stubPasswordFilter', $passwordFilter->getDecoratedFilter()); 
    4344        $this->assertType('stubMinLengthValidator', $passwordFilter->getMinLengthValidator()); 
    4445        $this->assertEquals(6, $passwordFilter->getMinLengthValidator()->getValue()); 
    45         $this->assertNull($passwordFilter->getEncoder()); 
    4646    } 
    4747 
     
    5555        $this->passwordFilterAnnotation->setMinLength(8); 
    5656        $passwordFilter = $this->passwordFilterAnnotation->getFilter(); 
    57         $this->assertType('stubPasswordFilter', $passwordFilter); 
     57        $this->assertType('stubLengthFilterDecorator', $passwordFilter); 
     58        $this->assertType('stubPasswordFilter', $passwordFilter->getDecoratedFilter()); 
    5859        $this->assertType('stubMinLengthValidator', $passwordFilter->getMinLengthValidator()); 
    5960        $this->assertEquals(8, $passwordFilter->getMinLengthValidator()->getValue()); 
    60         $this->assertNull($passwordFilter->getEncoder()); 
    6161    } 
    6262 
     
    7070        $this->passwordFilterAnnotation->setEncoder(new stubReflectionClass('net::stubbles::php::string::stubMd5Encoder')); 
    7171        $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()); 
    7375        $this->assertType('stubMd5Encoder', $passwordFilter->getEncoder()); 
    7476    } 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubMailFilterTestCase.php

    r1274 r1338  
    5353    public function value() 
    5454    { 
     55        $this->assertSame($this->mockMailValidator, $this->mailFilter->getMailValidator()); 
    5556        $this->mockMailValidator->expects($this->once())->method('validate')->will($this->returnValue(true)); 
    5657        $this->assertEquals('example@example.org', $this->mailFilter->execute('example@example.org')); 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php

    r1323 r1338  
    2323    protected $mockRequestValueErrorFactory; 
    2424    /** 
    25      * a mock to be used for the minimum validator 
    26      * 
    27      * @var  PHPUnit_Framework_MockObject_MockObject 
    28      */ 
    29     protected $mockMinLengthValidator; 
    30     /** 
    3125     * the instance to test 
    3226     * 
     
    4236    { 
    4337        $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); 
    4740    } 
    4841 
     
    5447    public function value() 
    5548    { 
    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')); 
    8351    } 
    8452 
     
    10270    public function arrayValue() 
    10371    { 
    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'))); 
    10873    } 
    10974 
     
    13196    public function unexpectedValue() 
    13297    { 
    133         $this->passwordFilter->setNonAllowedValues(array('bar')); 
     98        $this->passwordFilter->nonAllowedValues(array('bar')); 
     99        $this->assertEquals(array('bar'), $this->passwordFilter->getNonAllowedValues()); 
    134100        $this->mockRequestValueErrorFactory->expects($this->once()) 
    135101                                           ->method('create') 
     
    146112    public function minDiffChars() 
    147113    { 
    148         $this->passwordFilter->setMinDiffChars(5); 
     114        $this->passwordFilter->minDiffChars(5); 
    149115        $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'))); 
    154117    } 
    155118 
     
    162125    public function minDiffCharsFails() 
    163126    { 
    164         $this->passwordFilter->setMinDiffChars(5); 
     127        $this->passwordFilter->minDiffChars(5); 
    165128        $this->assertEquals(5, $this->passwordFilter->getMinDiffChars()); 
    166         $this->mockMinLengthValidator->expects($this->once()) 
    167                                      ->method('validate') 
    168                                      ->will($this->returnValue(true)); 
    169129        $this->mockRequestValueErrorFactory->expects($this->once()) 
    170130                                           ->method('create') 
     
    173133        $this->passwordFilter->execute(array('abcdd', 'abcdd')); 
    174134    } 
    175  
    176     /** 
    177      * test that the encoder is used if set 
    178      * 
    179      * @test 
    180      */ 
    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     } 
    194135} 
    195136?> 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecoratorTestCase.php

    r1324 r1338  
    9797    public function validationFails() 
    9898    { 
     99        $this->assertEquals('FIELD_WRONG_VALUE', $this->validatorFilterDecorator->getErrorId()); 
    99100        $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 
    100101        $this->mockRequestValueErrorFactory->expects($this->once()) 
     
    114115    { 
    115116        $this->validatorFilterDecorator->setErrorId('foo'); 
     117        $this->assertEquals('foo', $this->validatorFilterDecorator->getErrorId()); 
    116118        $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 
    117119        $this->mockRequestValueErrorFactory->expects($this->once())