Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hotfix/strategies-configurable-with-specialized-model' of

  • Loading branch information...
commit 2e6faca1f1a75557e2537a04ebb981d56e5c3820 2 parents f52be85 + be61b55
@weierophinney weierophinney authored
View
12 library/Zend/View/Strategy/FeedStrategy.php
@@ -85,25 +85,20 @@ public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
- if ($model instanceof Model\FeedModel) {
- // FeedModel found
- return $this->renderer;
- }
-
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
- return;
+ return ($model instanceof Model\FeedModel) ? $this->renderer : null;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
- return;
+ return ($model instanceof Model\FeedModel) ? $this->renderer : null;
}
$accept = $headers->get('accept');
if (($match = $accept->match('application/rss+xml, application/atom+xml')) == false) {
- return;
+ return ($model instanceof Model\FeedModel) ? $this->renderer : null;
}
if ($match->getTypeString() == 'application/rss+xml') {
@@ -116,6 +111,7 @@ public function selectRenderer(ViewEvent $e)
return $this->renderer;
}
+ return ($model instanceof Model\FeedModel) ? $this->renderer : null;
}
/**
View
21 tests/ZendTest/View/Strategy/FeedStrategyTest.php
@@ -62,6 +62,27 @@ public function testAtomAcceptHeaderSelectsFeedStrategy()
$this->assertSame($this->renderer, $result);
}
+ public function testViewModelMatchedAcceptHeaderMatchSelectsFeedStrategy()
+ {
+ $this->event->setModel(new FeedModel());
+ $request = new HttpRequest();
+ $request->getHeaders()->addHeaderLine('Accept', '*/*');
+ $this->event->setRequest($request);
+ $result = $this->strategy->selectRenderer($this->event);
+ $this->assertSame($this->renderer, $result);
+ }
+
+ public function testViewModelAcceptHeaderSelectsFeedStrategyAndSetsFeedtype()
+ {
+ $this->event->setModel(new FeedModel());
+ $request = new HttpRequest();
+ $request->getHeaders()->addHeaderLine('Accept', 'application/atom+xml');
+ $this->event->setRequest($request);
+ $result = $this->strategy->selectRenderer($this->event);
+ $this->assertSame($this->renderer, $result);
+ $this->assertSame('atom', $result->getFeedType());
+ }
+
public function testLackOfFeedModelOrAcceptHeaderDoesNotSelectFeedStrategy()
{
$result = $this->strategy->selectRenderer($this->event);
Please sign in to comment.
Something went wrong with that request. Please try again.