Changeset 968

Show
Ignore:
Timestamp:
10/21/07 19:22:39 (1 year ago)
Author:
mikey
Message:

allow string encoders to be used within string filters

Files:

Legend:

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

    r731 r968  
    2626     * @var  stubValidator 
    2727     */ 
    28     protected $minLength = null; 
     28    protected $minLength   = null; 
    2929    /** 
    3030     * validator for maximum length of string 
     
    3232     * @var  stubValidator 
    3333     */ 
    34     protected $maxLength = null; 
     34    protected $maxLength   = null; 
     35    /** 
     36     * the encoder to be applied on the value to filter 
     37     * 
     38     * @var  stubStringEncoder 
     39     */ 
     40    protected $encoder     = null; 
     41    /** 
     42     * the encoding mode to be applied on the value to filter 
     43     * 
     44     * @var  int 
     45     */ 
     46    protected $encoderMode = stubStringEncoder::MODE_DECODE; 
    3547 
    3648    /** 
     
    7587 
    7688    /** 
     89     * sets the encoder to be applied onto the value to filter 
     90     * 
     91     * @param  stubStringEncoder  $encoder 
     92     * @param  int                $mode 
     93     */ 
     94    public function setEncoder(stubStringEncoder $encoder, $mode = stubStringEncoder::MODE_DECODE) 
     95    { 
     96        $this->encoder     = $encoder; 
     97        $this->encoderMode = $mode; 
     98    } 
     99 
     100    /** 
    77101     * filter strings 
    78102     * 
     
    96120        } 
    97121 
     122        if (null !== $this->encoder) { 
     123            $value = $this->encoder->apply($value, $this->encoderMode); 
     124        } 
     125         
    98126        return $value; 
    99127    } 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubStringFilterTestCase.php

    r696 r968  
    1010Mock::generate('stubRequestValueErrorFactory'); 
    1111Mock::generate('stubValidator'); 
     12Mock::generate('stubStringEncoder'); 
    1213/** 
    1314 * Tests for ipo.request.filters.stubStringFilter 
     
    135136        $this->stringFilter->execute('regexTest'); 
    136137    } 
     138 
     139    /** 
     140     * test that encoder is applied correct 
     141     */ 
     142    public function testEncoder() 
     143    { 
     144        $mockEncoder = new MockstubStringEncoder(); 
     145        $mockEncoder->expectAt(0, 'apply', array('foo', stubStringEncoder::MODE_DECODE)); 
     146        $mockEncoder->setReturnValueAt(0, 'apply', 'decoded'); 
     147        $mockEncoder->expectAt(1, 'apply', array('foo', stubStringEncoder::MODE_ENCODE)); 
     148        $mockEncoder->setReturnValueAt(1, 'apply', 'encoded'); 
     149        $mockEncoder->expectCallcount('apply', 2); 
     150        $this->mockRegexValidator->setReturnValue('validate', true); 
     151        $this->stringFilter->setEncoder($mockEncoder); 
     152        $this->assertEqual($this->stringFilter->execute('foo'), 'decoded'); 
     153        $this->stringFilter->setEncoder($mockEncoder, stubStringEncoder::MODE_ENCODE); 
     154        $this->assertEqual($this->stringFilter->execute('foo'), 'encoded'); 
     155    } 
    137156} 
    138157?>