Fixing RequestHandlerComponent::prefers() when using extensions, fixes #4056

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6575 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-15 05:48:56 +00:00
parent 6a1cdf2138
commit 38c7dab9f5
2 changed files with 15 additions and 2 deletions

View file

@ -505,7 +505,7 @@ class RequestHandlerComponent extends Object {
function prefers($type = null) {
$this->__initializeTypes();
if ($type == null) {
if (!empty($this->ext)) {
if (empty($this->ext)) {
$accept = $this->accepts(null);
if (is_array($accept)) {
return $accept[0];
@ -515,9 +515,10 @@ class RequestHandlerComponent extends Object {
return $this->ext;
}
}
uses('set');
App::import('Core', 'Set');
$types = Set::normalize($type, false);
$accepts = array();
foreach ($types as $type) {
if ($this->accepts($type)) {
$accepts[] = $type;

View file

@ -58,6 +58,18 @@ class RequestHandlerComponentTest extends CakeTestCase {
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}
function testClientPreference() {
$this->assertNotEqual($this->RequestHandler->prefers(), 'rss');
$this->RequestHandler->ext = 'rss';
$this->assertEqual($this->RequestHandler->prefers(), 'rss');
$accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
$_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$this->RequestHandler = new RequestHandlerComponent();
$this->assertEqual($this->RequestHandler->prefers(), 'xml');
$_SERVER['HTTP_ACCEPT'] = $accept;
}
function tearDown() {
unset($this->RequestHandler);
unset($this->Controller);