1 | <?php |
||
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_extension_manager, $user, $phpbb_root_path, $phpEx; |
||
49 | global $auth, $config, $phpbb_filesystem, $template, $db, $phpbb_path_helper, $phpbb_dispatcher; |
||
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 | $this->auth = new \phpbb\auth\auth; |
||
62 | |||
63 | $this->cache = new \phpbb_mock_cache(); |
||
64 | $this->cache->purge(); |
||
65 | |||
66 | $this->config = new \phpbb\config\config(array()); |
||
67 | |||
68 | $this->db = $this->new_dbal(); |
||
69 | |||
70 | $this->filesystem = new \phpbb\filesystem\filesystem(); |
||
71 | |||
72 | $this->phpbb_path_helper = new \phpbb\path_helper( |
||
73 | new \phpbb\symfony_request(new \phpbb_mock_request()), |
||
74 | new \phpbb_mock_request(), |
||
75 | $phpbb_root_path, |
||
76 | $phpEx |
||
77 | ); |
||
78 | |||
79 | $this->lang = new \phpbb\language\language( |
||
80 | new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) |
||
81 | ); |
||
82 | |||
83 | $this->user = new \phpbb\user($this->lang, '\phpbb\datetime'); |
||
84 | |||
85 | $this->user->timezone = new \DateTimeZone('UTC'); |
||
86 | $this->user->lang = array( |
||
87 | 'datetime' => array(), |
||
88 | 'DATE_FORMAT' => 'm/d/Y', |
||
89 | ); |
||
90 | |||
91 | $this->request = $this->createMock('\phpbb\request\request'); |
||
92 | |||
93 | $this->template = $this->getMockBuilder('\phpbb\template\template')->getMock(); |
||
94 | |||
95 | $this->dispatcher = new \phpbb\event\dispatcher(new \phpbb_mock_container_builder()); |
||
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 | |||
107 | $this->helper->expects($this->any()) |
||
108 | ->method('message') |
||
109 | ->willReturnCallback(function ($message, array $parameters = array(), $title = 'INFORMATION', $code = 200) { |
||
110 | return new \Symfony\Component\HttpFoundation\Response($message, $code); |
||
111 | }); |
||
112 | |||
113 | $this->helper |
||
114 | ->method('route') |
||
115 | ->will($this->returnArgument(0)); |
||
116 | |||
117 | $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $this->dispatcher); |
||
118 | |||
119 | $this->user_loader = $this->getMockBuilder('\phpbb\user_loader') |
||
120 | ->disableOriginalConstructor() |
||
121 | ->getMock(); |
||
122 | |||
123 | $this->notification_helper = $this->getMockBuilder('\phpbb\notification\manager') |
||
124 | ->disableOriginalConstructor() |
||
125 | ->getMock(); |
||
126 | |||
127 | $this->phpbb_extension_manager = new \phpbb_mock_extension_manager($phpbb_root_path); |
||
128 | |||
129 | $phpbb_container = new \phpbb_mock_container_builder(); |
||
130 | $phpbb_container = $this->get_test_case_helpers()->set_s9e_services($phpbb_container); |
||
131 | $phpbb_container->set('config', $config); |
||
132 | $phpbb_container->set('controller.helper', $this->helper); |
||
133 | $phpbb_container->set('filesystem', $this->filesystem); |
||
134 | $phpbb_container->set('path_helper', $this->phpbb_path_helper); |
||
135 | $phpbb_container->set('ext.manager', $this->phpbb_extension_manager); |
||
136 | $phpbb_container->set('pagination', $this->pagination); |
||
137 | $phpbb_container->set('user', $this->user); |
||
138 | $phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'); |
||
139 | |||
140 | $context = new \phpbb\template\context(); |
||
141 | $twig_extension = new \phpbb\template\twig\extension($context, $this->lang); |
||
142 | $phpbb_container->set('template.twig.extensions.phpbb', $twig_extension); |
||
143 | |||
144 | $twig_extensions_collection = new \phpbb\di\service_collection($phpbb_container); |
||
145 | $twig_extensions_collection->add('template.twig.extensions.phpbb'); |
||
146 | $phpbb_container->set('template.twig.extensions.collection', $twig_extensions_collection); |
||
147 | |||
148 | $phpbb_container->set('ernadoo.phpbbdirectory.core.nestedset_category', |
||
149 | new \ernadoo\phpbbdirectory\core\nestedset_category( |
||
150 | $this->db, |
||
151 | new \phpbb\lock\db( |
||
152 | 'ernadoo.phpbbdirectory.table_lock.directory_cats', |
||
153 | $this->config, |
||
154 | $this->db |
||
155 | ), |
||
156 | $table_categories |
||
157 | ) |
||
158 | ); |
||
159 | |||
160 | $plugins = new \phpbb\di\service_collection($phpbb_container); |
||
161 | $plugins->add('core.captcha.plugins.nogd'); |
||
162 | $this->captcha_factory = new \phpbb\captcha\factory($phpbb_container,$plugins); |
||
163 | |||
164 | $phpbb_container->set('core.captcha.plugins.nogd', new \phpbb\captcha\plugins\nogd); |
||
165 | |||
166 | $imagesize = new \FastImageSize\FastImageSize; |
||
167 | |||
168 | $files = $this->getMockBuilder('\phpbb\files\factory') |
||
169 | ->disableOriginalConstructor() |
||
170 | ->getMock(); |
||
171 | |||
172 | $phpbb_log = new \phpbb\log\log($this->db, $this->user, $this->auth, $this->dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
||
173 | |||
174 | $this->core_link = new \ernadoo\phpbbdirectory\core\link( |
||
175 | $this->db, |
||
176 | $this->config, |
||
177 | $this->lang, |
||
178 | $this->template, |
||
179 | $this->user, |
||
180 | $this->helper, |
||
181 | $this->request, |
||
182 | $this->auth, |
||
183 | $this->notification_helper, |
||
184 | $this->filesystem, |
||
185 | $imagesize, |
||
186 | $files, |
||
187 | $phpbb_root_path, |
||
188 | $phpEx |
||
189 | ); |
||
190 | $this->core_link->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
||
191 | $this->core_link->set_path_helper($this->phpbb_path_helper); |
||
192 | $this->core_link->set_extension_manager($this->phpbb_extension_manager); |
||
193 | |||
194 | $this->core_cron = new \ernadoo\phpbbdirectory\core\cron( |
||
195 | $this->db, |
||
196 | $this->config, |
||
197 | $phpbb_log, |
||
198 | $this->user, |
||
199 | $this->notification_helper, |
||
200 | $this->core_link, |
||
201 | $phpbb_root_path, |
||
202 | $phpEx |
||
203 | ); |
||
204 | $this->core_cron->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
||
205 | $this->core_cron->set_path_helper($this->phpbb_path_helper); |
||
206 | $this->core_cron->set_extension_manager($this->phpbb_extension_manager); |
||
207 | |||
208 | $cron_task = new \ernadoo\phpbbdirectory\cron\task\core\prune_categorie( |
||
209 | $this->config, |
||
210 | $this->core_cron, |
||
211 | $phpEx |
||
212 | ); |
||
213 | $cron_task->set_name('ernadoo.phpbbdirectory.cron.task.core.prune_categorie'); |
||
214 | |||
215 | $this->cron = $this->create_cron_manager(array($cron_task)); |
||
216 | $phpbb_container->set('cron.manager', $this->cron); |
||
217 | |||
218 | $this->core_categorie = new \ernadoo\phpbbdirectory\core\categorie( |
||
219 | $this->db, |
||
220 | $this->config, |
||
221 | $this->lang, |
||
222 | $this->template, |
||
223 | $this->user, |
||
224 | $this->helper, |
||
225 | $this->request, |
||
226 | $this->auth, |
||
227 | $this->cron |
||
228 | ); |
||
229 | $this->core_categorie->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
||
230 | $this->core_categorie->set_path_helper($this->phpbb_path_helper); |
||
231 | $this->core_categorie->set_extension_manager($this->phpbb_extension_manager); |
||
232 | |||
233 | $this->core_comment = new \ernadoo\phpbbdirectory\core\comment( |
||
234 | $this->db, |
||
235 | $this->lang |
||
236 | ); |
||
237 | $this->core_comment->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch); |
||
238 | $this->core_comment->set_path_helper($this->phpbb_path_helper); |
||
239 | $this->core_comment->set_extension_manager($this->phpbb_extension_manager); |
||
240 | |||
241 | // Global vars |
||
242 | $auth = $this->auth; |
||
243 | $cache = $this->cache; |
||
244 | $config = $this->config; |
||
245 | $db = $this->db; |
||
246 | $phpbb_dispatcher = $this->dispatcher; |
||
247 | $phpbb_extension_manager = $this->phpbb_extension_manager; |
||
248 | $phpbb_filesystem = $this->filesystem; |
||
249 | $phpbb_path_helper = $this->phpbb_path_helper; |
||
250 | $template = $this->template; |
||
251 | $user = $this->user; |
||
252 | } |
||
253 | |||
254 | private function create_cron_manager($tasks) |
||
255 | { |
||
256 | global $phpbb_root_path, $phpEx; |
||
287 |