diff options
-rw-r--r-- | tests/functional/feed_test.php | 1373 |
1 files changed, 1373 insertions, 0 deletions
diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php new file mode 100644 index 0000000000..9aff0340f4 --- /dev/null +++ b/tests/functional/feed_test.php @@ -0,0 +1,1373 @@ +<?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(); + + 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() + { + $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(); + $values = $form->getValues(); + + // 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); + + // 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->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + + // News 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->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + 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' => 4, + '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' => 1, + 'xpath' => array( + '//entry/title[contains(., "#exclude")]' => 0, + ), + ), + ), + 'topics' => array( + array( + 'nb_entries' => 1, + 'xpath' => array( + '//entry/title[contains(., "#exclude")]' => 0, + ), + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 1, + 'xpath' => array( + '//entry/title[contains(., "#exclude")]' => 0, + ), + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 1, + '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']; + + $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}"); + + $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' => 4, + 'xpath' => array( + '//entry/title[contains(., "#news")]' => 3, + ), + ), + ), + 'topics' => array( + array( + 'nb_entries' => 3, + 'xpath' => array( + '//entry/title[contains(., "#news")]' => 2, + ), + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 3, + 'xpath' => array( + '//entry/title[contains(., "#news")]' => 2, + ), + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 3, + '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']; + + $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->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']; + + // 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->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->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' => 8, + 'contents_lang' => array( + 1 => 'POST_DELETED', + ), + ), + ), + ), 'admin'); + } + + public function test_feeds_softdeleted_post_guest() + { + $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' => 7, + ), + ), + )); + } + + public function test_softdelete_topic() + { + $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->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' => 8, + 'contents_lang' => array( + 1 => 'POST_DELETED', + 2 => 'POST_DELETED', + ), + ), + ), + 'topics' => array( + array( + 'nb_entries' => 6, + 'contents_lang' => array( + 1 => 'TOPIC_DELETED', + ), + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 6, + 'contents_lang' => array( + 1 => 'TOPIC_DELETED', + ), + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 6, + 'contents_lang' => array( + 1 => 'TOPIC_DELETED', + ), + ), + ), + ), 'admin'); + } + + public function test_feeds_softdeleted_topic_guest() + { + $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' => 6, + ), + ), + 'topics' => array( + array( + 'nb_entries' => 5, + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 5, + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 5, + ), + ), + )); + } + + public function test_create_unapproved_post() + { + $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->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' => 10, + 'contents_lang' => array( + 1 => 'POST_UNAPPROVED', + ), + ), + ), + ), 'admin'); + } + + public function test_feeds_unapproved_post_disapprove_user() + { + $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' => 7, + ), + ), + ), 'disapprove_user'); + } + + public function test_create_unapproved_topic() + { + $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->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' => 11, + 'contents_lang' => array( + 1 => 'POST_UNAPPROVED', + ), + ), + ), + 'topics' => array( + array( + 'nb_entries' => 8, + 'contents_lang' => array( + 1 => 'TOPIC_UNAPPROVED', + ), + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 8, + 'contents_lang' => array( + 1 => 'TOPIC_UNAPPROVED', + ), + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 8, + 'contents_lang' => array( + 1 => 'TOPIC_UNAPPROVED', + ), + ), + ), + ), 'admin'); + } + + public function test_feeds_unapproved_topic_disapprove_user() + { + $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' => 7, + ), + ), + 'topics' => array( + array( + 'nb_entries' => 6, + ), + ), + 'topics_new' => array( + array( + 'nb_entries' => 6, + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 6, + ), + ), + ), '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' => 4, + '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' => 12, + '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' => 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' => true, + ), + ), + ), + ), + ), + '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' => true, + ), + ), + ), + ), + ), + 'topics_active' => 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' => 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' => 8, + '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' => 7, + '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' => 7, + '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' => 7, + '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, + ), + ), + ), + ), + ), + )); + } + + // Disabled until PHPBB3-12418 is fixed and merged + /*public function test_create_missing_attachment_post() + { + $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->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); + } + + 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 + { + $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 (!(isset($data['invalid']) && $data['invalid'])) + { + self::assert_response_xml(); + $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'"); + + if (sizeof($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 (sizeof($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 (sizeof($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 (sizeof($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 (sizeof($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); + } + } + } +} |