forked from zendframework/zendframework
/
UrlIntegrationTest.php
130 lines (123 loc) · 5.53 KB
/
UrlIntegrationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
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
*
* @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',
'SendResponseListener' => 'Zend\Mvc\SendResponseListener'
),
'factories' => array(
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
'ConsoleViewManager' => 'Zend\Mvc\Service\ConsoleViewManagerFactory',
'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',
'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory',
'RoutePluginManager' => 'Zend\Mvc\Service\RoutePluginManagerFactory',
'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);
$router = $this->serviceManager->get('Router');
$router->setRequestUri($request->getUri());
$request->setUri('http://example.com/test');
$viewHelpers = $this->serviceManager->get('ViewHelperManager');
$urlHelper = $viewHelpers->get('url');
$test = $urlHelper('test', array(), array('force_canonical' => true));
$this->assertContains('/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);
}
}