Changeset 1454

Show
Ignore:
Timestamp:
03/23/08 01:28:05 (4 months ago)
Author:
mikey
Message:

completed unit test for net::stubbles::websites::variantmanager::stubVariantsMap

Files:

Legend:

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

    r1301 r1454  
    11<?php 
    22/** 
    3  * VariantsMap 
     3 * The variants map knows all configured variants and to check validity of a 
     4 * variant and if a variant is enforcing. 
    45 * 
    56 * @author      Niels Schelbach <niels@schlund.de> 
     
    1516); 
    1617/** 
    17  * VariantsMap 
    18  * 
    19  * Stores all variants in two ways: 
    20  * - Flat HashMap containing all variants 
    21  * - Tree structure 
     18 * The variants map knows all configured variants and to check validity of a 
     19 * variant and if a variant is enforcing. 
    2220 * 
    2321 * @package     stubbles 
     
    2725{ 
    2826    /** 
    29      * Name of the current variant configuration 
     27     * name of the current variant configuration 
    3028     *  
    3129     * @var  string 
     
    3331    private $name; 
    3432    /** 
    35      * Whether persistence should be used 
     33     * switch whether persistence should be used or  
    3634     *  
    3735     * @var  boolean 
     
    4543    private $variants       = array(); 
    4644    /** 
    47      * Tree structure of the variants 
     45     * tree structure of the variants 
    4846     *  
    4947     * @var  stubRootVariant 
     
    7068 
    7169    /** 
    72      * Return a flat list of all variants 
     70     * returns a flat list of all variants 
    7371     *  
    7472     * @return  array<String,stubVariant> 
     
    8078 
    8179    /** 
    82      * Get a variant by supplying its name 
     80     * returns a variant by supplying its name 
    8381     *  
    8482     * @param   string           $variantName 
     
    9593 
    9694    /** 
    97      * Get a list of all variants. 
     95     * returns a list of all variants 
    9896     *  
    9997     * @return  array<String> 
     
    105103 
    106104    /** 
    107      * Add a new variant 
     105     * adds a new variant 
    108106     *  
    109107     * @param  stubVariant  $child 
     
    116114 
    117115    /** 
    118      * Store a variant and all of its children in the flat variant list 
     116     * store a variant and all of its children in the flat variant list 
    119117     *  
    120118     * @param  stubVariant  $variant 
     
    130128 
    131129    /** 
    132      * Get the name of the current variant configuration 
     130     * returns the name of the current variant configuration 
    133131     *  
    134132     * @return  string 
     
    140138 
    141139    /** 
    142      * Set the name of the variant configuration 
     140     * sets the name of the variant configuration 
    143141     *  
    144142     * @param  string  $name 
     
    150148 
    151149    /** 
    152      * check whether we should use persistence or not 
     150     * checks whether we should use persistence or not 
    153151     *  
    154152     * @return  boolean 
     
    160158 
    161159    /** 
    162      * set whether persistence should be used or not 
     160     * sets whether persistence should be used or not 
    163161     *  
    164162     * @param  boolean  $usePersistence  the usePersistence to set 
     
    204202 
    205203    /** 
    206      * Get a variant that enforces to be used based on the context of the user 
     204     * returns a variant that enforces to be used based on the session of the user 
    207205     * and the current request 
    208206     *  
     
    214212    { 
    215213        $enforcing = $this->root->getEnforcingVariant($session, $request); 
    216         if (null == $enforcing) { 
     214        if (null === $enforcing || $enforcing instanceof stubRootVariant) { 
    217215            return null; 
    218216        } 
    219217         
    220         if ($enforcing instanceof stubRootVariant) { 
    221             return null; 
    222         } 
    223          
    224218        return $enforcing; 
    225219    } 
    226220 
    227221    /** 
    228      * Get the matching variant based on the current request and the context 
     222     * returns the matching variant based on the current request and the session 
    229223     * of the user 
    230224     *  
     
    245239 
    246240    /** 
    247      * Checks, whether a specified variant exists 
     241     * checks, whether a specified variant exists 
    248242     *  
    249243     * @param   string   $variantName 
     
    256250 
    257251    /** 
    258      * Build a string representation of the enclosed variant tree. 
    259      *  
    260      * @return  string 
    261      */ 
    262     public function __toString() 
    263     { 
    264         return $this->root->toString(); 
    265     } 
    266  
    267     /** 
    268      * Get the root variant 
     252     * returns the root variant 
    269253     *  
    270254     * @return  stubRootVariant 
  • trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubDummyVariant.php

    r1231 r1454  
    3030        return false; 
    3131    } 
    32      
     32 
    3333    /** 
    3434     * check whether the variant is valid 
  • trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsMapTestCase.php

    r1269 r1454  
    99 */ 
    1010stubClassLoader::load('net::stubbles::websites::variantmanager::stubVariantsMap', 
    11                       'net::stubbles::websites::variantmanager::types::stubLeadVariant' 
     11                      'net::stubbles::websites::variantmanager::types::stubLeadVariant', 
     12                      'net::stubbles::websites::variantmanager::types::stubRequestParamVariant' 
    1213); 
     14/** 
     15 * Enforcing variant to be used in the tests. 
     16 * 
     17 * @package     stubbles 
     18 * @subpackage  websites_variantmanager_test 
     19 */ 
     20class EnforcingVariant extends stubAbstractVariant 
     21{ 
     22    /** 
     23     * check whether the variant is an enforcing variant 
     24     *  
     25     * @param   stubSession  $session  access to session 
     26     * @param   stubRequest  $request  access to request parameters 
     27     * @return  bool 
     28     */ 
     29    public function isEnforcing(stubSession $session, stubRequest $request) 
     30    { 
     31        return true; 
     32    } 
     33 
     34    /** 
     35     * check whether the variant is valid 
     36     *  
     37     * @param   stubSession  $session  access to session 
     38     * @param   stubRequest  $request  access to request parameters 
     39     * @return  bool 
     40     */ 
     41    public function isValid(stubSession $session, stubRequest $request) 
     42    { 
     43        return true; 
     44    } 
     45} 
    1346/** 
    1447 * Test for net::stubbles::websites::variantmanager::stubVariantsMap. 
     
    158191 
    159192    /** 
     193     * Test that variant is not valid 
     194     * 
     195     * @test 
     196     */ 
     197    public function invalidVariant() 
     198    { 
     199        $var = new stubRequestParamVariant(); 
     200        $var->setName('foo'); 
     201        $var->setParamName('foo'); 
     202        $this->mockRequest->expects($this->any())->method('hasValue')->will($this->onConsecutiveCalls(false, true, false)); 
     203        $var2 = clone $var; 
     204        $var2->setName('bar'); 
     205        $var->addChild($var2); 
     206        $this->variantMap->addChild($var); 
     207        $this->variantMap->addChild($this->v1); 
     208         
     209        $this->assertFalse($this->variantMap->isVariantValid('foo', $this->mockSession, $this->mockRequest)); 
     210        $this->assertFalse($this->variantMap->isVariantValid('bar', $this->mockSession, $this->mockRequest)); 
     211    } 
     212 
     213    /** 
    160214     * Test that no enforcing variant is returned when there is no enforcing variant set 
    161215     * 
     
    169223         
    170224        $this->assertNull($this->variantMap->getEnforcingVariant($this->mockSession, $this->mockRequest)); 
     225    } 
     226 
     227    /** 
     228     * Test that no enforcing variant is returned when there is no enforcing variant set 
     229     * 
     230     * @test 
     231     */ 
     232    public function enforcingVariantIsReturned() 
     233    { 
     234        $enforcingVariant = new EnforcingVariant(); 
     235        $enforcingVariant->setName('enforcing'); 
     236        $this->variantMap->addChild($this->v3); 
     237        $this->variantMap->addChild($enforcingVariant); 
     238        $this->variantMap->addChild($this->v1); 
     239         
     240        $this->assertSame($enforcingVariant, $this->variantMap->getEnforcingVariant($this->mockSession, $this->mockRequest)); 
    171241    } 
    172242