aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/memberlist_test.php
blob: 0065147d113112cee42d15dac77e5bcc52c2675e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?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 = $this->request('GET', 'memberlist.php?sid=' . $this->sid);
		$this->assert_response_success();
		$this->assertContains('memberlist-test-user', $crawler->text());

		// restrict by first character
		$crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
		$this->assert_response_success();
		$this->assertContains('memberlist-test-user', $crawler->text());

		// make sure results for wrong character are not returned
		$crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
		$this->assert_response_success();
		$this->assertNotContains('memberlist-test-user', $crawler->text());
	}

	public function test_viewprofile()
	{
		$this->login();
		// XXX hardcoded user id
		$crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
		$this->assert_response_success();
		$this->assertContains('admin', $crawler->filter('h2')->text());
	}

	protected function get_memberlist_leaders_crawler()
	{
		$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
		$this->assert_response_success();

		return $crawler;
	}

	protected function get_crawler_table_text($crawler, $table)
	{
		return $crawler->filter('.forumbg-table')->eq($table)->text();
	}

	public function test_leaders()
	{
		$this->login();
		$this->create_user('memberlist-test-moderator');

		$crawler = $this->get_memberlist_leaders_crawler();

		// Admin in admin group, but not in moderators
		$this->assertContains('admin', $this->get_crawler_table_text($crawler, 0));
		$this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1));

		// memberlist-test-user in neither group
		$this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 0));
		$this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 1));

		// memberlist-test-moderator in neither group
		$this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0));
		$this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1));
	}

	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_crawler();
		$this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0));
		$this->assertContains('admin', $this->get_crawler_table_text($crawler, 1));

		// Remove admin from moderators, should not be visible anymore
		$this->remove_user_group('GLOBAL_MODERATORS', array('admin'));
		$crawler = $this->get_memberlist_leaders_crawler();
		$this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0));
		$this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1));
	}

	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_crawler();
		$this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0));
		$this->assertContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1));
	}
}