Changeset 1582

Show
Ignore:
Timestamp:
05/24/08 00:24:25 (5 months ago)
Author:
mikey
Message:

fix empty value behavior

Files:

Legend:

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

    r1547 r1582  
    143143    protected function doExecute($value) 
    144144    { 
     145        if (strlen($value) === 0) { 
     146            return null; 
     147        } 
     148         
    145149        if (null != $this->minLength && $this->minLength->validate($value) === false) { 
    146150            // input is shorter than maximal allowed length 
  • trunk/src/main/php/net/stubbles/ipo/request/filter/stubValidatorFilterDecorator.php

    r1575 r1582  
    8585    protected function doExecute($value) 
    8686    { 
    87         if ($this->validator->validate($value) == false) { 
     87        if (strlen($value) === 0) { 
     88            return null; 
     89        } 
     90         
     91        if ($this->validator->validate($value) === false) { 
    8892            throw new stubFilterException($this->rveFactory->create($this->errorId)); 
    8993        } 
  • trunk/src/test/php/net/stubbles/ipo/request/filter/stubLengthFilterDecoratorTestCase.php

    r1546 r1582  
    7070 
    7171    /** 
     72     * test handling of empty values 
     73     * 
     74     * @test 
     75     */ 
     76    public function emptyValues() 
     77    { 
     78        $mockMinLengthValidaror = $this->getMock('stubValidator'); 
     79        $mockMinLengthValidaror->expects($this->never()) 
     80                               ->method('validate'); 
     81        $this->lengthFilterDecorator->setMinLengthValidator($mockMinLengthValidaror); 
     82        $mockMaxLengthValidaror = $this->getMock('stubValidator'); 
     83        $mockMaxLengthValidaror->expects($this->never()) 
     84                               ->method('validate'); 
     85        $this->lengthFilterDecorator->setMaxLengthValidator($mockMaxLengthValidaror); 
     86        $this->assertNull($this->lengthFilterDecorator->callDoExecute(null)); 
     87        $this->assertNull($this->lengthFilterDecorator->callDoExecute('')); 
     88    } 
     89 
     90    /** 
     91     * test handling of non-empty values 
     92     * 
     93     * @test 
     94     */ 
     95    public function nonEmptyValues() 
     96    { 
     97        $mockMinLengthValidaror = $this->getMock('stubValidator'); 
     98        $mockMinLengthValidaror->expects($this->exactly(2)) 
     99                               ->method('validate') 
     100                               ->will($this->returnValue(true)); 
     101        $this->lengthFilterDecorator->setMinLengthValidator($mockMinLengthValidaror); 
     102        $mockMaxLengthValidaror = $this->getMock('stubValidator'); 
     103        $mockMaxLengthValidaror->expects($this->exactly(2)) 
     104                               ->method('validate') 
     105                               ->will($this->returnValue(true)); 
     106        $this->lengthFilterDecorator->setMaxLengthValidator($mockMaxLengthValidaror); 
     107        $this->assertEquals(0, $this->lengthFilterDecorator->callDoExecute(0)); 
     108        $this->assertEquals('0', $this->lengthFilterDecorator->callDoExecute('0')); 
     109    } 
     110 
     111    /** 
    72112     * assure that filtering a string with minimum length is ok and a string 
    73113     * with length shorter than minimum length throws an FilterException 
  • trunk/src/test/php/net/stubbles/ipo/request/filter/stubValidatorFilterDecoratorTestCase.php

    r1546 r1582  
    123123        $this->validatorFilterDecorator->callDoExecute('test_value'); 
    124124    } 
     125 
     126    /** 
     127     * test handling of empty values 
     128     * 
     129     * @test 
     130     */ 
     131    public function emptyValues() 
     132    { 
     133        $this->mockValidator->expects($this->never()) 
     134                            ->method('validate'); 
     135        $this->assertNull($this->validatorFilterDecorator->callDoExecute(null)); 
     136        $this->assertNull($this->validatorFilterDecorator->callDoExecute('')); 
     137    } 
     138 
     139    /** 
     140     * test handling of non-empty values 
     141     * 
     142     * @test 
     143     */ 
     144    public function nonEmptyValues() 
     145    { 
     146        $this->mockValidator->expects($this->exactly(2)) 
     147                               ->method('validate') 
     148                               ->will($this->returnValue(true)); 
     149        $this->assertEquals(0, $this->validatorFilterDecorator->callDoExecute(0)); 
     150        $this->assertEquals('0', $this->validatorFilterDecorator->callDoExecute('0')); 
     151    } 
     152 
    125153} 
    126154?>