Changeset 1324
- Timestamp:
- 02/03/08 21:48:27 (7 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotation.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecorator.php (moved) (moved from trunk/src/main/php/net/stubbles/ipo/request/filters/stubRegexCheckFilterDecorator.php) (4 diffs)
- trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecoratorTestCase.php (moved) (moved from trunk/src/test/php/net/stubbles/ipo/request/filters/stubRegexCheckFilterDecoratorTestCase.php) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotation.php
r1323 r1324 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ipo::request::broker::annotations::stubAbstractStringFilterAnnotation', 10 'net::stubbles::ipo::request::filters::stub RegexCheckFilterDecorator',10 'net::stubbles::ipo::request::filters::stubValidatorFilterDecorator', 11 11 'net::stubbles::ipo::request::filters::stubStringFilter', 12 12 'net::stubbles::util::validators::stubRegexValidator' … … 46 46 $stringFilter = new stubStringFilter(); 47 47 if (null !== $this->regex) { 48 $stringFilter = new stub RegexCheckFilterDecorator($stringFilter, $this->createRVEFactory(), new stubRegexValidator($this->regex));48 $stringFilter = new stubValidatorFilterDecorator($stringFilter, $this->createRVEFactory(), new stubRegexValidator($this->regex)); 49 49 } 50 50 trunk/src/main/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecorator.php
r1323 r1324 1 1 <?php 2 2 /** 3 * Class for checking values against a regular expession.3 * Class for checking values against any validator. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 12 12 ); 13 13 /** 14 * Class for checking values against a regular expession. 15 * 16 * If the regular expression is not satisfied with the given value it will be 17 * rejected. 14 * Class for checking values against any validator. 18 15 * 19 16 * @package stubbles 20 17 * @subpackage ipo_request_filters 21 18 */ 22 class stub RegexCheckFilterDecorator extends stubStrategyFilterDecorator19 class stubValidatorFilterDecorator extends stubStrategyFilterDecorator 23 20 { 24 21 /** 25 * validator to use for checking the password22 * validator to use for the check 26 23 * 27 24 * @var stubValidator 28 25 */ 29 protected $regex; 26 protected $validator; 27 /** 28 * the error id to use in case the validation fails 29 * 30 * @var string 31 */ 32 protected $errorId = 'FIELD_WRONG_VALUE'; 30 33 31 34 /** … … 34 37 * @param stubFilter $filter decorated filter 35 38 * @param stubRequestValueErrorFactory $rveFactory factory to create RequestValueErrors 36 * @param stubValidator $ regex validator to use for checking the string39 * @param stubValidator $validator validator to use for the check 37 40 */ 38 public function __construct(stubFilter $filter, stubRequestValueErrorFactory $rveFactory, stubValidator $ regex)41 public function __construct(stubFilter $filter, stubRequestValueErrorFactory $rveFactory, stubValidator $validator) 39 42 { 40 43 $this->setDecoratedFilter($filter); 41 44 $this->rveFactory = $rveFactory; 42 $this-> regex = $regex;45 $this->validator = $validator; 43 46 } 44 47 45 48 /** 46 * returns the regexvalidator49 * returns the validator 47 50 * 48 51 * @return stubValidator 49 52 */ 50 public function get RegexValidator()53 public function getValidator() 51 54 { 52 return $this->regex; 55 return $this->validator; 56 } 57 58 /** 59 * sets the error id to be used 60 * 61 * @param string $errorId 62 */ 63 public function setErrorId($errorId) 64 { 65 $this->errorId = $errorId; 53 66 } 54 67 … … 62 75 protected function doExecute($value) 63 76 { 64 if ($this-> regex->validate($value) == false) {65 throw new stubFilterException($this->rveFactory->create( 'FIELD_WRONG_VALUE'));77 if ($this->validator->validate($value) == false) { 78 throw new stubFilterException($this->rveFactory->create($this->errorId)); 66 79 } 67 80 trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php
r1323 r1324 53 53 $suite->addTestFile($dir . '/request/filters/stubPassThruFilterTestCase.php'); 54 54 $suite->addTestFile($dir . '/request/filters/stubPasswordFilterTestCase.php'); 55 $suite->addTestFile($dir . '/request/filters/stubRegexCheckFilterDecoratorTestCase.php');56 55 $suite->addTestFile($dir . '/request/filters/stubRegexChangeFilterDecoratorTestCase.php'); 57 56 $suite->addTestFile($dir . '/request/filters/stubRequiredFilterDecoratorTestCase.php'); … … 59 58 $suite->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php'); 60 59 $suite->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 60 $suite->addTestFile($dir . '/request/filters/stubValidatorFilterDecoratorTestCase.php'); 61 61 62 62 $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php
r1323 r1324 52 52 $this->stringFilterAnnotation->setRegex('/foo/'); 53 53 $filter = $this->stringFilterAnnotation->getFilter(); 54 $this->assertType('stub RegexCheckFilterDecorator', $filter);55 $this->assertType('stubRegexValidator', $filter->get RegexValidator());56 $this->assertEquals('/foo/', $filter->get RegexValidator()->getValue());54 $this->assertType('stubValidatorFilterDecorator', $filter); 55 $this->assertType('stubRegexValidator', $filter->getValidator()); 56 $this->assertEquals('/foo/', $filter->getValidator()->getValue()); 57 57 $this->assertType('stubStringFilter', $filter->getDecoratedFilter()); 58 58 } trunk/src/test/php/net/stubbles/ipo/request/filters/stubValidatorFilterDecoratorTestCase.php
r1323 r1324 1 1 <?php 2 2 /** 3 * Tests for net::stubbles::ipo::request::filters::stub RegexCheckFilterDecorator.3 * Tests for net::stubbles::ipo::request::filters::stubValidatorFilterDecorator. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage ipo_request_filters_test 8 8 */ 9 stubClassLoader::load('net::stubbles::ipo::request::filters::stub RegexCheckFilterDecorator');9 stubClassLoader::load('net::stubbles::ipo::request::filters::stubValidatorFilterDecorator'); 10 10 /** 11 11 * Helper class for the test. … … 14 14 * @subpackage ipo_request_filters_test 15 15 */ 16 class Teststub RegexCheckFilterDecorator extends stubRegexCheckFilterDecorator16 class TeststubValidatorFilterDecorator extends stubValidatorFilterDecorator 17 17 { 18 18 /** … … 28 28 } 29 29 /** 30 * Tests for net::stubbles::ipo::request::filters::stub RegexCheckFilterDecorator.30 * Tests for net::stubbles::ipo::request::filters::stubValidatorFilterDecorator. 31 31 * 32 32 * @package stubbles 33 33 * @subpackage ipo_request_filters_test 34 34 */ 35 class stub RegexCheckFilterDecoratorTestCase extends PHPUnit_Framework_TestCase35 class stubValidatorFilterDecoratorTestCase extends PHPUnit_Framework_TestCase 36 36 { 37 37 /** … … 46 46 * @var PHPUnit_Framework_MockObject_MockObject 47 47 */ 48 protected $mock RegexValidator;48 protected $mockValidator; 49 49 /** 50 50 * the instance to test 51 51 * 52 * @var Teststub RegexCheckFilterDecorator52 * @var TeststubValidatorFilterDecorator 53 53 */ 54 protected $ regexCheckFilterDecorator;54 protected $validatorFilterDecorator; 55 55 56 56 /** … … 60 60 { 61 61 $this->mockRequestValueErrorFactory = $this->getMock('stubRequestValueErrorFactory'); 62 $this->mock RegexValidator= $this->getMock('stubValidator');62 $this->mockValidator = $this->getMock('stubValidator'); 63 63 $this->mockFilter = $this->getMock('stubFilter'); 64 $this-> regexCheckFilterDecorator = new TeststubRegexCheckFilterDecorator($this->mockFilter, $this->mockRequestValueErrorFactory, $this->mockRegexValidator);64 $this->validatorFilterDecorator = new TeststubValidatorFilterDecorator($this->mockFilter, $this->mockRequestValueErrorFactory, $this->mockValidator); 65 65 } 66 66 … … 72 72 public function values() 73 73 { 74 $this->assertSame($this->mockFilter, $this-> regexCheckFilterDecorator->getDecoratedFilter());75 $this->assertSame($this->mock RegexValidator, $this->regexCheckFilterDecorator->getRegexValidator());74 $this->assertSame($this->mockFilter, $this->validatorFilterDecorator->getDecoratedFilter()); 75 $this->assertSame($this->mockValidator, $this->validatorFilterDecorator->getValidator()); 76 76 } 77 77 … … 81 81 * @test 82 82 */ 83 public function regexSucceeds()83 public function validationSucceeds() 84 84 { 85 85 86 $this->mock RegexValidator->expects($this->once())->method('validate')->will($this->returnValue(true));86 $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(true)); 87 87 $this->mockRequestValueErrorFactory->expects($this->never())->method('create'); 88 $this->assertEquals(' regexTest', $this->regexCheckFilterDecorator->callDoExecute('regexTest'));88 $this->assertEquals('test_value', $this->validatorFilterDecorator->callDoExecute('test_value')); 89 89 } 90 90 … … 95 95 * @expectedException stubFilterException 96 96 */ 97 public function regexFails()97 public function validationFails() 98 98 { 99 $this->mock RegexValidator->expects($this->once())->method('validate')->will($this->returnValue(false));99 $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 100 100 $this->mockRequestValueErrorFactory->expects($this->once()) 101 101 ->method('create') 102 102 ->with($this->equalTo('FIELD_WRONG_VALUE')) 103 ->will($this->returnValue(new stubRequestValueError('FIELD_WRONG_VALUE', array('en_EN' => 'Something wrent wrong.')))); 104 $this->validatorFilterDecorator->callDoExecute('test_value'); 105 } 106 107 /** 108 * assure that filtering a string with regular expressions works correct 109 * 110 * @test 111 * @expectedException stubFilterException 112 */ 113 public function validationFailsWithOtherErrorId() 114 { 115 $this->validatorFilterDecorator->setErrorId('foo'); 116 $this->mockValidator->expects($this->once())->method('validate')->will($this->returnValue(false)); 117 $this->mockRequestValueErrorFactory->expects($this->once()) 118 ->method('create') 119 ->with($this->equalTo('foo')) 103 120 ->will($this->returnValue(new stubRequestValueError('foo', array('en_EN' => 'Something wrent wrong.')))); 104 $this-> regexCheckFilterDecorator->callDoExecute('regexTest');121 $this->validatorFilterDecorator->callDoExecute('test_value'); 105 122 } 106 123 }
