Development

Changeset 13074

You must first sign up to be able to contribute.

Changeset 13074

Show
Ignore:
Timestamp:
11/17/08 20:41:55 (8 months ago)
Author:
fabien
Message:

[1.2] reverted request format auto-configuration based on the Accept header (closes #4920)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/request/sfWebRequest.class.php

    r13018 r13074  
    668668   * Gets the request format. 
    669669   * 
    670    * If no format is defined by the user, it defaults to the sf_format request parameter if available. 
     670   * Here is the process to determine the format: 
     671   * 
     672   *  * format defined by the user (with setRequestFormat()) 
     673   *  * sf_format request parameter 
     674   *  * null 
    671675   * 
    672676   * @return string The request format 
     
    676680    if (is_null($this->format)) 
    677681    { 
    678       if ($this->getParameter('sf_format')) 
    679       { 
    680         $this->setRequestFormat($this->getParameter('sf_format')); 
    681       } 
    682       else 
    683       { 
    684         $acceptableContentTypes = $this->getAcceptableContentTypes(); 
    685  
    686         // skip if no acceptable content types or browsers 
    687         if (isset($acceptableContentTypes[0]) && ('text/xml' != $acceptableContentTypes[0] && 'application/xml' != $acceptableContentTypes[0])) 
    688         { 
    689           $this->setRequestFormat($this->getFormat($acceptableContentTypes[0])); 
    690         } 
    691       } 
     682      $this->setRequestFormat($this->getParameter('sf_format')); 
    692683    } 
    693684 
  • branches/1.2/test/functional/formatTest.php

    r11805 r13074  
    7171 
    7272$b-> 
    73   setHttpHeader('Accept', 'application/javascript')-> 
    74   get('/format/jsWithAccept')-> 
    75   isStatusCode(200)-> 
    76   isRequestParameter('module', 'format')-> 
    77   isRequestParameter('action', 'jsWithAccept')-> 
    78   isRequestFormat('js')-> 
    79   isResponseHeader('content-type', 'application/javascript') 
    80 ; 
    81 $b->test()->like($b->getResponse()->getContent(), '/This is a js file/', 'response content is ok'); 
    82  
    83 $b-> 
    8473  get('/format/js')-> 
    8574  isStatusCode(200)-> 
     
    10796  throwsException('Exception', '/message/') 
    10897; 
    109  
    110 $b-> 
    111   setHttpHeader('Accept', 'application/javascript')-> 
    112   getAndCheck('format', 'throwsException', null, 500)-> 
    113   isRequestFormat('js')-> 
    114   isResponseHeader('content-type', 'application/javascript')-> 
    115   throwsException('Exception', '/message/') 
    116 ; 
    117 $b->test()->like($b->getResponse()->getContent(), '/Exception/', 'response is exception template'); 
    118  
    119 $b-> 
    120   setHttpHeader('Accept', 'text/css')-> 
    121   getAndCheck('format', 'throwsNonDebugException', null, 500)-> 
    122   isRequestFormat('css')-> 
    123   isResponseHeader('content-type', 'text/css; charset=utf-8')-> 
    124   throwsException('Exception', '/message/') 
    125 ; 
    126 $b->test()->unlike($b->getResponse()->getContent(), '/Exception/', 'response is error 500 template'); 
  • branches/1.2/test/unit/request/sfWebRequestTest.php

    r13018 r13074  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(37, new lime_output_color()); 
     13$t = new lime_test(36, new lime_output_color()); 
    1414 
    1515class myRequest extends sfWebRequest 
     
    9494$t->is($request->getRequestFormat(), 'css', '->setRequestFormat() sets the request format'); 
    9595 
    96 $request->acceptableContentTypes = null; 
    97 $_SERVER['HTTP_ACCEPT'] = 'application/json'; 
    98 $request->setFormat('json', 'application/json'); 
    99 $request->setParameter('sf_format', null); 
    100 $request->setRequestFormat(null); 
    101 $t->is($request->getRequestFormat(), 'json', '->getRequestFormat() uses the Accept HTTP header to guess the format'); 
    102  
    10396// ->getFormat() ->setFormat() 
    10497$t->diag('->getFormat() ->setFormat()'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.