Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 1157
0.00% covered (danger)
0.00%
0 / 35
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functional_feed_test
0.00% covered (danger)
0.00%
0 / 1157
0.00% covered (danger)
0.00%
0 / 35
5256
0.00% covered (danger)
0.00%
0 / 1
 setUp
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 test_setup_config_before_state
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
2
 test_dump_board_state
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
2
 test_setup_forums
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 1
2
 test_setup_config_after_forums
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_empty
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_exclude_topic
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_disabled
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_exclude
0.00% covered (danger)
0.00%
0 / 58
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_news_topics
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_news_admin
0.00% covered (danger)
0.00%
0 / 71
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_news_guest
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_sub_forum_topic
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_sub_forum
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_softdelete_post
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 test_softdelete_post
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_softdeleted_post_admin
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_softdeleted_post_guest
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
2
 test_softdelete_topic
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_softdeleted_topic_admin
0.00% covered (danger)
0.00%
0 / 63
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_softdeleted_topic_guest
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_unapproved_post
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_unapproved_post_admin
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_unapproved_post_disapprove_user
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_unapproved_topic
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_unapproved_topic_admin
0.00% covered (danger)
0.00%
0 / 60
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_unapproved_topic_disapprove_user
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_attachment_topic
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_attachment_admin
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_attachment_guest
0.00% covered (danger)
0.00%
0 / 94
0.00% covered (danger)
0.00%
0 / 1
2
 test_create_missing_attachment_post
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 test_feeds_missing_attachment_admin
0.00% covered (danger)
0.00%
0 / 75
0.00% covered (danger)
0.00%
0 / 1
2
 assert_feeds
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
182
 assert_feed
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
240
 load_ids
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 1
156
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @group functional
16*/
17class phpbb_functional_feed_test extends phpbb_functional_test_case
18{
19    protected $data = array();
20
21    static public $init_values = array();
22
23    protected function setUp(): void
24    {
25        parent::setUp();
26
27        $this->setBackupStaticPropertiesExcludeList([
28            'phpbb_functional_feed_test' => ['init_values'],
29        ]);
30
31        $this->purge_cache();
32    }
33
34    public function test_setup_config_before_state()
35    {
36        $this->login();
37        $this->admin_login();
38
39        $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
40
41        $form = $crawler->selectButton('Submit')->form();
42        $values = $form->getValues();
43
44        self::$init_values['post_base_items'] = (int) $values['config[feed_limit_post]'];
45        self::$init_values['topic_base_items'] = (int) $values['config[feed_limit_topic]'];
46
47        // Enable all feeds
48        $values['config[feed_enable]'] = 1;
49        $values['config[feed_forum]'] = 1;
50        $values['config[feed_item_statistics]'] = 1;
51        $values['config[feed_overall]'] = 1;
52        $values['config[feed_overall_forums]'] = 1;
53        $values['config[feed_topic]'] = 1;
54        $values['config[feed_topics_active]'] = 1;
55        $values['config[feed_topics_new]'] = 1;
56
57        $form->setValues($values);
58
59        $crawler = self::submit($form);
60        self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
61
62        // Disable showing unapproved posts to users
63        $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=features");
64        $form = $crawler->selectButton('Submit')->form();
65        $form->setValues(['config[display_unapproved_posts]' => 0]);
66        $crawler = self::submit($form);
67        self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
68
69        // Special config (Guest can't see attachments)
70        $this->add_lang('acp/permissions');
71
72        $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1");
73        self::assertStringContainsString($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
74
75        $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
76        $form['setting[1][0][u_download]']->select(-1);
77
78        $crawler = self::submit($form);
79        self::assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text());
80    }
81
82    public function test_dump_board_state()
83    {
84        $crawler = self::request('GET', 'app.php/feed/forums', array(), false);
85        self::assert_response_xml();
86        self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count();
87
88        $crawler = self::request('GET', 'app.php/feed/overall', array(), false);
89        self::assert_response_xml();
90        self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count();
91
92        $crawler = self::request('GET', 'app.php/feed/topics', array(), false);
93        self::assert_response_xml();
94        self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count();
95
96        $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false);
97        self::assert_response_xml();
98        self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
99
100        $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false);
101        self::assert_response_xml();
102        self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
103
104        $this->login();
105
106        $crawler = self::request('GET', 'app.php/feed/forums', array(), false);
107        self::assert_response_xml();
108        self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count();
109
110        $crawler = self::request('GET', 'app.php/feed/overall', array(), false);
111        self::assert_response_xml();
112        self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count();
113
114        $crawler = self::request('GET', 'app.php/feed/topics', array(), false);
115        self::assert_response_xml();
116        self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count();
117
118        $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false);
119        self::assert_response_xml();
120        self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
121
122        $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false);
123        self::assert_response_xml();
124        self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
125    }
126
127    public function test_setup_forums()
128    {
129        $this->login();
130        $this->admin_login();
131        $this->create_user('disapprove_user');
132        $this->add_user_group('NEWLY_REGISTERED', array('disapprove_user'));
133
134        $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
135        $form = $crawler->selectButton('addforum')->form(array(
136            'forum_name'    => 'Feeds #1',
137        ));
138        $crawler = self::submit($form);
139        $form = $crawler->selectButton('update')->form(array(
140            'forum_perm_from'    => 2,
141        ));
142        self::submit($form);
143
144        $this->load_ids(array(
145            'forums' => array(
146                'Feeds #1',
147            ),
148        ));
149
150        // 'Feeds #1.1' is a sub-forum of 'Feeds #1'
151        $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$this->data['forums']['Feeds #1']}");
152        $form = $crawler->selectButton('addforum')->form(array(
153            'forum_name'    => 'Feeds #1.1',
154        ));
155        $crawler = self::submit($form);
156        $form = $crawler->selectButton('update')->form(array(
157            'forum_perm_from'    => 2,
158        ));
159        self::submit($form);
160
161        // 'Feeds #news' will be used for feed.php?mode=news
162        $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
163        $form = $crawler->selectButton('addforum')->form(array(
164            'forum_name'    => 'Feeds #news',
165        ));
166        $crawler = self::submit($form);
167        $form = $crawler->selectButton('update')->form(array(
168            'forum_perm_from'    => 2,
169        ));
170        self::submit($form);
171
172        // 'Feeds #exclude' will not be displayed on app.php/feed/forums
173        $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
174        $form = $crawler->selectButton('addforum')->form(array(
175            'forum_name'    => 'Feeds #exclude',
176        ));
177        $crawler = self::submit($form);
178        $form = $crawler->selectButton('update')->form(array(
179            'forum_perm_from'    => 2,
180        ));
181        self::submit($form);
182    }
183
184    public function test_setup_config_after_forums()
185    {
186        $this->login();
187        $this->admin_login();
188
189        $this->load_ids(array(
190            'forums' => array(
191                'Feeds #news',
192                'Feeds #exclude',
193            ),
194        ));
195
196        $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
197
198        $form = $crawler->selectButton('Submit')->form();
199
200        // News/Exclude's forums config
201        $form['feed_news_id']->select(array($this->data['forums']['Feeds #news']));
202        $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude']));
203
204        $crawler = self::submit($form);
205        self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
206    }
207
208    public function test_feeds_empty()
209    {
210        $this->load_ids(array(
211            'forums' => array(
212                'Feeds #1',
213                'Feeds #1.1',
214            ),
215        ));
216
217        // Excluded forums (and topics under them) shouldn't be displayed in feeds
218        $this->assert_feeds(array(
219            'f' => array(
220                array(
221                    'id' => $this->data['forums']['Feeds #1'],
222                    'nb_entries' => 0,
223                ),
224                array(
225                    'id' => $this->data['forums']['Feeds #1.1'],
226                    'nb_entries' => 0,
227                ),
228            ),
229            'forums' => array(
230                array(
231                    'nb_entries' => 3,
232                    'xpath' => array(
233                        '//entry/category[@label="Feeds #exclude"]' => 0,
234                    ),
235                ),
236            ),
237            'news' => array(
238                array(
239                    'nb_entries' => 0,
240                ),
241            ),
242        ), 'admin');
243    }
244
245    public function test_create_exclude_topic()
246    {
247        $this->login();
248        $this->load_ids(array(
249            'forums' => array(
250                'Feeds #exclude',
251            ),
252        ));
253
254        $post = $this->create_topic($this->data['forums']['Feeds #exclude'], 'Feeds #exclude - Topic #1', 'This is a test topic posted by the testing framework.');
255        $this->data['topics']['Feeds #exclude - Topic #1'] = (int) $post['topic_id'];
256    }
257
258    public function test_feeds_disabled()
259    {
260        $this->login();
261        $this->admin_login();
262
263        // Disable feeds in ACP
264        $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
265        $form = $crawler->selectButton('Submit')->form();
266        $crawler = self::submit($form, ['config[feed_enable]' => 0]);
267        self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
268
269        // Assert that feeds aren't available
270        $crawler = self::request('GET', 'app.php/feed/overall', array(), false);
271        self::assert_response_status_code(404);
272        $this->assertContainsLang('NO_FEED_ENABLED', $crawler->text());
273
274        // Enable feeds again in ACP
275        $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
276        $form = $crawler->selectButton('Submit')->form();
277        $crawler = self::submit($form, ['config[feed_enable]' => 1]);
278        self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
279    }
280
281    public function test_feeds_exclude()
282    {
283        $this->load_ids(array(
284            'forums' => array(
285                'Feeds #exclude',
286            ),
287            'topics' => array(
288                'Feeds #exclude - Topic #1',
289            ),
290        ));
291
292        // Assert that feeds aren't available for excluded forums
293        $this->assert_feeds(array(
294            'f' => array(
295                array(
296                    'id' => $this->data['forums']['Feeds #exclude'],
297                    'contents_lang' => array('NO_FEED'),
298                    'invalid' => true,
299                    'response_code' => 404,
300                ),
301            ),
302            't' => array(
303                array(
304                    'id' => $this->data['topics']['Feeds #exclude - Topic #1'],
305                    'contents_lang' => array('NO_FEED'),
306                    'invalid' => true,
307                    'response_code' => 404,
308                ),
309            ),
310            'overall' => array(
311                array(
312                    'nb_entries' => 0,
313                    'xpath' => array(
314                        '//entry/title[contains(., "#exclude")]' => 0,
315                    ),
316                ),
317            ),
318            'topics' => array(
319                array(
320                    'nb_entries' => 0,
321                    'xpath' => array(
322                        '//entry/title[contains(., "#exclude")]' => 0,
323                    ),
324                ),
325            ),
326            'topics_new' => array(
327                array(
328                    'nb_entries' => 0,
329                    'xpath' => array(
330                        '//entry/title[contains(., "#exclude")]' => 0,
331                    ),
332                ),
333            ),
334            'topics_active' => array(
335                array(
336                    'nb_entries' => 0,
337                    'xpath' => array(
338                        '//entry/title[contains(., "#exclude")]' => 0,
339                    ),
340                ),
341            ),
342        ), 'admin');
343    }
344
345    public function test_create_news_topics()
346    {
347        $this->login();
348        $this->load_ids(array(
349            'forums' => array(
350                'Feeds #news',
351            ),
352        ));
353
354        $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.');
355        $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id'];
356
357        $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.');
358        $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
359
360        self::assertStringContainsString('Feeds #news - Topic #2', $crawler->filter('html')->text());
361        $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id'];
362        $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
363
364        // Test creating a reply
365        $post2 = $this->create_post($this->data['forums']['Feeds #news'], $post['topic_id'], 'Re: Feeds #news - Topic #2', 'This is a test post posted by the testing framework.');
366        $crawler = self::request('GET', "viewtopic.php?p={$post2['post_id']}&sid={$this->sid}");
367
368        self::assertStringContainsString('Re: Feeds #news - Topic #2', $crawler->filter('html')->text());
369        $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id'];
370    }
371
372    public function test_feeds_news_admin()
373    {
374        $this->load_ids(array(
375            'forums' => array(
376                'Feeds #news',
377            ),
378            'topics' => array(
379                'Feeds #news - Topic #1',
380                'Feeds #news - Topic #2',
381            ),
382            'posts' => array(
383                'Feeds #news - Topic #2',
384            ),
385        ));
386
387        // Assert that the first post of the two topics are displayed in news feed
388        $this->assert_feeds(array(
389            'news' => array(
390                array(
391                    'nb_entries' => 2,
392                    'contents' => array(
393                        1 => 'This is a test topic posted by the testing framework.',
394                        2 => 'This is a test topic posted by the testing framework.',
395                    ),
396                ),
397            ),
398            // News should also be displayed in other feeds
399            'f' => array(
400                array(
401                    'nb_entries' => 3,
402                    'id' => $this->data['forums']['Feeds #news'],
403                ),
404            ),
405            't' => array(
406                array(
407                    'nb_entries' => 1,
408                    'id' => $this->data['topics']['Feeds #news - Topic #1'],
409                ),
410                array(
411                    'nb_entries' => 2,
412                    'id' => $this->data['topics']['Feeds #news - Topic #2'],
413                ),
414            ),
415            'overall' => array(
416                array(
417                    'nb_entries' => 3,
418                    'xpath' => array(
419                        '//entry/title[contains(., "#news")]' => 3,
420                    ),
421                ),
422            ),
423            'topics' => array(
424                array(
425                    'nb_entries' => 2,
426                    'xpath' => array(
427                        '//entry/title[contains(., "#news")]' => 2,
428                    ),
429                ),
430            ),
431            'topics_new' => array(
432                array(
433                    'nb_entries' => 2,
434                    'xpath' => array(
435                        '//entry/title[contains(., "#news")]' => 2,
436                    ),
437                ),
438            ),
439            'topics_active' => array(
440                array(
441                    'nb_entries' => 2,
442                    'xpath' => array(
443                        '//entry/title[contains(., "#news")]' => 2,
444                    ),
445                ),
446            ),
447        ), 'admin');
448    }
449
450    public function test_feeds_news_guest()
451    {
452        $this->load_ids(array(
453            'posts' => array(
454                'Feeds #news - Topic #2',
455            ),
456        ));
457
458        // Assert that first post of the the two topics are displayed in news feed
459        $this->assert_feeds(array(
460            'news' => array(
461                array(
462                    'nb_entries' => 2,
463                    'contents' => array(
464                        1 => 'This is a test topic posted by the testing framework.',
465                        2 => 'This is a test topic posted by the testing framework.',
466                    ),
467                ),
468            ),
469        ));
470    }
471
472    public function test_create_sub_forum_topic()
473    {
474        $this->login();
475        $this->load_ids(array(
476            'forums' => array(
477                'Feeds #1',
478                'Feeds #1.1',
479            ),
480        ));
481
482        $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.');
483        $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id'];
484
485        $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #1', 'This is a test topic posted by the testing framework.');
486        $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id'];
487    }
488
489    public function test_feeds_sub_forum()
490    {
491        $this->load_ids(array(
492            'forums' => array(
493                'Feeds #1',
494            ),
495        ));
496
497        // The topics of the sub-forum shouldn't be displayed
498        $this->assert_feeds(array(
499            'f' => array(
500                array(
501                    'nb_entries' => 1,
502                    'id' => $this->data['forums']['Feeds #1'],
503                ),
504            ),
505        ), 'admin');
506    }
507
508    public function test_create_softdelete_post()
509    {
510        $this->login();
511        $this->load_ids(array(
512            'forums' => array(
513                'Feeds #1',
514            ),
515        ));
516
517        $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.');
518        $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id'];
519
520        // Test creating a reply
521        $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.');
522        $crawler = self::request('GET', "viewtopic.php?p={$post2['post_id']}&sid={$this->sid}");
523
524        self::assertStringContainsString('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text());
525        $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id'];
526    }
527
528    public function test_softdelete_post()
529    {
530        $this->login();
531        $this->load_ids(array(
532            'forums' => array(
533                'Feeds #1',
534            ),
535            'topics' => array(
536                'Feeds #1 - Topic #2',
537            ),
538            'posts' => array(
539                'Re: Feeds #1 - Topic #2',
540            ),
541        ));
542        $this->add_lang('posting');
543
544        $crawler = self::request('GET', "posting.php?mode=delete&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}");
545        self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
546
547        $form = $crawler->selectButton('Yes')->form();
548        $crawler = self::submit($form);
549        self::assertContainsLang('POST_DELETED', $crawler->text());
550
551        $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
552        self::assertStringContainsString($this->lang('POST_DISPLAY'), $crawler->text());
553    }
554
555    public function test_feeds_softdeleted_post_admin()
556    {
557        $this->load_ids(array(
558            'forums' => array(
559                'Feeds #1',
560            ),
561            'topics' => array(
562                'Feeds #1 - Topic #2',
563            ),
564        ));
565
566        // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
567        $this->assert_feeds(array(
568            'f' => array(
569                array(
570                    'nb_entries' => 3,
571                    'id' => $this->data['forums']['Feeds #1'],
572                    'contents_lang' => array(
573                        1 => 'POST_DELETED',
574                    ),
575                ),
576            ),
577            't' => array(
578                array(
579                    'nb_entries' => 2,
580                    'id' => $this->data['topics']['Feeds #1 - Topic #2'],
581                    'contents_lang' => array(
582                        1 => 'POST_DELETED',
583                    ),
584                ),
585            ),
586            'overall' => array(
587                array(
588                    'nb_entries' => 7,
589                    'contents_lang' => array(
590                        1 => 'POST_DELETED',
591                    ),
592                ),
593            ),
594        ), 'admin');
595    }
596
597    public function test_feeds_softdeleted_post_guest()
598    {
599        $this->load_ids(array(
600            'forums' => array(
601                'Feeds #1',
602            ),
603            'topics' => array(
604                'Feeds #1 - Topic #2',
605            ),
606        ));
607
608        // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
609        $this->assert_feeds(array(
610            'f' => array(
611                array(
612                    'nb_entries' => 2,
613                    'id' => $this->data['forums']['Feeds #1'],
614                ),
615            ),
616            't' => array(
617                array(
618                    'nb_entries' => 1,
619                    'id' => $this->data['topics']['Feeds #1 - Topic #2'],
620                ),
621            ),
622            'overall' => array(
623                array(
624                    'nb_entries' => 6,
625                ),
626            ),
627        ));
628    }
629
630    public function test_softdelete_topic()
631    {
632        $this->login();
633        $this->load_ids(array(
634            'forums' => array(
635                'Feeds #1',
636            ),
637            'topics' => array(
638                'Feeds #1 - Topic #2',
639            ),
640        ));
641
642        $this->add_lang('posting');
643        $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC');
644        self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
645
646        $this->add_lang('mcp');
647        $form = $crawler->selectButton('Yes')->form();
648        $crawler = self::submit($form);
649        self::assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
650
651        $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
652        self::assertStringContainsString('Feeds #1 - Topic #2', $crawler->filter('h2')->text());
653    }
654
655    public function test_feeds_softdeleted_topic_admin()
656    {
657        $this->load_ids(array(
658            'forums' => array(
659                'Feeds #1',
660            ),
661            'topics' => array(
662                'Feeds #1 - Topic #2',
663            ),
664        ));
665
666        // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
667        $this->assert_feeds(array(
668            'f' => array(
669                array(
670                    'nb_entries' => 3,
671                    'id' => $this->data['forums']['Feeds #1'],
672                    'contents_lang' => array(
673                        1 => 'POST_DELETED',
674                        2 => 'POST_DELETED',
675                    ),
676                ),
677            ),
678            't' => array(
679                array(
680                    'nb_entries' => 2,
681                    'id' => $this->data['topics']['Feeds #1 - Topic #2'],
682                    'contents_lang' => array(
683                        1 => 'POST_DELETED',
684                        2 => 'POST_DELETED',
685                    ),
686                ),
687            ),
688            'overall' => array(
689                array(
690                    'nb_entries' => 7,
691                    'contents_lang' => array(
692                        1 => 'POST_DELETED',
693                        2 => 'POST_DELETED',
694                    ),
695                ),
696            ),
697            'topics' => array(
698                array(
699                    'nb_entries' => 5,
700                    'contents_lang' => array(
701                        1 => 'TOPIC_DELETED',
702                    ),
703                ),
704            ),
705            'topics_new' => array(
706                array(
707                    'nb_entries' => 5,
708                    'contents_lang' => array(
709                        1 => 'TOPIC_DELETED',
710                    ),
711                ),
712            ),
713            'topics_active' => array(
714                array(
715                    'nb_entries' => 5,
716                    'contents_lang' => array(
717                        1 => 'TOPIC_DELETED',
718                    ),
719                ),
720            ),
721        ), 'admin');
722    }
723
724    public function test_feeds_softdeleted_topic_guest()
725    {
726        $this->load_ids(array(
727            'forums' => array(
728                'Feeds #1',
729            ),
730            'topics' => array(
731                'Feeds #1 - Topic #2',
732            ),
733        ));
734
735        $this->assert_feeds(array(
736            'f' => array(
737                array(
738                    'nb_entries' => 1,
739                    'id' => $this->data['forums']['Feeds #1'],
740                ),
741            ),
742            't' => array(
743                array(
744                    'id' => $this->data['topics']['Feeds #1 - Topic #2'],
745                    'contents_lang' => array('SORRY_AUTH_READ_TOPIC'),
746                    'invalid' => true,
747                    'response_code' => 403,
748                ),
749            ),
750            'overall' => array(
751                array(
752                    'nb_entries' => 5,
753                ),
754            ),
755            'topics' => array(
756                array(
757                    'nb_entries' => 4,
758                ),
759            ),
760            'topics_new' => array(
761                array(
762                    'nb_entries' => 4,
763                ),
764            ),
765            'topics_active' => array(
766                array(
767                    'nb_entries' => 4,
768                ),
769            ),
770        ));
771    }
772
773    public function test_create_unapproved_post()
774    {
775        $this->load_ids(array(
776            'forums' => array(
777                'Feeds #1.1',
778            ),
779        ));
780
781        $this->login('admin');
782        $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #2', 'This is a test topic posted by the testing framework.');
783        $this->data['topics']['Feeds #1.1 - Topic #2'] = (int) $post['topic_id'];
784        $this->logout();
785
786        // Test creating a reply
787        $this->login('disapprove_user');
788        $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD');
789
790        $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}");
791        self::assertStringNotContainsString('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text());
792    }
793
794    public function test_feeds_unapproved_post_admin()
795    {
796        $this->load_ids(array(
797            'forums' => array(
798                'Feeds #1.1',
799            ),
800            'topics' => array(
801                'Feeds #1.1 - Topic #2',
802            ),
803        ));
804
805        // Assert that the unapproved post is marked as unapproved for users that have the right to see it.
806        $this->assert_feeds(array(
807            'f' => array(
808                array(
809                    'nb_entries' => 3,
810                    'id' => $this->data['forums']['Feeds #1.1'],
811                    'contents_lang' => array(
812                        1 => 'POST_UNAPPROVED',
813                    ),
814                ),
815            ),
816            't' => array(
817                array(
818                    'nb_entries' => 2,
819                    'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
820                    'contents_lang' => array(
821                        1 => 'POST_UNAPPROVED',
822                    ),
823                ),
824            ),
825            'overall' => array(
826                array(
827                    'nb_entries' => 9,
828                    'contents_lang' => array(
829                        1 => 'POST_UNAPPROVED',
830                    ),
831                ),
832            ),
833        ), 'admin');
834    }
835
836    public function test_feeds_unapproved_post_disapprove_user()
837    {
838        $this->load_ids(array(
839            'forums' => array(
840                'Feeds #1.1',
841            ),
842            'topics' => array(
843                'Feeds #1.1 - Topic #2',
844            ),
845        ));
846
847        // Assert that the unapproved isn't displayed for regular users
848        $this->assert_feeds(array(
849            'f' => array(
850                array(
851                    'nb_entries' => 2,
852                    'id' => $this->data['forums']['Feeds #1.1'],
853                ),
854            ),
855            't' => array(
856                array(
857                    'nb_entries' => 1,
858                    'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
859                ),
860            ),
861            'overall' => array(
862                array(
863                    'nb_entries' => 6,
864                ),
865            ),
866        ), 'disapprove_user');
867    }
868
869    public function test_create_unapproved_topic()
870    {
871        $this->load_ids(array(
872            'forums' => array(
873                'Feeds #1.1',
874            ),
875        ));
876        $this->set_flood_interval(0);
877
878        $this->login('disapprove_user');
879        $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD');
880
881        $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}");
882        self::assertStringNotContainsString('Feeds #1.1 - Topic #3', $crawler->filter('html')->text());
883
884        $this->logout();
885        $this->set_flood_interval(15);
886    }
887
888    public function test_feeds_unapproved_topic_admin()
889    {
890        $this->load_ids(array(
891            'forums' => array(
892                'Feeds #1.1',
893            ),
894            'topics' => array(
895                'Feeds #1.1 - Topic #3',
896            ),
897        ));
898
899        // Assert that the unapproved topic is marked as unapproved for users that have the right to see it.
900        $this->assert_feeds(array(
901            'f' => array(
902                array(
903                    'nb_entries' => 4,
904                    'id' => $this->data['forums']['Feeds #1.1'],
905                    'contents_lang' => array(
906                        1 => 'POST_UNAPPROVED',
907                    ),
908                ),
909            ),
910            't' => array(
911                array(
912                    'nb_entries' => 1,
913                    'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
914                    'contents_lang' => array(
915                        1 => 'POST_UNAPPROVED',
916                    ),
917                ),
918            ),
919            'overall' => array(
920                array(
921                    'nb_entries' => 10,
922                    'contents_lang' => array(
923                        1 => 'POST_UNAPPROVED',
924                    ),
925                ),
926            ),
927            'topics' => array(
928                array(
929                    'nb_entries' => 7,
930                    'contents_lang' => array(
931                        1 => 'TOPIC_UNAPPROVED',
932                    ),
933                ),
934            ),
935            'topics_new' => array(
936                array(
937                    'nb_entries' => 7,
938                    'contents_lang' => array(
939                        1 => 'TOPIC_UNAPPROVED',
940                    ),
941                ),
942            ),
943            'topics_active' => array(
944                array(
945                    'nb_entries' => 7,
946                    'contents_lang' => array(
947                        1 => 'TOPIC_UNAPPROVED',
948                    ),
949                ),
950            ),
951        ), 'admin');
952    }
953
954    public function test_feeds_unapproved_topic_disapprove_user()
955    {
956        $this->load_ids(array(
957            'forums' => array(
958                'Feeds #1.1',
959            ),
960            'topics' => array(
961                'Feeds #1.1 - Topic #3',
962            ),
963        ));
964
965        $this->assert_feeds(array(
966            'f' => array(
967                array(
968                    'nb_entries' => 2,
969                    'id' => $this->data['forums']['Feeds #1.1'],
970                ),
971            ),
972            't' => array(
973                array(
974                    'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
975                    'contents_lang' => array('SORRY_AUTH_READ_TOPIC'),
976                    'invalid' => true,
977                    'response_code' => 403,
978                ),
979            ),
980            'overall' => array(
981                array(
982                    'nb_entries' => 6,
983                ),
984            ),
985            'topics' => array(
986                array(
987                    'nb_entries' => 5,
988                ),
989            ),
990            'topics_new' => array(
991                array(
992                    'nb_entries' => 5,
993                ),
994            ),
995            'topics_active' => array(
996                array(
997                    'nb_entries' => 5,
998                ),
999            ),
1000        ), 'disapprove_user');
1001    }
1002
1003    public function test_create_attachment_topic()
1004    {
1005        $this->login();
1006        $this->load_ids(array(
1007            'forums' => array(
1008                'Feeds #1',
1009            ),
1010        ));
1011
1012        // Test creating a topic with 1 attachment
1013        $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #3', 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]', array('upload_files' => 1));
1014        $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
1015
1016        self::assertStringContainsString('Feeds #1 - Topic #3', $crawler->filter('html')->text());
1017        $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
1018    }
1019
1020    public function test_feeds_attachment_admin()
1021    {
1022        $this->load_ids(array(
1023            'forums' => array(
1024                'Feeds #1',
1025            ),
1026            'topics' => array(
1027                'Feeds #1 - Topic #3',
1028            ),
1029            'posts' => array(
1030                'Feeds #1 - Topic #3',
1031            ),
1032            'attachments' => true,
1033        ));
1034
1035        $this->assert_feeds(array(
1036            'f' => array(
1037                array(
1038                    'nb_entries' => 4,
1039                    'id' => $this->data['forums']['Feeds #1'],
1040                    'attachments' => array(
1041                        1 => array( // First entry
1042                            array( // First attachment to fetch
1043                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1044                                'displayed' => true,
1045                            ),
1046                        ),
1047                    ),
1048                ),
1049            ),
1050            't' => array(
1051                array(
1052                    'nb_entries' => 1,
1053                    'id' => $this->data['topics']['Feeds #1 - Topic #3'],
1054                    'attachments' => array(
1055                        1 => array( // First entry
1056                            array( // First attachment to fetch
1057                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1058                                'displayed' => true,
1059                            ),
1060                        ),
1061                    ),
1062                ),
1063            ),
1064            'overall' => array(
1065                array(
1066                    'nb_entries' => 11,
1067                    'attachments' => array(
1068                        1 => array( // First entry
1069                            array( // First attachment to fetch
1070                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1071                                'displayed' => true,
1072                            ),
1073                        ),
1074                    ),
1075                ),
1076            ),
1077            'topics' => array(
1078                array(
1079                    'nb_entries' => 8,
1080                    'attachments' => array(
1081                        1 => array( // First entry
1082                            array( // First attachment to fetch
1083                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1084                                'displayed' => true,
1085                            ),
1086                        ),
1087                    ),
1088                ),
1089            ),
1090            'topics_new' => array(
1091                array(
1092                    'nb_entries' => 8,
1093                    'attachments' => array(
1094                        1 => array( // First entry
1095                            array( // First attachment to fetch
1096                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1097                                'displayed' => true,
1098                            ),
1099                        ),
1100                    ),
1101                ),
1102            ),
1103            'topics_active' => array(
1104                array(
1105                    'nb_entries' => 8,
1106                    'attachments' => array(
1107                        1 => array( // First entry
1108                            array( // First attachment to fetch
1109                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1110                                'displayed' => true,
1111                            ),
1112                        ),
1113                    ),
1114                ),
1115            ),
1116        ), 'admin');
1117    }
1118
1119    public function test_feeds_attachment_guest()
1120    {
1121        $this->load_ids(array(
1122            'forums' => array(
1123                'Feeds #1',
1124            ),
1125            'topics' => array(
1126                'Feeds #1 - Topic #3',
1127            ),
1128            'posts' => array(
1129                'Feeds #1 - Topic #3',
1130            ),
1131            'attachments' => true,
1132        ));
1133
1134        $this->assert_feeds(array(
1135            'f' => array(
1136                array(
1137                    'nb_entries' => 2,
1138                    'id' => $this->data['forums']['Feeds #1'],
1139                    'attachments' => array(
1140                        1 => array( // First entry
1141                            array( // First attachment to fetch
1142                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1143                                'displayed' => false,
1144                            ),
1145                        ),
1146                    ),
1147                ),
1148            ),
1149            't' => array(
1150                array(
1151                    'nb_entries' => 1,
1152                    'id' => $this->data['topics']['Feeds #1 - Topic #3'],
1153                    'attachments' => array(
1154                        1 => array( // First entry
1155                            array( // First attachment to fetch
1156                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1157                                'displayed' => false,
1158                            ),
1159                        ),
1160                    ),
1161                ),
1162            ),
1163            'overall' => array(
1164                array(
1165                    'nb_entries' => 7,
1166                    'attachments' => array(
1167                        1 => array( // First entry
1168                            array( // First attachment to fetch
1169                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1170                                'displayed' => false,
1171                            ),
1172                        ),
1173                    ),
1174                ),
1175            ),
1176            'topics' => array(
1177                array(
1178                    'nb_entries' => 6,
1179                    'attachments' => array(
1180                        1 => array( // First entry
1181                            array( // First attachment to fetch
1182                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1183                                'displayed' => false,
1184                            ),
1185                        ),
1186                    ),
1187                ),
1188            ),
1189            'topics_new' => array(
1190                array(
1191                    'nb_entries' => 6,
1192                    'attachments' => array(
1193                        1 => array( // First entry
1194                            array( // First attachment to fetch
1195                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1196                                'displayed' => false,
1197                            ),
1198                        ),
1199                    ),
1200                ),
1201            ),
1202            'topics_active' => array(
1203                array(
1204                    'nb_entries' => 6,
1205                    'attachments' => array(
1206                        1 => array( // First entry
1207                            array( // First attachment to fetch
1208                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1209                                'displayed' => false,
1210                            ),
1211                        ),
1212                    ),
1213                ),
1214            ),
1215        ));
1216    }
1217
1218    public function test_create_missing_attachment_post()
1219    {
1220        $this->login();
1221        $this->load_ids(array(
1222            'forums' => array(
1223                'Feeds #1',
1224            ),
1225            'topics' => array(
1226                'Feeds #1 - Topic #3',
1227            ),
1228        ));
1229
1230        // Test creating a reply with 1 missing attachment
1231        $post2 = $this->create_post($this->data['forums']['Feeds #1'], $this->data['topics']['Feeds #1 - Topic #3'], 'Re: Feeds #1 - Topic #3-1', 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]');
1232        $crawler = self::request('GET', "viewtopic.php?p={$post2['post_id']}&sid={$this->sid}");
1233
1234        self::assertStringContainsString('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text());
1235        $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id'];
1236    }
1237
1238    public function test_feeds_missing_attachment_admin()
1239    {
1240        $this->load_ids(array(
1241            'forums' => array(
1242                'Feeds #1',
1243            ),
1244            'topics' => array(
1245                'Feeds #1 - Topic #3',
1246            ),
1247            'posts' => array(
1248                'Feeds #1 - Topic #3',
1249            ),
1250            'attachments' => array(),
1251        ));
1252
1253        $this->add_lang('viewtopic');
1254
1255        $this->assert_feeds(array(
1256            'f' => array(
1257                array(
1258                    'nb_entries' => 5,
1259                    'id' => $this->data['forums']['Feeds #1'],
1260                    'contents' => array(
1261                        1 => 'Attachment #0',
1262                    ),
1263                ),
1264            ),
1265            't' => array(
1266                array(
1267                    'nb_entries' => 2,
1268                    'id' => $this->data['topics']['Feeds #1 - Topic #3'],
1269                    'contents' => array(
1270                        1 => 'Attachment #0',
1271                    ),
1272                ),
1273            ),
1274            'overall' => array(
1275                array(
1276                    'nb_entries' => 12,
1277                    'contents' => array(
1278                        1 => 'Attachment #0',
1279                    ),
1280                ),
1281            ),
1282            'topics' => array(
1283                array(
1284                    'nb_entries' => 8,
1285                    'attachments' => array(
1286                        1 => array( // First entry
1287                            array( // First attachment to fetch
1288                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1289                                'displayed' => true,
1290                            ),
1291                        ),
1292                    ),
1293                ),
1294            ),
1295            'topics_new' => array(
1296                array(
1297                    'nb_entries' => 8,
1298                    'attachments' => array(
1299                        1 => array( // First entry
1300                            array( // First attachment to fetch
1301                                'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
1302                                'displayed' => true,
1303                            ),
1304                        ),
1305                    ),
1306                ),
1307            ),
1308            'topics_active' => array(
1309                array(
1310                    'nb_entries' => 8,
1311                    'contents' => array(
1312                        1 => 'Attachment #0',
1313                    ),
1314                ),
1315            ),
1316        ), 'admin');
1317    }
1318
1319    protected function assert_feeds($data, $username = false)
1320    {
1321        if ($username)
1322        {
1323            $this->login($username);
1324            $init_values = self::$init_values[$username];
1325        }
1326        else
1327        {
1328            $init_values = self::$init_values['disapprove_user'];
1329        }
1330
1331        foreach ($data as $mode => $feeds)
1332        {
1333            foreach ($feeds as $feed_data)
1334            {
1335                if ($mode === 'f')
1336                {
1337                    $params = "/forum/{$feed_data['id']}";
1338                    $this->assert_feed($params, $feed_data);
1339                }
1340                else if ($mode === 't')
1341                {
1342                    $params = "/topic/{$feed_data['id']}";
1343                    $this->assert_feed($params, $feed_data);
1344                }
1345                else
1346                {
1347                    switch ($mode) {
1348                        case 'forums':
1349                            $feed_data['nb_entries'] = ((int)$feed_data['nb_entries'] + $init_values['forums_value']);
1350                            break;
1351                        case 'overall':
1352                            $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['overall_value'], self::$init_values['post_base_items']);
1353                            break;
1354                        case 'topics':
1355                            $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_value'],  self::$init_values['topic_base_items']);
1356                            break;
1357                        case 'topics_new':
1358                            $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_new_value'],  self::$init_values['topic_base_items']);
1359                            break;
1360                        case 'topics_active':
1361                            $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_active_value'], self::$init_values['topic_base_items']);
1362                            break;
1363                        case 'news':
1364                            break;
1365                        default:
1366                            self::fail('Unsupported feed mode: ' . $mode);
1367                    }
1368
1369                    $params = "/{$mode}";
1370                    $this->assert_feed($params, $feed_data);
1371                }
1372            }
1373        }
1374    }
1375
1376    protected function assert_feed($params, $data)
1377    {
1378        $crawler = self::request('GET', 'app.php/feed' . $params, array(), false);
1379
1380        if (empty($data['invalid']))
1381        {
1382            self::assert_response_xml();
1383            self::assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'app.php/feed{$params}'");
1384
1385            if (!empty($data['xpath']))
1386            {
1387
1388                foreach($data['xpath'] as $xpath => $count_expected)
1389                {
1390                    self::assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'app.php/feed{$params}', Search for {$xpath}");
1391                }
1392            }
1393
1394            if (!empty($data['contents']))
1395            {
1396                foreach($data['contents'] as $entry_id => $string)
1397                {
1398                    $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
1399                    self::assertStringContainsString($string, $content, "Tested feed : 'app.php/feed{$params}'");
1400                }
1401            }
1402
1403            if (!empty($data['contents_lang']))
1404            {
1405                foreach($data['contents_lang'] as $entry_id => $string)
1406                {
1407                    $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
1408                    self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'");
1409                }
1410            }
1411
1412            if (!empty($data['attachments']))
1413            {
1414                foreach($data['attachments'] as $entry_id => $attachments)
1415                {
1416                    $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
1417                    foreach ($attachments as $i => $attachment)
1418                    {
1419                        $url = self::$root_url . "app.php/download/attachment/{$attachment['id']}";
1420                        $string = "Attachment #{$i}";
1421
1422                        if ($attachment['displayed'])
1423                        {
1424                            self::assertStringContainsString($url, $content, "Tested feed : 'app.php/feed{$params}'");
1425                            self::assertStringNotContainsString($string, $content, "Tested feed : 'app.php/feed{$params}'");
1426                        }
1427                        else
1428                        {
1429                            self::assertStringContainsString($string, $content, "Tested feed : 'app.php/feed{$params}'");
1430                            self::assertStringNotContainsString($url, $content, "Tested feed : 'app.php/feed{$params}'");
1431                        }
1432                    }
1433                }
1434            }
1435        }
1436        else
1437        {
1438            self::assert_response_html($data['response_code'] ?: 202);
1439
1440            if (!empty($data['contents_lang']))
1441            {
1442                $content = $crawler->filter('html')->text();
1443                foreach($data['contents_lang'] as $string)
1444                {
1445                    self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'");
1446                }
1447            }
1448        }
1449    }
1450
1451    protected function load_ids($data)
1452    {
1453        if (!empty($data['forums']))
1454        {
1455            $sql = 'SELECT *
1456                FROM phpbb_forums
1457                WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
1458            $result = $this->db->sql_query($sql);
1459            while ($row = $this->db->sql_fetchrow($result))
1460            {
1461                if (in_array($row['forum_name'], $data['forums'], false))
1462                {
1463                    $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
1464                }
1465            }
1466            $this->db->sql_freeresult($result);
1467        }
1468
1469        if (!empty($data['topics']))
1470        {
1471            $sql = 'SELECT *
1472                FROM phpbb_topics
1473                WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
1474            $result = $this->db->sql_query($sql);
1475            while ($row = $this->db->sql_fetchrow($result))
1476            {
1477                if (in_array($row['topic_title'], $data['topics'], false))
1478                {
1479                    $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
1480                }
1481            }
1482            $this->db->sql_freeresult($result);
1483        }
1484
1485        $post_ids = array();
1486        if (!empty($data['posts']))
1487        {
1488            $sql = 'SELECT *
1489                FROM phpbb_posts
1490                WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
1491            $result = $this->db->sql_query($sql);
1492            while ($row = $this->db->sql_fetchrow($result))
1493            {
1494                if (in_array($row['post_subject'], $data['posts'], false))
1495                {
1496                    $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
1497                    $post_ids[] = (int) $row['post_id'];
1498                }
1499            }
1500            $this->db->sql_freeresult($result);
1501
1502            if (isset($data['attachments']))
1503            {
1504                $sql = 'SELECT *
1505                    FROM phpbb_attachments
1506                    WHERE in_message = 0 AND ' . $this->db->sql_in_set('post_msg_id', $post_ids);
1507                $result = $this->db->sql_query($sql);
1508                while ($row = $this->db->sql_fetchrow($result))
1509                {
1510                    $this->data['attachments'][(int) $row['post_msg_id']][] = (int) $row['attach_id'];
1511                }
1512                $this->db->sql_freeresult($result);
1513            }
1514        }
1515    }
1516}