|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* phpBB Directory extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com> |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ernadoo\phpbbdirectory\tests\controller; |
|
12
|
|
|
|
|
13
|
|
|
abstract class controller_base extends \phpbb_database_test_case |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\phpbb\auth\auth */ |
|
16
|
|
|
protected $auth; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \phpbb\config\config */ |
|
19
|
|
|
protected $config; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\DependencyInjection\ContainerInterface */ |
|
22
|
|
|
protected $container; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\phpbb\controller\helper */ |
|
25
|
|
|
protected $helper; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \phpbb\language\language */ |
|
28
|
|
|
protected $lang; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|\phpbb\template\template */ |
|
31
|
|
|
protected $template; |
|
32
|
|
|
|
|
33
|
|
|
/** @var \phpbb\user */ |
|
34
|
|
|
protected $user; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Define the extensions to be tested |
|
38
|
|
|
* |
|
39
|
|
|
* @return array vendor/name of extension(s) to test |
|
40
|
|
|
*/ |
|
41
|
|
|
static protected function setup_extensions() |
|
42
|
|
|
{ |
|
43
|
|
|
return array('ernadoo/phpbbdirectory'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setUp() |
|
47
|
|
|
{ |
|
48
|
|
|
global $cache, $phpbb_container, $phpbb_path_helper, $phpbb_extension_manager, $request, $user, $phpbb_root_path, $cron, $phpEx; |
|
49
|
|
|
global $phpbb_dispatcher, $auth, $config, $phpbb_filesystem, $template; |
|
50
|
|
|
global $table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch; |
|
51
|
|
|
|
|
52
|
|
|
parent::setUp(); |
|
53
|
|
|
|
|
54
|
|
|
$table_categories = 'phpbb_directory_cats'; |
|
55
|
|
|
$tables_comments = 'phpbb_directory_comments'; |
|
56
|
|
|
$tables_links = 'phpbb_directory_links'; |
|
57
|
|
|
$tables_votes = 'phpbb_directory_votes'; |
|
58
|
|
|
$tables_watch = 'phpbb_directory_watch'; |
|
59
|
|
|
|
|
60
|
|
|
//Let's build some deps |
|
61
|
|
|
$auth = $this->auth = $this->getMock('\phpbb\auth\auth'); |
|
62
|
|
|
|
|
63
|
|
|
$config = $this->config = new \phpbb\config\config(array()); |
|
64
|
|
|
|
|
65
|
|
|
$db = $this->db = $this->new_dbal(); |
|
66
|
|
|
|
|
67
|
|
|
$this->request = $this->getMock('\phpbb\request\request'); |
|
68
|
|
|
|
|
69
|
|
|
$this->template = $this->getMockBuilder('\phpbb\template\template')->getMock(); |
|
70
|
|
|
|
|
71
|
|
|
$request = new \phpbb_mock_request(); |
|
72
|
|
|
|
|
73
|
|
|
$symfony_request = new \phpbb\symfony_request( |
|
74
|
|
|
$request |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$phpbb_filesystem = $this->filesystem = new \phpbb\filesystem\filesystem(); |
|
78
|
|
|
|
|
79
|
|
|
$phpbb_path_helper = $this->phpbb_path_helper = new \phpbb\path_helper( |
|
80
|
|
|
$symfony_request, |
|
81
|
|
|
$this->filesystem, |
|
82
|
|
|
$request, |
|
83
|
|
|
$phpbb_root_path, |
|
84
|
|
|
$phpEx |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
|
88
|
|
|
$this->lang = new \phpbb\language\language($lang_loader); |
|
89
|
|
|
|
|
90
|
|
|
$user = $this->user = new \phpbb\user($this->lang, '\phpbb\datetime'); |
|
91
|
|
|
$this->user->timezone = new \DateTimeZone('UTC'); |
|
92
|
|
|
$this->user->lang = array( |
|
93
|
|
|
'datetime' => array(), |
|
94
|
|
|
'DATE_FORMAT' => 'm/d/Y', |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
$this->helper = $this->getMockBuilder('\phpbb\controller\helper') |
|
98
|
|
|
->disableOriginalConstructor() |
|
99
|
|
|
->getMock(); |
|
100
|
|
|
|
|
101
|
|
|
$this->helper->expects($this->any()) |
|
102
|
|
|
->method('render') |
|
103
|
|
|
->willReturnCallback(function ($template_file, $page_title = '', $status_code = 200, $display_online_list = false) { |
|
|
|
|
|
|
104
|
|
|
return new \Symfony\Component\HttpFoundation\Response($template_file, $status_code); |
|
105
|
|
|
}); |
|
106
|
|
|
$this->helper |
|
107
|
|
|
->method('route') |
|
108
|
|
|
->will($this->returnArgument(0)); |
|
109
|
|
|
|
|
110
|
|
|
$cache = $this->cache = new \phpbb_mock_cache(); |
|
111
|
|
|
|
|
112
|
|
|
$this->cache->purge(); |
|
113
|
|
|
|
|
114
|
|
|
$phpbb_dispatcher = $this->dispatcher = new \phpbb_mock_event_dispatcher(); |
|
115
|
|
|
|
|
116
|
|
|
$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher); |
|
117
|
|
|
|
|
118
|
|
|
$this->user_loader = $this->getMockBuilder('\phpbb\user_loader') |
|
119
|
|
|
->disableOriginalConstructor() |
|
120
|
|
|
->getMock(); |
|
121
|
|
|
|
|
122
|
|
|
$this->notification_helper = $this->getMockBuilder('\phpbb\notification\manager') |
|
123
|
|
|
->disableOriginalConstructor() |
|
124
|
|
|
->getMock(); |
|
125
|
|
|
|
|
126
|
|
|
$phpbb_extension_manager = new \phpbb_mock_extension_manager($phpbb_root_path); |
|
127
|
|
|
|
|
128
|
|
|
$phpbb_container = new \phpbb_mock_container_builder(); |
|
129
|
|
|
$phpbb_container->set('config', $config); |
|
130
|
|
|
$phpbb_container->set('filesystem', $phpbb_filesystem); |
|
131
|
|
|
$phpbb_container->set('path_helper', $phpbb_path_helper); |
|
132
|
|
|
$phpbb_container->set('ext.manager', $phpbb_extension_manager); |
|
133
|
|
|
$phpbb_container->set('user', $this->user); |
|
134
|
|
|
$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'); |
|
135
|
|
|
|
|
136
|
|
|
$context = new \phpbb\template\context(); |
|
137
|
|
|
$twig_extension = new \phpbb\template\twig\extension($context, $this->lang); |
|
138
|
|
|
$phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); |
|
139
|
|
|
|
|
140
|
|
|
$twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); |
|
141
|
|
|
$twig_extensions_collection->add('template.twig.extensions.phpbb'); |
|
142
|
|
|
$phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection); |
|
143
|
|
|
|
|
144
|
|
|
$phpbb_container->set('ernadoo.phpbbdirectory.core.nestedset_category', |
|
145
|
|
|
new \ernadoo\phpbbdirectory\core\nestedset_category( |
|
146
|
|
|
$this->db, |
|
147
|
|
|
new \phpbb\lock\db( |
|
148
|
|
|
'ernadoo.phpbbdirectory.table_lock.directory_cats', |
|
149
|
|
|
$this->config, |
|
150
|
|
|
$this->db |
|
151
|
|
|
), |
|
152
|
|
|
$table_categories |
|
153
|
|
|
) |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
$imagesize = $this->getMockBuilder('\FastImageSize\FastImageSize') |
|
157
|
|
|
->getMock(); |
|
158
|
|
|
|
|
159
|
|
|
$files = $this->getMockBuilder('\phpbb\files\factory') |
|
160
|
|
|
->disableOriginalConstructor() |
|
161
|
|
|
->getMock(); |
|
162
|
|
|
|
|
163
|
|
|
$phpbb_log = new \phpbb\log\log($this->db, $this->user, $this->auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
|
164
|
|
|
|
|
165
|
|
|
$this->core_link = new \ernadoo\phpbbdirectory\core\link( |
|
166
|
|
|
$this->db, |
|
167
|
|
|
$config, |
|
168
|
|
|
$this->lang, |
|
169
|
|
|
$this->template, |
|
170
|
|
|
$this->user, |
|
171
|
|
|
$this->helper, |
|
172
|
|
|
$this->request, |
|
173
|
|
|
$auth, |
|
174
|
|
|
$this->notification_helper, |
|
175
|
|
|
$this->filesystem, |
|
176
|
|
|
$imagesize, |
|
177
|
|
|
$files, |
|
178
|
|
|
$phpbb_root_path, |
|
179
|
|
|
$phpEx |
|
180
|
|
|
); |
|
181
|
|
|
$this->core_link->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
|
182
|
|
|
$this->core_link->set_path_helper($phpbb_path_helper); |
|
183
|
|
|
$this->core_link->set_extension_manager($phpbb_extension_manager); |
|
184
|
|
|
|
|
185
|
|
|
$this->core_cron = new \ernadoo\phpbbdirectory\core\cron( |
|
186
|
|
|
$this->db, |
|
187
|
|
|
$this->config, |
|
188
|
|
|
$phpbb_log, |
|
189
|
|
|
$this->user, |
|
190
|
|
|
$this->notification_helper, |
|
191
|
|
|
$this->core_link, |
|
192
|
|
|
$phpbb_root_path, |
|
193
|
|
|
$phpEx |
|
194
|
|
|
); |
|
195
|
|
|
$this->core_cron->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
|
196
|
|
|
$this->core_cron->set_path_helper($phpbb_path_helper); |
|
197
|
|
|
$this->core_cron->set_extension_manager($phpbb_extension_manager); |
|
198
|
|
|
|
|
199
|
|
|
$cron_task = new \ernadoo\phpbbdirectory\cron\task\core\prune_categorie( |
|
200
|
|
|
$this->config, |
|
201
|
|
|
$this->core_cron, |
|
202
|
|
|
$phpEx |
|
203
|
|
|
); |
|
204
|
|
|
$cron_task->set_name('ernadoo.phpbbdirectory.cron.task.core.prune_categorie'); |
|
205
|
|
|
|
|
206
|
|
|
$this->cron = $this->create_cron_manager(array($cron_task)); |
|
207
|
|
|
|
|
208
|
|
|
$this->core_categorie = new \ernadoo\phpbbdirectory\core\categorie( |
|
209
|
|
|
$db, |
|
210
|
|
|
$config, |
|
211
|
|
|
$this->lang, |
|
212
|
|
|
$this->template, |
|
213
|
|
|
$this->user, |
|
214
|
|
|
$this->helper, |
|
215
|
|
|
$this->request, |
|
216
|
|
|
$auth, |
|
217
|
|
|
$this->cron |
|
218
|
|
|
); |
|
219
|
|
|
$this->core_categorie->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
|
220
|
|
|
$this->core_categorie->set_path_helper($phpbb_path_helper); |
|
221
|
|
|
$this->core_categorie->set_extension_manager($phpbb_extension_manager); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
private function create_cron_manager($tasks) |
|
225
|
|
|
{ |
|
226
|
|
|
global $phpbb_root_path, $phpEx; |
|
227
|
|
|
|
|
228
|
|
|
return new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx); |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.