diff options
Diffstat (limited to 'tests/functional')
82 files changed, 7472 insertions, 67 deletions
diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 3d8cabb086..9dfdc93474 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -1,21 +1,124 @@ <?php /** * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -require_once dirname(__FILE__) . '/common_groups_test.php'; +require_once dirname(__FILE__) . '/common_groups_test_case.php'; /** * @group functional */ -class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test +class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test_case { + protected $form_data; + protected function get_url() { return 'adm/index.php?i=groups&mode=manage&action=edit'; } + + public function acp_group_test_data() + { + return array( + 'both_yes' => array( + 5, + true, + true, + ), + 'legend_no_teampage' => array( + 5, + true, + false, + ), + 'no_legend_teampage' => array( + 5, + false, + true, + ), + 'both_no' => array( + 5, + false, + false, + ), + 'no_change' => array( + 5, + NULL, + NULL, + ), + 'back_to_default' => array( + 5, + true, + true, + ), + // Remove and add moderators back in order to reset + // group order to default one + 'mods_both_no' => array( + 4, + false, + false, + ), + 'mods_back_to_default' => array( + 4, + true, + true, + ), + ); + } + + /** + * @dataProvider acp_group_test_data + */ + public function test_acp_groups_teampage($group_id, $tick_legend, $tick_teampage) + { + $this->group_manage_login(); + + // Manage Administrators group + $form = $this->get_group_manage_form($group_id); + $this->form_data[0] = $form->getValues(); + + if (isset($tick_legend) && isset($tick_teampage)) + { + if ($tick_legend) + { + $form['group_legend']->tick(); + } + else + { + $form['group_legend']->untick(); + } + + if ($tick_teampage) + { + $form['group_teampage']->tick(); + } + else + { + $form['group_teampage']->untick(); + } + } + $crawler = self::submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $form = $this->get_group_manage_form($group_id); + if (!isset($tick_legend) && !isset($tick_teampage)) + { + $this->form_data[1] = $form->getValues(); + unset($this->form_data[0]['creation_time'], $this->form_data[0]['form_token'], $this->form_data[1]['creation_time'], $this->form_data[1]['form_token']); + $this->assertEquals($this->form_data[0], $this->form_data[1]); + } + else + { + $this->form_data = $form->getValues(); + $this->assertEquals($tick_legend, $this->form_data['group_legend']); + $this->assertEquals($tick_teampage, $this->form_data['group_teampage']); + } + } } diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php new file mode 100644 index 0000000000..0a40e76057 --- /dev/null +++ b/tests/functional/acp_permissions_test.php @@ -0,0 +1,127 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case +{ + public function setUp() + { + parent::setUp(); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + } + + public function test_permissions_tab() + { + // Permissions tab + // XXX hardcoded id + $crawler = self::request('GET', 'adm/index.php?i=16&sid=' . $this->sid); + // these language strings are html + $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content()); + } + + public function test_select_user() + { + // User permissions + $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content()); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = self::submit($form); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + } + + public function permissions_data() + { + return array( + // description + // permission type + // permission name + // mode + // object name + // object id + array( + 'user permission', + 'u_', + 'u_hideonline', + 'setting_user_global', + 'user_id', + 2, + ), + array( + 'moderator permission', + 'm_', + 'm_ban', + 'setting_mod_global', + 'group_id', + 4, + ), + /* Admin does not work yet, probably because founder can do everything + array( + 'admin permission', + 'a_', + 'a_forum', + 'setting_admin_global', + 'group_id', + 5, + ), + */ + ); + } + + /** + * @dataProvider permissions_data + */ + public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id) + { + // Get the form + $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + + // XXX globals for \phpbb\auth\auth, refactor it later + global $db, $cache; + $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; + + $auth = new \phpbb\auth\auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(1, $auth->acl_get($permission)); + + // Set u_hideonline to never + $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); + // initially it should be a yes + $values = $form->getValues(); + $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]); + // set to never + $data = array("setting[$object_id][0][$permission]" => '0'); + $form->setValues($data); + $crawler = self::submit($form); + $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + + // check acl again + $auth = new \phpbb\auth\auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(0, $auth->acl_get($permission)); + } +} diff --git a/tests/functional/acp_profile_field_test.php b/tests/functional/acp_profile_field_test.php new file mode 100644 index 0000000000..88df782faa --- /dev/null +++ b/tests/functional/acp_profile_field_test.php @@ -0,0 +1,71 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case +{ + public function setUp() + { + parent::setUp(); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/profile'); + } + + public function data_add_profile_field() + { + return array( + array('bool', 'profilefields.type.bool', + array( + 'lang_options[0]' => 'foo', + 'lang_options[1]' => 'bar', + ), + array(), + ), + array('dropdown', 'profilefields.type.dropdown', + array( + 'lang_options' => "foo\nbar\nbar\nfoo", + ), + array(), + ), + ); + } + + /** + * @dataProvider data_add_profile_field + */ + public function test_add_profile_field($name, $type, $page1_settings, $page2_settings) + { + // Custom profile fields page + $crawler = self::request('GET', 'adm/index.php?i=acp_profile&mode=profile&sid=' . $this->sid); + // these language strings are html + $form = $crawler->selectButton('Create new field')->form(array( + 'field_ident' => $name, + 'field_type' => $type, + )); + $crawler = self::submit($form); + + // Fill form for profile field options + $form = $crawler->selectButton('Profile type specific options')->form($page1_settings); + $crawler = self::submit($form); + + // Fill form for profile field specific options + $form = $crawler->selectButton('Save')->form($page2_settings); + $crawler= self::submit($form); + + $this->assertContainsLang('ADDED_PROFILE_FIELD', $crawler->text()); + } +} diff --git a/tests/functional/acp_registration_test.php b/tests/functional/acp_registration_test.php new file mode 100644 index 0000000000..ef9843679e --- /dev/null +++ b/tests/functional/acp_registration_test.php @@ -0,0 +1,55 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_registration_test extends phpbb_functional_test_case +{ + protected function set_email_enable($db, $status) + { + $sql = "UPDATE phpbb_config + SET config_value = '" . (($status) ? '1' : '0') . "' + WHERE config_name = 'email_enable'"; + $db->sql_query($sql); + + $this->purge_cache(); + } + + public function test_submitting_activation_method() + { + $db = $this->get_db(); + + $this->set_email_enable($db, false); + + $this->add_lang('acp/board'); + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid); + $this->assertContainsLang('ACP_REGISTER_SETTINGS_EXPLAIN', $this->get_content()); + + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[require_activation]']->select(USER_ACTIVATION_ADMIN); + $crawler = self::submit($form); + $this->assertContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[require_activation]']->select(USER_ACTIVATION_NONE); + $crawler = self::submit($form); + $this->assertNotContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text()); + + $this->set_email_enable($db, true); + } +} diff --git a/tests/functional/acp_users_test.php b/tests/functional/acp_users_test.php index 50d9a67dc1..78028aacb8 100644 --- a/tests/functional/acp_users_test.php +++ b/tests/functional/acp_users_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index afb4f15fc2..76e1709afb 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -18,7 +22,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check for logout link $crawler = self::request('GET', 'index.php'); - $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); + $this->assertContains($this->lang('LOGOUT', 'admin'), $crawler->filter('.navbar')->text()); } public function test_login_other() @@ -26,7 +30,26 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->create_user('anothertestuser'); $this->login('anothertestuser'); $crawler = self::request('GET', 'index.php'); - $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); + $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); + } + + /** + * @dependsOn test_login_other + */ + public function test_login_ucp_other_auth_provider() + { + global $cache, $config; + $cache = new phpbb_mock_null_cache; + $db = $this->get_db(); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $config['auth_method'] = 'foobar'; + $this->login('anothertestuser'); + $crawler = self::request('GET', 'index.php'); + $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $config['auth_method'] = 'db'; } /** @@ -39,10 +62,19 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } + + public function test_acp_login() + { + $this->login(); + $this->admin_login(); + + // check that we are logged in + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); + } } diff --git a/tests/functional/avatar_acp_groups_test.php b/tests/functional/avatar_acp_groups_test.php new file mode 100644 index 0000000000..ca8c84ab2e --- /dev/null +++ b/tests/functional/avatar_acp_groups_test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test_case +{ + public function get_url() + { + return 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5'; + } + + public function avatar_acp_groups_data() + { + return array( + // Correct Gravatar + array( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Gravatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 120, + 'avatar_gravatar_height' => 120, + ), + ), + // Delete avatar image to reset group settings + array( + array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'), + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + array( + 'The URL you specified is invalid.', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + ); + } + + /** + * @dataProvider avatar_acp_groups_data + */ + public function test_avatar_acp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } + + // Test if avatar was really deleted + public function test_no_avatar_acp_groups() + { + $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form_data = $form->getValues(); + $this->assertEmpty($form_data['avatar_type']); + } +} diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php new file mode 100644 index 0000000000..8b05a28658 --- /dev/null +++ b/tests/functional/avatar_acp_users_test.php @@ -0,0 +1,65 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test_case +{ + public function get_url() + { + return 'adm/index.php?i=acp_users&u=2&mode=avatar'; + } + + public function avatar_acp_users_data() + { + return array( + // Gravatar with incorrect email + array( + 'EMAIL_INVALID_EMAIL', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test.example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Remote avatar with correct link + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ), + ), + // Reset avatar settings + array( + array('CONFIRM_AVATAR_DELETE', 'USER_AVATAR_UPDATED'), + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_acp_users_data + */ + public function test_avatar_acp_users($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_ucp_groups_test.php b/tests/functional/avatar_ucp_groups_test.php new file mode 100644 index 0000000000..52ef67543e --- /dev/null +++ b/tests/functional/avatar_ucp_groups_test.php @@ -0,0 +1,74 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test_case +{ + public function get_url() + { + return 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5'; + } + + public function avatar_ucp_groups_data() + { + return array( + // Incorrect URL + array( + 'AVATAR_URL_INVALID', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80', + ), + ), + /* + // Does not work due to DomCrawler issue + // Valid file upload + array( + 'GROUP_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'), + ), + ), + */ + // Correct remote avatar + array( + 'GROUP_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + array( + array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'), + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_ucp_groups_data + */ + public function test_avatar_ucp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_ucp_users_test.php b/tests/functional/avatar_ucp_users_test.php new file mode 100644 index 0000000000..2f0832e092 --- /dev/null +++ b/tests/functional/avatar_ucp_users_test.php @@ -0,0 +1,73 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test_case +{ + public function get_url() + { + return 'ucp.php?i=ucp_profile&mode=avatar'; + } + + public function avatar_ucp_groups_data() + { + return array( + // Gravatar with correct settings + array( + 'PROFILE_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + + array( + array('CONFIRM_AVATAR_DELETE', 'PROFILE_UPDATED'), + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_ucp_groups_data + */ + public function test_avatar_ucp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } + + public function test_display_upload_avatar() + { + $this->assert_avatar_submit('PROFILE_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ) + ); + + $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid); + $avatar_link = $crawler->filter('img')->attr('src'); + $crawler = self::request('GET', $avatar_link . '&sid=' . $this->sid, array(), false); + $content = self::$client->getResponse()->getContent(); + self::assertEquals(false, stripos(trim($content), 'debug'), 'Output contains debug message'); + } +} diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 18a2ad9464..b9e74a280f 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -29,4 +33,11 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } + + public function test_feed() + { + $crawler = self::request('GET', 'feed.php', array(), false); + self::assert_response_xml(); + $this->assertGreaterThan(0, $crawler->filter('entry')->count()); + } } diff --git a/tests/functional/common_avatar_test_case.php b/tests/functional/common_avatar_test_case.php new file mode 100644 index 0000000000..7278f23bcc --- /dev/null +++ b/tests/functional/common_avatar_test_case.php @@ -0,0 +1,97 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** + * @group functional + */ +abstract class phpbb_functional_common_avatar_test_case extends phpbb_functional_test_case +{ + private $path; + private $form_content; + + abstract function get_url(); + + public function setUp() + { + parent::setUp(); + $this->path = __DIR__ . '/fixtures/files/'; + $this->login(); + $this->admin_login(); + $this->add_lang(array('acp/board', 'ucp', 'acp/users', 'acp/groups')); + $this->set_acp_settings(); + } + + private function set_acp_settings() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid); + // Check the default entries we should have + $this->assertContainsLang('ALLOW_GRAVATAR', $crawler->text()); + $this->assertContainsLang('ALLOW_REMOTE_UPLOAD', $crawler->text()); + $this->assertContainsLang('ALLOW_AVATARS', $crawler->text()); + $this->assertContainsLang('ALLOW_LOCAL', $crawler->text()); + + // Now start setting the needed settings + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[allow_avatar_local]']->select(1); + $form['config[allow_avatar_gravatar]']->select(1); + $form['config[allow_avatar_remote]']->select(1); + $form['config[allow_avatar_remote_upload]']->select(1); + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); + } + + public function assert_avatar_submit($expected, $type, $data, $delete = false, $button_text = 'SUBMIT') + { + $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid); + + // Test if setting a gravatar avatar properly works + $form = $crawler->selectButton($this->lang($button_text))->form(); + $form['avatar_driver']->select($type); + + foreach ($data as $key => $value) + { + if (is_array($value)) + { + $form[$key]->$value[0]($value[1]); + } + else + { + $form[$key]->setValue($value); + } + } + + $crawler = self::submit($form); + + if (is_array($expected)) + { + $delete_expected = $expected[1]; + $expected = $expected[0]; + } + + try + { + $this->assertContainsLang($expected, $crawler->text()); + } + catch (Exception $e) + { + $this->assertContains($expected, $crawler->text()); + } + + if ($delete) + { + $form = $crawler->selectButton('confirm')->form(); + $crawler = self::submit($form); + $this->assertContainsLang($delete_expected, $crawler->text()); + } + } +} diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test_case.php index 427a930cb9..521b7c84d2 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test_case.php @@ -1,19 +1,45 @@ <?php /** * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ /** * @group functional */ -abstract class phpbb_functional_common_groups_test extends phpbb_functional_test_case +abstract class phpbb_functional_common_groups_test_case extends phpbb_functional_test_case { abstract protected function get_url(); + /** + * Get group_manage form + * @param int $group_id ID of the group that should be managed + */ + protected function get_group_manage_form($group_id = 5) + { + // Manage Administrators group + $crawler = self::request('GET', $this->get_url() . "&g=$group_id&sid=" . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + return $form; + } + + /** + * Execute login calls and add_lang() calls for tests + */ + protected function group_manage_login() + { + $this->login(); + $this->admin_login(); + $this->add_lang(array('ucp', 'acp/groups')); + } + // Enable all avatars in the ACP protected function enable_all_avatars() { @@ -21,7 +47,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $crawler = self::request('GET', 'adm/index.php?i=board&mode=avatar&sid=' . $this->sid); // Check the default entries we should have - $this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text()); + $this->assertContains($this->lang('ALLOW_REMOTE_UPLOAD'), $crawler->text()); $this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text()); $this->assertContains($this->lang('ALLOW_LOCAL'), $crawler->text()); @@ -50,13 +76,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test */ public function test_groups_manage($input, $expected) { - $this->login(); - $this->admin_login(); - $this->add_lang(array('ucp', 'acp/groups')); + $this->group_manage_login(); // Manage Administrators group - $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form = $this->get_group_manage_form(); $form['group_colour']->setValue($input); $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); @@ -65,19 +88,19 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test public function group_avatar_min_max_data() { return array( - array('uploadurl', 'foo', 'TOO_SHORT'), - array('uploadurl', 'foobar', 'AVATAR_URL_INVALID'), - array('uploadurl', str_repeat('f', 256), 'TOO_LONG'), - array('remotelink', 'foo', 'TOO_SHORT'), - array('remotelink', 'foobar', 'AVATAR_URL_INVALID'), - array('remotelink', str_repeat('f', 256), 'TOO_LONG'), + array('avatar_driver_upload', 'avatar_upload_url', 'foo', 'AVATAR_URL_INVALID'), + array('avatar_driver_upload', 'avatar_upload_url', 'foobar', 'AVATAR_URL_INVALID'), + array('avatar_driver_upload', 'avatar_upload_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), + array('avatar_driver_remote', 'avatar_remote_url', 'foo', 'AVATAR_URL_INVALID'), + array('avatar_driver_remote', 'avatar_remote_url', 'foobar', 'AVATAR_URL_INVALID'), + array('avatar_driver_remote', 'avatar_remote_url', 'http://www.phpbb.com/' . str_repeat('f', 240) . '.png', 'TOO_LONG'), ); } /** * @dataProvider group_avatar_min_max_data */ - public function test_group_avatar_min_max($form_name, $input, $expected) + public function test_group_avatar_min_max($avatar_type, $form_name, $input, $expected) { $this->login(); $this->admin_login(); @@ -86,6 +109,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['avatar_driver']->setValue($avatar_type); $form[$form_name]->setValue($input); $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php new file mode 100644 index 0000000000..4e4995c21e --- /dev/null +++ b/tests/functional/download_test.php @@ -0,0 +1,281 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +/** +* @group functional +*/ +class phpbb_functional_download_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->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) $post2['post_id']; + } + + 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 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'); + + // 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 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', + ), + )); + + $this->add_lang('posting'); + $crawler = $this->get_quickmod_page($this->data['topics']['Download Topic #1'], 'DELETE_TOPIC'); + $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'); + + // 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 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); + } + } + } +} diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php new file mode 100644 index 0000000000..7be8957ec7 --- /dev/null +++ b/tests/functional/extension_acp_test.php @@ -0,0 +1,235 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_extension_acp_test extends phpbb_functional_test_case +{ + static private $helper; + + static protected $fixtures = array( + './', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/../extension/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + // Clear the phpbb_ext table + $this->db->sql_query('DELETE FROM phpbb_ext'); + + // Insert our base data + $insert_rows = array( + array( + 'ext_name' => 'vendor2/foo', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'vendor/moo', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + + // do not exist + array( + 'ext_name' => 'vendor/test2', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'vendor/test3', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + ); + $this->db->sql_multi_insert('phpbb_ext', $insert_rows); + + $this->login(); + $this->admin_login(); + + $this->add_lang('acp/extensions'); + } + + public function test_list() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + + $this->assertCount(1, $crawler->filter('.ext_enabled')); + $this->assertCount(6, $crawler->filter('.ext_disabled')); + + $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); + $this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text()); + + $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('EXTENSION_ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('EXTENSION_DELETE_DATA', $crawler->filter('.ext_disabled')->eq(2)->text()); + + $this->assertContains('The “vendor/test2” extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); + + $this->assertContains('The “vendor/test3” extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text()); + + $this->assertContains('phpBB Bar Extension', $crawler->filter('.ext_disabled')->eq(3)->text()); + $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(3)->text()); + $this->assertContainsLang('EXTENSION_ENABLE', $crawler->filter('.ext_disabled')->eq(3)->text()); + + // Check that invalid extensions are not listed. + $this->assertNotContains('phpBB BarFoo Extension', $crawler->filter('.table1')->text()); + $this->assertNotContains('barfoo', $crawler->filter('.table1')->text()); + + $this->assertNotContains('vendor3/bar', $crawler->filter('.table1')->text()); + } + + public function test_details() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=vendor2%2Ffoo&sid=' . $this->sid); + + $validation = array( + 'DISPLAY_NAME' => 'phpBB Foo Extension', + 'CLEAN_NAME' => 'vendor2/foo', + 'TYPE' => 'phpbb-extension', + 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.', + 'VERSION' => '1.0.0', + 'TIME' => '2012-02-15 01:01:01', + 'LICENSE' => 'GPL-2.0', + 'PHPBB_VERSION' => '3.1.*@dev', + 'PHP_VERSION' => '>=5.3', + 'AUTHOR_NAME' => 'John Smith', + 'AUTHOR_EMAIL' => 'email@phpbb.com', + 'AUTHOR_HOMEPAGE' => 'http://phpbb.com', + 'AUTHOR_ROLE' => 'N/A', + ); + + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) + { + $text = $crawler->filter('dl')->eq($i)->text(); + + $match = false; + + foreach ($validation as $language_key => $expected) + { + if (strpos($text, $this->lang($language_key)) === 0) + { + $match = true; + + $this->assertContains($expected, $text); + } + } + + if (!$match) + { + $this->fail('Unexpected field: "' . $text . '"'); + } + } + } + + public function test_enable_pre() + { + // Foo is already enabled (redirect to list) + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContains($this->lang('EXTENSION_ENABLE_CONFIRM', 'phpBB Moo Extension'), $crawler->filter('#main')->text()); + + // Correctly submit the enable form + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor3%2Ffoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_ENABLEABLE', $crawler->filter('.errorbox')->text()); + } + + public function test_disable_pre() + { + // Moo is not enabled (redirect to list) + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid); + $this->assertContains($this->lang('EXTENSION_DISABLE_CONFIRM', 'phpBB Foo Extension'), $crawler->filter('#main')->text()); + } + + public function test_delete_data_pre() + { + // test2 is not available (error) + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=test2&sid=' . $this->sid); + $this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('.errorbox')->text()); + + // foo is not disabled (redirect to list) + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('div.main thead')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('div.main thead')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContains('Are you sure that you wish to delete the data associated with “phpBB Moo Extension”?', $crawler->filter('.errorbox')->text()); + } + + public function test_actions() + { + // Access enable page without hash + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text()); + + // Correctly submit the enable form + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $form = $crawler->selectButton('enable')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('.successbox')->text()); + + // Access disable page without hash + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text()); + + // Correctly submit the disable form + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $form = $crawler->selectButton('disable')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('EXTENSION_DISABLE_SUCCESS', $crawler->filter('.successbox')->text()); + + // Access delete_data page without hash + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('FORM_INVALID', $crawler->filter('.errorbox')->text()); + + // Correctly submit the delete data form + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $form = $crawler->selectButton('delete_data')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('EXTENSION_DELETE_DATA_SUCCESS', $crawler->filter('.successbox')->text()); + + // Attempt to enable invalid extension + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=barfoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_DIR_INVALID', $crawler->filter('.errorbox')->text()); + } +} diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php new file mode 100644 index 0000000000..18eb9ad4c6 --- /dev/null +++ b/tests/functional/extension_controller_test.php @@ -0,0 +1,181 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_extension_controller_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helper; + + static protected $fixtures = array( + 'foo/bar/config/', + 'foo/bar/controller/', + 'foo/bar/event/', + 'foo/bar/language/en/', + 'foo/bar/styles/prosilver/template/', + 'foo/foo/config/', + 'foo/foo/controller/', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + parent::setUp(); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + } + + /** + * Check a controller for extension foo/bar. + */ + public function test_foo_bar() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/bar', array(), false); + self::assert_response_status_code(); + $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check a controller for extension foo/bar. + */ + public function test_routing_resources() + { + $this->phpbb_extension_manager->enable('foo/foo'); + $crawler = self::request('GET', 'app.php/foo/foo', array(), false); + self::assert_response_status_code(); + $this->assertContains("foo/foo controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/foo'); + } + + /** + * Check the output of a controller using the template system + */ + public function test_controller_with_template() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/template'); + $this->assertContains("I am a variable", $crawler->filter('#content')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the error produced by calling a controller without a required + * argument. + */ + public function test_missing_argument() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/baz', array(), false); + $this->assert_response_html(500); + $this->assertContains('Missing value for argument #1: test in class foo\bar\controller\controller:baz', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the status code resulting from an exception thrown by a controller + */ + public function test_exception_should_result_in_500_status_code() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/exception', array(), false); + $this->assert_response_html(500); + $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the error produced by extension at ./ext/does/not/exist. + * + * If an extension is disabled, its routes are not loaded. Because we + * are not looking for a controller based on a specified extension, + * we don't know the difference between a route in a disabled + * extension and a route that is not defined anyway; it is the same + * error message. + */ + public function test_error_ext_disabled_or_404() + { + $crawler = self::request('GET', 'app.php/does/not/exist', array(), false); + $this->assert_response_html(404); + $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); + } + + /** + * Check the redirect after using the login_box() form + */ + public function test_login_redirect() + { + $this->markTestIncomplete('Session table contains incorrect data for controllers on travis,' + . 'therefor the redirect fails.'); + + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/login_redirect'); + $this->assertContainsLang('LOGIN', $crawler->filter('h2')->text()); + $form = $crawler->selectButton('login')->form(array( + 'username' => 'admin', + 'password' => 'adminadmin', + )); + $this->assertStringStartsWith('./app.php/foo/login_redirect', $form->get('redirect')->getValue()); + + $crawler = self::submit($form); + $this->assertContains("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()'); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the output of a controller using the template system + */ + public function test_redirect() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = self::request('GET', 'app.php/foo/redirect'); + + $nodes = $crawler->filter('div')->extract(array('id')); + + foreach ($nodes as $redirect) + { + if (strpos($redirect, 'redirect_expected') !== 0) + { + continue; + } + + $row_num = str_replace('redirect_expected_', '', $redirect); + + $redirect = $crawler->filter('#redirect_' . $row_num)->text(); + $redirect = substr($redirect, 0, strpos($redirect, 'sid') - 1); + $this->assertEquals($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect); + } + + $this->phpbb_extension_manager->purge('foo/bar'); + } +} diff --git a/tests/functional/extension_global_lang_test.php b/tests/functional/extension_global_lang_test.php new file mode 100644 index 0000000000..53bb9af5ca --- /dev/null +++ b/tests/functional/extension_global_lang_test.php @@ -0,0 +1,68 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helper; + + static protected $fixtures = array( + 'foo/bar/config/', + 'foo/bar/event/', + 'foo/bar/language/en/', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + } + + public function test_load_extension_lang_globally() + { + $this->phpbb_extension_manager->enable('foo/bar'); + + // The board index, which should contain an overwritten translation + $crawler = self::request('GET', 'index.php'); + + // language from language/en/common.php + $this->assertNotContains('Skip to content', $crawler->filter('.skiplink')->text()); + + // language from ext/foo/bar/language/en/foo_global.php + $this->assertContains('Overwritten by foo', $crawler->filter('.skiplink')->text()); + } +} diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php new file mode 100644 index 0000000000..ee084720e4 --- /dev/null +++ b/tests/functional/extension_module_test.php @@ -0,0 +1,136 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; + +/** +* @group functional +*/ +class phpbb_functional_extension_module_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helper; + + static protected $fixtures = array( + './', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + global $db; + + parent::setUp(); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + $this->phpbb_extension_manager->enable('foo/bar'); + + $modules = new acp_modules(); + $db = $this->get_db(); + + $sql = 'SELECT module_id + FROM ' . MODULES_TABLE . " + WHERE module_langname = 'acp' + AND module_class = 'ACP_CAT_DOT_MODS'"; + $result = $db->sql_query($sql); + $module_id = (int) $db->sql_fetchfield('module_id'); + $db->sql_freeresult($result); + + $parent_data = array( + 'module_basename' => '', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => $module_id, + 'module_class' => 'acp', + 'module_langname' => 'ACP_FOOBAR_TITLE', + 'module_mode' => '', + 'module_auth' => '', + ); + $modules->update_module_data($parent_data, true); + + $module_data = array( + 'module_basename' => 'foo\\bar\\acp\\main_module', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => $parent_data['module_id'], + 'module_class' => 'acp', + 'module_langname' => 'ACP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ); + $modules->update_module_data($module_data, true); + + $parent_data = array( + 'module_basename' => '', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => 0, + 'module_class' => 'ucp', + 'module_langname' => 'UCP_FOOBAR_TITLE', + 'module_mode' => '', + 'module_auth' => '', + ); + $modules->update_module_data($parent_data, true); + + $module_data = array( + 'module_basename' => 'foo\\bar\\ucp\\main_module', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => $parent_data['module_id'], + 'module_class' => 'ucp', + 'module_langname' => 'UCP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ); + $modules->update_module_data($module_data, true); + + $this->purge_cache(); + } + + public function test_acp() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=foo%5cbar%5cacp%5cmain_module&mode=mode&sid=' . $this->sid); + $this->assertContains('Bertie rulez!', $crawler->filter('#main')->text()); + } + + public function test_ucp() + { + $this->login(); + + $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid); + $this->assertContains('UCP_FOOBAR_TITLE', $crawler->filter('#tabs')->text()); + + $link = $crawler->selectLink('UCP_FOOBAR_TITLE')->link()->getUri(); + $crawler = self::request('GET', substr($link, strpos($link, 'ucp.'))); + $this->assertContains('UCP Extension Template Test Passed!', $crawler->filter('#content')->text()); + + $this->phpbb_extension_manager->purge('foo/bar'); + } +} diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php new file mode 100644 index 0000000000..92d8d596c7 --- /dev/null +++ b/tests/functional/extension_permission_lang_test.php @@ -0,0 +1,86 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_extension_permission_lang_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helper; + + static protected $fixtures = array( + 'foo/bar/config/', + 'foo/bar/event/', + 'foo/bar/language/en/', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + $acl_ary = array( + 'auth_option' => 'u_foo', + 'is_global' => 1, + ); + + $sql = 'INSERT INTO phpbb_acl_options ' . $this->db->sql_build_array('INSERT', $acl_ary); + $this->db->sql_query($sql); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + } + + public function test_auto_include_permission_lang_from_extensions() + { + $this->phpbb_extension_manager->enable('foo/bar'); + + // User permissions + $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = self::submit($form); + + // language from language/en/acp/permissions_phpbb.php + $this->assertContains('Can attach files', $crawler->filter('body')->text()); + + // language from ext/foo/bar/language/en/permissions_foo.php + $this->assertContains('Can view foobar', $crawler->filter('body')->text()); + } +} diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php new file mode 100644 index 0000000000..9041c8dc69 --- /dev/null +++ b/tests/functional/feed_test.php @@ -0,0 +1,1497 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @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']; + + $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' => 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']; + + $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' => 7, + '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' => 6, + ), + ), + )); + } + + public function test_softdelete_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Feeds #1', + ), + 'topics' => array( + 'Feeds #1 - Topic #2', + ), + )); + + $this->add_lang('posting'); + $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC'); + $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' => 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->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->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' => 9, + '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' => 6, + ), + ), + ), 'disapprove_user'); + } + + public function test_create_unapproved_topic() + { + $this->load_ids(array( + 'forums' => array( + 'Feeds #1.1', + ), + )); + $this->set_flood_interval(0); + + $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()); + + $this->logout(); + $this->set_flood_interval(15); + } + + protected function set_flood_interval($flood_interval) + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[flood_interval]"] = $flood_interval; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + + $this->logout(); + } + + 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' => 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->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' => 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' => 11, + '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' => 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' => true, + ), + ), + ), + ), + ), + 'topics_new' => 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' => true, + ), + ), + ), + ), + ), + 'topics_active' => 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' => 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' => 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' => 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_new' => 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_active' => 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, + ), + ), + ), + ), + ), + )); + } + + 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' => 12, + 'contents' => array( + 1 => 'Attachment #0', + ), + ), + ), + 'topics' => 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' => true, + ), + ), + ), + ), + ), + 'topics_new' => 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' => true, + ), + ), + ), + ), + ), + 'topics_active' => array( + array( + 'nb_entries' => 8, + '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 + { + $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); + } + } + } +} diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php new file mode 100644 index 0000000000..d381fa1ae2 --- /dev/null +++ b/tests/functional/fileupload_form_test.php @@ -0,0 +1,145 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** + * @group functional + */ +class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case +{ + private $path; + + public function setUp() + { + parent::setUp(); + $this->path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + } + + public function tearDown() + { + $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/'); + foreach ($iterator as $fileinfo) + { + if ( + $fileinfo->isDot() + || $fileinfo->isDir() + || $fileinfo->getFilename() === 'index.htm' + || $fileinfo->getFilename() === '.htaccess' + ) + { + continue; + } + + unlink($fileinfo->getPathname()); + } + } + + private function upload_file($filename, $mimetype) + { + $file = array( + 'tmp_name' => $this->path . $filename, + 'name' => $filename, + 'type' => $mimetype, + 'size' => filesize($this->path . $filename), + 'error' => UPLOAD_ERR_OK, + ); + + $crawler = self::$client->request( + 'POST', + 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid, + array('add_file' => $this->lang('ADD_FILE')), + array('fileupload' => $file) + ); + + return $crawler; + } + + public function test_empty_file() + { + $this->login(); + + $crawler = $this->upload_file('empty.png', 'image/png'); + $this->assertEquals($this->lang('EMPTY_FILEUPLOAD'), $crawler->filter('p.error')->text()); + } + + public function test_invalid_extension() + { + $this->login(); + + $crawler = $this->upload_file('illegal-extension.bif', 'application/octet-stream'); + $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text()); + } + + public function test_disallowed_content() + { + $this->login(); + + $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg'); + $this->assertEquals($this->lang('DISALLOWED_CONTENT'), $crawler->filter('p.error')->text()); + } + + public function test_disallowed_content_no_check() + { + $this->login(); + $this->admin_login(); + $this->add_lang('ucp'); + + // Make sure check_attachment_content is set to false + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_attachments&mode=attach'); + + $form = $crawler->selectButton('Submit')->form(array( + 'config[check_attachment_content]' => 0, + 'config[img_imagick]' => '', + )); + self::submit($form); + + // Request index for correct URL + self::request('GET', 'index.php?sid=' . $this->sid); + + $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg'); + + // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the + // DISALLOWED_CONTENT check + $this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text()); + + // Reset check_attachment_content to default (enabled) + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_attachments&mode=attach'); + + $form = $crawler->selectButton('Submit')->form(array( + 'config[check_attachment_content]' => 1, + )); + self::submit($form); + } + + public function test_too_large() + { + $this->create_user('fileupload'); + $this->login('fileupload'); + + $crawler = $this->upload_file('too-large.png', 'image/png'); + $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text()); + } + + public function test_valid_file() + { + $this->login(); + + $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); + + // Ensure there was no error message rendered + $this->assertNotContains('<h2>' . $this->lang('INFORMATION') . '</h2>', $this->get_content()); + + // Also the file name should be in the first row of the files table + $this->assertEquals('valid.jpg', $crawler->filter('span.file-name')->eq(1)->text()); + } +} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php new file mode 100644 index 0000000000..6ece150b23 --- /dev/null +++ b/tests/functional/fileupload_remote_test.php @@ -0,0 +1,79 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; + +/** + * @group functional + */ +class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case +{ + public function setUp() + { + parent::setUp(); + // Only doing this within the functional framework because we need a + // URL + + // Global $config required by unique_id + // Global $user required by fileupload::remote_upload + global $config, $user; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); + } + + public function tearDown() + { + global $config, $user; + $user = null; + $config = array(); + } + + public function test_invalid_extension() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload(self::$root_url . 'develop/blank.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_empty_file() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload(self::$root_url . 'develop/blank.jpg'); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); + } + + public function test_successful_upload() + { + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } + + public function test_too_large() + { + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php new file mode 100644 index 0000000000..ec378e0e75 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -0,0 +1,37 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\acp; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class main_info +{ + function module() + { + return array( + 'filename' => 'foo\bar\acp\main_module', + 'title' => 'ACP_FOOBAR_TITLE', + 'version' => '1.0.0', + 'modes' => array( + 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), + ), + ); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php new file mode 100644 index 0000000000..ee797c718d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\acp; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class main_module +{ + var $u_action; + + function main($id, $mode) + { + $this->tpl_name = 'foobar'; + $this->page_title = 'Bertie'; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html new file mode 100644 index 0000000000..3cb45c269c --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html @@ -0,0 +1,3 @@ +<!-- INCLUDE overall_header.html --> +Bertie rulez! +<!-- INCLUDE overall_footer.html --> diff --git a/tests/functional/fixtures/ext/foo/bar/composer.json b/tests/functional/fixtures/ext/foo/bar/composer.json new file mode 100644 index 0000000000..f0c7f0e6c1 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/composer.json @@ -0,0 +1,24 @@ +{ + "name": "foo/bar", + "type": "phpbb-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "Joas Schilling", + "email": "nickvergessen@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml new file mode 100644 index 0000000000..374a58046d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -0,0 +1,35 @@ +foo_bar_controller: + path: /foo/bar + defaults: { _controller: foo_bar.controller:handle } + +foo_baz_controller: + path: /foo/baz + defaults: { _controller: foo_bar.controller:baz } + +foo_template_controller: + path: /foo/template + defaults: { _controller: foo_bar.controller:template } + +foo_exception_controller: + path: /foo/exception + defaults: { _controller: foo_bar.controller:exception } + +foo_login_redirect_controller: + path: /foo/login_redirect + defaults: { _controller: foo_bar.controller:login_redirect } + +foo_redirect_controller: + path: /foo/redirect + defaults: { _controller: foo_bar.controller:redirect } + +foo_index_controller: + path: /index + defaults: { _controller: foo_bar.controller:redirect } + +foo_tests_index_controller: + path: /tests/index + defaults: { _controller: foo_bar.controller:redirect } + +foo_tests_dotdot_index_controller: + path: /tests/../index + defaults: { _controller: foo_bar.controller:redirect } diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml new file mode 100644 index 0000000000..d35be7955a --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -0,0 +1,20 @@ +services: + foo_bar.controller: + class: foo\bar\controller\controller + arguments: + - @controller.helper + - @path_helper + - @template + - @config + - @user + - %core.root_path% + - %core.php_ext% + + foo_bar.listener.permission: + class: foo\bar\event\permission + tags: + - { name: event.listener } + foo_bar.listener.user_setup: + class: foo\bar\event\user_setup + tags: + - { name: event.listener } diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php new file mode 100644 index 0000000000..47d856a5df --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -0,0 +1,109 @@ +<?php + +namespace foo\bar\controller; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ + protected $template; + protected $helper; + protected $path_helper; + protected $config; + protected $user; + + public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, \phpbb\user $user, $root_path, $php_ext) + { + $this->template = $template; + $this->helper = $helper; + $this->path_helper = $path_helper; + $this->config = $config; + $this->user = $user; + $this->root_path = $root_path; + $this->php_ext = $php_ext; + } + + public function handle() + { + return new Response('foo/bar controller handle() method', 200); + } + + public function baz($test) + { + return new Response('Value of "test" URL argument is: ' . $test); + } + + public function template() + { + $this->template->assign_var('A_VARIABLE', 'I am a variable'); + + return $this->helper->render('foo_bar_body.html'); + } + + public function exception() + { + throw new \phpbb\controller\exception('Exception thrown from foo/exception route'); + } + + public function login_redirect() + { + if (!$this->user->data['is_registered']) + { + login_box(); + } + + $this->template->assign_var('A_VARIABLE', 'I am a variable'); + + return $this->helper->render('foo_bar_body.html'); + } + + public function redirect() + { + $url_root = generate_board_url(); + + $rewrite_prefix = (!empty($this->config['enable_mod_rewrite'])) ? '' : 'app.php/'; + + $redirects = array( + array( + append_sid($this->root_path . 'index.' . $this->php_ext), + 'index.php', + ), + array( + append_sid($this->root_path . 'foo/bar/index.' . $this->php_ext), + 'foo/bar/index.php', + ), + array( + append_sid($this->root_path . 'tests/index.' . $this->php_ext), + 'tests/index.php', + ), + array( + $this->helper->route('foo_index_controller'), + $rewrite_prefix . 'index', + ), + array( + $this->helper->route('foo_tests_index_controller'), + $rewrite_prefix . 'tests/index', + ), + /** + * Symfony does not allow /../ in routes + array( + $this->helper->route('foo_tests_dotdot_index_controller'), + $rewrite_prefix . 'index', + ), + */ + ); + + foreach ($redirects as $redirect) + { + $this->template->assign_block_vars('redirects', array( + 'URL' => redirect($redirect[0], true), + )); + + $this->template->assign_block_vars('redirects_expected', array( + 'URL' => $this->path_helper->clean_url($url_root . '/' . $redirect[1]), + )); + } + + return $this->helper->render('redirect_body.html'); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/event/permission.php b/tests/functional/fixtures/ext/foo/bar/event/permission.php new file mode 100644 index 0000000000..cdbdf40465 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/event/permission.php @@ -0,0 +1,36 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\event; + +/** +* Event listener +*/ +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class permission implements EventSubscriberInterface +{ + static public function getSubscribedEvents() + { + return array( + 'core.permissions' => 'add_permissions', + ); + } + + public function add_permissions($event) + { + $permissions = $event['permissions']; + $permissions['u_foo'] = array('lang' => 'ACL_U_FOOBAR', 'cat' => 'post'); + $event['permissions'] = $permissions; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/event/user_setup.php b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php new file mode 100644 index 0000000000..3a60019f68 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/event/user_setup.php @@ -0,0 +1,39 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\event; + +/** +* Event listener +*/ +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class user_setup implements EventSubscriberInterface +{ + static public function getSubscribedEvents() + { + return array( + 'core.user_setup' => 'add_global_translations', + ); + } + + public function add_global_translations($event) + { + $lang_set_ext = $event['lang_set_ext']; + $lang_set_ext[] = array( + 'ext_name' => 'foo/bar', + 'lang_set' => 'foo_global', + ); + $event['lang_set_ext'] = $lang_set_ext; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php new file mode 100644 index 0000000000..1288edd5ec --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -0,0 +1,8 @@ +<?php + +namespace foo\bar; + +class ext extends \phpbb\extension\base +{ + +} diff --git a/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php b/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php new file mode 100644 index 0000000000..a6af8680d3 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/language/en/foo_global.php @@ -0,0 +1,5 @@ +<?php + +$lang = array_merge($lang, array( + 'SKIP' => 'Overwritten by foo', +)); diff --git a/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php new file mode 100644 index 0000000000..64b497c394 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php @@ -0,0 +1,5 @@ +<?php + +$lang = array_merge($lang, array( + 'ACL_U_FOOBAR' => 'Can view foobar with permission foo', +)); diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html new file mode 100644 index 0000000000..8fb6994d3d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html @@ -0,0 +1,3 @@ +<!-- INCLUDE overall_header.html --> +<div id="content">{A_VARIABLE}</div> +<!-- INCLUDE overall_footer.html --> diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html new file mode 100644 index 0000000000..cbded623f4 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar.html @@ -0,0 +1,3 @@ +<!-- INCLUDE overall_header.html --> +<div id="content">UCP Extension Template Test Passed!</div> +<!-- INCLUDE overall_footer.html --> diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html new file mode 100644 index 0000000000..2b70b0fe59 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/redirect_body.html @@ -0,0 +1,8 @@ +<!-- INCLUDE overall_header.html --> +<!-- BEGIN redirects --> +<div id="redirect_{redirects.S_ROW_COUNT}">{redirects.URL}</div> +<!-- END redirects --> +<!-- BEGIN redirects_expected --> +<div id="redirect_expected_{redirects_expected.S_ROW_COUNT}">{redirects_expected.URL}</div> +<!-- END redirects_expected --> +<!-- INCLUDE overall_footer.html --> diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php new file mode 100644 index 0000000000..d34244f800 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php @@ -0,0 +1,29 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\ucp; + +class main_info +{ + function module() + { + return array( + 'filename' => '\foo\bar\ucp\main_module', + 'title' => 'ACP_FOOBAR_TITLE', + 'version' => '1.0.0', + 'modes' => array( + 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), + ), + ); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php new file mode 100644 index 0000000000..f1cd03f4ab --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_module.php @@ -0,0 +1,25 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\ucp; + +class main_module +{ + var $u_action; + + function main($id, $mode) + { + $this->tpl_name = 'foobar'; + $this->page_title = 'Bertie'; + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/composer.json b/tests/functional/fixtures/ext/foo/foo/composer.json new file mode 100644 index 0000000000..d85c76a6a2 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/composer.json @@ -0,0 +1,24 @@ +{ + "name": "foo/foo", + "type": "phpbb-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "Tristan Darricau", + "email": "nicofuma@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/config/resource.yml b/tests/functional/fixtures/ext/foo/foo/config/resource.yml new file mode 100644 index 0000000000..4f2b9cce70 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/resource.yml @@ -0,0 +1,3 @@ +foo_foo_controller: + path: /foo + defaults: { _controller: foo_foo.controller:handle } diff --git a/tests/functional/fixtures/ext/foo/foo/config/routing.yml b/tests/functional/fixtures/ext/foo/foo/config/routing.yml new file mode 100644 index 0000000000..c2c401687d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/routing.yml @@ -0,0 +1,3 @@ +foo_foo.general: + resource: "resource.yml" + prefix: /foo diff --git a/tests/functional/fixtures/ext/foo/foo/config/services.yml b/tests/functional/fixtures/ext/foo/foo/config/services.yml new file mode 100644 index 0000000000..b3c7719715 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/services.yml @@ -0,0 +1,3 @@ +services: + foo_foo.controller: + class: foo\foo\controller\controller diff --git a/tests/functional/fixtures/ext/foo/foo/controller/controller.php b/tests/functional/fixtures/ext/foo/foo/controller/controller.php new file mode 100644 index 0000000000..771eaeacfc --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/controller/controller.php @@ -0,0 +1,13 @@ +<?php + +namespace foo\foo\controller; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ + public function handle() + { + return new Response('foo/foo controller handle() method', 200); + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/ext.php b/tests/functional/fixtures/ext/foo/foo/ext.php new file mode 100644 index 0000000000..80acda74fe --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/ext.php @@ -0,0 +1,8 @@ +<?php + +namespace foo\foo; + +class ext extends \phpbb\extension\base +{ + +} diff --git a/tests/functional/fixtures/files/disallowed.jpg b/tests/functional/fixtures/files/disallowed.jpg Binary files differnew file mode 100644 index 0000000000..06a437585a --- /dev/null +++ b/tests/functional/fixtures/files/disallowed.jpg diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/functional/fixtures/files/empty.png diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif Binary files differnew file mode 100644 index 0000000000..3cd5038e38 --- /dev/null +++ b/tests/functional/fixtures/files/illegal-extension.bif diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png Binary files differnew file mode 100644 index 0000000000..ed4b0abd80 --- /dev/null +++ b/tests/functional/fixtures/files/too-large.png diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg Binary files differnew file mode 100644 index 0000000000..95a87ddbdf --- /dev/null +++ b/tests/functional/fixtures/files/valid.jpg diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php new file mode 100644 index 0000000000..64fa19557f --- /dev/null +++ b/tests/functional/forgot_password_test.php @@ -0,0 +1,61 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_forgot_password_test extends phpbb_functional_test_case +{ + public function test_forgot_password_enabled() + { + global $config; + $this->add_lang('ucp'); + $crawler = self::request('GET', 'ucp.php?mode=sendpassword'); + $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text()); + } + + public function test_forgot_password_disabled() + { + $this->login(); + $this->admin_login(); + $this->add_lang('ucp'); + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[allow_password_reset]"] = 0; + $form->setValues($values); + $crawler = self::submit($form); + + $this->logout(); + + $crawler = self::request('GET', 'ucp.php?mode=sendpassword'); + $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text()); + + } + + public function tearDown() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); + + // Enable allow_password_reset again after test + $form = $crawler->selectButton('Submit')->form(array( + 'config[allow_password_reset]' => 1, + )); + $crawler = self::submit($form); + } +} diff --git a/tests/functional/forum_password_test.php b/tests/functional/forum_password_test.php new file mode 100644 index 0000000000..4b2b69a92c --- /dev/null +++ b/tests/functional/forum_password_test.php @@ -0,0 +1,59 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_forum_password_test extends phpbb_functional_test_case +{ + public function test_setup_forum_with_password() + { + $this->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' => 'Password protected', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + 'forum_password' => 'foobar', + 'forum_password_confirm' => 'foobar', + )); + $crawler = self::submit($form); + } + + public function data_enter_forum_with_password() + { + return array( + array('foowrong', 'WRONG_PASSWORD'), + array('foobar', 'NO_TOPICS'), + ); + } + + /** + * @dataProvider data_enter_forum_with_password + */ + public function test_enter_forum_with_password($password, $message) + { + $crawler = self::request('GET', "index.php?sid={$this->sid}"); + preg_match('/.?f=([0-9])/', $crawler->selectLink('Password protected')->link()->getUri(), $match); + $crawler = self::request('GET', "viewforum.php?f={$match[1]}&sid={$this->sid}"); + $form = $crawler->selectButton('login')->form(array( + 'password' => $password, + )); + $crawler = self::submit($form); + $this->assertContainsLang($message, $crawler->text()); + } +} diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php index 59f7341eb6..65be94f4d0 100644 --- a/tests/functional/forum_style_test.php +++ b/tests/functional/forum_style_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/functional/group_create_test.php b/tests/functional/group_create_test.php new file mode 100644 index 0000000000..a1417b5ba0 --- /dev/null +++ b/tests/functional/group_create_test.php @@ -0,0 +1,35 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_group_create_test extends phpbb_functional_test_case +{ + + public function test_create_group() + { + $this->login(); + $this->admin_login(); + $this->add_lang('acp/groups'); + + $crawler = self::request('GET', 'adm/index.php?i=acp_groups&mode=manage&sid=' . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $crawler = self::submit($form, array('group_name' => 'testtest')); + + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $crawler = self::submit($form, array('group_name' => 'testtest')); + + $this->assertContainsLang('GROUP_CREATED', $crawler->filter('#main')->text()); + } +} diff --git a/tests/functional/jumpbox_test.php b/tests/functional/jumpbox_test.php new file mode 100644 index 0000000000..f5a671b1b9 --- /dev/null +++ b/tests/functional/jumpbox_test.php @@ -0,0 +1,35 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_jumpbox_test extends phpbb_functional_test_case +{ + public function test_jumpbox() + { + $this->login(); + + $this->crawler = $this->get_quickmod_page(1, 'MERGE_TOPIC'); + $this->check_valid_jump('Your first forum'); + + $link = $this->crawler->filter('#jumpbox')->selectLink('Your first category')->link()->getUri(); + $this->crawler = self::request('GET', substr($link, strpos($link, 'mcp.'))); + $this->check_valid_jump('Your first category'); + } + + protected function check_valid_jump($forum) + { + $this->assertContains($this->lang('FORUM') . ": $forum", $this->crawler->filter('#cp-main h2')->text(), $this->crawler->text()); + } +} diff --git a/tests/functional/lang_test.php b/tests/functional/lang_test.php index 053806a431..7cffd0ef61 100644 --- a/tests/functional/lang_test.php +++ b/tests/functional/lang_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/functional/mcp_test.php b/tests/functional/mcp_test.php index f65a7d0784..40615d66a5 100644 --- a/tests/functional/mcp_test.php +++ b/tests/functional/mcp_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -31,11 +35,7 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case public function test_handle_quickmod($crawler) { // Test moving a post - $form = $crawler->selectButton('Go')->eq(1)->form(); - $form['action']->select('merge'); - $crawler = self::submit($form); - - return $crawler; + return $this->get_quickmod_page(0, 'MERGE_POSTS', $crawler); } /** @@ -64,4 +64,20 @@ class phpbb_functional_mcp_test extends phpbb_functional_test_case $crawler = self::submit($form); $this->assertContains($this->lang('POSTS_MERGED_SUCCESS'), $crawler->text()); } + + public function test_delete_logs() + { + $this->login(); + $crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}"); + $this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton($this->lang('DELETE_ALL'))->form(); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + + $this->assertCount(0, $crawler->filter('input[type=checkbox]')); + } } diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php new file mode 100644 index 0000000000..1da5c39401 --- /dev/null +++ b/tests/functional/memberlist_test.php @@ -0,0 +1,137 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_memberlist_test extends phpbb_functional_test_case +{ + public function test_memberlist() + { + $this->create_user('memberlist-test-user'); + // logs in as admin + $this->login(); + $crawler = self::request('GET', 'memberlist.php?sid=' . $this->sid); + $this->assertContains('memberlist-test-user', $crawler->text()); + + // restrict by first character + $crawler = self::request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid); + $this->assertContains('memberlist-test-user', $crawler->text()); + + // make sure results for wrong character are not returned + $crawler = self::request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid); + $this->assertNotContains('memberlist-test-user', $crawler->text()); + } + + public function test_viewprofile() + { + $this->login(); + // XXX hardcoded user id + $crawler = self::request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid); + $this->assertContains('admin', $crawler->filter('h2')->text()); + } + + protected function get_memberlist_leaders_table_crawler() + { + $crawler = self::request('GET', 'memberlist.php?mode=team&sid=' . $this->sid); + return $crawler->filter('.forumbg-table'); + } + + public function test_leaders() + { + $this->login(); + $this->create_user('memberlist-test-moderator'); + + $crawler = $this->get_memberlist_leaders_table_crawler(); + + // Admin in admin group, but not in moderators + $this->assertContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); + + // memberlist-test-user in neither group + $this->assertNotContains('memberlist-test-user', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-user', $crawler->eq(1)->text()); + + // memberlist-test-moderator in neither group + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(1)->text()); + } + + public function test_leaders_remove_users() + { + $this->login(); + + // Remove admin from admins, but is now in moderators + $this->remove_user_group('ADMINISTRATORS', array('admin')); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertContains('admin', $crawler->eq(1)->text()); + + // Remove admin from moderators, should not be visible anymore + $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); + } + + public function test_leaders_add_users() + { + $this->login(); + + // Add memberlist-test-moderator to moderators + $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); + $this->assertContains('memberlist-test-moderator', $crawler->eq(1)->text()); + + // Add admin to moderators, should be visible as moderator + $this->add_user_group('GLOBAL_MODERATORS', array('admin'), true); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertContains('admin', $crawler->eq(1)->text()); + + // Add admin to admins as leader, should be visible as admin, not moderator + $this->add_user_group('ADMINISTRATORS', array('admin'), true, true); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); + } + + public function test_group_rank() + { + copy(__DIR__ . '/fixtures/files/valid.jpg', __DIR__ . '/../../phpBB/images/ranks/valid.jpg'); + + $this->login(); + $this->admin_login(); + $this->add_lang(array('acp/groups', 'acp/posting')); + + // Set a group rank to the registered users + $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_groups&mode=manage&action=edit&g=2"); + $form = $crawler->selectButton('Submit')->form(); + $form['group_rank']->select('1'); + $crawler = self::submit($form); + $this->assertContainsLang('GROUP_UPDATED', $crawler->filter('.successbox')->text()); + + // Set a rank image for site_admin + $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_ranks&mode=ranks&action=edit&id=1"); + $form = $crawler->selectButton('Submit')->form(); + $form['rank_image']->select('valid.jpg'); + $crawler = self::submit($form); + $this->assertContainsLang('RANK_UPDATED', $crawler->filter('.successbox')->text()); + + $crawler = self::request('GET', 'memberlist.php?mode=group&g=2'); + $this->assertContains('memberlist-test-user', $crawler->text()); + + unlink(__DIR__ . '/../../phpBB/images/ranks/valid.jpg'); + } +} diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php new file mode 100644 index 0000000000..080822d249 --- /dev/null +++ b/tests/functional/metadata_manager_test.php @@ -0,0 +1,87 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helper; + + static protected $fixtures = array( + 'foo/bar/', + ); + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } + + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); + } + + public function setUp() + { + parent::setUp(); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + $this->phpbb_extension_manager->enable('foo/bar'); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/extensions'); + } + + public function test_extensions_list() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text()); + $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text()); + $this->assertContains('Details', $crawler->filter('#main')->text()); + } + + public function test_extensions_details() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid); + + // Test whether the details are displayed + $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text()); + $this->assertContains('foo/bar', $crawler->filter('#meta_name')->text()); + + $this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#main')->text()); + $this->assertContains('>=5.3', $crawler->filter('#require_php')->text()); + // Details should be html escaped + // However, text() only returns the displayed text, so HTML Special Chars are decoded. + // So we test this directly on the content of the response. + $this->assertContains('<span id="require_php">>=5.3</span>', $this->get_content()); + } + + public function test_extensions_details_notexists() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid); + + // Error message because the files do not exist + $this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('#main')->text()); + } +} diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php new file mode 100644 index 0000000000..ec03f7a6a4 --- /dev/null +++ b/tests/functional/notification_test.php @@ -0,0 +1,87 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_notification_test extends phpbb_functional_test_case +{ + static public function user_subscription_data() + { + return array( + // Rows inserted by phpBB/install/schemas/schema_data.sql + // Also see PHPBB3-11460 + array('notification.type.post_notification', true), + array('notification.type.topic_notification', true), + array('notification.type.post_notification.method.email', true), + array('notification.type.topic_notification.method.email', true), + + // Default behaviour for in-board notifications: + // If user did not opt-out, in-board notifications are on. + array('notification.type.bookmark_notification', true), + array('notification.type.quote_notification', true), + + // Default behaviour for email notifications: + // If user did not opt-in, email notifications are off. + array('notification.type.bookmark_notification.method.email', false), + array('notification.type.quote_notification.method.email', false), + ); + } + + /** + * @dataProvider user_subscription_data + */ + public function test_user_subscriptions($checkbox_name, $expected_status) + { + $this->login(); + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); + + $cplist = $crawler->filter('.table1'); + if ($expected_status) + { + $this->assert_checkbox_is_checked($cplist, $checkbox_name); + } + else + { + $this->assert_checkbox_is_unchecked($cplist, $checkbox_name); + } + } + + public function test_mark_notifications_read() + { + // Create a new standard user + $this->create_user('notificationtestuser'); + $this->add_user_group('NEWLY_REGISTERED', array('notificationtestuser')); + $this->login('notificationtestuser'); + + // Post a new post that needs approval + $this->create_post(2, 1, 'Re: Welcome to phpBB3', 'This is a test [b]post[/b] posted by notificationtestuser.', array(), 'POST_STORED_MOD'); + $crawler = self::request('GET', "viewtopic.php?t=1&sid={$this->sid}"); + $this->assertNotContains('This is a test post posted by notificationtestuser.', $crawler->filter('html')->text()); + + // Login as admin + $this->logout(); + $this->login(); + $this->add_lang('ucp'); + + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications'); + + // At least one notification should exist + $this->assertGreaterThan(0, $crawler->filter('#notification_list_button strong')->text()); + + // Get form token + $link = $crawler->selectLink($this->lang('NOTIFICATIONS_MARK_ALL_READ'))->link()->getUri(); + $crawler = self::request('GET', substr($link, strpos($link, 'ucp.'))); + $this->assertEquals(0, $crawler->filter('#notification_list_button strong')->text()); + } +} diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php new file mode 100644 index 0000000000..cfaf9104a8 --- /dev/null +++ b/tests/functional/paging_test.php @@ -0,0 +1,43 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_paging_test extends phpbb_functional_test_case +{ + + public function test_pagination() + { + $this->login(); + + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); + for ($post_id = 1; $post_id <= 16; $post_id++) + { + $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.'); + } + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $this->assertContains('post no4', $crawler->text()); + $this->assertNotContains('post no16', $crawler->text()); + + $next_link = $crawler->filter('.pagination > ul > li.next > a')->attr('href'); + $crawler = self::request('GET', $next_link); + $this->assertNotContains('post no4', $crawler->text()); + $this->assertContains('post no16', $crawler->text()); + + $prev_link = $crawler->filter('.pagination > ul > li.previous > a')->attr('href'); + $crawler = self::request('GET', $prev_link); + $this->assertContains('post no4', $crawler->text()); + $this->assertNotContains('post no16', $crawler->text()); + } +} diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php new file mode 100644 index 0000000000..ee71597ffc --- /dev/null +++ b/tests/functional/plupload_test.php @@ -0,0 +1,153 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** + * @group functional + */ +class phpbb_functional_plupload_test extends phpbb_functional_test_case +{ + const CHUNKS = 4; + private $path; + + protected function set_extension_group_permission($val) + { + $db = $this->get_db(); + $query = " + UPDATE phpbb_extension_groups + SET allow_in_pm = '$val' + WHERE group_name = 'IMAGES' + "; + $db->sql_query($query); + } + + public function setUp() + { + parent::setUp(); + $this->set_extension_group_permission(1); + $this->path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + $this->login(); + } + + public function tearDown() + { + $this->set_extension_group_permission(0); + $iterator = new DirectoryIterator(__DIR__ . '/../../phpBB/files/'); + foreach ($iterator as $fileinfo) + { + if ( + $fileinfo->isDot() + || $fileinfo->isDir() + || $fileinfo->getFilename() === 'index.htm' + || $fileinfo->getFilename() === '.htaccess' + ) + { + continue; + } + + unlink($fileinfo->getPathname()); + } + } + + public function get_urls() + { + return array( + array('posting.php?mode=reply&f=2&t=1'), + array('ucp.php?i=pm&mode=compose'), + ); + } + + /** + * @dataProvider get_urls + */ + public function test_chunked_upload($url) + { + $chunk_size = ceil(filesize($this->path . 'valid.jpg') / self::CHUNKS); + $handle = fopen($this->path . 'valid.jpg', 'rb'); + + for ($i = 0; $i < self::CHUNKS; $i++) + { + $chunk = fread($handle, $chunk_size); + file_put_contents($this-> path . 'chunk', $chunk); + + $file = array( + 'tmp_name' => $this->path . 'chunk', + 'name' => 'blob', + 'type' => 'application/octet-stream', + 'size' => strlen($chunk), + 'error' => UPLOAD_ERR_OK, + ); + + self::$client->setServerParameter('HTTP_X_PHPBB_USING_PLUPLOAD', '1'); + + $crawler = self::$client->request( + 'POST', + $url . '&sid=' . $this->sid, + array( + 'chunk' => $i, + 'chunks' => self::CHUNKS, + 'name' => md5('valid') . '.jpg', + 'real_filename' => 'valid.jpg', + 'add_file' => $this->lang('ADD_FILE'), + ), + array('fileupload' => $file), + array('X-PHPBB-USING-PLUPLOAD' => '1') + ); + + if ($i < self::CHUNKS - 1) + { + $this->assertContains('{"jsonrpc":"2.0","id":"id","result":null}', self::$client->getResponse()->getContent()); + } + else + { + $response = json_decode(self::$client->getResponse()->getContent(), true); + $this->assertEquals('valid.jpg', $response['data'][0]['real_filename']); + } + + unlink($this->path . 'chunk'); + } + + fclose($handle); + } + + /** + * @dataProvider get_urls + */ + public function test_normal_upload($url) + { + $file = array( + 'tmp_name' => $this->path . 'valid.jpg', + 'name' => 'valid.jpg', + 'type' => 'image/jpeg', + 'size' => filesize($this->path . 'valid.jpg'), + 'error' => UPLOAD_ERR_OK, + ); + + $crawler = self::$client->request( + 'POST', + $url . '&sid=' . $this->sid, + array( + 'chunk' => '0', + 'chunks' => '1', + 'name' => md5('valid') . '.jpg', + 'real_filename' => 'valid.jpg', + 'add_file' => $this->lang('ADD_FILE'), + ), + array('fileupload' => $file), + array('X-PHPBB-USING-PLUPLOAD' => '1') + ); + + $response = json_decode(self::$client->getResponse()->getContent(), true); + $this->assertEquals('valid.jpg', $response['data'][0]['real_filename']); + } +} diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 7fd1e4fdcf..fd802eed45 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -22,8 +26,8 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); - // Test creating a reply - $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); + // Test creating a reply with bbcode + $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test [b]post[/b] posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); @@ -32,4 +36,27 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } + + public function test_unsupported_characters() + { + $this->login(); + + $this->add_lang('posting'); + + self::create_post(2, + 1, + 'Unsupported characters', + "This is a test with these weird characters: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", + array(), + 'Your message contains the following unsupported characters' + ); + + self::create_post(2, + 1, + "Unsupported: \xF0\x9F\x88\xB3 \xF0\x9F\x9A\xB6", + 'This is a test with emoji characters in the topic title.', + array(), + 'Your subject contains the following unsupported characters' + ); + } } diff --git a/tests/functional/private_messages_test.php b/tests/functional/private_messages_test.php index 15aa2b681a..1f6dc3a979 100644 --- a/tests/functional/private_messages_test.php +++ b/tests/functional/private_messages_test.php @@ -1,9 +1,13 @@ <?php /** * -* @package testing -* @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php new file mode 100644 index 0000000000..c014119b98 --- /dev/null +++ b/tests/functional/prune_shadow_topic_test.php @@ -0,0 +1,211 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_case +{ + protected $data = array(); + protected $post; + + public function test_setup_forums() + { + $this->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' => 'Prune Shadow', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + 'enable_shadow_prune' => true, + 'prune_shadow_freq' => 1, + 'prune_shadow_days' => 1, + )); + $crawler = self::submit($form); + } + + public function test_create_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Prune Shadow', + ), + )); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic + $this->post = $this->create_topic($this->data['forums']['Prune Shadow'], 'Prune Shadow #1', 'This is a test topic posted by the testing framework.'); + $crawler = self::request('GET', "viewtopic.php?t={$this->post['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Prune Shadow #1', $crawler->filter('html')->text()); + $this->data['topics']['Prune Shadow #1'] = (int) $this->post['topic_id']; + $this->data['posts']['Prune Shadow #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Prune Shadow #1'], + ), 'after creating topic #1'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Prune Shadow'], $this->post['topic_id'], 'Re: Prune Shadow #1-#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: Prune Shadow #1-#2', $crawler->filter('html')->text()); + $this->data['posts']['Re: Prune Shadow #1-#2'] = (int) $post2['post_id']; + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Prune Shadow #1-#2'], + ), 'after replying'); + } + + public function test_move_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Prune Shadow', + ), + 'topics' => array( + 'Prune Shadow #1', + ), + )); + + $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Prune Shadow']}&i=main&action=move&mode=forum_view&start=0&topic_id_list[]={$this->data['topics']['Prune Shadow #1']}&sid={$this->sid}"); + $form = $crawler->selectButton('confirm')->form(array( + 'to_forum_id' => 2, + 'move_leave_shadow' => true, + )); + $crawler = self::submit($form); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after moving'); + + $this->db = $this->get_db(); + // Date topic 3 days back + $sql = 'UPDATE phpbb_topics + SET topic_last_post_time = ' . (time() - 60*60*24*3) . ' + WHERE topic_id = ' . ($this->data['topics']['Prune Shadow #1'] + 1); + $result = $this->db->sql_query($sql); + + $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}"); + $this->assertNotEmpty($crawler->filter('img')->last()->attr('src')); + self::request('GET', "cron.php?cron_type=cron.task.core.prune_shadow_topics&f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after the cron job'); + } + + public function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + 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); + } + + 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']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functional/registration_test.php b/tests/functional/registration_test.php new file mode 100644 index 0000000000..690f4ae9f2 --- /dev/null +++ b/tests/functional/registration_test.php @@ -0,0 +1,67 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_registration_test extends phpbb_functional_test_case +{ + public function test_disable_captcha_on_registration() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_board&mode=registration&sid={$this->sid}"); + $form = $crawler->selectButton('Submit')->form(); + $form['config[enable_confirm]']->setValue('0'); + $crawler = self::submit($form); + + $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('#main .successbox')->text()); + } + + /** + * @depends test_disable_captcha_on_registration + */ + public function test_register_new_account() + { + $this->add_lang('ucp'); + + $crawler = self::request('GET', 'ucp.php?mode=register'); + $this->assertContainsLang('REGISTRATION', $crawler->filter('div.content h2')->text()); + + $form = $crawler->selectButton('I agree to these terms')->form(); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Submit')->form(array( + 'username' => 'user-reg-test', + 'email' => 'user-reg-test@phpbb.com', + 'new_password' => 'user-reg-testuser-reg-test', + 'password_confirm' => 'user-reg-testuser-reg-test', + )); + $form['tz']->select('Europe/Berlin'); + $crawler = self::submit($form); + + $this->assertContainsLang('ACCOUNT_ADDED', $crawler->filter('#message')->text()); + } + + /** + * @depends test_register_new_account + */ + public function test_default_subscription_options() + { + $this->login('user-reg-test'); + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options&sid=' . $this->sid); + $this->assert_checkbox_is_checked($crawler, 'notification.type.post_notification.method.email'); + $this->assert_checkbox_is_checked($crawler, 'notification.type.topic_notification.method.email'); + } +} diff --git a/tests/functional/report_post_captcha_test.php b/tests/functional/report_post_captcha_test.php index 8283465041..93a03bd931 100644 --- a/tests/functional/report_post_captcha_test.php +++ b/tests/functional/report_post_captcha_test.php @@ -1,11 +1,15 @@ <?php /** - * - * @package testing - * @copyright (c) 2013 phpBB Group - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 - * - */ +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ /** * @group functional diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php new file mode 100644 index 0000000000..1d37d748df --- /dev/null +++ b/tests/functional/search/base.php @@ -0,0 +1,104 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +abstract class phpbb_functional_search_base extends phpbb_functional_test_case +{ + protected function assert_search_found($keywords, $posts_found, $words_highlighted) + { + $crawler = self::request('GET', 'search.php?keywords=' . $keywords); + $this->assertEquals($posts_found, $crawler->filter('.postbody')->count()); + $this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count()); + } + + protected function assert_search_not_found($keywords) + { + $crawler = self::request('GET', 'search.php?keywords=' . $keywords); + $this->assertEquals(0, $crawler->filter('.postbody')->count()); + $split_keywords_string = str_replace(array('+', '-'), ' ', $keywords); + $this->assertEquals($split_keywords_string, $crawler->filter('#keywords')->attr('value')); + } + + public function test_search_backend() + { + $this->login(); + $this->admin_login(); + + $post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.'); + + $crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + if ($values["config[search_type]"] != $this->search_backend) + { + $values["config[search_type]"] = $this->search_backend; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Yes')->form(); + $values = $form->getValues(); + $crawler = self::submit($form); + + // check if search backend is not supported + if ($crawler->filter('.errorbox')->count() > 0) + { + $this->delete_topic($post['topic_id']); + $this->markTestSkipped("Search backend is not supported/running"); + } + $this->create_search_index(); + } + + $this->logout(); + $this->assert_search_found('phpbb3+installation', 1, 3); + $this->assert_search_found('foosubject+barsearch', 1, 2); + $this->assert_search_not_found('loremipsumdedo'); + + $this->login(); + $this->admin_login(); + $this->delete_search_index(); + $this->delete_topic($post['topic_id']); + } + + protected function create_search_index() + { + $this->add_lang('acp/search'); + $crawler = self::request( + 'POST', + 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid, + array( + 'search_type' => $this->search_backend, + 'action' => 'create', + 'submit' => true, + ) + ); + $this->assertContainsLang('SEARCH_INDEX_CREATED', $crawler->text()); + } + + protected function delete_search_index() + { + $this->add_lang('acp/search'); + $crawler = self::request( + 'POST', + 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid, + array( + 'search_type' => $this->search_backend, + 'action' => 'delete', + 'submit' => true, + ) + ); + $this->assertContainsLang('SEARCH_INDEX_REMOVED', $crawler->text()); + } +} diff --git a/tests/functional/search/mysql_test.php b/tests/functional/search/mysql_test.php new file mode 100644 index 0000000000..a97b12e905 --- /dev/null +++ b/tests/functional/search/mysql_test.php @@ -0,0 +1,23 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/base.php'; + +/** +* @group functional +*/ +class phpbb_functional_search_mysql_test extends phpbb_functional_search_base +{ + protected $search_backend = '\phpbb\search\fulltext_mysql'; + +} diff --git a/tests/functional/search/native_test.php b/tests/functional/search/native_test.php new file mode 100644 index 0000000000..9908b9cdaa --- /dev/null +++ b/tests/functional/search/native_test.php @@ -0,0 +1,22 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/base.php'; + +/** +* @group functional +*/ +class phpbb_functional_search_native_test extends phpbb_functional_search_base +{ + protected $search_backend = '\phpbb\search\fulltext_native'; +} diff --git a/tests/functional/search/postgres_test.php b/tests/functional/search/postgres_test.php new file mode 100644 index 0000000000..a76cc13493 --- /dev/null +++ b/tests/functional/search/postgres_test.php @@ -0,0 +1,23 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/base.php'; + +/** +* @group functional +*/ +class phpbb_functional_search_postgres_test extends phpbb_functional_search_base +{ + protected $search_backend = '\phpbb\search\fulltext_postgres'; + +} diff --git a/tests/functional/search/sphinx_test.php b/tests/functional/search/sphinx_test.php new file mode 100644 index 0000000000..4bf1ab0e16 --- /dev/null +++ b/tests/functional/search/sphinx_test.php @@ -0,0 +1,27 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/base.php'; + +/** +* @group functional +*/ +class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base +{ + protected $search_backend = '\phpbb\search\fulltext_sphinx'; + + public function test_search_backend() + { + $this->markTestIncomplete('Sphinx Tests are not supported'); + } +} diff --git a/tests/functional/ucp_allow_pm_test.php b/tests/functional/ucp_allow_pm_test.php new file mode 100644 index 0000000000..2d41296ddf --- /dev/null +++ b/tests/functional/ucp_allow_pm_test.php @@ -0,0 +1,74 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_allow_pm_test extends phpbb_functional_test_case +{ + static protected $data = array(); + + public function __construct() + { + parent::__construct(); + + $this->backupStaticAttributesBlacklist += array( + 'phpbb_functional_ucp_allow_pm_test' => array('data'), + ); + } + + // user A sends a PM to user B where B accepts PM + public function test_enabled_pm_user_to_user() + { + // setup + $this->create_user('test_ucp_allow_pm_sender'); + $this->login('test_ucp_allow_pm_sender'); + self::$data['recipient_id'] = $this->create_user('test_ucp_allow_pm_recipient'); + self::$data['pm_url'] = "ucp.php?i=pm&mode=compose&u=" . (int) self::$data['recipient_id'] . "&sid={$this->sid}"; + + // the actual test + $this->set_user_allow_pm(self::$data['recipient_id'], 1); + $crawler = self::request('GET', self::$data['pm_url']); + $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text()); + } + + // user A sends a PM to user B where B does not accept PM + public function test_disabled_pm_user_to_user() + { + $this->login('test_ucp_allow_pm_sender'); + $this->set_user_allow_pm(self::$data['recipient_id'], 0); + $crawler = self::request('GET', self::$data['pm_url']); + $this->assertContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('.error')->text()); + } + + + // An admin sends a PM to user B where B does not accept PM, but cannot + // ignore a PM from an admin + public function test_disabled_pm_admin_to_user() + { + $this->login(); + $crawler = self::request('GET', self::$data['pm_url']); + $this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text()); + } + + // enable or disable PM for a user, like from ucp + protected function set_user_allow_pm($user_id, $allow) + { + $db = $this->get_db(); + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_allow_pm = " . $allow . " + WHERE user_id = " . $user_id; + $result = $db->sql_query($sql); + $db->sql_freeresult($result); + } +} diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 9c6b1edc5e..cd18a0fcae 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -1,21 +1,57 @@ <?php /** * -* @package testing -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -require_once dirname(__FILE__) . '/common_groups_test.php'; +require_once dirname(__FILE__) . '/common_groups_test_case.php'; /** * @group functional */ -class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test +class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test_case { + protected $db; + protected function get_url() { return 'ucp.php?i=groups&mode=manage&action=edit'; } + + protected function get_teampage_settings() + { + if (!isset($this->db)) + { + $this->db = $this->get_db(); + } + $sql = 'SELECT g.group_legend AS group_legend, t.teampage_position AS group_teampage + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = 5'; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + return $group_row; + } + + public function test_ucp_groups_teampage() + { + $this->group_manage_login(); + + // Test if group_legend or group_teampage are modified while + // submitting the ucp_group_manage page + $form = $this->get_group_manage_form(); + $teampage_settings = $this->get_teampage_settings(); + $crawler = self::submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + $this->assertEquals($teampage_settings, $this->get_teampage_settings()); + } } diff --git a/tests/functional/ucp_pm_test.php b/tests/functional/ucp_pm_test.php new file mode 100644 index 0000000000..ddd5c8d791 --- /dev/null +++ b/tests/functional/ucp_pm_test.php @@ -0,0 +1,52 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_pm_test extends phpbb_functional_test_case +{ + public function setUp() + { + parent::setUp(); + $this->login(); + $this->admin_login(); + } + + public function test_pm_enabled() + { + $crawler = self::request('GET', 'ucp.php'); + $this->assertContainsLang('PRIVATE_MESSAGES', $crawler->filter('html')->text()); + } + + public function test_pm_disabled() + { + $this->set_allow_pm(0); + $crawler = self::request('GET', 'ucp.php'); + $this->assertNotContainsLang('PRIVATE_MESSAGES', $crawler->filter('html')->text()); + $this->set_allow_pm(1); + } + + protected function set_allow_pm($enable_pm) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=message'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[allow_privmsg]"] = $enable_pm; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } +} diff --git a/tests/functional/ucp_preferences_test.php b/tests/functional/ucp_preferences_test.php new file mode 100644 index 0000000000..7ef325dc4b --- /dev/null +++ b/tests/functional/ucp_preferences_test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_preferences_test extends phpbb_functional_test_case +{ + public function test_submitting_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'topic_sk' => 'a', + 'topic_sd' => 'a', + 'topic_st' => '1', + 'post_sk' => 'a', + 'post_sd' => 'a', + 'post_st' => '1', + )); + + $crawler = self::submit($form); + $this->assertContainsLang('PREFERENCES_UPDATED', $crawler->filter('#message')->text()); + } + + public function test_submitting_invalid_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + if (!method_exists($form, 'disableValidation')) + { + $this->markTestIncomplete('The crawler cannot select invalid values, until Symfony 2.4!'); + } + + $form = $form->disableValidation(); + $form['topic_sk']->select('z'); + $form['topic_sd']->select('z'); + $form['topic_st']->select('test'); + $form['post_sk']->select('z'); + $form['post_sd']->select('z'); + $form['post_st']->select('test'); + + $crawler = self::submit($form); + $this->assertContainsLang('WRONG_DATA_POST_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_POST_SK', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SK', $crawler->filter('#cp-main')->text()); + } + + public function test_read_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + $this->assertEquals('a', $form->get('topic_sk')->getValue()); + $this->assertEquals('a', $form->get('topic_sd')->getValue()); + $this->assertEquals('1', $form->get('topic_st')->getValue()); + $this->assertEquals('a', $form->get('post_sk')->getValue()); + $this->assertEquals('a', $form->get('post_sd')->getValue()); + $this->assertEquals('1', $form->get('post_st')->getValue()); + } +} diff --git a/tests/functional/ucp_profile_test.php b/tests/functional/ucp_profile_test.php new file mode 100644 index 0000000000..e7abba9255 --- /dev/null +++ b/tests/functional/ucp_profile_test.php @@ -0,0 +1,49 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case +{ + public function test_submitting_profile_info() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info'); + $this->assertContainsLang('UCP_PROFILE_PROFILE_INFO', $crawler->filter('#cp-main h2')->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'pf_phpbb_facebook' => 'phpbb', + 'pf_phpbb_googleplus' => 'phpbb', + 'pf_phpbb_location' => 'Bertie´s Empire', + 'pf_phpbb_skype' => 'phpbb.skype.account', + 'pf_phpbb_twitter' => 'phpbb_twitter', + 'pf_phpbb_youtube' => 'phpbb.youtube', + )); + + $crawler = self::submit($form); + $this->assertContainsLang('PROFILE_UPDATED', $crawler->filter('#message')->text()); + + $crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info'); + $form = $crawler->selectButton('Submit')->form(); + + $this->assertEquals('phpbb', $form->get('pf_phpbb_facebook')->getValue()); + $this->assertEquals('phpbb', $form->get('pf_phpbb_googleplus')->getValue()); + $this->assertEquals('Bertie´s Empire', $form->get('pf_phpbb_location')->getValue()); + $this->assertEquals('phpbb.skype.account', $form->get('pf_phpbb_skype')->getValue()); + $this->assertEquals('phpbb_twitter', $form->get('pf_phpbb_twitter')->getValue()); + $this->assertEquals('phpbb.youtube', $form->get('pf_phpbb_youtube')->getValue()); + } +} diff --git a/tests/functional/user_password_reset_test.php b/tests/functional/user_password_reset_test.php new file mode 100644 index 0000000000..f9406f0eb5 --- /dev/null +++ b/tests/functional/user_password_reset_test.php @@ -0,0 +1,126 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_user_password_reset_test extends phpbb_functional_test_case +{ + protected $user_data; + + public function test_password_reset() + { + $this->add_lang('ucp'); + $user_id = $this->create_user('reset-password-test-user'); + + $crawler = self::request('GET', "ucp.php?mode=sendpassword&sid={$this->sid}"); + $form = $crawler->selectButton('submit')->form(array( + 'username' => 'reset-password-test-user', + )); + $crawler = self::submit($form); + $this->assertContainsLang('NO_EMAIL_USER', $crawler->text()); + + $crawler = self::request('GET', "ucp.php?mode=sendpassword&sid={$this->sid}"); + $form = $crawler->selectButton('submit')->form(array( + 'username' => 'reset-password-test-user', + 'email' => 'nobody@example.com', + )); + $crawler = self::submit($form); + $this->assertContainsLang('PASSWORD_UPDATED', $crawler->text()); + + // Check if columns in database were updated for password reset + $this->get_user_data(); + $this->assertNotNull($this->user_data['user_actkey']); + $this->assertNotNull($this->user_data['user_newpasswd']); + + // Make sure we know the password + $db = $this->get_db(); + $this->passwords_manager = $this->get_passwords_manager(); + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_newpasswd = '" . $db->sql_escape($this->passwords_manager->hash('reset-password-test-user')) . "' + WHERE user_id = " . $user_id; + $db->sql_query($sql); + } + + public function test_login_after_reset() + { + $this->login('reset-password-test-user'); + } + + public function data_activate_new_password() + { + return array( + array('WRONG_ACTIVATION', false, 'FOOBAR'), + array('ALREADY_ACTIVATED', 2, 'FOOBAR'), + array('PASSWORD_ACTIVATED', false, false), + array('ALREADY_ACTIVATED', false, false), + ); + } + + /** + * @dataProvider data_activate_new_password + */ + public function test_activate_new_password($expected, $user_id, $act_key) + { + $this->add_lang('ucp'); + $this->get_user_data(); + $user_id = (!$user_id) ? $this->user_data['user_id'] : $user_id; + $act_key = (!$act_key) ? $this->user_data['user_actkey'] : $act_key; + + $crawler = self::request('GET', "ucp.php?mode=activate&u=$user_id&k=$act_key&sid={$this->sid}"); + $this->assertContainsLang($expected, $crawler->text()); + } + + public function test_login() + { + $this->add_lang('ucp'); + $crawler = self::request('GET', 'ucp.php'); + $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + $crawler = self::submit($form, array('username' => 'reset-password-test-user', 'password' => 'reset-password-test-user')); + $this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text()); + + $cookies = self::$cookieJar->all(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + $this->logout(); + + $crawler = self::request('GET', 'ucp.php'); + $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + // Try logging in with the old password + $crawler = self::submit($form, array('username' => 'reset-password-test-user', 'password' => 'reset-password-test-userreset-password-test-user')); + $this->assertContains($this->lang('LOGIN_ERROR_PASSWORD', '', ''), $crawler->filter('html')->text()); + } + + protected function get_user_data() + { + $db = $this->get_db(); + $sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason + FROM ' . USERS_TABLE . " + WHERE username = 'reset-password-test-user'"; + $result = $db->sql_query($sql); + $this->user_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } +} diff --git a/tests/functional/viewforum_paging_test.php b/tests/functional/viewforum_paging_test.php new file mode 100644 index 0000000000..4a574bebbb --- /dev/null +++ b/tests/functional/viewforum_paging_test.php @@ -0,0 +1,256 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class viewforum_paging_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->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' => 'Viewforum Pagination Test #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Viewforum Pagination Test #2', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $this->set_post_settings(array( + 'flood_interval' => 0, + 'topics_per_page' => 3, + )); + } + + public function test_create_posts() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + for ($topic_id = 1; $topic_id <= 6; $topic_id++) + { + $this->create_topic($this->data['forums']['Viewforum Pagination Test #1'], 'Viewforum Pagination TestTopic #' . $topic_id, 'This is a test topic posted by the testing framework.'); + } + + $this->create_topic($this->data['forums']['Viewforum Pagination Test #2'], 'Viewforum Pagination TestTopic #GA1', 'This is a test topic posted by the testing framework.', array( + 'topic_type' => POST_GLOBAL, + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array( + 'forum_posts_approved' => 6, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 6, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating topics'); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating GA'); + + // Set flood interval back to 15 + $this->admin_login(); + $this->set_post_settings(array( + 'flood_interval' => 15, + )); + } + + public function test_viewforum_first_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1']); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #6', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #5', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #4', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: 1 - 2 - Next + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 1 does not match'); + $this->assertContains('1', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContainsLang('NEXT', $top_pagination->filter('li')->eq(2)->text()); + } + + public function test_viewforum_second_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1'] . '&start=3'); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #3', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #2', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #1', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: Previous - 1 - 2 + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 2 does not match'); + $this->assertContainsLang('PREVIOUS', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('1', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(2)->text()); + } + + protected function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + /** + * Sets the post setting via the ACP page + * + * @param array $settings + */ + protected function set_post_settings($settings) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + foreach ($settings as $setting => $value) + { + $values["config[{$setting}]"] = $value; + } + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + /** + * Loads forum, topic and post IDs + * + * @param array $data + */ + 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); + } + + 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']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functional/visibility_disapprove_test.php b/tests/functional/visibility_disapprove_test.php new file mode 100644 index 0000000000..6f6edba422 --- /dev/null +++ b/tests/functional/visibility_disapprove_test.php @@ -0,0 +1,323 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_visibility_disapprove_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->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' => 'Disapprove Test #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + + // Set flood interval to 0 + $this->set_flood_interval(0); + } + + public function test_create_posts() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Disapprove Test #1', + ), + )); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic #1 + $post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove Test Topic #1', '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('Disapprove Test Topic #1', $crawler->filter('html')->text()); + $this->data['topics']['Disapprove Test Topic #1'] = (int) $post['topic_id']; + $this->data['posts']['Disapprove Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'after creating topic #1'); + + $this->logout(); + $this->create_user('disapprove_testuser'); + $this->add_user_group('NEWLY_REGISTERED', array('disapprove_testuser')); + $this->login('disapprove_testuser'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Disapprove Test #1'], $post['topic_id'], 'Re: Disapprove Test Topic #1-#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']['Disapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'after replying'); + + // Test creating topic #2 + $post = $this->create_topic($this->data['forums']['Disapprove Test #1'], 'Disapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); + $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Disapprove Test #1']}&sid={$this->sid}"); + + $this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text()); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 2, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'after creating topic #2'); + + $this->logout(); + } + + public function test_reset_flood_interval() + { + $this->login(); + $this->admin_login(); + + // Set flood interval back to 15 + $this->set_flood_interval(15); + } + + public function test_disapprove_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Disapprove Test #1', + ), + 'topics' => array( + 'Disapprove Test Topic #1', + 'Disapprove Test Topic #2', + ), + 'posts' => array( + 'Disapprove Test Topic #1', + 'Re: Disapprove Test Topic #1-#2', + 'Disapprove Test Topic #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 2, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'before disapproving post'); + + $this->add_lang('posting'); + $this->add_lang('viewtopic'); + $this->add_lang('mcp'); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text()); + $this->assertContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form(); + $crawler = self::submit($form); + $form = $crawler->selectButton($this->lang('YES'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POST_DISAPPROVED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'after disapproving post'); + + $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); + $link_url = $link->getUri(); + $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Disapprove Test #1'] . '&t=' . $this->data['topics']['Disapprove Test Topic #1'], $link_url); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertContains('Disapprove Test Topic #1', $crawler->filter('html')->text()); + $this->assertNotContains('Re: Disapprove Test Topic #1-#2', $crawler->filter('html')->text()); + } + + public function test_disapprove_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Disapprove Test #1', + ), + 'topics' => array( + 'Disapprove Test Topic #1', + 'Disapprove Test Topic #2', + ), + 'posts' => array( + 'Disapprove Test Topic #1', + 'Disapprove Test Topic #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'before disapproving topic'); + + $this->add_lang('posting'); + $this->add_lang('viewtopic'); + $this->add_lang('mcp'); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}"); + $this->assertContains('Disapprove Test Topic #2', $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('DISAPPROVE'))->form(); + $crawler = self::submit($form); + $form = $crawler->selectButton($this->lang('YES'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_DISAPPROVED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Disapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Disapprove Test Topic #1'], + ), 'after disapproving topic'); + + $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); + $link_url = $link->getUri(); + $this->assertContains('viewforum.php?f=' . $this->data['forums']['Disapprove Test #1'], $link_url); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Disapprove Test Topic #2']}&sid={$this->sid}", array(), false); + self::assert_response_html(404); + $this->assertNotContains('Disapprove Test Topic #2', $crawler->filter('html')->text()); + } + + protected function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + protected function set_flood_interval($flood_interval) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[flood_interval]"] = $flood_interval; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + 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); + } + + 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']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functional/visibility_reapprove_test.php b/tests/functional/visibility_reapprove_test.php new file mode 100644 index 0000000000..5af2ddafa4 --- /dev/null +++ b/tests/functional/visibility_reapprove_test.php @@ -0,0 +1,419 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_visibility_reapprove_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->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' => 'Reapprove Test #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + + // Set flood interval to 0 + $this->set_flood_interval(0); + } + + public function test_create_posts() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Reapprove Test #1', + ), + )); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic #1 + $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #1', '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('Reapprove Test Topic #1', $crawler->filter('h2')->text()); + $this->data['topics']['Reapprove Test Topic #1'] = (int) $post['topic_id']; + $this->data['posts']['Reapprove Test Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], + ), 'after creating topic #1'); + + $this->logout(); + $this->create_user('reapprove_testuser'); + $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser')); + $this->login('reapprove_testuser'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Reapprove Test #1'], $post['topic_id'], 'Re: Reapprove Test Topic #1-#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']['Reapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], + ), 'after replying'); + + // Test creating topic #2 + $post = $this->create_topic($this->data['forums']['Reapprove Test #1'], 'Reapprove Test Topic #2', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); + $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Reapprove Test #1']}&sid={$this->sid}"); + + $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('html')->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 2, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], + ), 'after creating topic #2'); + + $this->logout(); + } + + public function test_approve_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Reapprove Test #1', + ), + 'topics' => array( + 'Reapprove Test Topic #1', + 'Reapprove Test Topic #2', + ), + 'posts' => array( + 'Reapprove Test Topic #1', + 'Re: Reapprove Test Topic #1-#2', + 'Reapprove Test Topic #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 2, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], + ), 'before approving post'); + + $this->add_lang('posting'); + $this->add_lang('viewtopic'); + $this->add_lang('mcp'); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text()); + $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); + + $form = $crawler->selectButton($this->lang('APPROVE'))->form(); + $crawler = self::submit($form); + $form = $crawler->selectButton($this->lang('YES'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POST_APPROVED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'], + ), 'after approving post'); + + $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); + $link_url = $link->getUri(); + $this->assertContains('viewtopic.php?f=' . $this->data['forums']['Reapprove Test #1'] . '&t=' . $this->data['topics']['Reapprove Test Topic #1'], $link_url); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertContains('Reapprove Test Topic #1', $crawler->filter('h2')->text()); + $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); + } + + public function test_approve_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Reapprove Test #1', + ), + 'topics' => array( + 'Reapprove Test Topic #1', + 'Reapprove Test Topic #2', + ), + 'posts' => array( + 'Reapprove Test Topic #1', + 'Re: Reapprove Test Topic #1-#2', + 'Reapprove Test Topic #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Reapprove Test Topic #1-#2'], + ), 'before approving topic'); + + $this->add_lang('posting'); + $this->add_lang('viewtopic'); + $this->add_lang('mcp'); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}"); + $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text()); + + $form = $crawler->selectButton($this->lang('APPROVE'))->form(); + $crawler = self::submit($form); + $form = $crawler->selectButton($this->lang('YES'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_APPROVED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 3, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 2, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], + ), 'after approving topic'); + + $link = $crawler->selectLink($this->lang('RETURN_PAGE', '', ''))->link(); + $link_url = $link->getUri(); + $this->assertContains('viewtopic.php?f=' . $this->data['topic']['Reapprove Test Topic #2'], $link_url); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}"); + $this->assertContains('Reapprove Test Topic #2', $crawler->filter('h2')->text()); + } + + public function test_edit_posts() + { + $this->load_ids(array( + 'forums' => array( + 'Reapprove Test #1', + ), + 'topics' => array( + 'Reapprove Test Topic #1', + 'Reapprove Test Topic #2', + ), + 'posts' => array( + 'Reapprove Test Topic #1', + 'Re: Reapprove Test Topic #1-#2', + 'Reapprove Test Topic #2', + ), + )); + $this->add_lang('posting'); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 3, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 2, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], + ), 'before editing post'); + + $this->login('reapprove_testuser'); + $this->add_user_group('NEWLY_REGISTERED', array('reapprove_testuser')); + + // Test editing a post + $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Re: Reapprove Test Topic #1-#2']}&sid={$this->sid}"; + $form_data = array( + 'message' => 'Post edited by testing framework', + 'subject' => 'Re: Reapprove Test Topic #1-#2', + 'post' => true, + ); + $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertNotContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); + $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 1, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 2, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #2'], + ), 'after editing post'); + + // Test editing a topic + $posting_url = "posting.php?mode=edit&f={$this->data['forums']['Reapprove Test #1']}&p={$this->data['posts']['Reapprove Test Topic #2']}&sid={$this->sid}"; + $form_data = array( + 'message' => 'Post edited by testing framework', + 'subject' => 'Reapprove Test Topic #2', + 'post' => true, + ); + $this->submit_post($posting_url, 'EDIT_POST', $form_data, 'POST_EDITED_MOD'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #2']}&sid={$this->sid}", array(), false); + self::assert_response_html(404); + $this->assertNotContains('Reapprove Test Topic #2', $crawler->filter('#page-body')->text()); + $this->assertNotContains('Post edited by testing framework', $crawler->filter('#page-body')->text()); + + $this->assert_forum_details($this->data['forums']['Reapprove Test #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 2, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 1, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Reapprove Test Topic #1'], + ), 'after editing topic'); + + $this->logout(); + $this->login(); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Reapprove Test Topic #1']}&sid={$this->sid}"); + $this->assertContains('Re: Reapprove Test Topic #1-#2', $crawler->filter('#page-body')->text()); + $this->assertContains('Post edited by testing framework', $crawler->filter('#page-body')->text()); + } + + public function test_approve_post_again() + { + $this->test_approve_post(); + } + + public function test_approve_topic_again() + { + $this->test_approve_topic(); + } + + public function test_reset_flood_interval() + { + $this->login(); + $this->admin_login(); + + // Set flood interval back to 15 + $this->set_flood_interval(15); + } + + protected function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + protected function set_flood_interval($flood_interval) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[flood_interval]"] = $flood_interval; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + 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); + } + + 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']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functional/visibility_softdelete_test.php b/tests/functional/visibility_softdelete_test.php new file mode 100644 index 0000000000..794f0cde68 --- /dev/null +++ b/tests/functional/visibility_softdelete_test.php @@ -0,0 +1,747 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->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' => 'Soft Delete #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + $crawler = self::submit($form); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Soft Delete #2', + )); + $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( + 'Soft Delete #1', + 'Soft Delete #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic + $post = $this->create_topic($this->data['forums']['Soft Delete #1'], 'Soft Delete Topic #1', '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('Soft Delete Topic #1', $crawler->filter('html')->text()); + $this->data['topics']['Soft Delete Topic #1'] = (int) $post['topic_id']; + $this->data['posts']['Soft Delete Topic #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after creating topic #1'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Soft Delete #1'], $post['topic_id'], 'Re: Soft Delete Topic #1-#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: Soft Delete Topic #1-#2', $crawler->filter('html')->text()); + $this->data['posts']['Re: Soft Delete Topic #1-#2'] = (int) $post2['post_id']; + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'], + ), 'after replying'); + } + + public function test_softdelete_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Soft Delete Topic #1-#2'], + ), 'before softdelete'); + + $this->add_lang('posting'); + $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Soft Delete #1']}&p={$this->data['posts']['Re: Soft Delete 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()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after softdelete'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); + } + + public function test_move_softdeleted_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before moving #2'); + + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'MOVE_TOPIC'); + $this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after moving #2'); + } + + public function test_softdelete_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before softdeleting #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before softdeleting #2'); + + $this->add_lang('posting'); + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'DELETE_TOPIC'); + $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']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #2', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after moving #2'); + } + + public function test_move_softdeleted_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'before moving #2'); + + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'MOVE_TOPIC'); + $this->assertContainsLang('SELECT_DESTINATION_FORUM', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_MOVED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after moving #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after moving #2'); + } + + public function test_restore_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 2, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'before restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before restoring #2'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->filter('#p' . $this->data['posts']['Soft Delete Topic #1'])->selectButton($this->lang('RESTORE'))->form(); + $crawler = self::submit($form); + $this->assertContainsLang('RESTORE_POST', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POST_RESTORED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete #1', $crawler->filter('.navlinks')->text()); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'after restoring #2'); + } + + public function test_split_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before splitting #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before splitting #2'); + + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'SPLIT_TOPIC'); + + $this->add_lang('mcp'); + $this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'subject' => 'Soft Delete Topic #2', + )); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $form['post_id_list'][1]->tick(); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_SPLIT_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + $this->assertNotContains('Re: Soft Delete Topic #1-#2', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after restoring #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => 0, + ), 'after restoring #2'); + } + + public function test_move_topic_back() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + 'Soft Delete Topic #2', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MOVE_TOPIC'); + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); + $crawler = self::submit($form); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after moving back'); + } + + public function test_merge_topics() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + 'Soft Delete Topic #2', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 1, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before merging #1'); + + $this->add_lang('viewtopic'); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + + $bookmark_tag = $crawler->filter('a.bookmark-link'); + $this->assertContainsLang('BOOKMARK_TOPIC', $bookmark_tag->text()); + $bookmark_link = $bookmark_tag->attr('href'); + $crawler_bookmark = self::request('GET', $bookmark_link); + $this->assertContainsLang('BOOKMARK_ADDED', $crawler_bookmark->text()); + + $this->add_lang('mcp'); + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MERGE_TOPIC', $crawler); + $this->assertContainsLang('SELECT_MERGE', $crawler->text()); + + $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}"); + $this->assertContainsLang('MERGE_TOPICS_CONFIRM', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('POSTS_MERGED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + $this->assertContains('Soft Delete Topic #1', $crawler->filter('h2')->text()); + $this->assertContainsLang('POST_DELETED_ACTION', $crawler->filter('body')->text()); + $this->assertContainsLang('BOOKMARK_TOPIC_REMOVE', $crawler->filter('body')->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after merging #1'); + } + + public function test_fork_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Soft Delete #1', + 'Soft Delete #2', + ), + 'topics' => array( + 'Soft Delete Topic #1', + ), + 'posts' => array( + 'Soft Delete Topic #1', + 'Re: Soft Delete Topic #1-#2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'before forking #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'before forking #2'); + + $this->add_lang('mcp'); + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #1'], 'FORK_TOPIC'); + $this->assertContainsLang('FORK_TOPIC', $crawler->text()); + + $form = $crawler->selectButton('Yes')->form(); + $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_FORKED_SUCCESS', $crawler->text()); + + $this->assert_forum_details($this->data['forums']['Soft Delete #1'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'], + ), 'after forking #1'); + + $this->assert_forum_details($this->data['forums']['Soft Delete #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 1, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Soft Delete Topic #1'] + 2, + ), 'after forking #2'); + } + + public function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + 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); + } + + 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']; + } + } + $this->db->sql_freeresult($result); + } + } +} |