From 38c7dab9f5ccf6241721321eb4481f379e901a81 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 15 Mar 2008 05:48:56 +0000 Subject: [PATCH] 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 --- cake/libs/controller/components/request_handler.php | 5 +++-- .../controller/components/request_handler.test.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index e9f903107..cfc896d5d 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -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; diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index 74202b3ba..32eaf01f9 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -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);