Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#2400] Added integration tests
Browse files Browse the repository at this point in the history
- 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
weierophinney committed Sep 21, 2012
1 parent e34a942 commit aee52bc
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions test/Helper/UrlIntegrationTest.php
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);
}
}

0 comments on commit aee52bc

Please sign in to comment.