From 09a17b4944da95a5e3e3104541994babaa37f455 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 10 Feb 2014 12:19:08 +0100 Subject: [ticket/12171] Add functional tests for downloading attachments PHPBB3-12171 --- tests/functional/download_test.php | 345 +++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 tests/functional/download_test.php (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php new file mode 100644 index 0000000000..24366992d5 --- /dev/null +++ b/tests/functional/download_test.php @@ -0,0 +1,345 @@ +login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Download #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + } + + public function test_create_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + )); + + // Test creating topic + $post = $this->create_topic($this->data['forums']['Download #1'], 'Download Topic #1', 'This is a test topic posted by the testing framework.', array('upload_files' => 1)); + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Download Topic #1', $crawler->filter('html')->text()); + $this->data['topics']['Download Topic #1'] = (int) $post['topic_id']; + $this->data['posts']['Download Topic #1'] = (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']['Download #1'], $post['topic_id'], 'Re: Download Topic #1-#2', 'This is a test post posted by the testing framework.', array('upload_files' => 1)); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Re: Download Topic #1-#2', $crawler->filter('html')->text()); + $this->data['posts']['Re: Download Topic #1-#2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + } + + public function test_download_accessible() + { + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + 'topics' => array( + 'Download Topic #1', + ), + 'posts' => array( + 'Download Topic #1', + 'Re: Download Topic #1-#2', + ), + 'attachments' => true, + )); + + // Download topic archive as guest + $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download post archive as guest + $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download attachment as guest + $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('image/jpeg', $finfo->buffer($content)); + } + + public function test_softdelete_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + 'topics' => array( + 'Download Topic #1', + ), + 'posts' => array( + 'Download Topic #1', + 'Re: Download Topic #1-#2', + ), + )); + $this->add_lang('posting'); + + $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Download #1']}&p={$this->data['posts']['Re: Download Topic #1-#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']['Download Topic #1']}&sid={$this->sid}"); + $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); + } + + public function test_download_softdeleted_post() + { + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + 'topics' => array( + 'Download Topic #1', + ), + 'posts' => array( + 'Download Topic #1', + 'Re: Download Topic #1-#2', + ), + 'attachments' => true, + )); + $this->add_lang('viewtopic'); + + // Download topic archive as guest: still works + $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // No download post archive as guest + $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); + self::assert_response_html(404); + $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); + + // No download attachment as guest + $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); + self::assert_response_html(404); + $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); + + // Login as admin and try again, should work now. + $this->login(); + + // Download topic archive as admin + $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download post archive as admin + $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download attachment as admin + $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('image/jpeg', $finfo->buffer($content)); + } + + public function test_softdelete_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + 'topics' => array( + 'Download Topic #1', + ), + 'posts' => array( + 'Download Topic #1', + 'Re: Download Topic #1-#2', + ), + )); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Download Topic #1']}&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']['Download Topic #1']}&sid={$this->sid}"); + $this->assertContains('Download Topic #1', $crawler->filter('h2')->text()); + } + + public function test_download_softdeleted_topic() + { + $this->load_ids(array( + 'forums' => array( + 'Download #1', + ), + 'topics' => array( + 'Download Topic #1', + ), + 'posts' => array( + 'Download Topic #1', + 'Re: Download Topic #1-#2', + ), + 'attachments' => true, + )); + $this->add_lang('viewtopic'); + + // Download topic archive as guest: still works + $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); + self::assert_response_html(404); + $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); + + // No download post archive as guest + $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); + self::assert_response_html(404); + $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); + + // No download attachment as guest + $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); + self::assert_response_html(404); + $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); + + // Login as admin and try again, should work now. + $this->login(); + + // Download topic archive as admin + $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download post archive as admin + $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('application/zip', $finfo->buffer($content)); + + // Download attachment as admin + $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); + self::assert_response_status_code(200); + $content = self::$client->getResponse()->getContent(); + $finfo = new finfo(FILEINFO_MIME_TYPE); + self::assertEquals('image/jpeg', $finfo->buffer($content)); + } + + public 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); + } + } + } +} -- cgit v1.2.1 From 5124920d22be22d8961cdee5b4716e6111ea37bb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 12 Apr 2014 14:36:05 +0200 Subject: [ticket/12398] Use return of submit_post in softdelete and download tests PHPBB3-12398 --- tests/functional/download_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 24366992d5..087250157d 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -57,7 +57,7 @@ class phpbb_functional_download_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('Re: Download Topic #1-#2', $crawler->filter('html')->text()); - $this->data['posts']['Re: Download Topic #1-#2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + $this->data['posts']['Re: Download Topic #1-#2'] = (int) $post2['post_id']; } public function test_download_accessible() -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- tests/functional/download_test.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 087250157d..dbf197fcfa 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From d95c97c3b4bd3f6efbdf3b457e6f9377fed640d3 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Sat, 14 Jun 2014 15:36:36 -0700 Subject: [ticket/12013] Fix functional tests and sniffer issue. PHPBB3-12013 --- tests/functional/download_test.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index dbf197fcfa..6a6df14c81 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -205,12 +205,8 @@ class phpbb_functional_download_test extends phpbb_functional_test_case ), )); - $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Download Topic #1']}&sid={$this->sid}"); - $this->add_lang('posting'); - $form = $crawler->selectButton('Go')->eq(2)->form(); - $form['action']->select('delete_topic'); - $crawler = self::submit($form); + $crawler = $this->get_quickmod_page($this->data['topics']['Download Topic #1'], 'DELETE_TOPIC'); $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); $this->add_lang('mcp'); -- cgit v1.2.1 From 74c3579693bac0c09bfd3bd9eded18cf57107c33 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 10 Aug 2014 01:27:28 +0200 Subject: [ticket/12938] Remove functional tests for 'Download all attachments'. PHPBB3-12938 --- tests/functional/download_test.php | 64 -------------------------------------- 1 file changed, 64 deletions(-) (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 6a6df14c81..4e4995c21e 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -80,20 +80,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case 'attachments' => true, )); - // Download topic archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); @@ -147,18 +133,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case )); $this->add_lang('viewtopic'); - // Download topic archive as guest: still works - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // No download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - // No download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_html(404); @@ -167,20 +141,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case // Login as admin and try again, should work now. $this->login(); - // Download topic archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as admin $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); @@ -235,16 +195,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case )); $this->add_lang('viewtopic'); - // Download topic archive as guest: still works - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - - // No download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - // No download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_html(404); @@ -253,20 +203,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case // Login as admin and try again, should work now. $this->login(); - // Download topic archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as admin $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); -- cgit v1.2.1 From c1d644769f991604aa783f55c93984778a565eb4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 4 Feb 2015 15:24:25 +0100 Subject: [ticket/13577] Skip functional tests requiring fileinfo if not enabled PHPBB3-13577 --- tests/functional/download_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/functional/download_test.php') diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 4e4995c21e..1e863210e6 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -66,6 +66,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_accessible() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', @@ -118,6 +123,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_softdeleted_post() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', @@ -180,6 +190,11 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function test_download_softdeleted_topic() { + if (!class_exists('finfo')) + { + $this->markTestSkipped('Unable to run test with fileinfo disabled'); + } + $this->load_ids(array( 'forums' => array( 'Download #1', -- cgit v1.2.1