Fixing RequestHandlerComponent::prefers() with array input. Test case updated. Fixes #6290

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8141 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2009-04-14 13:16:25 +00:00
parent 225e5e6aa8
commit 97652231a0
2 changed files with 7 additions and 1 deletions

View file

@ -524,6 +524,7 @@ class RequestHandlerComponent extends Object {
return $this->ext;
}
$types = $type;
if (is_string($type)) {
$types = array($type);
}
@ -550,7 +551,11 @@ class RequestHandlerComponent extends Object {
return $accepts[0];
}
$accepts = array_intersect($this->__acceptTypes, $accepts);
$acceptedTypes = array();
foreach ($this->__acceptTypes as $type) {
$acceptedTypes[] = $this->mapType($type);
}
$accepts = array_intersect($acceptedTypes, $accepts);
return $accepts[0];
}
/**

View file

@ -416,6 +416,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->RequestHandler->ext = 'rss';
$this->assertEqual($this->RequestHandler->prefers(), 'rss');
$this->assertFalse($this->RequestHandler->prefers('xml'));
$this->assertEqual($this->RequestHandler->prefers(array('js', 'xml', 'xhtml')), 'xml');
$this->assertTrue($this->RequestHandler->accepts('xml'));
$_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';