This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zendframework/zendframework#2400] Added integration tests
- Test integration with MVC services, in particular console vs HTTP routers. - Required being able to override value of Console::isConsole(); added a $isConsole protected static member, and an overrideIsConsole($flag) public static method; if the flag is a boolean, its value will be returned via isConsole().
- Loading branch information
1 parent
e34a942
commit aee52bc
Showing
1 changed file
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?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_View | ||
*/ | ||
|
||
namespace ZendTest\View\Helper; | ||
|
||
use Zend\Console\Console; | ||
use Zend\ServiceManager\ServiceManager; | ||
use Zend\ServiceManager\Config as ServiceManagerConfig; | ||
use Zend\View\Helper\Url as UrlHelper; | ||
|
||
/** | ||
* url() helper test -- tests integration with MVC | ||
* | ||
* @category Zend | ||
* @package Zend_View | ||
* @subpackage UnitTests | ||
* @group Zend_View | ||
* @group Zend_View_Helper | ||
*/ | ||
class UrlIntegrationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
$config = array( | ||
'router' => array( | ||
'routes' => array( | ||
'test' => array( | ||
'type' => 'Literal', | ||
'options' => array( | ||
'route' => '/test', | ||
'defaults' => array( | ||
'controller' => 'Test\Controller\Test', | ||
), | ||
), | ||
), | ||
), | ||
), | ||
'console' => array( | ||
'router' => array( | ||
'routes' => array( | ||
'test' => array( | ||
'type' => 'Simple', | ||
'options' => array( | ||
'route' => 'test this', | ||
'defaults' => array( | ||
'controller' => 'Test\Controller\TestConsole', | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
$serviceConfig = array( | ||
'invokables' => array( | ||
'SharedEventManager' => 'Zend\EventManager\SharedEventManager', | ||
'DispatchListener' => 'Zend\Mvc\DispatchListener', | ||
'RouteListener' => 'Zend\Mvc\RouteListener', | ||
), | ||
'factories' => array( | ||
'Application' => 'Zend\Mvc\Service\ApplicationFactory', | ||
'EventManager' => 'Zend\Mvc\Service\EventManagerFactory', | ||
'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory', | ||
'Request' => 'Zend\Mvc\Service\RequestFactory', | ||
'Response' => 'Zend\Mvc\Service\ResponseFactory', | ||
'Router' => 'Zend\Mvc\Service\RouterFactory', | ||
'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory', | ||
'HttpRouter' => 'Zend\Mvc\Service\RouterFactory', | ||
'ViewManager' => 'Zend\Mvc\Service\ViewManagerFactory', | ||
'ViewResolver' => 'Zend\Mvc\Service\ViewResolverFactory', | ||
'ViewTemplateMapResolver' => 'Zend\Mvc\Service\ViewTemplateMapResolverFactory', | ||
'ViewTemplatePathStack' => 'Zend\Mvc\Service\ViewTemplatePathStackFactory', | ||
), | ||
'shared' => array( | ||
'EventManager' => false, | ||
), | ||
); | ||
$serviceConfig = new ServiceManagerConfig($serviceConfig); | ||
|
||
$this->serviceManager = new ServiceManager($serviceConfig); | ||
$this->serviceManager->setService('Config', $config); | ||
$this->serviceManager->setAlias('Configuration', 'Config'); | ||
} | ||
|
||
public function testUrlHelperWorksUnderNormalHttpParadigms() | ||
{ | ||
Console::overrideIsConsole(false); | ||
$this->serviceManager->get('Application')->bootstrap(); | ||
$request = $this->serviceManager->get('Request'); | ||
$this->assertInstanceOf('Zend\Http\Request', $request); | ||
$viewHelpers = $this->serviceManager->get('ViewHelperManager'); | ||
$urlHelper = $viewHelpers->get('url'); | ||
$test = $urlHelper('test'); | ||
$this->assertEquals('/test', $test); | ||
} | ||
|
||
public function testUrlHelperWorksWithForceCanonicalFlag() | ||
{ | ||
Console::overrideIsConsole(false); | ||
$this->serviceManager->get('Application')->bootstrap(); | ||
$request = $this->serviceManager->get('Request'); | ||
$this->assertInstanceOf('Zend\Http\Request', $request); | ||
$request->setUri('http://example.com/test'); | ||
$viewHelpers = $this->serviceManager->get('ViewHelperManager'); | ||
$urlHelper = $viewHelpers->get('url'); | ||
$test = $urlHelper('test', array(), array('force_canonical' => true)); | ||
$this->assertEquals('/test', $test); | ||
} | ||
|
||
public function testUrlHelperUnderConsoleParadigmShouldReturnHttpRoutes() | ||
{ | ||
Console::overrideIsConsole(true); | ||
$this->serviceManager->get('Application')->bootstrap(); | ||
$request = $this->serviceManager->get('Request'); | ||
$this->assertInstanceOf('Zend\Console\Request', $request); | ||
$viewHelpers = $this->serviceManager->get('ViewHelperManager'); | ||
$urlHelper = $viewHelpers->get('url'); | ||
$test = $urlHelper('test'); | ||
$this->assertEquals('/test', $test); | ||
} | ||
} |