aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-02 15:08:15 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-05-02 15:08:15 +0200
commitfa1ac3c54d471f93b0fb10ef58aba13008dfa119 (patch)
treeab69fbc46128753bf4f2bd9968913635bf33fcea
parent4f17d0653ab9eaa51c730f2e1f5ad6fbcfc279ba (diff)
parent8812cfcfbf4ae82eb0270c268d227ba729b42107 (diff)
downloadforums-fa1ac3c54d471f93b0fb10ef58aba13008dfa119.tar
forums-fa1ac3c54d471f93b0fb10ef58aba13008dfa119.tar.gz
forums-fa1ac3c54d471f93b0fb10ef58aba13008dfa119.tar.bz2
forums-fa1ac3c54d471f93b0fb10ef58aba13008dfa119.tar.xz
forums-fa1ac3c54d471f93b0fb10ef58aba13008dfa119.zip
Merge pull request #2336 from Nicofuma/ticket/12413
[ticket/12413] Fatal Error log created for feed.php file
-rw-r--r--phpBB/feed.php5
-rw-r--r--phpBB/phpbb/feed/attachments_base.php83
-rw-r--r--phpBB/phpbb/feed/forum.php2
-rw-r--r--phpBB/phpbb/feed/post_base.php39
-rw-r--r--phpBB/phpbb/feed/topic.php2
-rw-r--r--phpBB/phpbb/feed/topic_base.php2
-rw-r--r--tests/functional/feed_test.php1506
7 files changed, 1596 insertions, 43 deletions
diff --git a/phpBB/feed.php b/phpBB/feed.php
index 9ff8c66b9d..0c4cc32fdb 100644
--- a/phpBB/feed.php
+++ b/phpBB/feed.php
@@ -73,9 +73,6 @@ if ($feed === false)
trigger_error('NO_FEED');
}
-// Get attachments for this feed
-$feed->fetch_attachments();
-
// Open Feed
$feed->open();
@@ -111,7 +108,7 @@ while ($row = $feed->get_item())
'title' => censor_text($title),
'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '',
'category_name' => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '',
- 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], (($row['post_attachment']) ? $feed->attachments[$row['post_id']] : array()))),
+ 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ((isset($row['post_attachment']) && $row['post_attachment']) ? $feed->get_attachments($row['post_id']) : array()))),
'statistics' => '',
);
diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php
new file mode 100644
index 0000000000..a9a8175928
--- /dev/null
+++ b/phpBB/phpbb/feed/attachments_base.php
@@ -0,0 +1,83 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\feed;
+
+/**
+* Abstract class for feeds displaying attachments
+*
+* @package phpBB3
+*/
+abstract class attachments_base extends \phpbb\feed\base
+{
+ /**
+ * Attachments that may be displayed
+ */
+ protected $attachments = array();
+
+ /**
+ * Retrieve the list of attachments that may be displayed
+ */
+ protected function fetch_attachments()
+ {
+ $sql_array = array(
+ 'SELECT' => 'a.*',
+ 'FROM' => array(
+ ATTACHMENTS_TABLE => 'a'
+ ),
+ 'WHERE' => 'a.in_message = 0 ',
+ 'ORDER_BY' => 'a.filetime DESC, a.post_msg_id ASC',
+ );
+
+ if (isset($this->topic_id))
+ {
+ $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int) $this->topic_id;
+ }
+ else if (isset($this->forum_id))
+ {
+ $sql_array['LEFT_JOIN'] = array(
+ array(
+ 'FROM' => array(TOPICS_TABLE => 't'),
+ 'ON' => 'a.topic_id = t.topic_id',
+ )
+ );
+ $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int) $this->forum_id;
+ }
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
+ $result = $this->db->sql_query($sql);
+
+ // Set attachments in feed items
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->attachments[$row['post_msg_id']][] = $row;
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function open()
+ {
+ parent::open();
+ $this->fetch_attachments();
+ }
+
+ /**
+ * Get attachments related to a given post
+ *
+ * @param $post_id int Post id
+ * @return mixed Attachments related to $post_id
+ */
+ public function get_attachments($post_id)
+ {
+ return $this->attachments[$post_id];
+ }
+}
diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php
index 85ecb60f7e..8e6490923d 100644
--- a/phpBB/phpbb/feed/forum.php
+++ b/phpBB/phpbb/feed/forum.php
@@ -80,6 +80,8 @@ class forum extends \phpbb\feed\post_base
unset($forum_ids_passworded);
}
+
+ parent::open();
}
function get_sql()
diff --git a/phpBB/phpbb/feed/post_base.php b/phpBB/phpbb/feed/post_base.php
index c797d6a8ca..de98f446f3 100644
--- a/phpBB/phpbb/feed/post_base.php
+++ b/phpBB/phpbb/feed/post_base.php
@@ -14,7 +14,7 @@ namespace phpbb\feed;
*
* @package phpBB3
*/
-abstract class post_base extends \phpbb\feed\base
+abstract class post_base extends \phpbb\feed\attachments_base
{
var $num_items = 'feed_limit_post';
var $attachments = array();
@@ -49,41 +49,4 @@ abstract class post_base extends \phpbb\feed\base
. (($this->is_moderator_approve_forum($row['forum_id']) && $row['post_visibility'] !== ITEM_APPROVED) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : '');
}
}
-
- function fetch_attachments()
- {
- $sql_array = array(
- 'SELECT' => 'a.*',
- 'FROM' => array(
- ATTACHMENTS_TABLE => 'a'
- ),
- 'WHERE' => 'a.in_message = 0 ',
- 'ORDER_BY' => 'a.filetime DESC, a.post_msg_id ASC',
- );
-
- if (isset($this->topic_id))
- {
- $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int) $this->topic_id;
- }
- else if (isset($this->forum_id))
- {
- $sql_array['LEFT_JOIN'] = array(
- array(
- 'FROM' => array(TOPICS_TABLE => 't'),
- 'ON' => 'a.topic_id = t.topic_id',
- )
- );
- $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int) $this->forum_id;
- }
-
- $sql = $this->db->sql_build_query('SELECT', $sql_array);
- $result = $this->db->sql_query($sql);
-
- // Set attachments in feed items
- while ($row = $this->db->sql_fetchrow($result))
- {
- $this->attachments[$row['post_msg_id']][] = $row;
- }
- $this->db->sql_freeresult($result);
- }
}
diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php
index a7acfb502f..fb49aa65cc 100644
--- a/phpBB/phpbb/feed/topic.php
+++ b/phpBB/phpbb/feed/topic.php
@@ -83,6 +83,8 @@ class topic extends \phpbb\feed\post_base
unset($forum_ids_passworded);
}
+
+ parent::open();
}
function get_sql()
diff --git a/phpBB/phpbb/feed/topic_base.php b/phpBB/phpbb/feed/topic_base.php
index 7e28e67b82..e8639a6fa6 100644
--- a/phpBB/phpbb/feed/topic_base.php
+++ b/phpBB/phpbb/feed/topic_base.php
@@ -14,7 +14,7 @@ namespace phpbb\feed;
*
* @package phpBB3
*/
-abstract class topic_base extends \phpbb\feed\base
+abstract class topic_base extends \phpbb\feed\attachments_base
{
var $num_items = 'feed_limit_topic';
diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php
new file mode 100644
index 0000000000..fbcbfa3943
--- /dev/null
+++ b/tests/functional/feed_test.php
@@ -0,0 +1,1506 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_feed_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+
+ static public $init_values = array();
+
+ public function __construct($name = null, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+
+ $this->backupStaticAttributesBlacklist += array(
+ 'phpbb_functional_feed_test' => array('init_values'),
+ );
+ }
+
+ public function test_setup_config_before_state()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+ $values = $form->getValues();
+
+ self::$init_values['post_base_items'] = (int) $values['config[feed_limit_post]'];
+ self::$init_values['topic_base_items'] = (int) $values['config[feed_limit_topic]'];
+
+ // Enable all feeds
+ $values['config[feed_enable]'] = true;
+ $values['config[feed_forum]'] = true;
+ $values['config[feed_item_statistics]'] = true;
+ $values['config[feed_overall]'] = true;
+ $values['config[feed_overall_forums]'] = true;
+ $values['config[feed_topic]'] = true;
+ $values['config[feed_topics_active]'] = true;
+ $values['config[feed_topics_new]'] = true;
+
+ $form->setValues($values);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+
+ // Special config (Guest can't see attachments)
+ $this->add_lang('acp/permissions');
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1");
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ $form['setting[1][0][u_download]']->select(-1);
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_dump_board_state()
+ {
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+ $this->login();
+
+ $crawler = self::request('GET', 'feed.php?mode=forums', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=overall', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count();
+
+ $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false);
+ self::assert_response_xml();
+ self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count();
+
+
+ }
+
+ public function test_setup_forums()
+ {
+ $this->login();
+ $this->admin_login();
+ $this->create_user('disapprove_user');
+ $this->add_user_group('NEWLY_REGISTERED', array('disapprove_user'));
+
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // 'Feeds #1.1' is a sub-forum of 'Feeds #1'
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$this->data['forums']['Feeds #1']}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #1.1',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #news' will be used for feed.php?mode=news
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #news',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+
+ // 'Feeds #exclude' will not be displayed on feed.php?mode=forums
+ $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
+ $form = $crawler->selectButton('addforum')->form(array(
+ 'forum_name' => 'Feeds #exclude',
+ ));
+ $crawler = self::submit($form);
+ $form = $crawler->selectButton('update')->form(array(
+ 'forum_perm_from' => 2,
+ ));
+ $crawler = self::submit($form);
+ }
+
+ public function test_setup_config_after_forums()
+ {
+ $this->login();
+ $this->admin_login();
+
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=feed");
+
+ $form = $crawler->selectButton('Submit')->form();
+
+ // News/Exclude's forums config
+ $form['feed_news_id']->select(array($this->data['forums']['Feeds #news']));
+ $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude']));
+
+ $crawler = self::submit($form);
+ $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text());
+ }
+
+ public function test_feeds_empty()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ // Excluded forums (and topics under them) shouldn't be displayed in feeds
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'nb_entries' => 0,
+ ),
+ array(
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'nb_entries' => 0,
+ ),
+ ),
+ 'forums' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/category[@label="Feeds #exclude"]' => 0,
+ ),
+ ),
+ ),
+ 'news' => array(
+ array(
+ 'nb_entries' => 0,
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_exclude_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #exclude'], 'Feeds #exclude - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #exclude - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_exclude()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #exclude',
+ ),
+ 'topics' => array(
+ 'Feeds #exclude - Topic #1',
+ ),
+ ));
+
+ // Assert that feeds aren't available for excluded forums
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'id' => $this->data['forums']['Feeds #exclude'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #exclude - Topic #1'],
+ 'contents_lang' => array('NO_FEED'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 0,
+ 'xpath' => array(
+ '//entry/title[contains(., "#exclude")]' => 0,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_news_topics()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id'];
+ $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p');
+
+ // Test creating a reply
+ $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.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_news_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #news',
+ ),
+ 'topics' => array(
+ 'Feeds #news - Topic #1',
+ 'Feeds #news - Topic #2',
+ ),
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that the first post of the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ // News should also be displayed in other feeds
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #news'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #news - Topic #1'],
+ ),
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #news - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 3,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 3,
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 2,
+ 'xpath' => array(
+ '//entry/title[contains(., "#news")]' => 2,
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_news_guest()
+ {
+ $this->load_ids(array(
+ 'posts' => array(
+ 'Feeds #news - Topic #2',
+ ),
+ ));
+
+ // Assert that first post of the the two topics are displayed in news feed
+ $this->assert_feeds(array(
+ 'news' => array(
+ array(
+ 'nb_entries' => 2,
+ 'contents' => array(
+ 1 => 'This is a test topic posted by the testing framework.',
+ 2 => 'This is a test topic posted by the testing framework.',
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_sub_forum_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ $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.');
+ $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_sub_forum()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // The topics of the sub-forum shouldn't be displayed
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_create_softdelete_post()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.');
+ $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id'];
+
+ // Travis is too fast, so we have to wait
+ sleep(1);
+
+ // Test creating a reply
+ $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.');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id'];
+ }
+
+ public function test_softdelete_post()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ 'posts' => array(
+ 'Re: Feeds #1 - Topic #2',
+ ),
+ ));
+ $this->add_lang('posting');
+
+ $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Feeds #1']}&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('POST_DELETED', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text());
+ }
+
+ public function test_feeds_softdeleted_post_admin()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_post_guest()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ));
+ }
+
+ public function test_softdelete_topic()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+
+ $this->add_lang('posting');
+ $form = $crawler->selectButton('Go')->eq(2)->form();
+ $form['action']->select('delete_topic');
+ $crawler = self::submit($form);
+ $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text());
+
+ $this->add_lang('mcp');
+ $form = $crawler->selectButton('Yes')->form();
+ $crawler = self::submit($form);
+ $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text());
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}");
+ $this->assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text());
+ }
+
+ public function test_feeds_softdeleted_topic_admin()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the soft-deleted post is marked as soft-delete for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'POST_DELETED',
+ 2 => 'POST_DELETED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_DELETED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_softdeleted_topic_guest()
+ {
+ $this->markTestIncomplete('Softdeleted posts/topics are not marked in feeds yet, see PHPBB3-12460');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #2',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['forums']['Feeds #1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1 - Topic #2'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 4,
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_unapproved_post()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+
+ $this->login('admin');
+ $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.');
+ $this->data['topics']['Feeds #1.1 - Topic #2'] = (int) $post['topic_id'];
+ $this->logout();
+
+ // Test creating a reply
+ $this->login('disapprove_user');
+ $post2 = $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');
+
+ $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}");
+ $this->assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text());
+ }
+
+ public function test_feeds_unapproved_post_admin()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved post is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 3,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 9,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_post_disapprove_user()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #2',
+ ),
+ ));
+
+ // Assert that the unapproved isn't displayed for regular users
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #2'],
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_unapproved_topic()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ ));
+
+ // We have to wait because of the flood interval.
+ sleep(15);
+
+ $this->login('disapprove_user');
+ $post = $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');
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}");
+
+ $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text());
+ }
+
+ public function test_feeds_unapproved_topic_admin()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ // Assert that the unapproved topic is marked as unapproved for users that have the right to see it.
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 4,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 10,
+ 'contents_lang' => array(
+ 1 => 'POST_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 7,
+ 'contents_lang' => array(
+ 1 => 'TOPIC_UNAPPROVED',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_unapproved_topic_disapprove_user()
+ {
+ $this->markTestIncomplete('Unapproved posts/topics are not marked in feeds yet, see PHPBB3-12459');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1.1',
+ ),
+ 'topics' => array(
+ 'Feeds #1.1 - Topic #3',
+ ),
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1.1'],
+ ),
+ ),
+ 't' => array(
+ array(
+ 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'],
+ 'contents_lang' => array('SORRY_AUTH_READ'),
+ 'invalid' => true,
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ ),
+ ),
+ ), 'disapprove_user');
+ }
+
+ public function test_create_attachment_topic()
+ {
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ ));
+
+ // Test creating a topic with 1 attachment
+ $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));
+ $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text());
+ $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id'];
+ }
+
+ public function test_feeds_attachment_admin()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ public function test_feeds_attachment_guest()
+ {
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'attachments' => true,
+ ));
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 1,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 6,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 5,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ));
+ }
+
+ public function test_create_missing_attachment_post()
+ {
+ $this->markTestIncomplete('Missing attachments in posts/topics are not marked in feeds yet, see PHPBB3-12418');
+ $this->login();
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ // Test creating a reply with 1 missing attachment
+ $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]');
+ $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+
+ $this->assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text());
+ $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id'];
+ }
+
+ public function test_feeds_missing_attachment_admin()
+ {
+ $this->markTestIncomplete('Missing attachments in posts/topics are not marked in feeds yet, see PHPBB3-12418');
+ $this->load_ids(array(
+ 'forums' => array(
+ 'Feeds #1',
+ ),
+ 'topics' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ 'posts' => array(
+ 'Feeds #1 - Topic #3',
+ ),
+ ));
+
+ $this->add_lang('viewtopic');
+
+ $this->assert_feeds(array(
+ 'f' => array(
+ array(
+ 'nb_entries' => 5,
+ 'id' => $this->data['forums']['Feeds #1'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 't' => array(
+ array(
+ 'nb_entries' => 2,
+ 'id' => $this->data['topics']['Feeds #1 - Topic #3'],
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'overall' => array(
+ array(
+ 'nb_entries' => 13,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ 'topics' => array(
+ array(
+ 'nb_entries' => 9,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_new' => array(
+ array(
+ 'nb_entries' => 9,
+ 'attachments' => array(
+ 1 => array( // First entry
+ array( // First attachment to fetch
+ 'id' => $this->data['attachments'][$this->data['posts']['Feeds #1 - Topic #3']][0],
+ 'displayed' => false,
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'topics_active' => array(
+ array(
+ 'nb_entries' => 9,
+ 'contents' => array(
+ 1 => 'Attachment #0',
+ ),
+ ),
+ ),
+ ), 'admin');
+ }
+
+ protected function assert_feeds($data, $username = false)
+ {
+ if ($username)
+ {
+ $this->login($username);
+ $init_values = self::$init_values[$username];
+ }
+ else
+ {
+ $init_values = self::$init_values['disapprove_user'];
+ }
+
+ foreach ($data as $mode => $feeds)
+ {
+ foreach ($feeds as $feed_data)
+ {
+ if ($mode === 'f' || $mode === 't')
+ {
+ $params = "?{$mode}={$feed_data['id']}";
+ $this->assert_feed($params, $feed_data);
+ }
+ else
+ {
+ switch ($mode) {
+ case 'forums':
+ $feed_data['nb_entries'] = ((int)$feed_data['nb_entries'] + $init_values['forums_value']);
+ break;
+ case 'overall':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['overall_value'], self::$init_values['post_base_items']);
+ break;
+ case 'topics':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_new':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_new_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'topics_active':
+ $feed_data['nb_entries'] = min($feed_data['nb_entries'] + $init_values['topics_active_value'], self::$init_values['topic_base_items']);
+ break;
+ case 'news':
+ break;
+ default:
+ $this->fail('Unsupported feed mode: ' . $mode);
+ }
+
+ $params = "?mode={$mode}";
+ $this->assert_feed($params, $feed_data);
+ }
+ }
+ }
+ }
+
+ protected function assert_feed($params, $data)
+ {
+ $crawler = self::request('GET', 'feed.php' . $params, array(), false);
+
+ if (empty($data['invalid']))
+ {
+ self::assert_response_xml();
+ $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'");
+
+ if (!empty($data['xpath']))
+ {
+
+ foreach($data['xpath'] as $xpath => $count_expected)
+ {
+ $this->assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'feed.php{$params}', Search for {$xpath}");
+ }
+ }
+
+ if (!empty($data['contents']))
+ {
+ foreach($data['contents'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $entry_id => $string)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+
+ if (!empty($data['attachments']))
+ {
+ foreach($data['attachments'] as $entry_id => $attachments)
+ {
+ foreach ($attachments as $i => $attachment)
+ {
+ $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text();
+ $url = "./download/file.php?id={$attachment['id']}";
+ $string = "Attachment #{$i}";
+
+ if ($attachment['displayed'])
+ {
+ $this->assertContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ // $this->assertNotContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ else
+ {
+ // Disabled until PHPBB3-12421 is fixed and merged
+ // $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'");
+ // $this->assertNotContains($url, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ self::assert_response_html();
+
+ if (!empty($data['contents_lang']))
+ {
+ foreach($data['contents_lang'] as $string)
+ {
+ $content = $crawler->filter('html')->text();
+ $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'");
+ }
+ }
+ }
+ }
+
+ protected function load_ids($data)
+ {
+ $this->db = $this->get_db();
+
+ if (!empty($data['forums']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_forums
+ WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['forum_name'], $data['forums']))
+ {
+ $this->data['forums'][$row['forum_name']] = (int) $row['forum_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!empty($data['topics']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_topics
+ WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['topic_title'], $data['topics']))
+ {
+ $this->data['topics'][$row['topic_title']] = (int) $row['topic_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ $post_ids = array();
+ if (!empty($data['posts']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_posts
+ WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (in_array($row['post_subject'], $data['posts']))
+ {
+ $this->data['posts'][$row['post_subject']] = (int) $row['post_id'];
+ $post_ids[] = (int) $row['post_id'];
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ if (isset($data['attachments']))
+ {
+ $sql = 'SELECT *
+ FROM phpbb_attachments
+ WHERE in_message = 0 AND ' . $this->db->sql_in_set('post_msg_id', $post_ids);
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->data['attachments'][(int) $row['post_msg_id']][] = (int) $row['attach_id'];
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+ }
+}