From cbfe866eba5b2a7bb9f141e5145292dbef135e78 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Apr 2013 18:03:02 +0200 Subject: [ticket/11494] Use functions instead of repeating PHPBB3-11494 --- tests/functional/memberlist_test.php | 48 ++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 2e3d7907bf..0065147d11 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -41,25 +41,37 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $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->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); + $crawler = $this->get_memberlist_leaders_crawler(); // Admin in admin group, but not in moderators - $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('memberlist-test-user', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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() @@ -68,16 +80,15 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Remove admin from admins, but is now in moderators $this->remove_user_group('ADMINISTRATORS', array('admin')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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() @@ -86,9 +97,8 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Add memberlist-test-moderator to moderators $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); + $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)); } } -- cgit v1.2.1