diff options
Diffstat (limited to 'tests/functional')
31 files changed, 1398 insertions, 106 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..ff4d3ced5c 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -45,4 +45,14 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case  		$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/common_groups_test.php b/tests/functional/common_groups_test.php index 7c88ec900d..8c014aebed 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')); +	} +  	public function groups_manage_test_data()  	{  		return array( @@ -30,13 +52,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()); 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..9ddf1e3e5c --- /dev/null +++ b/tests/functional/extension_controller_test.php @@ -0,0 +1,113 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + +/** +* @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..c573ea5410 --- /dev/null +++ b/tests/functional/extension_module_test.php @@ -0,0 +1,99 @@ +<?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/db/db_tools.php'; +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..6c1720735c --- /dev/null +++ b/tests/functional/extension_permission_lang_test.php @@ -0,0 +1,80 @@ +<?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/', +	); + +	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 foo', $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/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..cd4b9a32d1 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php @@ -0,0 +1,6 @@ +<?php + +// Admin Permissions +$lang = array_merge($lang, array( +    'acl_u_foo'    => array('lang' => 'Can view foo', 'cat' => 'misc'), +)); 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.bifBinary files differ new 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.pngBinary files differ new 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.jpgBinary files differ new 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..c55e7373ea --- /dev/null +++ b/tests/functional/metadata_manager_test.php @@ -0,0 +1,85 @@ +<?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/db/db_tools.php'; + +/** +* @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/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()); +	}  } | 
