Changeset 284

Show
Ignore:
Timestamp:
02/21/07 16:22:49 (2 years ago)
Author:
mikey
Message:

made net.stubbles.websites.processors.stubDefaultProcessorResolver more reliable against missing or wrong configuration

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/processors/stubDefaultProcessorResolver.php

    r281 r284  
    7979    public function resolve(stubRequest $request, stubSession $session) 
    8080    { 
     81        if (count($this->processors) == 0) { 
     82            throw new stubProcessorException('Configuration error: no processors have been added to the resolver.'); 
     83        } 
     84         
     85        if (isset($this->processors[$this->defaultProcessor]) == false) { 
     86            throw new stubProcessorException('Configuration error: the default processor ' . $this->defaultProcessor . ' is not set.'); 
     87        } 
     88         
    8189        if ($request->hasValue('processor') == false) { 
    8290            $paramValue = $this->defaultProcessor; 
  • trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php

    r281 r284  
    5050    { 
    5151        $this->defaultProcessorResolver = new stubDefaultProcessorResolver(); 
    52         $this->defaultProcessorResolver->addProcessor('foo', '_test.FooProcessor'); 
    53         $this->defaultProcessorResolver->addProcessor('bar', '_test.BarProcessor'); 
    54         $this->defaultProcessorResolver->addProcessor('baz', '_test.BazProcessor'); 
    55         $this->defaultProcessorResolver->setDefaultProcessor('foo'); 
    5652         
    5753        $this->mockPageFactory = new MockstubPageFactory(); 
     
    6359     
    6460    /** 
     61     * helper method to add the processors to the resolver 
     62     */ 
     63    protected function addProcessors() 
     64    { 
     65        $this->defaultProcessorResolver->addProcessor('foo', '_test.FooProcessor'); 
     66        $this->defaultProcessorResolver->addProcessor('bar', '_test.BarProcessor'); 
     67        $this->defaultProcessorResolver->addProcessor('baz', '_test.BazProcessor'); 
     68        $this->defaultProcessorResolver->setDefaultProcessor('foo'); 
     69    } 
     70     
     71    /** 
    6572     * assure that the default processor is returned and it has all required classes 
    6673     */ 
    6774    public function testDefaultProcessor() 
    6875    { 
     76        $this->addProcessors(); 
    6977        $this->mockRequest->setReturnValue('hasValue', false); 
    7078        $processor = $this->defaultProcessorResolver->resolve($this->mockRequest, $this->mockSession); 
     
    8391    public function testSelectedProcessor() 
    8492    { 
     93        $this->addProcessors(); 
    8594        $this->mockRequest->setReturnValue('hasValue', true); 
    8695        $this->mockRequest->setReturnValue('getValidatedValue', 'bar'); 
     
    100109    public function testDefaultFallbackProcessor() 
    101110    { 
     111        $this->addProcessors(); 
    102112        $this->mockRequest->setReturnValue('hasValue', true); 
    103113        $this->mockRequest->setReturnValue('getValidatedValue', null); 
     
    111121    public function testFalseProcessor() 
    112122    { 
     123        $this->addProcessors(); 
    113124        $this->mockRequest->setReturnValue('hasValue', true); 
    114125        $this->mockRequest->setReturnValue('getValidatedValue', 'baz'); 
     
    116127        $this->defaultProcessorResolver->resolve($this->mockRequest, $this->mockSession); 
    117128    } 
     129     
     130    /** 
     131     * assure that no added processors triggers an exception 
     132     */ 
     133    public function testNoProcessors() 
     134    { 
     135        $this->expectException('stubProcessorException'); 
     136        $this->defaultProcessorResolver->resolve($this->mockRequest, $this->mockSession); 
     137    } 
     138     
     139    /** 
     140     * assure that a wrong default processor triggers an exception 
     141     */ 
     142    public function testWrongDefaultProcessors() 
     143    { 
     144        $this->defaultProcessorResolver->addProcessor('foo', '_test.FooProcessor'); 
     145        $this->defaultProcessorResolver->setDefaultProcessor('bar'); 
     146        $this->expectException('stubProcessorException'); 
     147        $this->defaultProcessorResolver->resolve($this->mockRequest, $this->mockSession); 
     148    } 
    118149} 
    119150?>