Changeset 1454
- Timestamp:
- 03/23/08 01:28:05 (4 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/variantmanager/stubVariantsMap.php (modified) (18 diffs)
- trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubDummyVariant.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsMapTestCase.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/variantmanager/stubVariantsMap.php
r1301 r1454 1 1 <?php 2 2 /** 3 * VariantsMap 3 * The variants map knows all configured variants and to check validity of a 4 * variant and if a variant is enforcing. 4 5 * 5 6 * @author Niels Schelbach <niels@schlund.de> … … 15 16 ); 16 17 /** 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. 22 20 * 23 21 * @package stubbles … … 27 25 { 28 26 /** 29 * Name of the current variant configuration27 * name of the current variant configuration 30 28 * 31 29 * @var string … … 33 31 private $name; 34 32 /** 35 * Whether persistence should be used33 * switch whether persistence should be used or 36 34 * 37 35 * @var boolean … … 45 43 private $variants = array(); 46 44 /** 47 * Tree structure of the variants45 * tree structure of the variants 48 46 * 49 47 * @var stubRootVariant … … 70 68 71 69 /** 72 * Returna flat list of all variants70 * returns a flat list of all variants 73 71 * 74 72 * @return array<String,stubVariant> … … 80 78 81 79 /** 82 * Geta variant by supplying its name80 * returns a variant by supplying its name 83 81 * 84 82 * @param string $variantName … … 95 93 96 94 /** 97 * Get a list of all variants.95 * returns a list of all variants 98 96 * 99 97 * @return array<String> … … 105 103 106 104 /** 107 * Adda new variant105 * adds a new variant 108 106 * 109 107 * @param stubVariant $child … … 116 114 117 115 /** 118 * Store a variant and all of its children in the flat variant list116 * store a variant and all of its children in the flat variant list 119 117 * 120 118 * @param stubVariant $variant … … 130 128 131 129 /** 132 * Getthe name of the current variant configuration130 * returns the name of the current variant configuration 133 131 * 134 132 * @return string … … 140 138 141 139 /** 142 * Setthe name of the variant configuration140 * sets the name of the variant configuration 143 141 * 144 142 * @param string $name … … 150 148 151 149 /** 152 * check whether we should use persistence or not150 * checks whether we should use persistence or not 153 151 * 154 152 * @return boolean … … 160 158 161 159 /** 162 * set whether persistence should be used or not160 * sets whether persistence should be used or not 163 161 * 164 162 * @param boolean $usePersistence the usePersistence to set … … 204 202 205 203 /** 206 * Get a variant that enforces to be used based on the contextof the user204 * returns a variant that enforces to be used based on the session of the user 207 205 * and the current request 208 206 * … … 214 212 { 215 213 $enforcing = $this->root->getEnforcingVariant($session, $request); 216 if (null == $enforcing) {214 if (null === $enforcing || $enforcing instanceof stubRootVariant) { 217 215 return null; 218 216 } 219 217 220 if ($enforcing instanceof stubRootVariant) {221 return null;222 }223 224 218 return $enforcing; 225 219 } 226 220 227 221 /** 228 * Get the matching variant based on the current request and the context222 * returns the matching variant based on the current request and the session 229 223 * of the user 230 224 * … … 245 239 246 240 /** 247 * Checks, whether a specified variant exists241 * checks, whether a specified variant exists 248 242 * 249 243 * @param string $variantName … … 256 250 257 251 /** 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 269 253 * 270 254 * @return stubRootVariant trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubDummyVariant.php
r1231 r1454 30 30 return false; 31 31 } 32 32 33 33 /** 34 34 * check whether the variant is valid trunk/src/test/php/net/stubbles/websites/variantmanager/stubVariantsMapTestCase.php
r1269 r1454 9 9 */ 10 10 stubClassLoader::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' 12 13 ); 14 /** 15 * Enforcing variant to be used in the tests. 16 * 17 * @package stubbles 18 * @subpackage websites_variantmanager_test 19 */ 20 class 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 } 13 46 /** 14 47 * Test for net::stubbles::websites::variantmanager::stubVariantsMap. … … 158 191 159 192 /** 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 /** 160 214 * Test that no enforcing variant is returned when there is no enforcing variant set 161 215 * … … 169 223 170 224 $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)); 171 241 } 172 242
