Changeset 968
- Timestamp:
- 10/21/07 19:22:39 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/filters/stubAbstractStringFilter.php
r731 r968 26 26 * @var stubValidator 27 27 */ 28 protected $minLength = null;28 protected $minLength = null; 29 29 /** 30 30 * validator for maximum length of string … … 32 32 * @var stubValidator 33 33 */ 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; 35 47 36 48 /** … … 75 87 76 88 /** 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 /** 77 101 * filter strings 78 102 * … … 96 120 } 97 121 122 if (null !== $this->encoder) { 123 $value = $this->encoder->apply($value, $this->encoderMode); 124 } 125 98 126 return $value; 99 127 } trunk/src/test/php/net/stubbles/ipo/request/filters/stubStringFilterTestCase.php
r696 r968 10 10 Mock::generate('stubRequestValueErrorFactory'); 11 11 Mock::generate('stubValidator'); 12 Mock::generate('stubStringEncoder'); 12 13 /** 13 14 * Tests for ipo.request.filters.stubStringFilter … … 135 136 $this->stringFilter->execute('regexTest'); 136 137 } 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 } 137 156 } 138 157 ?>
