diff options
Diffstat (limited to 'tests/functional')
39 files changed, 2562 insertions, 114 deletions
diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 3d8cabb086..cdf8bf5117 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -14,8 +14,107 @@ require_once dirname(__FILE__) . '/common_groups_test.php'; */ class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test { + 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..a3d272906f --- /dev/null +++ b/tests/functional/acp_permissions_test.php @@ -0,0 +1,123 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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, refactor it later + global $db, $cache; + $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; + + $auth = new phpbb_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; + // 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/auth_test.php b/tests/functional/auth_test.php index afb4f15fc2..cfd85571b7 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -39,10 +39,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..9fdc29cc76 --- /dev/null +++ b/tests/functional/avatar_acp_groups_test.php @@ -0,0 +1,63 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test +{ + 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( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_acp_groups_data + */ + public function test_avatar_acp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php new file mode 100644 index 0000000000..0afd05e530 --- /dev/null +++ b/tests/functional/avatar_acp_users_test.php @@ -0,0 +1,61 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test +{ + 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( + '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..233b7d36e1 --- /dev/null +++ b/tests/functional/avatar_ucp_groups_test.php @@ -0,0 +1,71 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test +{ + 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( + '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..f828559e0d --- /dev/null +++ b/tests/functional/avatar_ucp_users_test.php @@ -0,0 +1,78 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test +{ + 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, + ), + ), + // Wrong driver selected + array( + 'NO_AVATAR_SELECTED', + 'avatar_driver_upload', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + array( + '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..c3be301762 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -29,4 +29,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.php b/tests/functional/common_avatar_test.php new file mode 100644 index 0000000000..c0f21d07c2 --- /dev/null +++ b/tests/functional/common_avatar_test.php @@ -0,0 +1,80 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * @group functional + */ +abstract class phpbb_functional_common_avatar_test 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', $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, $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); + + try + { + $this->assertContainsLang($expected, $crawler->text()); + } + catch (Exception $e) + { + $this->assertContains($expected, $crawler->text()); + } + } +} diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 427a930cb9..6c6572af62 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -14,6 +14,28 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test { 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() { @@ -50,13 +72,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 +84,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 +105,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/extension_acp_test.php b/tests/functional/extension_acp_test.php new file mode 100644 index 0000000000..8614c0c963 --- /dev/null +++ b/tests/functional/extension_acp_test.php @@ -0,0 +1,187 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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' => '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' => 'test2', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => '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(5, $crawler->filter('.ext_disabled')); + + $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); + + $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); + + $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->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('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text()); + + $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text()); + } + + public function test_details() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + + $validation = array( + 'DISPLAY_NAME' => 'phpBB Foo Extension', + 'CLEAN_NAME' => 'foo/example', + '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', + 'LICENCE' => 'GPL-2.0', + 'PHPBB_VERSION' => '3.1.0-dev', + 'PHP_VERSION' => '>=5.3', + 'AUTHOR_NAME' => 'Nathan Guse', + 'AUTHOR_EMAIL' => 'email@phpbb.com', + 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org', + '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=foo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->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('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_purge_pre() + { + // test2 is not available (error) + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid); + $this->assertContains('The required file does not exist', $crawler->filter('html')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_actions() + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); + } +}
\ No newline at end of file diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php new file mode 100644 index 0000000000..7d29f0000c --- /dev/null +++ b/tests/functional/extension_controller_test.php @@ -0,0 +1,112 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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/styles/prosilver/template/', + ); + + 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?controller=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 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?controller=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?controller=foo/baz', array(), false); + $this->assert_response_html(500); + $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_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?controller=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?controller=does/not/exist', array(), false); + $this->assert_response_html(404); + $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); + } +} diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php new file mode 100644 index 0000000000..c31a892ce9 --- /dev/null +++ b/tests/functional/extension_module_test.php @@ -0,0 +1,97 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +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' => 'phpbb_ext_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); + + $this->purge_cache(); + } + + /** + * Check a controller for extension foo/bar. + */ + public function test_foo_bar() + { + $this->login(); + $this->admin_login(); + $crawler = self::request('GET', 'adm/index.php?i=phpbb_ext_foo_bar_acp_main_module&mode=mode&sid=' . $this->sid); + $this->assertContains("Bertie rulez!", $crawler->filter('#main')->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..19adb89819 --- /dev/null +++ b/tests/functional/extension_permission_lang_test.php @@ -0,0 +1,81 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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/language/en/', + 'foo/bar/event/', + ); + + 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/fileupload_form_test.php b/tests/functional/fileupload_form_test.php new file mode 100644 index 0000000000..998c402fa3 --- /dev/null +++ b/tests/functional/fileupload_form_test.php @@ -0,0 +1,73 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * @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'); + $this->login(); + } + + 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->markTestIncomplete('Test fails intermittently.'); + $crawler = $this->upload_file('empty.png', 'image/png'); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text()); + } + + public function test_invalid_extension() + { + $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_too_large() + { + $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); + $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->markTestIncomplete('Test fails intermittently.'); + $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()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->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..8e361ab77b --- /dev/null +++ b/tests/functional/fileupload_remote_test.php @@ -0,0 +1,73 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * @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('http://example.com/image.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_non_existant() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.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..21e38b09b5 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -0,0 +1,32 @@ +<?php + +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class phpbb_ext_foo_bar_acp_main_info +{ + function module() + { + return array( + 'filename' => 'phpbb_ext_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..c4ab69fb38 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -0,0 +1,28 @@ +<?php + +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class phpbb_ext_foo_bar_acp_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..067a9d38eb --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/composer.json @@ -0,0 +1,23 @@ +{ + "name": "foo/bar", + "type": "phpbb3-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "licence": "GPL-2.0", + "authors": [{ + "name": "Joas Schilling", + "username": "nickvergessen", + "email": "nickvergessen@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3", + "phpbb": ">=3.1.0-dev" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing" + } +} 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..09a30a8c67 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -0,0 +1,15 @@ +foo_bar_controller: + pattern: /foo/bar + defaults: { _controller: foo_bar.controller:handle } + +foo_baz_controller: + pattern: /foo/baz + defaults: { _controller: foo_bar.controller:baz } + +foo_template_controller: + pattern: /foo/template + defaults: { _controller: foo_bar.controller:template } + +foo_exception_controller: + pattern: /foo/exception + defaults: { _controller: foo_bar.controller:exception } 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..33ced55af9 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -0,0 +1,6 @@ +services: + foo_bar.controller: + class: phpbb_ext_foo_bar_controller + arguments: + - @controller.helper + - @template 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..5a91b5f681 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -0,0 +1,35 @@ +<?php +use Symfony\Component\HttpFoundation\Response; + +class phpbb_ext_foo_bar_controller +{ + protected $template; + + public function __construct(phpbb_controller_helper $helper, phpbb_template $template) + { + $this->template = $template; + $this->helper = $helper; + } + + 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'); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/event/permission_listener.php b/tests/functional/fixtures/ext/foo/bar/event/permission_listener.php new file mode 100644 index 0000000000..6986755f71 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/event/permission_listener.php @@ -0,0 +1,40 @@ +<?php + +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ + +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Event listener +*/ +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class phpbb_ext_foo_bar_event_permission_listener 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/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php new file mode 100644 index 0000000000..74359d51ab --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -0,0 +1,6 @@ +<?php + +class phpbb_ext_foo_bar_ext extends phpbb_extension_base +{ + +} 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/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..906224efbb --- /dev/null +++ b/tests/functional/forgot_password_test.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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()); + + } + +} diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php new file mode 100644 index 0000000000..738ec4f9dd --- /dev/null +++ b/tests/functional/memberlist_test.php @@ -0,0 +1,105 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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=leaders&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()); + } +} diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php new file mode 100644 index 0000000000..651c99a99d --- /dev/null +++ b/tests/functional/metadata_manager_test.php @@ -0,0 +1,83 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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('<p id="require_php">>=5.3</p>', $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('The required file does not exist:', $crawler->filter('#main')->text()); + } +} diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php new file mode 100644 index 0000000000..7f33ad1859 --- /dev/null +++ b/tests/functional/notification_test.php @@ -0,0 +1,55 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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('post_notification', true), + array('topic_notification', true), + array('post_email', true), + array('topic_email', true), + + // Default behaviour for in-board notifications: + // If user did not opt-out, in-board notifications are on. + array('bookmark_notification', true), + array('quote_notification', true), + + // Default behaviour for email notifications: + // If user did not opt-in, email notifications are off. + array('bookmark_email', false), + array('quote_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); + } + } +} diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php new file mode 100644 index 0000000000..d5adc6ad0a --- /dev/null +++ b/tests/functional/paging_test.php @@ -0,0 +1,39 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @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 < 20; $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 no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); + + $next_link = $crawler->filter('#viewtopic > fieldset > a.arrow-right')->attr('href'); + $crawler = self::request('GET', $next_link); + $this->assertContains('post no19', $crawler->text()); + $this->assertNotContains('post no9', $crawler->text()); + + $prev_link = $crawler->filter('#viewtopic > fieldset > a.arrow-left')->attr('href'); + $crawler = self::request('GET', $prev_link); + $this->assertContains('post no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); + } +} diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 9bcfcc2fda..7fd1e4fdcf 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -32,105 +32,4 @@ 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()); } - - /** - * Creates a topic - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_TOPIC', $form_data); - } - - /** - * Creates a post - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_REPLY', $form_data); - } - - /** - * Helper for submitting posts - * - * @param string $posting_url - * @param string $posting_contains - * @param array $form_data - * @return array post_id, topic_id - */ - protected function submit_post($posting_url, $posting_contains, $form_data) - { - $this->add_lang('posting'); - - $crawler = self::request('GET', $posting_url); - $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = self::request('POST', $posting_url, $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); - - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, - ); - } } diff --git a/tests/functional/softdelete_test.php b/tests/functional/softdelete_test.php new file mode 100644 index 0000000000..bd4d34cf99 --- /dev/null +++ b/tests/functional/softdelete_test.php @@ -0,0 +1,761 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_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) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $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 = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + $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'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('posting'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('delete_topic'); + $crawler = self::submit($form); + $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Yes')->form(); + $crawler = self::submit($form); + $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['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 = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + $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->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 = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('split'); + $crawler = self::submit($form); + $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 = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + + $form = $crawler->selectButton('Go')->eq(1)->form(); + $form['action']->select('move'); + $crawler = self::submit($form); + + $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'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(1)->form(); + $form['action']->select('merge_topic'); + $crawler = self::submit($form); + $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', $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'); + + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #1']}&sid={$this->sid}"); + + $this->add_lang('mcp'); + $form = $crawler->selectButton('Go')->eq(2)->form(); + $form['action']->select('fork'); + $crawler = self::submit($form); + $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); + } + } +} diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 9c6b1edc5e..f48c793ea1 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -14,8 +14,40 @@ require_once dirname(__FILE__) . '/common_groups_test.php'; */ class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test { + 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()); + } } |