Changeset 13074
- Timestamp:
- 11/17/08 20:41:55 (8 months ago)
- Files:
-
- branches/1.2/lib/request/sfWebRequest.class.php (modified) (2 diffs)
- branches/1.2/test/functional/formatTest.php (modified) (2 diffs)
- branches/1.2/test/unit/request/sfWebRequestTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/request/sfWebRequest.class.php
r13018 r13074 668 668 * Gets the request format. 669 669 * 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 671 675 * 672 676 * @return string The request format … … 676 680 if (is_null($this->format)) 677 681 { 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')); 692 683 } 693 684 branches/1.2/test/functional/formatTest.php
r11805 r13074 71 71 72 72 $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->84 73 get('/format/js')-> 85 74 isStatusCode(200)-> … … 107 96 throwsException('Exception', '/message/') 108 97 ; 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 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(3 7, new lime_output_color());13 $t = new lime_test(36, new lime_output_color()); 14 14 15 15 class myRequest extends sfWebRequest … … 94 94 $t->is($request->getRequestFormat(), 'css', '->setRequestFormat() sets the request format'); 95 95 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 103 96 // ->getFormat() ->setFormat() 104 97 $t->diag('->getFormat() ->setFormat()');

