This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
TestAbstract.php
189 lines (163 loc) · 5.08 KB
/
TestAbstract.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_View
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @namespace
*/
namespace ZendTest\View\Helper\Navigation;
use Zend\Navigation,
Zend\Controller,
Zend\Acl\Role,
Zend\Acl\Resource;
/**
* Base class for navigation view helper tests
*
* @category Zend
* @package Zend_View
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_View
* @group Zend_View_Helper
*/
abstract class TestAbstract extends \PHPUnit_Framework_TestCase
{
const REGISTRY_KEY = 'Zend_Navigation';
/**
* Path to files needed for test
*
* @var string
*/
protected $_files;
/**
* Class name for view helper to test
*
* @var string
*/
protected $_helperName;
/**
* View helper
*
* @var Zend_View_Helper_Navigation_HelperAbstract
*/
protected $_helper;
/**
* The first container in the config file (_files/navigation.xml)
*
* @var Zend_Navigation
*/
protected $_nav1;
/**
* The second container in the config file (_files/navigation.xml)
*
* @var Zend_Navigation
*/
protected $_nav2;
private $_oldControllerDir;
/**
* Prepares the environment before running a test
*
*/
protected function setUp()
{
$cwd = __DIR__;
// read navigation config
$this->_files = $cwd . '/_files';
$config = new \Zend\Config\Xml($this->_files . '/navigation.xml');
// setup containers from config
$this->_nav1 = new Navigation\Navigation($config->get('nav_test1'));
$this->_nav2 = new Navigation\Navigation($config->get('nav_test2'));
// setup view
$view = new \Zend\View\PhpRenderer();
$view->resolver()->addPath($cwd . '/_files/mvc/views');
// setup front
$front = Controller\Front::getInstance();
$this->_oldControllerDir = $front->getControllerDirectory('test');
$front->setControllerDirectory($cwd . '/_files/mvc/controllers');
// create helper
$this->_helper = new $this->_helperName;
$this->_helper->setView($view);
// set nav1 in helper as default
$this->_helper->setContainer($this->_nav1);
}
/**
* Cleans up the environment after running a test
*
*/
protected function tearDown()
{
$front = Controller\Front::getInstance();
if ($this->_oldControllerDir) {
$front->setControllerDirectory($this->_oldControllerDir, 'test');
} else {
$front->removeControllerDirectory('test');
}
}
/**
* Returns the contens of the exepcted $file
* @param string $file
* @return string
*/
protected function _getExpected($file)
{
return file_get_contents($this->_files . '/expected/' . $file);
}
/**
* Sets up ACL
*
* @return Zend_Acl
*/
protected function _getAcl()
{
$acl = new \Zend\Acl\Acl();
$acl->addRole(new Role\GenericRole('guest'));
$acl->addRole(new Role\GenericRole('member'), 'guest');
$acl->addRole(new Role\GenericRole('admin'), 'member');
$acl->addRole(new Role\GenericRole('special'), 'member');
$acl->addResource(new Resource\GenericResource('guest_foo'));
$acl->addResource(new Resource\GenericResource('member_foo'), 'guest_foo');
$acl->addResource(new Resource\GenericResource('admin_foo', 'member_foo'));
$acl->addResource(new Resource\GenericResource('special_foo'), 'member_foo');
$acl->allow('guest', 'guest_foo');
$acl->allow('member', 'member_foo');
$acl->allow('admin', 'admin_foo');
$acl->allow('special', 'special_foo');
$acl->allow('special', 'admin_foo', 'read');
return array('acl' => $acl, 'role' => 'special');
}
/**
* Returns translator
*
* @return Zend_Translate
*/
protected function _getTranslator()
{
$data = array(
'Page 1' => 'Side 1',
'Page 1.1' => 'Side 1.1',
'Page 2' => 'Side 2',
'Page 2.3' => 'Side 2.3',
'Page 2.3.3.1' => 'Side 2.3.3.1',
'Home' => 'Hjem',
'Go home' => 'Gå hjem'
);
return new \Zend\Translator\Translator('ArrayAdapter', $data, 'nb_NO');
}
}