Changeset 4895
- Timestamp:
- 08/24/07 15:26:53 (2 years ago)
- Files:
-
- trunk/data/generator/sfPropelAdmin/default/template/templates/_edit_messages.php (modified) (1 diff)
- trunk/data/generator/sfPropelAdmin/default/template/templates/_list_messages.php (modified) (1 diff)
- trunk/lib/config/sfFactoryConfigHandler.class.php (modified) (2 diffs)
- trunk/lib/helper/AssetHelper.php (modified) (2 diffs)
- trunk/lib/helper/ValidationHelper.php (modified) (2 diffs)
- trunk/lib/request/sfConsoleRequest.class.php (modified) (1 diff)
- trunk/lib/request/sfRequest.class.php (modified) (9 diffs)
- trunk/lib/request/sfWebRequest.class.php (modified) (5 diffs)
- trunk/lib/response/sfConsoleResponse.class.php (modified) (1 diff)
- trunk/lib/response/sfResponse.class.php (modified) (5 diffs)
- trunk/lib/response/sfWebResponse.class.php (modified) (13 diffs)
- trunk/lib/util/sfContext.class.php (modified) (1 diff)
- trunk/test/unit/helper/AssetHelperTest.php (modified) (3 diffs)
- trunk/test/unit/request/sfRequestTest.php (modified) (5 diffs)
- trunk/test/unit/response/sfResponseTest.php (modified) (4 diffs)
- trunk/test/unit/response/sfWebResponseTest.php (modified) (7 diffs)
- trunk/test/unit/sfContextMock.class.php (modified) (1 diff)
- trunk/test/unit/sfWebRequestMock.class.php (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/data/generator/sfPropelAdmin/default/template/templates/_edit_messages.php
r2786 r4895 5 5 [?php foreach ($sf_request->getErrorNames() as $name): ?] 6 6 <dt>[?php echo __($labels[$name]) ?]</dt> 7 <dd>[?php echo $sf_request->getError($name) ?]</dd>7 <dd>[?php echo __($sf_request->getError($name)) ?]</dd> 8 8 [?php endforeach; ?] 9 9 </dl> trunk/data/generator/sfPropelAdmin/default/template/templates/_list_messages.php
r4622 r4895 1 [?php if ($sf_request-> getError('delete')): ?]1 [?php if ($sf_request->hasError('delete')): ?] 2 2 <div class="form-errors"> 3 3 <h2>[?php echo __('Could not delete the selected %name%', array('%name%' => '<?php echo sfInflector::humanize($this->getSingularName()) ?>')) ?]</h2> 4 4 <ul> 5 <li>[?php echo $sf_request->getError('delete') ?]</li>5 <li>[?php echo __($sf_request->getError('delete')) ?]</li> 6 6 </ul> 7 7 </div> trunk/lib/config/sfFactoryConfigHandler.class.php
r4894 r4895 111 111 112 112 // append instance initialization 113 $inits[] = sprintf(" \$this->factories['request']->initialize(\$this , sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true));113 $inits[] = sprintf(" \$this->factories['request']->initialize(\$this->factories['logger'], \$this->factories['routing'], sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true)); 114 114 break; 115 115 … … 119 119 120 120 // append instance initialization 121 $inits[] = sprintf(" \$this->factories['response']->initialize(\$this, sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 121 $inits[] = sprintf(" \$this->factories['response']->initialize(\$this->factories['logger'], sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 122 $inits[] = sprintf(" if ('HEAD' == \$this->factories['request']->getMethodName())\n { \n \$this->factories['response']->setHeaderOnly(true);\n }\n"); 122 123 break; 123 124 trunk/lib/helper/AssetHelper.php
r4885 r4895 384 384 * </code> 385 385 * 386 * <b>Note:</b> Modify the sfResponse object or the view.ymlto change, add or remove metas.386 * <b>Note:</b> Modify the view.yml or use sfWebResponse::addMeta() to change, add or remove metas. 387 387 * 388 388 * @return string XHTML compliant <meta> tag(s) 389 389 * @see include_http_metas 390 * @see sfWebResponse::addMeta() 390 391 */ 391 392 function include_metas() 392 393 { 393 foreach (sfContext::getInstance()->getResponse()->getMetas() as $name => $content) 394 { 395 echo tag('meta', array('name' => $name, 'content' => $content))."\n"; 394 $context = sfContext::getInstance(); 395 $i18n = sfConfig::get('sf_i18n') ? $context->getI18N() : null; 396 foreach ($context->getResponse()->getMetas() as $name => $content) 397 { 398 echo tag('meta', array('name' => $name, 'content' => is_null($i18n) ? $content : $i18n->__($content)))."\n"; 396 399 } 397 400 } … … 407 410 * </code> 408 411 * 409 * <b>Note:</b> Modify the sfResponse object or the view.yml to change, add or removemetas.412 * <b>Note:</b> Modify the view.yml or use sfWebResponse::addMeta() to change, add or remove HTTP metas. 410 413 * 411 414 * @return string XHTML compliant <meta> tag(s) 412 * @see include_metas 415 * @see include_metas 416 * @see sfWebResponse::addHttpMeta() 413 417 */ 414 418 function include_http_metas() trunk/lib/helper/ValidationHelper.php
r1553 r4895 30 30 $options = _parse_attributes($options); 31 31 32 $request = sfContext::getInstance()->getRequest(); 32 $context = sfContext::getInstance(); 33 $request = $context->getRequest(); 33 34 34 35 $style = $request->hasError($param_for_sf) ? '' : 'display:none;'; … … 58 59 } 59 60 60 $error = $request->getError($param_for_sf, $catalogue); 61 // translate error message if needed 62 $error = $request->getError($param_for_sf); 63 if (sfConfig::get('sf_i18n')) 64 { 65 $error = $context->getI18N()->__($error, null, $catalogue); 66 } 61 67 62 68 return content_tag('div', $prefix.$error.$suffix, $options)."\n"; trunk/lib/request/sfConsoleRequest.class.php
r3597 r4895 23 23 * Initializes this sfRequest. 24 24 * 25 * @param sfContext A sfContext instance 26 * @param array An associative array of initialization parameters 27 * @param array An associative array of initialization attributes 25 * @param sfLogger A sfLogger instance (can be null) 26 * @param sfRouting A sfRouting instance (can be null) 27 * @param array An associative array of initialization parameters 28 * @param array An associative array of initialization attributes 28 29 * 29 * @return boolean true, if initialization completes successfully, otherwise false30 * @return Boolean true, if initialization completes successfully, otherwise false 30 31 * 31 32 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 32 33 */ 33 public function initialize( $context, $parameters = array(), $attributes = array())34 public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 34 35 { 35 parent::initialize($ context, $parameters, $attributes);36 parent::initialize($logger, $routing, $parameters, $attributes); 36 37 37 38 $this->getParameterHolder()->add($_SERVER['argv']); 38 39 } 39 40 /**41 * Executes the shutdown procedure.42 *43 */44 public function shutdown()45 {46 }47 40 } trunk/lib/request/sfRequest.class.php
r4597 r4895 61 61 protected 62 62 $errors = array(), 63 $context = null, 63 $logger = null, 64 $routing = null, 64 65 $method = null, 65 66 $parameterHolder = null, … … 68 69 69 70 /** 71 * Initializes this sfRequest. 72 * 73 * @param sfLogger A sfLogger instance (can be null) 74 * @param sfRouting A sfRouting instance (can be null) 75 * @param array An associative array of initialization parameters 76 * @param array An associative array of initialization attributes 77 * 78 * @return Boolean true, if initialization completes successfully, otherwise false 79 * 80 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 81 */ 82 public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 83 { 84 $this->logger = $logger; 85 $this->routing = $routing; 86 87 // initialize parameter and attribute holders 88 $this->parameterHolder = new sfParameterHolder(); 89 $this->attributeHolder = new sfParameterHolder(); 90 91 $this->parameterHolder->add($parameters); 92 $this->attributeHolder->add($attributes); 93 } 94 95 /** 70 96 * Extracts parameter values from the request. 71 97 * … … 76 102 * be returned for its value 77 103 */ 78 public function &extractParameters($names)104 public function extractParameters($names) 79 105 { 80 106 $array = array(); 81 107 82 $parameters = &$this->parameterHolder->getAll();83 foreach ($parameters as $key => &$value)108 $parameters = $this->parameterHolder->getAll(); 109 foreach ($parameters as $key => $value) 84 110 { 85 111 if (in_array($key, $names)) 86 112 { 87 $array[$key] = &$value;113 $array[$key] = $value; 88 114 } 89 115 } … … 99 125 * @return string An error message, if the error exists, otherwise null 100 126 */ 101 public function getError($name, $catalogue = 'messages') 102 { 103 $retval = null; 104 105 if (isset($this->errors[$name])) 106 { 107 $retval = $this->errors[$name]; 108 109 // translate error message if needed 110 if (sfConfig::get('sf_i18n')) 111 { 112 $retval = $this->context->getI18N()->__($retval, null, $catalogue); 113 } 114 } 115 116 return $retval; 127 public function getError($name) 128 { 129 return isset($this->errors[$name]) ? $this->errors[$name] : null; 117 130 } 118 131 … … 168 181 public function hasErrors() 169 182 { 170 return (count($this->errors) > 0); 171 } 172 173 /** 174 * Initializes this sfRequest. 175 * 176 * @param sfContext A sfContext instance 177 * @param array An associative array of initialization parameters 178 * @param array An associative array of initialization attributes 179 * 180 * @return boolean true, if initialization completes successfully, otherwise false 181 * 182 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 183 */ 184 public function initialize($context, $parameters = array(), $attributes = array()) 185 { 186 $this->context = $context; 187 188 // initialize parameter and attribute holders 189 $this->parameterHolder = new sfParameterHolder(); 190 $this->attributeHolder = new sfParameterHolder(); 191 192 $this->parameterHolder->add($parameters); 193 $this->attributeHolder->add($attributes); 194 } 195 196 /** 197 * Retrieves the current application context. 198 * 199 * @return sfContext Current application context 200 */ 201 public function getContext() 202 { 203 return $this->context; 183 return count($this->errors) > 0; 204 184 } 205 185 … … 232 212 * @return string An error message, if the error was removed, otherwise null 233 213 */ 234 public function &removeError($name)214 public function removeError($name) 235 215 { 236 216 $retval = null; … … 238 218 if (isset($this->errors[$name])) 239 219 { 240 $retval = &$this->errors[$name];220 $retval = $this->errors[$name]; 241 221 242 222 unset($this->errors[$name]); … … 255 235 public function setError($name, $message) 256 236 { 257 if ( sfConfig::get('sf_logging_enabled'))258 { 259 $this-> context->getLogger()->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")');237 if (!is_null($this->logger)) 238 { 239 $this->logger->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")'); 260 240 } 261 241 … … 406 386 407 387 /** 408 * Executes the shutdown procedure.409 *410 */411 abstract function shutdown();412 413 /**414 388 * Overloads a given method. 415 389 * trunk/lib/request/sfWebRequest.class.php
r4892 r4895 35 35 36 36 /** 37 * Initializes this sfRequest. 38 * 39 * @param sfLogger A sfLogger instance (can be null) 40 * @param sfRouting A sfRouting instance (can be null) 41 * @param array An associative array of initialization parameters 42 * @param array An associative array of initialization attributes 43 * 44 * @return Boolean true, if initialization completes successfully, otherwise false 45 * 46 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 47 */ 48 public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 49 { 50 parent::initialize($logger, $routing, $parameters, $attributes); 51 52 if (isset($_SERVER['REQUEST_METHOD'])) 53 { 54 switch ($_SERVER['REQUEST_METHOD']) 55 { 56 case 'GET': 57 $this->setMethod(self::GET); 58 break; 59 60 case 'POST': 61 $this->setMethod(self::POST); 62 break; 63 64 case 'PUT': 65 $this->setMethod(self::PUT); 66 break; 67 68 case 'DELETE': 69 $this->setMethod(self::DELETE); 70 break; 71 72 case 'HEAD': 73 $this->setMethod(self::HEAD); 74 break; 75 76 default: 77 $this->setMethod(self::GET); 78 } 79 } 80 else 81 { 82 // set the default method 83 $this->setMethod(self::GET); 84 } 85 86 // load parameters from GET/PATH_INFO/POST 87 $this->loadParameters(); 88 } 89 90 /** 37 91 * Retrieves an array of file information. 38 92 * … … 263 317 264 318 return isset($mimeTypes[$fileType]) ? '.'.$mimeTypes[$fileType] : '.bin'; 265 }266 267 /**268 * Initializes this sfRequest.269 *270 * @param sfContext A sfContext instance271 * @param array An associative array of initialization parameters272 * @param array An associative array of initialization attributes273 *274 * @return boolean true, if initialization completes successfully, otherwise false275 *276 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request277 */278 public function initialize($context, $parameters = array(), $attributes = array())279 {280 parent::initialize($context, $parameters, $attributes);281 282 if (isset($_SERVER['REQUEST_METHOD']))283 {284 switch ($_SERVER['REQUEST_METHOD'])285 {286 case 'GET':287 $this->setMethod(self::GET);288 break;289 290 case 'POST':291 $this->setMethod(self::POST);292 break;293 294 case 'PUT':295 $this->setMethod(self::PUT);296 break;297 298 case 'DELETE':299 $this->setMethod(self::DELETE);300 break;301 302 case 'HEAD':303 $this->setMethod(self::HEAD);304 break;305 306 default:307 $this->setMethod(self::GET);308 }309 }310 else311 {312 // set the default method313 $this->setMethod(self::GET);314 }315 316 // load parameters from GET/PATH_INFO/POST317 $this->loadParameters();318 319 } 319 320 … … 724 725 725 726 /** 726 * Executes the shutdown procedure.727 *728 */729 public function shutdown()730 {731 }732 733 /**734 727 * Splits an HTTP header for the current web request. 735 728 * … … 789 782 protected function parseRoutingParameters() 790 783 { 791 $parameters = $this->context->getRouting()->parse($this->getPathInfo()); 784 if (is_null($this->routing)) 785 { 786 return; 787 } 788 789 $parameters = $this->routing->parse($this->getPathInfo()); 792 790 if (!is_null($parameters)) 793 791 { 794 792 if (!isset($parameters['module'])) 795 793 { 796 $parameters['module'] = sfConfig::get('sf_default_module' );794 $parameters['module'] = sfConfig::get('sf_default_module', 'default'); 797 795 } 798 796 799 797 if (!isset($parameters['action'])) 800 798 { 801 $parameters['action'] = sfConfig::get('sf_default_action' );799 $parameters['action'] = sfConfig::get('sf_default_action', 'index'); 802 800 } 803 801 } 804 802 else 805 803 { 806 $parameters['module'] = sfConfig::get('sf_error_404_module' );807 $parameters['action'] = sfConfig::get('sf_error_404_action' );804 $parameters['module'] = sfConfig::get('sf_error_404_module', 'default'); 805 $parameters['action'] = sfConfig::get('sf_error_404_action', 'error404'); 808 806 } 809 807 … … 839 837 } 840 838 841 if ( sfConfig::get('sf_logging_enabled'))842 { 843 $this-> context->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true))));839 if (!is_null($this->logger)) 840 { 841 $this->logger->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 844 842 } 845 843 } trunk/lib/response/sfConsoleResponse.class.php
r3250 r4895 19 19 class sfConsoleResponse extends sfResponse 20 20 { 21 /**22 * Executes the shutdown procedure.23 *24 */25 public function shutdown()26 {27 }28 21 } trunk/lib/response/sfResponse.class.php
r4597 r4895 22 22 protected 23 23 $parameterHolder = null, 24 $ context= null,24 $logger = null, 25 25 $content = ''; 26 26 … … 28 28 * Initializes this sfResponse. 29 29 * 30 * @param sfContext A sfContext instance30 * @param sfLogger A sfLogger instance (can be null) 31 31 * 32 * @return booleantrue, if initialization completes successfully, otherwise false32 * @return Boolean true, if initialization completes successfully, otherwise false 33 33 * 34 34 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 35 35 */ 36 public function initialize( $context, $parameters = array())36 public function initialize(sfLogger $logger = null, $parameters = array()) 37 37 { 38 $this-> context = $context;38 $this->logger = $logger; 39 39 40 40 $this->parameterHolder = new sfParameterHolder(); 41 41 $this->parameterHolder->add($parameters); 42 }43 44 /**45 * Retrieves the current application context.46 *47 * @return sfContext The application context48 */49 public function getContext()50 {51 return $this->context;52 42 } 53 43 … … 59 49 * @return sfResponse A sfResponse implementation instance 60 50 * 61 * @throws <b>sfFactoryException</b> If a re questimplementation instance cannot be created51 * @throws <b>sfFactoryException</b> If a response implementation instance cannot be created 62 52 */ 63 53 public static function newInstance($class) … … 98 88 public function sendContent() 99 89 { 100 if ( sfConfig::get('sf_logging_enabled'))90 if (!is_null($this->logger)) 101 91 { 102 $this-> context->getLogger()->info('{sfResponse} send content ('.strlen($this->getContent()).' o)');92 $this->logger->info('{sfResponse} send content ('.strlen($this->getContent()).' o)'); 103 93 } 104 94 … … 156 146 157 147 /** 158 * Executes the shutdown procedure.159 *160 */161 abstract function shutdown();162 163 /**164 148 * Overloads a given method. 165 149 * trunk/lib/response/sfWebResponse.class.php
r4604 r4895 31 31 * Initializes this sfWebResponse. 32 32 * 33 * @param sfContext A sfContext instance34 * 35 * @return booleantrue, if initialization completes successfully, otherwise false33 * @param sfLogger A sfLogger instance (can be null) 34 * 35 * @return Boolean true, if initialization completes successfully, otherwise false 36 36 * 37 37 * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 38 38 */ 39 public function initialize($context, $parameters = array()) 40 { 41 parent::initialize($context, $parameters); 42 43 if ('HEAD' == $context->getRequest()->getMethodName()) 44 { 45 $this->setHeaderOnly(true); 46 } 39 public function initialize(sfLogger $logger = null, $parameters = array()) 40 { 41 parent::initialize($logger, $parameters); 47 42 48 43 $this->statusTexts = array( … … 179 174 * Sets a HTTP header. 180 175 * 181 * @param string HTTP header name182 * @param string Value176 * @param string HTTP header name 177 * @param string Value (if null, remove the HTTP header) 183 178 * @param boolean Replace for the value 184 179 * … … 187 182 { 188 183 $name = $this->normalizeHeaderName($name); 184 185 if (is_null($value)) 186 { 187 $this->getParameterHolder()->remove($name, 'symfony/response/http/headers'); 188 189 return; 190 } 189 191 190 192 if ('Content-Type' == $name) … … 264 266 header($status); 265 267 266 if ( sfConfig::get('sf_logging_enabled'))267 { 268 $this-> context->getLogger()->info('{sfResponse} send status "'.$status.'"');268 if (!is_null($this->logger)) 269 { 270 $this->logger->info('{sfResponse} send status "'.$status.'"'); 269 271 } 270 272 … … 274 276 header($name.': '.$value); 275 277 276 if ( sfConfig::get('sf_logging_enabled') && $value != '')277 { 278 $this-> context->getLogger()->info('{sfResponse} send header "'.$name.'": "'.$value.'"');278 if (!is_null($this->logger) && $value != '') 279 { 280 $this->logger->info('{sfResponse} send header "'.$name.'": "'.$value.'"'); 279 281 } 280 282 } … … 292 294 } 293 295 294 if ( sfConfig::get('sf_logging_enabled'))295 { 296 $this-> context->getLogger()->info('{sfResponse} send cookie "'.$cookie['name'].'": "'.$cookie['value'].'"');296 if (!is_null($this->logger)) 297 { 298 $this->logger->info('{sfResponse} send cookie "'.$cookie['name'].'": "'.$cookie['value'].'"'); 297 299 } 298 300 } … … 415 417 416 418 /** 417 * Adds meta headers to the current web response.418 * 419 * @param string Key to replace420 * @param string Value for the replacement419 * Adds a HTTP meta header. 420 * 421 * @param string Key to replace 422 * @param string HTTP meta header value (if null, remove the HTTP meta) 421 423 * @param boolean Replace or not 422 424 */ … … 428 430 $this->setHttpHeader($key, $value, $replace); 429 431 432 if (is_null($value)) 433 { 434 $this->getParameterHolder()->remove($key, 'helper/asset/auto/httpmeta'); 435 436 return; 437 } 438 430 439 if ('Content-Type' == $key) 431 440 { … … 443 452 444 453 /** 445 * Retrieves all meta headers for the current web response.454 * Retrieves all meta headers. 446 455 * 447 456 * @return array List of meta headers … … 453 462 454 463 /** 455 * Adds a meta header to the current web response.456 * 457 * @param string Name of the header458 * @param string Meta header to be set464 * Adds a meta header. 465 * 466 * @param string Name of the header 467 * @param string Meta header value (if null, remove the meta) 459 468 * @param boolean true if it's replaceable 460 469 * @param boolean true for escaping the header … … 464 473 $key = strtolower($key); 465 474 466 if (sfConfig::get('sf_i18n')) 467 { 468 $value = $this->context->getI18N()->__($value); 469 } 470 475 if (is_null($value)) 476 { 477 $this->getParameterHolder()->remove($key, 'helper/asset/auto/meta'); 478 479 return; 480 } 481 482 // FIXME: If you use the i18n layer and escape the data here, it won't work 483 // see include_metas() in AssetHelper 471 484 if ($escape) 472 485 { … … 600 613 public function serialize() 601 614 { 602 return serialize(array($this->content, $this->statusCode, $this->statusText, $this->parameterHolder ));615 return serialize(array($this->content, $this->statusCode, $this->statusText, $this->parameterHolder, $this->cookies, $this->headerOnly)); 603 616 } 604 617 … … 610 623 $data = unserialize($serialized); 611 624 612 $this->initialize( sfContext::getInstance());613 614 $this->content = $data[0];615 $this->statusCode = $data[1];616 $this->statusText = $data[2];625 $this->initialize(); 626 627 $this->content = $data[0]; 628 $this->statusCode = $data[1]; 629 $this->statusText = $data[2]; 617 630 $this->parameterHolder = $data[3]; 618 } 619 620 /** 621 * Executes the shutdown procedure. 622 */ 623 public function shutdown() 624 { 631 $this->cookies = $data[4]; 632 $this->headerOnly = $data[5]; 625 633 } 626 634 } trunk/lib/util/sfContext.class.php
r4887 r4895 355 355 $this->getUser()->shutdown(); 356 356 $this->getStorage()->shutdown(); 357 $this->getRequest()->shutdown();358 $this->getResponse()->shutdown();359 357 $this->getRouting()->shutdown(); 360 358 trunk/test/unit/helper/AssetHelperTest.php
r4440 r4895 14 14 sfLoader::loadHelpers(array('Helper', 'Tag', 'Url', 'Asset')); 15 15 16 $t = new lime_test( 37, new lime_output_color());16 $t = new lime_test(45, new lime_output_color()); 17 17 18 18 class myRequest … … 36 36 } 37 37 38 $context = sfContext::getInstance(array('request' => 'myRequest' ));38 $context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse')); 39 39 40 40 // _compute_public_path() … … 118 118 $t->is(image_path('img.jpg', true), 'http://localhost/images/img.jpg', 'image_path() accepts a second parameter to output an absolute resource path'); 119 119 120 /* 120 // use_javascript() get_javascripts() 121 $t->diag('use_javascript() get_javascripts()'); 122 use_javascript('xmlhr'); 123 $t->is(get_javascripts(), 124 '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n", 125 'get_javascripts() returns a javascript previously added by use_javascript()'); 126 use_javascript('xmlhr', '', array('raw_name' => true)); 127 $t->is(get_javascripts(), 128 '<script type="text/javascript" src="xmlhr"></script>'."\n", 129 'use_javascript() accepts an array of options as a third parameter'); 130 use_javascript('xmlhr', '', array('absolute' => true)); 131 $t->is(get_javascripts(), 132 '<script type="text/javascript" src="http://localhost/js/xmlhr.js"></script>'."\n", 133 'use_javascript() accepts an array of options as a third parameter'); 134 use_javascript('xmlhr'); 135 use_javascript('xmlhr2'); 136 $t->is(get_javascripts(), 137 '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n".'<script type="text/javascript" src="/js/xmlhr2.js"></script>'."\n", 138 'get_javascripts() returns all the javascripts previously added by use_javascript()'); 121 139 122 // auto_discovery_link_tag() 123 $t->is(auto_discovery_link_tag(), 124 '<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />'); 125 126 $t->is(auto_discovery_link_tag('atom'), 127 '<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />'); 128 129 $t->is(auto_discovery_link_tag('rss', array('action' => 'feed')), 130 '<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />'); 131 132 $context->request = new sfWebRequest(); 133 sfConfig::set('test_sfWebRequest_relative_url_root', '/mypath'); 134 135 // auto_discovery() 136 $t->is(auto_discovery_link_tag('rss', array('action' => 'feed')), 137 '<link href="http://www.example.com/mypath" rel="alternate" title="RSS" type="application/rss+xml" />'); 138 139 $t->is(auto_discovery_link_tag('atom'), 140 '<link href="http://www.example.com/mypath" rel="alternate" title="ATOM" type="application/atom+xml" />'); 141 142 $t->is(auto_discovery_link_tag(), 143 '<link href="http://www.example.com/mypath" rel="alternate" title="RSS" type="application/rss+xml" />'); 144 145 */ 140 // use_stylesheet() get_stylesheets() 141 $t->diag('use_stylesheet() get_stylesheets()'); 142 use_stylesheet('style'); 143 $t->is(get_stylesheets(), 144 '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n", 145 'get_stylesheets() returns a stylesheet previously added by use_stylesheet()'); 146 use_stylesheet('style', '', array('raw_name' => true)); 147 $t->is(get_stylesheets(), 148 '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n", 149 'use_stylesheet() accepts an array of options as a third parameter'); 150 use_stylesheet('style', '', array('absolute' => true)); 151 $t->is(get_stylesheets(), 152 '<link rel="stylesheet" type="text/css" media="screen" href="http://localhost/css/style.css" />'."\n", 153 'use_stylesheet() accepts an array of options as a third parameter'); 154 use_stylesheet('style'); 155 use_stylesheet('style2'); 156 $t->is(get_stylesheets(), 157 '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n".'<link rel="stylesheet" type="text/css" media="screen" href="/css/style2.css" />'."\n", 158 'get_stylesheets() returns all the stylesheets previously added by use_stylesheet()'); trunk/test/unit/request/sfRequestTest.php
r4440 r4895 10 10 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 require_once($_test_dir.'/unit/sfContextMock.class.php');13 12 14 13 class myRequest extends sfRequest 15 14 { 16 function shutdown() {} 15 public function getRouting() 16 { 17 return $this->routing; 18 } 17 19 } 18 20 … … 21 23 } 22 24 23 $t = new lime_test(5 4, new lime_output_color());25 $t = new lime_test(53, new lime_output_color()); 24 26 25 $ context = sfContext::getInstance(array('routing' => 'sfNoRouting'));26 $ context->getRouting()->clearRoutes();27 $routing = new sfNoRouting(); 28 $routing->initialize(); 27 29 28 30 // ::newInstance() … … 44 46 $t->diag('->initialize()'); 45 47 $request = sfRequest::newInstance('myRequest'); 46 $t->is($request->getContext(), null, '->initialize() takes a sfContext object as its first argument'); 47 $request->initialize($context, array('foo' => 'bar')); 48 $request->initialize(null, $routing); 49 $t->is($routing, $request->getRouting(), '->initialize() takes a sfRouting object as its second argument'); 50 $request->initialize(null, $routing, array('foo' => 'bar')); 48 51 $t->is($request->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 49 50 // ->getContext()51 $t->diag('->getContext()');52 $request->initialize($context);53 $t->is($request->getContext(), $context, '->getContext() returns the current context');54 52 55 53 // ->getMethod() ->setMethod() … … 70 68 // ->extractParameters() 71 69 $t->diag('->extractParameters()'); 72 $request->initialize( $context, array('foo' => 'foo', 'bar' => 'bar'));70 $request->initialize(null, $routing, array('foo' => 'foo', 'bar' => 'bar')); 73 71 $t->is($request->extractParameters(array()), array(), '->extractParameters() returns parameters'); 74 72 $t->is($request->extractParameters(array('foo')), array('foo' => 'foo'), '->extractParameters() returns parameters for keys in its first parameter'); … … 76 74 77 75 $request = sfRequest::newInstance('myRequest'); 78 $request->initialize( $context);76 $request->initialize(null, $routing); 79 77 80 78 // ->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames trunk/test/unit/response/sfResponseTest.php
r4534 r4895 10 10 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 require_once($_test_dir.'/unit/sfContextMock.class.php');13 12 14 13 class myResponse extends sfResponse 15 14 { 16 function shutdown() {}17 15 function serialize() {} 18 16 function unserialize($serialized) {} … … 23 21 } 24 22 25 $t = new lime_test(25, new lime_output_color()); 26 27 $context = sfContext::getInstance(); 23 $t = new lime_test(23, new lime_output_color()); 28 24 29 25 // ::newInstance() … … 45 41 $t->diag('->initialize()'); 46 42 $response = sfResponse::newInstance('myResponse'); 47 $t->is($response->getContext(), null, '->initialize() takes a sfContext object as its first argument'); 48 $response->initialize($context, array('foo' => 'bar')); 43 $response->initialize(null, array('foo' => 'bar')); 49 44 $t->is($response->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 50 51 // ->getContext()52 $t->diag('->getContext()');53 $response->initialize($context);54 $t->is($response->getContext(), $context, '->getContext() returns the current context');55 45 56 46 // ->getContent() ->setContent() … … 73 63 // parameter holder proxy 74 64 require_once($_test_dir.'/unit/sfParameterHolderTest.class.php'); 65 $response = sfResponse::newInstance('myResponse'); 66 $response->initialize(); 75 67 $pht = new sfParameterHolderProxyTest($t); 76 68 $pht->launchTests($response, 'parameter'); trunk/test/unit/response/sfWebResponseTest.php
r4892 r4895 10 10 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 13 14 $t = new lime_test(72, new lime_output_color()); 12 13 $t = new lime_test(64, new lime_output_color()); 15 14 16 15 class myWebResponse extends sfWebResponse … … 27 26 } 28 27 29 $ context = sfContext::getInstance(array('routing' => 'sfNoRouting', 'request' => 'sfWebRequest', 'response' => 'myWebResponse'));30 $response = $context->response;28 $response = new myWebResponse(); 29 $response->initialize(); 31 30 32 31 // ->getStatusCode() ->setStatusCode() … … 162 161 $t->diag('->mergeProperties()'); 163 162 $response1 = sfResponse::newInstance('myWebResponse'); 164 $response1->initialize( $context);163 $response1->initialize(); 165 164 $response2 = sfResponse::newInstance('myWebResponse'); 166 $response2->initialize( $context);165 $response2->initialize(); 167 166 168 167 $response1->setHttpHeader('symfony', 'foo'); … … 178 177 $t->diag('->addStylesheet()'); 179 178 $response = sfResponse::newInstance('myWebResponse'); 180 $response->initialize( $context);179 $response->initialize(); 181 180 $response->addStylesheet('test'); 182 181 $t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/stylesheet'), '->addStylesheet() adds a new stylesheet for the response'); … … 199 198 $t->diag('->addJavascript()'); 200 199 $response = sfResponse::newInstance('myWebResponse'); 201 $response->initialize( $context);200 $response->initialize(); 202 201 $response->addJavascript('test'); 203 202 $t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/javascript'), '->addJavascript() adds a new javascript for the response'); … … 223 222 $t->diag('->setHeaderOnly() ->isHeaderOnly()'); 224 223 $response = sfResponse::newInstance('myWebResponse'); 225 $response->initialize( $context);224 $response->initialize(); 226 225 $t->is($response->isHeaderOnly(), false, '->isHeaderOnly() returns false if the content must be send to the client'); 227 226 $response->setHeaderOnly(true); … … 245 244 $t->diag('->serialize() ->unserialize()'); 246 245 $t->ok($response == unserialize(serialize($response)), 'sfWebResponse implements the Serializable interface'); 247 248 sfLoader::loadHelpers(array('Helper', 'Tag', 'Url', 'Asset'));249 $_SERVER['SCRIPT_NAME'] = '';250 251 // use and get javascript()252 $t->diag('use and get javascript from the template');253 use_javascript('xmlhr');254 $t->is(get_javascripts(),255 '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n",256 'get_javascripts() returns a javascript previously added by use_javascript()');257 use_javascript('xmlhr', '', array('raw_name' => true));258 $t->is(get_javascripts(),259 '<script type="text/javascript" src="xmlhr"></script>'."\n",260 'use_javascript() accepts an array of options as a third parameter');261 use_javascript('xmlhr', '', array('absolute' => true));262 $t->is(get_javascripts(),263 '<script type="text/javascript" src="http:///js/xmlhr.js"></script>'."\n",264 'use_javascript() accepts an array of options as a third parameter');265 use_javascript('xmlhr');266 use_javascript('xmlhr2');267 $t->is(get_javascripts(),268 '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n".'<script type="text/javascript" src="/js/xmlhr2.js"></script>'."\n",269 'get_javascripts() returns all the javascripts previously added by use_javascript()');270 271 // use and get stylesheet()272 $t->diag('use and get stylesheet from the template');273 use_stylesheet('style');274 $t->is(get_stylesheets(),275 '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n",276 'get_stylesheets() returns a stylesheet previously added by use_stylesheet()');277 use_stylesheet('style', '', array('raw_name' => true));278 $t->is(get_stylesheets(),279 '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n",280 'use_stylesheet() accepts an array of options as a third parameter');281 use_stylesheet('style', '', array('absolute' => true));282 $t->is(get_stylesheets(),283 '<link rel="stylesheet" type="text/css" media="screen" href="http:///css/style.css" />'."\n",284 'use_stylesheet() accepts an array of options as a third parameter');285 use_stylesheet('style');286 use_stylesheet('style2');287 $t->is(get_stylesheets(),288 '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n".'<link rel="stylesheet" type="text/css" media="screen" href="/css/style2.css" />'."\n",289 'get_stylesheets() returns all the stylesheets previously added by use_stylesheet()');trunk/test/unit/sfContextMock.class.php
r4892 r4895 85 85 if (method_exists($object, 'initialize')) 86 86 { 87 in_array($type, array('routing')) ? $object->initialize(null, $parameters) : $object->initialize($this, $parameters); 87 switch ($type) 88 { 89 case 'routing': 90 case 'response': 91 $object->initialize(null, $parameters); 92 break; 93 case request: 94 $object->initialize(null, $this->routing, $parameters); 95 break; 96 default: 97 $object->initialize($this, $parameters); 98 } 88 99 } 89 100 $this->$type = $object;

