This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better capabilities surrounding console notFoundAction
- Return a console response for non-HTTP response types; resolves comment noted in #3186
- Loading branch information
1 parent
6a3b2a1
commit c7467b4
Showing
4 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
tests/ZendTest/Mvc/View/Console/DefaultRenderingStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mvc | ||
*/ | ||
|
||
namespace ZendTest\Mvc\View\Console; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Zend\EventManager\Event; | ||
use Zend\EventManager\EventManager; | ||
use Zend\Mvc\MvcEvent; | ||
use Zend\Mvc\View\Console\DefaultRenderingStrategy; | ||
use Zend\Stdlib\Response; | ||
use Zend\View\Model; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mvc | ||
* @subpackage UnitTest | ||
*/ | ||
class DefaultRenderingStrategyTest extends TestCase | ||
{ | ||
protected $strategy; | ||
|
||
public function setUp() | ||
{ | ||
$this->strategy = new DefaultRenderingStrategy(); | ||
} | ||
|
||
public function testAttachesRendererAtExpectedPriority() | ||
{ | ||
$events = new EventManager(); | ||
$events->attachAggregate($this->strategy); | ||
$listeners = $events->getListeners(MvcEvent::EVENT_RENDER); | ||
|
||
$expectedCallback = array($this->strategy, 'render'); | ||
$expectedPriority = -10000; | ||
$found = false; | ||
foreach ($listeners as $listener) { | ||
$callback = $listener->getCallback(); | ||
if ($callback === $expectedCallback) { | ||
if ($listener->getMetadatum('priority') == $expectedPriority) { | ||
$found = true; | ||
break; | ||
} | ||
} | ||
} | ||
$this->assertTrue($found, 'Renderer not found'); | ||
} | ||
|
||
public function testCanDetachListenersFromEventManager() | ||
{ | ||
$events = new EventManager(); | ||
$events->attachAggregate($this->strategy); | ||
$this->assertEquals(1, count($events->getListeners(MvcEvent::EVENT_RENDER))); | ||
|
||
$events->detachAggregate($this->strategy); | ||
$this->assertEquals(0, count($events->getListeners(MvcEvent::EVENT_RENDER))); | ||
} | ||
|
||
public function testIgnoresNonConsoleModelNotContainingResultKeyWhenObtainingResult() | ||
{ | ||
$event = new MvcEvent(); | ||
$model = new Model\ViewModel(array('content' => 'Page not found')); | ||
$response = new Response(); | ||
$event->setResult($model); | ||
$event->setResponse($response); | ||
$this->strategy->render($event); | ||
$content = $response->getContent(); | ||
$this->assertNotContains('Page not found', $content); | ||
} | ||
} |