Changeset 1442
- Timestamp:
- 03/20/08 00:15:23 (2 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 2 removed
- 9 modified
-
main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php (modified) (10 diffs)
-
main/php/net/stubbles/websites/processors/stubAbstractPageProcessor.php (deleted)
-
main/php/net/stubbles/websites/processors/stubAbstractProcessor.php (modified) (2 diffs)
-
main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php (modified) (3 diffs)
-
main/php/net/stubbles/websites/processors/stubPageBasedProcessor.php (added)
-
main/php/net/stubbles/websites/rasmus/stubRasmusProcessor.php (modified) (2 diffs)
-
main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (6 diffs)
-
main/php/org/stubbles/test/FooProcessor.php (modified) (1 diff)
-
test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php (modified) (39 diffs)
-
test/php/net/stubbles/websites/processors/stubAbstractPageProcessorTestCase.php (deleted)
-
test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php (modified) (1 diff)
-
test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php
r1355 r1442 14 14 'net::stubbles::util::validators::stubPreSelectValidator', 15 15 'net::stubbles::websites::cache::stubCachableProcessor', 16 'net::stubbles::websites::processors::stubAbstractPageProcessor', 16 'net::stubbles::websites::processors::stubAbstractProcessor', 17 'net::stubbles::websites::processors::stubPageBasedProcessor', 17 18 'net::stubbles::websites::memphis::stubMemphisConfig', 18 19 'net::stubbles::websites::memphis::stubMemphisTemplate' … … 24 25 * @subpackage websites_memphis 25 26 */ 26 class stubMemphisProcessor extends stubAbstractP ageProcessor implements stubCachableProcessor27 class stubMemphisProcessor extends stubAbstractProcessor implements stubCachableProcessor, stubPageBasedProcessor 27 28 { 28 29 /** … … 44 45 */ 45 46 protected $cache; 47 /** 48 * page to display 49 * 50 * @var stubPage 51 */ 52 protected $page; 53 /** 54 * name of page to display 55 * 56 * @var string 57 */ 58 protected $pageName; 46 59 47 60 /** 48 61 * constructor 49 62 * 50 * @param stubRequest $request the current request 51 * @param stubSession $session the current session 52 * @param stubResponse $response the current response 53 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 54 * @throws stubException 55 */ 56 public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPageFactory $pageFactory) 57 { 58 parent::__construct($request, $session, $response, $pageFactory); 59 $this->config = $this->createConfig(); 63 * @param stubRequest $request the current request 64 * @param stubSession $session the current session 65 * @param stubResponse $response the current response 66 */ 67 public function __construct(stubRequest $request, stubSession $session, stubResponse $response) 68 { 69 parent::__construct($request, $session, $response); 70 $this->config = $this->createConfig(); 60 71 } 61 72 … … 68 79 { 69 80 $this->cache = $websiteCache; 81 } 82 83 /** 84 * selects the page to display with help of the page factory 85 * 86 * @param stubPageFactory $pageFactory 87 */ 88 public function selectPage(stubPageFactory $pageFactory) 89 { 90 $this->pageName = $pageFactory->getPageName($this->request); 91 $this->page = $pageFactory->getPage($this->pageName); 92 $this->session->putValue('net.stubbles.websites.lastPage', $this->pageName); 70 93 } 71 94 … … 97 120 98 121 /** 99 * does the real processing 100 * 101 * @param stubPage $page the page to process 102 * @param string $pageName name of the page to process 103 */ 104 protected function doProcess(stubPage $page, $pageName) 105 { 106 $elements = $page->getElements(); 122 * processes the request 123 */ 124 public function process() 125 { 126 $elements = $this->page->getElements(); 107 127 $prefixRequest = new stubRequestPrefixDecorator($this->request, ''); 108 128 $context = array('part' => null, 109 'page' => $ page129 'page' => $this->page 110 130 ); 111 $frameId = $this->getFrameId( $page);131 $frameId = $this->getFrameId(); 112 132 if (null !== $this->cache) { 113 $cachable = $this->processCacheVars($prefixRequest, $elements, $ pageName, $frameId, $context);114 if (true === $cachable && $this->cache->retrieve($this->request, $this->session, $this->response, $ pageName) === true) {133 $cachable = $this->processCacheVars($prefixRequest, $elements, $frameId, $context); 134 if (true === $cachable && $this->cache->retrieve($this->request, $this->session, $this->response, $this->pageName) === true) { 115 135 return; 116 136 } … … 120 140 $context['template'] = $this->template; 121 141 $this->template->readTemplatesFromInput($this->config->getFrame($frameId)); 122 $this->setTemplateVars($ page, $pageName, $frameId);142 $this->setTemplateVars($frameId); 123 143 $this->processPageElements($prefixRequest, $elements, $context); 124 144 if (null !== $this->cache) { 125 145 if (true === $cachable) { 126 $this->cache->store($this->request, $this->response, $ pageName);146 $this->cache->store($this->request, $this->response, $this->pageName); 127 147 } 128 148 … … 138 158 * @param stubRequest $prefixRequest 139 159 * @param array $elements 140 * @param string $pageName141 160 * @param string $frameId 142 161 * @param array $context 143 162 * @return bool true if page is cachable, else false 144 163 */ 145 protected function processCacheVars(stubRequest $prefixRequest, array $elements, $ pageName, $frameId, array $context)146 { 147 $this->cache->addCacheVar('page', $ pageName);164 protected function processCacheVars(stubRequest $prefixRequest, array $elements, $frameId, array $context) 165 { 166 $this->cache->addCacheVar('page', $this->pageName); 148 167 $this->cache->addCacheVar('frame', $frameId); 149 168 $this->cache->addCacheVar('variant', $this->session->getValue('net.stubbles.websites.variantmanager.variant.name', '')); … … 233 252 * helper method to get the name of the frame to use 234 253 * 235 * @param stubPage $page236 254 * @return string 237 255 */ 238 protected function getFrameId( stubPage $page)239 { 240 if ($ page->hasProperty('frame_fixed') === true && $page->getProperty('frame_fixed') === true) {241 return $ page->getProperty('frame');256 protected function getFrameId() 257 { 258 if ($this->page->hasProperty('frame_fixed') === true && $this->page->getProperty('frame_fixed') === true) { 259 return $this->page->getProperty('frame'); 242 260 } 243 261 … … 247 265 $frame = $this->session->getValue('net.stubbles.websites.memphis.frame'); 248 266 } else { 249 $frame = $ page->getProperty('frame');267 $frame = $this->page->getProperty('frame'); 250 268 } 251 269 … … 260 278 * helper method to set the template vars 261 279 * 262 * @param stubPage $page263 * @param string $pageName264 280 * @param string $frameId 265 281 */ 266 protected function setTemplateVars( stubPage $page, $pageName,$frameId)282 protected function setTemplateVars($frameId) 267 283 { 268 284 $this->template->addGlobalVar('UCUO_FRAME', $frameId); 269 $this->template->addGlobalVar('PAGE_TITLE', htmlentities($ page->getProperty('title')));270 $this->template->addGlobalVar('PAGE_NAME', $ pageName);285 $this->template->addGlobalVar('PAGE_TITLE', htmlentities($this->page->getProperty('title'))); 286 $this->template->addGlobalVar('PAGE_NAME', $this->pageName); 271 287 $this->template->addGlobalVar('VARIANT', $this->session->getValue('net.stubbles.websites.variantmanager.variant.name', '')); 272 288 $this->template->addGlobalVar('VARIANT_ALIAS', $this->session->getValue('net.stubbles.websites.variantmanager.variant.alias', '')); -
trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessor.php
r1441 r1442 38 38 protected $response; 39 39 /** 40 * the factory that creates the page instance41 *42 * @var stubPageFactory43 */44 protected $pageFactory;45 /**46 40 * the interceptor descriptor 47 41 * … … 59 53 * constructor 60 54 * 61 * @param stubRequest $request the current request 62 * @param stubSession $session the current session 63 * @param stubResponse $response the current response 64 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 55 * @param stubRequest $request the current request 56 * @param stubSession $session the current session 57 * @param stubResponse $response the current response 65 58 */ 66 public function __construct(stubRequest $request, stubSession $session, stubResponse $response , stubPageFactory $pageFactory)59 public function __construct(stubRequest $request, stubSession $session, stubResponse $response) 67 60 { 68 $this->request = $request; 69 $this->session = $session; 70 $this->response = $response; 71 $this->pageFactory = $pageFactory; 61 $this->request = $request; 62 $this->session = $session; 63 $this->response = $response; 72 64 } 73 65 -
trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php
r1231 r1442 7 7 * @subpackage websites_processors 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::processors::stubProcessorResolver'); 9 stubClassLoader::load('net::stubbles::websites::processors::stubPageBasedProcessor', 10 'net::stubbles::websites::processors::stubProcessorResolver' 11 ); 10 12 /** 11 13 * Basic abstract implementation of a processor resolver. … … 61 63 stubClassLoader::load($processorClassName); 62 64 $className = stubClassLoader::getNonQualifiedClassName($processorClassName); 63 $processor = new $className($request, $session, $response , $this->pageFactory);65 $processor = new $className($request, $session, $response); 64 66 if (($processor instanceof stubProcessor) == false) { 65 67 throw new stubProcessorException($processorClassName . ' is not an instance of ' . stubClassLoader::getFullQualifiedClassName('stubProcessor')); … … 67 69 68 70 $this->configureInterceptorDescriptor($processor); 71 72 if ($processor instanceof stubPageBasedProcessor) { 73 $processor->selectPage($this->pageFactory); 74 } 75 69 76 return $processor; 70 77 } -
trunk/src/main/php/net/stubbles/websites/rasmus/stubRasmusProcessor.php
r1248 r1442 7 7 * @subpackage websites_rasmus 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::processors::stubAbstractPageProcessor'); 9 stubClassLoader::load('net::stubbles::websites::processors::stubAbstractProcessor', 10 'net::stubbles::websites::processors::stubPageBasedProcessor' 11 ); 10 12 /** 11 13 * Processor for rasmus pages. … … 14 16 * @subpackage websites_rasmus 15 17 */ 16 class stubRasmusProcessor extends stubAbstractP ageProcessor18 class stubRasmusProcessor extends stubAbstractProcessor implements stubPageBasedProcessor 17 19 { 18 20 /** 19 * does the real processing21 * page to display 20 22 * 21 * @param stubPage $page the page to process 22 * @param string $pageName name of the page to process 23 * @var stubPage 23 24 */ 24 protected function doProcess(stubPage $page, $pageName) 25 protected $page; 26 27 /** 28 * selects the page to display with help of the page factory 29 * 30 * @param stubPageFactory $pageFactory 31 */ 32 public function selectPage(stubPageFactory $pageFactory) 25 33 { 26 $page->render($this->request, $this->session, $this->response); 34 $this->page = $pageFactory->getPage($pageFactory->getPageName($this->request)); 35 } 36 37 /** 38 * processes the request 39 */ 40 public function process() 41 { 42 $this->page->render($this->request, $this->session, $this->response); 27 43 $this->response->addHeader('X-Generator', 'Rasmus\' Template Engine :-) powered by Stubbles, http://stubbles.net/'); 28 44 } -
trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1431 r1442 11 11 'net::stubbles::lang::exceptions::stubRuntimeException', 12 12 'net::stubbles::util::stubRegistry', 13 'net::stubbles::websites::processors::stubAbstractPageProcessor', 13 'net::stubbles::websites::processors::stubAbstractProcessor', 14 'net::stubbles::websites::processors::stubPageBasedProcessor', 14 15 'net::stubbles::websites::xml::skin::stubSkinGeneratorFactory', 15 16 'net::stubbles::xml::stubXMLStreamWriterFactory', … … 22 23 * @subpackage websites_xml 23 24 */ 24 class stubXMLProcessor extends stubAbstractP ageProcessor25 class stubXMLProcessor extends stubAbstractProcessor implements stubPageBasedProcessor 25 26 { 26 27 /** … … 30 31 */ 31 32 protected $xmlGenerators = array(); 33 /** 34 * page to display 35 * 36 * @var stubPage 37 */ 38 protected $page; 39 /** 40 * name of page to display 41 * 42 * @var string 43 */ 44 protected $pageName; 32 45 33 46 /** 34 47 * constructor 35 48 * 36 * @param stubRequest $request the current request 37 * @param stubSession $session the current session 38 * @param stubResponse $response the current response 39 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 49 * @param stubRequest $request the current request 50 * @param stubSession $session the current session 51 * @param stubResponse $response the current response 40 52 */ 41 public function __construct(stubRequest $request, stubSession $session, stubResponse $response , stubPageFactory $pageFactory)53 public function __construct(stubRequest $request, stubSession $session, stubResponse $response) 42 54 { 43 parent::__construct($request, $session, $response, $pageFactory); 44 $this->pageDirPrefix = 'conf/'; 55 parent::__construct($request, $session, $response); 45 56 $this->configureXMLGenerators(); 46 57 } … … 58 69 59 70 /** 60 * does the real processing71 * selects the page to display with help of the page factory 61 72 * 62 * @param stubPage $page the page to process 63 * @param string $pageName name of the page to process 64 * @throws stubRuntimeException 73 * @param stubPageFactory $pageFactory 65 74 */ 66 protected function doProcess(stubPage $page, $pageName) 75 public function selectPage(stubPageFactory $pageFactory) 76 { 77 $pageFactory->setPagePrefix('conf/'); 78 $this->pageName = $pageFactory->getPageName($this->request); 79 $this->page = $pageFactory->getPage($this->pageName); 80 $this->session->putValue('net.stubbles.websites.lastPage', $this->pageName); 81 } 82 83 /** 84 * processes the request 85 */ 86 public function process() 67 87 { 68 88 $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); … … 71 91 } 72 92 73 $binder->bind('stubPage')->toInstance($ page);93 $binder->bind('stubPage')->toInstance($this->page); 74 94 $injector = $binder->getInjector(); 75 95 $xmlStreamWriter = $this->createXMLStreamWriter(); 76 96 $xmlStreamWriter->writeStartElement('document'); 77 $xmlStreamWriter->writeAttribute('page', $ pageName);97 $xmlStreamWriter->writeAttribute('page', $this->pageName); 78 98 $xmlSerializer = $this->createXMLSerializer(); 79 99 foreach ($this->xmlGenerators as $xmlGeneratorClassName) { … … 84 104 $xmlStreamWriter->writeEndElement(); // end document 85 105 $xslProcessor = $this->createXSLProcessor(); 86 $xslProcessor->importXSLStylesheet($this->createSkinGenerator()->generate($this->session, $ page));106 $xslProcessor->importXSLStylesheet($this->createSkinGenerator()->generate($this->session, $this->page)); 87 107 $xslProcessor->setXMLDocument($xmlStreamWriter->asDOM()); 88 108 $this->session->putValue('net.stubbles.websites.lastRequestResponseData', $xmlStreamWriter->asXML()); -
trunk/src/main/php/org/stubbles/test/FooProcessor.php
r1248 r1442 38 38 return $this->response; 39 39 } 40 41 public function getPageFactory()42 {43 return $this->pageFactory;44 }45 40 } 46 41 ?> -
trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php
r1355 r1442 119 119 * @param stubRequest $prefixRequest 120 120 * @param array $elements 121 * @param string $pageName122 121 * @param string $frameId 123 122 * @param array $context 124 123 * @return bool 125 124 */ 126 public function callProcessCacheVars(stubRequest $prefixRequest, array $elements, $ pageName, $frameId, array $context)127 { 128 return $this->processCacheVars($prefixRequest, $elements, $ pageName, $frameId, $context);125 public function callProcessCacheVars(stubRequest $prefixRequest, array $elements, $frameId, array $context) 126 { 127 return $this->processCacheVars($prefixRequest, $elements, $frameId, $context); 129 128 } 130 129 … … 144 143 * helper method to access protected method getFrameId() 145 144 * 146 * @param stubPage $page147 145 * @return string 148 146 */ 149 public function callGetFrameId( stubPage $page)150 { 151 return $this->getFrameId( $page);147 public function callGetFrameId() 148 { 149 return $this->getFrameId(); 152 150 } 153 151 /** 154 152 * helper method to access protected method setTemplateVars() 155 153 * 156 * @param stubPage $page157 * @param string $pageName158 154 * @param string $frameId 159 155 */ 160 public function callSetTemplateVars( stubPage $page, $pageName,$frameId)161 { 162 return $this->setTemplateVars($ page, $pageName, $frameId);156 public function callSetTemplateVars($frameId) 157 { 158 return $this->setTemplateVars($frameId); 163 159 } 164 160 } … … 174 170 * constructor 175 171 * 176 * @param stubRequest $request the current request 177 * @param stubSession $session the current session 178 * @param stubResponse $response the current response 179 * @param stubPageFactory $pageFactory page factory to use to read the page configuration 180 */ 181 public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPageFactory $pageFactory) 172 * @param stubRequest $request the current request 173 * @param stubSession $session the current session 174 * @param stubResponse $response the current response 175 */ 176 public function __construct(stubRequest $request, stubSession $session, stubResponse $response) 182 177 { 183 178 $this->request = $request; 184 179 $this->session = $session; 185 180 $this->response = $response; 186 $this->pageFactory = $pageFactory;187 181 } 188 182 … … 195 189 { 196 190 $this->config = $config; 197 }198 199 /**200 * helper method to call protected method doProcess()201 */202 public function callDoProcess($page, $pageName)203 {204 $this->doProcess($page, $pageName);205 191 } 206 192 } … … 274 260 $this->mockResponse = $this->getMock('stubResponse'); 275 261 $this->mockPageFactory = $this->getMock('stubPageFactory'); 276 $this->memphisProcessor = new TeststubMemphisProcessor($this->mockRequest, $this->mockSession, $this->mockResponse , $this->mockPageFactory);262 $this->memphisProcessor = new TeststubMemphisProcessor($this->mockRequest, $this->mockSession, $this->mockResponse); 277 263 $this->mockMemphisConfig = $this->getMock('TeststubMemphisConfig'); 278 264 $this->memphisProcessor->setConfig($this->mockMemphisConfig); … … 280 266 $this->memphisProcessor->setTemplate($this->mockMemphisTemplate); 281 267 $this->mockPage = $this->getMock('stubPage'); 268 $this->mockPageFactory->expects($this->any())->method('getPageName')->will($this->returnValue('index')); 282 269 $this->mockPageFactory->expects($this->any())->method('getPage')->will($this->returnValue($this->mockPage)); 270 $this->memphisProcessor->selectPage($this->mockPageFactory); 283 271 } 284 272 … … 292 280 $memphisProcessor = $this->getMock('Test2stubMemphisProcessor', 293 281 array('createTemplate', 294 'getPageName',295 282 'getFrameId', 296 283 'processCacheVars', … … 300 287 array($this->mockRequest, 301 288 $this->mockSession, 302 $this->mockResponse, 303 $this->mockPageFactory 289 $this->mockResponse 304 290 ) 305 291 ); 306 292 $memphisProcessor->setConfig($this->mockMemphisConfig); 293 $memphisProcessor->selectPage($this->mockPageFactory); 294 307 295 $memphisProcessor->expects($this->once())->method('createTemplate')->will($this->returnValue($this->mockMemphisTemplate)); 308 $memphisProcessor->expects($this->any())->method('getPageName')->will($this->returnValue('foo'));309 296 $memphisProcessor->expects($this->any())->method('getFrameId')->will($this->returnValue('bar')); 310 297 $mockPageElement = $this->getMock('stubPageElement'); … … 317 304 $this->mockResponse->expects($this->never())->method('getData'); 318 305 $this->mockResponse->expects($this->never())->method('replaceData'); 319 $memphisProcessor-> callDoProcess($this->mockPage, 'foo');306 $memphisProcessor->process(); 320 307 } 321 308 … … 329 316 $memphisProcessor = $this->getMock('Test2stubMemphisProcessor', 330 317 array('createTemplate', 331 'getPageName',332 318 'getFrameId', 333 319 'processCacheVars', … … 337 323 array($this->mockRequest, 338 324 $this->mockSession, 339 $this->mockResponse, 340 $this->mockPageFactory 325 $this->mockResponse 341 326 ) 342 327 ); 343 328 $memphisProcessor->setConfig($this->mockMemphisConfig); 329 $memphisProcessor->selectPage($this->mockPageFactory); 330 344 331 $memphisProcessor->expects($this->once())->method('createTemplate')->will($this->returnValue($this->mockMemphisTemplate)); 345 $memphisProcessor->expects($this->any())->method('getPageName')->will($this->returnValue('foo'));346 332 $memphisProcessor->expects($this->any())->method('getFrameId')->will($this->returnValue('bar')); 347 333 $mockPageElement = $this->getMock('stubPageElement'); … … 351 337 ->with($this->anything(), 352 338 $this->equalTo(array('baz' => $mockPageElement)), 353 $this->equalTo('foo'),354 339 $this->equalTo('bar')) 355 340 ->will($this->returnValue(true)); … … 363 348 $this->equalTo($this->mockSession), 364 349 $this->equalTo($this->mockResponse), 365 $this->equalTo(' foo'))350 $this->equalTo('index')) 366 351 ->will($this->returnValue(false)); 367 352 $mockCache->expects($this->once()) … … 369 354 ->with($this->equalTo($this->mockRequest), 370 355 $this->equalTo($this->mockResponse), 371 $this->equalTo(' foo'));356 $this->equalTo('index')); 372 357 $memphisProcessor->setWebsiteCache($mockCache); 373 358 $this->mockResponse->expects($this->once())->method('getData')->will($this->returnValue('$SID$SESSION_NAME$SESSION_ID')); … … 375 360 $this->mockSession->expects($this->any())->method('getName')->will($this->returnValue('name')); 376 361 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('name=idnameid')); 377 $memphisProcessor-> callDoProcess($this->mockPage, 'foo');362 $memphisProcessor->process(); 378 363 } 379 364 … … 387 372 $memphisProcessor = $this->getMock('Test2stubMemphisProcessor', 388 373 array('createTemplate', 389 'getPageName',390 374 'getFrameId', 391 375 'processCacheVars', … … 395 379 array($this->mockRequest, 396 380 $this->mockSession, 397 $this->mockResponse, 398 $this->mockPageFactory 381 $this->mockResponse 399 382 ) 400 383 ); 401 384 $memphisProcessor->setConfig($this->mockMemphisConfig); 385 $memphisProcessor->selectPage($this->mockPageFactory); 386 402 387 $memphisProcessor->expects($this->once())->method('createTemplate')->will($this->returnValue($this->mockMemphisTemplate)); 403 $memphisProcessor->expects($this->any())->method('getPageName')->will($this->returnValue('foo'));404 388 $memphisProcessor->expects($this->any())->method('getFrameId')->will($this->returnValue('bar')); 405 389 $mockPageElement = $this->getMock('stubPageElement'); … … 409 393 ->with($this->anything(), 410 394 $this->equalTo(array('baz' => $mockPageElement)), 411 $this->equalTo('foo'),412 395 $this->equalTo('bar')) 413 396 ->will($this->returnValue(false)); … … 423 406 $this->mockSession->expects($this->any())->method('getName')->will($this->returnValue('name')); 424 407 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('name=idnameid')); 425 $memphisProcessor-> callDoProcess($this->mockPage, 'foo');408 $memphisProcessor->process(); 426 409 } 427 410 … … 435 418 $memphisProcessor = $this->getMock('Test2stubMemphisProcessor', 436 419 array('createTemplate', 437 'getPageName',438 420 'getFrameId', 439 421 'processCacheVars', … … 443 425 array($this->mockRequest, 444 426 $this->mockSession, 445 $this->mockResponse, 446 $this->mockPageFactory 427 $this->mockResponse 447 428 ) 448 429 ); 449 430 $memphisProcessor->setConfig($this->mockMemphisConfig); 431 $memphisProcessor->selectPage($this->mockPageFactory); 432 450 433 $memphisProcessor->expects($this->never())->method('createTemplate'); 451 $memphisProcessor->expects($this->any())->method('getPageName')->will($this->returnValue('foo'));452 434 $memphisProcessor->expects($this->any())->method('getFrameId')->will($this->returnValue('bar')); 453 435 $mockPageElement = $this->getMock('stubPageElement'); … … 457 439 ->with($this->anything(), 458 440 $this->equalTo(array('baz' => $mockPageElement)), 459 $this->equalTo('foo'),460 441 $this->equalTo('bar')) 461 442 ->will($this->returnValue(true)); … … 470 451 $this->equalTo($this->mockSession), 471 452 $this->equalTo($this->mockResponse), 472 $this->equalTo(' foo'))453 $this->equalTo('index')) 473 454 ->will($this->returnValue(true)); 474 455 $mockCache->expects($this->never())->method('store'); … … 476 457 $this->mockResponse->expects($this->never())->method('getData'); 477 458 $this->mockResponse->expects($this->never())->method('replaceData'); 478 $memphisProcessor-> callDoProcess($this->mockPage, 'foo');459 $memphisProcessor->process(); 479 460 } 480 461 … … 515 496 $mockCache = new stubDummyWebsiteCache(); 516 497 $this->memphisProcessor->setWebsiteCache($mockCache); 517 $this->assertTrue($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), ' foo', 'bar', array()));518 $this->assertEquals(array('page' => ' foo',498 $this->assertTrue($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), 'bar', array())); 499 $this->assertEquals(array('page' => 'index', 519 500 'frame' => 'bar', 520 501 'variant' => null, … … 568 549 $mockCache = new stubDummyWebsiteCache(); 569 550 $this->memphisProcessor->setWebsiteCache($mockCache); 570 $this->assertFalse($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), ' foo', 'bar', array()));571 $this->assertEquals(array('page' => ' foo',551 $this->assertFalse($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), 'bar', array())); 552 $this->assertEquals(array('page' => 'index', 572 553 'frame' => 'bar', 573 554 'variant' => null, … … 621 602 $this->memphisProcessor->setSSL(true); 622 603 $this->memphisProcessor->setWebsiteCache($mockCache); 623 $this->assertFalse($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), ' foo', 'bar', array()));624 $this->assertEquals(array('page' => ' foo',604 $this->assertFalse($this->memphisProcessor->callProcessCacheVars($prefixRequest, array('mock1' => $mockPageElement1, 'mock2' => $mockPageElement2), 'bar', array())); 605 $this->assertEquals(array('page' => 'index', 625 606 'frame' => 'bar', 626 607 'variant' => null, … … 752 733 $this->mockMemphisConfig->expects($this->any())->method('getFrames')->will($this->returnValue(array('default'))); 753 734 $page = new stubPage(); 735 $mockPageFactory = $this->getMock('stubPageFactory'); 736 $mockPageFactory->expects($this->once())->method('getPageName')->will($this->returnValue('index')); 737 $mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($page)); 738 $this->memphisProcessor->selectPage($mockPageFactory); 754 739 $this->mockRequest->expects($this->any())->method('hasValue')->will($this->returnValue(true)); 755 740 $this->mockRequest->expects($this->exactly(3)) … … 757 742 ->will($this->onConsecutiveCalls('another', '', null)); 758 743 $this->mockSession->expects($this->never())->method('hasValue'); 759 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId( $page));760 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));761 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));744 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId()); 745 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 746 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 762 747 } 763 748 … … 770 755 { 771 756 $page = new stubPage(); 757 $mockPageFactory = $this->getMock('stubPageFactory'); 758 $mockPageFactory->expects($this->once())->method('getPageName')->will($this->returnValue('index')); 759 $mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($page)); 760 $this->memphisProcessor->selectPage($mockPageFactory); 772 761 $this->mockRequest->expects($this->any())->method('hasValue')->will($this->returnValue(false)); 773 762 $this->mockRequest->expects($this->never())->method('getValidatedValue'); … … 776 765 ->method('getValue') 777 766 ->will($this->onConsecutiveCalls('another', '', null)); 778 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId( $page));779 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));780 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));767 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId()); 768 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 769 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 781 770 } 782 771 … … 789 778 { 790 779 $page = new stubPage(); 780 $mockPageFactory = $this->getMock('stubPageFactory'); 781 $mockPageFactory->expects($this->once())->method('getPageName')->will($this->returnValue('index')); 782 $mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($page)); 783 $this->memphisProcessor->selectPage($mockPageFactory); 791 784 $this->mockRequest->expects($this->any())->method('hasValue')->will($this->returnValue(false)); 792 785 $this->mockRequest->expects($this->never())->method('getValidatedValue'); 793 786 $this->mockSession->expects($this->any())->method('hasValue')->will($this->returnValue(false)); 794 787 $this->mockSession->expects($this->never())->method('getValue'); 795 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));788 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 796 789 $page->setProperty('frame', ''); 797 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId( $page));790 $this->assertEquals('default', $this->memphisProcessor->callGetFrameId()); 798 791 $page->setProperty('frame', 'another'); 799 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId( $page));792 $this->assertEquals('another', $this->memphisProcessor->callGetFrameId()); 800 793 } 801 794 … … 810 803 $page->setProperty('frame', '404'); 811 804 $page->setProperty('frame_fixed', true); 805 $mockPageFactory = $this->getMock('stubPageFactory'); 806 $mockPageFactory->expects($this->once())->method('getPageName')->will($this->returnValue('index')); 807 $mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($page)); 808 $this->memphisProcessor->selectPage($mockPageFactory); 812 809 $this->mockRequest->expects($this->any())->method('hasValue'); 813 810 $this->mockSession->expects($this->any())->method('hasValue'); 814 $this->assertEquals('404', $this->memphisProcessor->callGetFrameId( $page));811 $this->assertEquals('404', $this->memphisProcessor->callGetFrameId()); 815 812 } 816 813 … … 822 819 public function setTemplateVars1() 823 820 { 821 $this->mockPage->expects($this->once())->method('getProperty')->will($this->returnValue('bar')); 824 822 $this->mockMemphisConfig->expects($this->any()) 825 823 ->method('getMetaTags') … … 835 833 $this->mockMemphisTemplate->expects($this->at(2)) 836 834 ->method('addGlobalVar') 837 ->with($this->equalTo('PAGE_NAME'), $this->equalTo(' baz'));835 ->with($this->equalTo('PAGE_NAME'), $this->equalTo('index')); 838 836 $this->mockMemphisTemplate->expects($this->at(3)) 839 837 ->method('addGlobalVar') … … 865 863 $this->mockSession->expects($this->any())->method('getName')->will($this->returnValue('sessionid')); 866 864 $this->mockSession->expects($this->any())->method('getId')->will($this->returnValue(313)); 867 $page = new stubPage(); 868 $page->setProperty('title', 'bar'); 869 $this->memphisProcessor->callSetTemplateVars($page, 'baz', 'foo'); 865 $this->memphisProcessor->callSetTemplateVars('foo'); 870 866 } 871 867 … … 877 873 public function setTemplateVars2() 878 874 { 875 $this->mockPage->expects($this->once())->method('getProperty')->will($this->returnValue('<bar>')); 879 876 $mockCache = $this->getMock('stubWebsiteCache'); 880 877 $this->memphisProcessor->setWebsiteCache($mockCache); … … 887 884 $this->mockMemphisTemplate->expects($this->at(1)) 888 885 ->method('addGlobalVar') 889 ->with($this->equalTo('PAGE_TITLE'), $this->equalTo(' bar'));886 ->with($this->equalTo('PAGE_TITLE'), $this->equalTo('<bar>')); 890 887 $this->mockMemphisTemplate->expects($this->at(2)) 891 888 ->method('addGlobalVar') 892 ->with($this->equalTo('PAGE_NAME'), $this->equalTo(' baz'));889 ->with($this->equalTo('PAGE_NAME'), $this->equalTo('index')); 893 890 $this->mockMemphisTemplate->expects($this->at(3)) 894 891 ->method('addGlobalVar') … … 917 914 $this->mockSession->expects($this->any())->method('getName')->will($this->returnValue('sessionid')); 918 915 $this->mockSession->expects($this->any())->method('getId')->will($this->returnValue(313)); 919 $page = new stubPage(); 920 $page->setProperty('title', 'bar'); 921 $this->memphisProcessor->callSetTemplateVars($page, 'baz', 'foo'); 916 $this->memphisProcessor->callSetTemplateVars('foo'); 922 917 } 923 918 } -
trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php
r1252 r1442 122 122 $response = $processor->getResponse(); 123 123 $this->assertSame($this->mockResponse, $response); 124 $pageFactory = $processor->getPageFactory();125 $this->assertSame($this->mockPageFactory, $pageFactory);126 124 } 127 125 -
trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php
r1426 r1442 91 91 'createXSLProcessor' 92 92 ), 93 array($this->mockRequest, $this->mockSession, $this->mockResponse , $this->mockPageFactory)93 array($this->mockRequest, $this->mockSession, $this->mockResponse) 94 94 ); 95 95 $this->mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 96 96 $this->mockXMLSerializer = $this->getMock('stubXMLSerializer'); 97 97 $this->page = new stubPage(); 98 $this->mockPageFactory->expects($this->any())->method('getPage')->will($this->returnValue($this->page)); 98 $this->mockPageFactory->expects($this->once())->method('getPageName')->will($this->returnValue('index')); 99 $this->mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($this->page)); 100 $this->mockSession->expects($this->at(0))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastPage'), $this->equalTo('index')); 101 $this->xmlProcessor->selectPage($this->mockPageFactory); 99 102 } 100 103 … … 116 119 { 117 120 stubRegistry::remove(stubBinder::REGISTRY_KEY); 118 $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false));119 $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index'));120 121 $this->xmlProcessor->expects($this->never())->method('createXMLStreamWriter'); 121 122 $this->xmlProcessor->expects($this->never())->method('createXMLSerializer'); … … 130 131 * @test 131 132 */ 132 public function defaultPage()133 public function correctPage() 133 134 { 134 $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false));135 $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index'));136 135 $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); 137 136 $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); … … 158 157 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 159 158 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 160 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 161 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 162 $this->xmlProcessor->process(); 163 } 164 165 /** 166 * assure that processing works as expected 167 * 168 * @test 169 */ 170 public function fallbackToDefaultPage() 171 { 172 $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 173 $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue(null)); 174 $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index')); 175 $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); 176 $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); 177 $this->mockXMLStreamWriter->expects($this->once())->method('writeStartElement'); 178 $this->mockXMLStreamWriter->expects($this->once())->method('writeAttribute')->with($this->equalTo('page'), $this->equalTo('index')); 179 $this->mockXMLStreamWriter->expects($this->once())->method('writeEndElement'); 180 $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 181 $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 182 $mockXMLGenerator->expects($this->exactly(3))->method('generate')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); 183 $resultXSL = new DOMDocument(); 184 $mockSkinGenerator = $this->getMock('stubSkinGenerator'); 185 $mockSkinGenerator->expects($this->once()) 186 ->method('generate') 187 ->will($this->returnValue($resultXSL)); 188 $this->xmlProcessor->expects($this->once())->method('createSkinGenerator')->will($this->returnValue($mockSkinGenerator)); 189 190 $mockXSLProcessor = $this->getMock('stubXSLProcessor'); 191 $mockXSLProcessor->expects($this->once())->method('importXSLStylesheet')->with($this->equalTo($resultXSL)); 192 $mockXSLProcessor->expects($this->once())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 193 $this->xmlProcessor->expects($this->once())->method('createXSLProcessor')->will($this->returnValue($mockXSLProcessor)); 194 195 $domDocument0 = new DOMDocument(); 196 $domDocument0->createElement('bar', 'foo'); 197 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 198 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 199 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 200 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 201 $this->xmlProcessor->process(); 202 } 203 204 /** 205 * assure that processing works as expected 206 * 207 * @test 208 */ 209 public function correctPage() 210 { 211 $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 212 $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue('baz')); 213 $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/baz')); 214 $this->mockPageFactory->expects($this->once())->method('hasPage')->will($this->returnValue(true)); 215 $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); 216 $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer)); 217 $this->mockXMLStreamWriter->expects($this->once())->method('writeStartElement'); 218 $this->mockXMLStreamWriter->expects($this->once())->method('writeAttribute')->with($this->equalTo('page'), $this->equalTo('baz')); 219 $this->mockXMLStreamWriter->expects($this->once())->method('writeEndElement'); 220 $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 221 $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 222 $mockXMLGenerator->expects($this->exactly(3))->method('generate')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); 223 $resultXSL = new DOMDocument(); 224 $mockSkinGenerator = $this->getMock('stubSkinGenerator'); 225 $mockSkinGenerator->expects($this->once()) 226 ->method('generate') 227 ->will($this->returnValue($resultXSL)); 228 $this->xmlProcessor->expects($this->once())->method('createSkinGenerator')->will($this->returnValue($mockSkinGenerator)); 229 230 $mockXSLProcessor = $this->getMock('stubXSLProcessor'); 231 $mockXSLProcessor->expects($this->once())->method('importXSLStylesheet')->with($this->equalTo($resultXSL)); 232 $mockXSLProcessor->expects($this->once())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 233 $this->xmlProcessor->expects($this->once())->method('createXSLProcessor')->will($this->returnValue($mockXSLProcessor)); 234 235 $domDocument0 = new DOMDocument(); 236 $domDocument0->createElement('bar', 'foo'); 237 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 238 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 239 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 159 $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 240 160 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 241 161 $this->xmlProcessor->process();
