Skip to content

Commit b51f8bc

Browse files
committed
[ticket/17543] Use class method to call db object instance where possible
PHPBB-17543
1 parent 70c07d4 commit b51f8bc

13 files changed

Lines changed: 73 additions & 97 deletions

tests/functional/acp_registration_test.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ protected function set_email_enable($db, $status)
2828

2929
public function test_submitting_activation_method()
3030
{
31-
$db = $this->get_db();
32-
33-
$this->set_email_enable($db, false);
31+
$this->set_email_enable($this->db, false);
3432

3533
$this->add_lang('acp/board');
3634
$this->login();
@@ -50,6 +48,6 @@ public function test_submitting_activation_method()
5048
$crawler = self::submit($form);
5149
$this->assertNotContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text());
5250

53-
$this->set_email_enable($db, true);
51+
$this->set_email_enable($this->db, true);
5452
}
5553
}

tests/functional/auth_test.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ public function test_login_ucp_other_auth_provider()
4040
{
4141
global $cache, $config;
4242
$cache = new phpbb_mock_null_cache;
43-
$db = $this->get_db();
4443
$sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'";
45-
$db->sql_query($sql);
44+
$this->db->sql_query($sql);
4645
$config['auth_method'] = 'foobar';
4746
$this->login('anothertestuser');
4847
$crawler = self::request('GET', 'index.php');
4948
$this->assertStringContainsString('anothertestuser', $crawler->filter('#username_logged_in')->text());
5049
$sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'";
51-
$db->sql_query($sql);
50+
$this->db->sql_query($sql);
5251
$config['auth_method'] = 'db';
5352
}
5453

tests/functional/forum_style_test.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public function test_default_forum_style()
3030

3131
public function test_custom_forum_style()
3232
{
33-
$db = $this->get_db();
3433
$this->add_style(2, 'test_style');
35-
$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2');
34+
$this->db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2');
3635

3736
$crawler = self::request('GET', 'viewtopic.php?t=1&f=2');
3837
$this->assertStringContainsString('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href'));
@@ -43,7 +42,7 @@ public function test_custom_forum_style()
4342
$crawler = self::request('GET', 'viewtopic.php?t=1&view=next');
4443
$this->assertStringContainsString('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->eq(1)->attr('href'));
4544

46-
$db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2');
45+
$this->db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2');
4746
$this->delete_style(2, 'test_style');
4847
}
4948
}

tests/functional/plupload_test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case
2121

2222
protected function set_extension_group_permission($val)
2323
{
24-
$db = $this->get_db();
2524
$query = "
2625
UPDATE phpbb_extension_groups
2726
SET allow_in_pm = '$val'
2827
WHERE group_name = 'IMAGES'
2928
";
30-
$db->sql_query($query);
29+
$this->db->sql_query($query);
3130
}
3231

3332
protected function setUp(): void

tests/functional/search/mysql_test.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ protected function create_search_index($backend = null)
3838
// Try optimizing posts table after creating search index.
3939
// Some versions of MariaDB might not return any results in the search
4040
// until the table has been optimized or the index deleted and re-created.
41-
$db = $this->get_db();
42-
$db->sql_return_on_error(true);
41+
$this->db->sql_return_on_error(true);
4342
$sql = 'OPTIMIZE TABLE ' . POSTS_TABLE;
44-
$db->sql_query($sql);
45-
$db->sql_return_on_error(false);
43+
$this->db->sql_query($sql);
44+
$this->db->sql_return_on_error(false);
4645
}
4746
}

tests/functional/session_page_update_test.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,29 @@ public function setUp(): void
2121
{
2222
parent::setUp();
2323

24-
global $db;
25-
26-
$db = $this->db;
27-
2824
// Delete previous session info for admin user
2925
$sql = 'DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = 2';
30-
$db->sql_query($sql);
26+
$this->db->sql_query($sql);
3127

3228
$this->login();
3329
}
3430

3531
public function test_session_page_update()
3632
{
37-
$db = $this->get_db();
38-
3933
// Request index page
4034
self::request('GET', 'index.php');
4135
$this->assertEquals(200, self::$client->getInternalResponse()->getStatusCode(), 'Failed asserting that status of index page is 200');
4236

4337
$sql = 'SELECT session_page FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = 2 ORDER BY session_time DESC';
44-
$db->sql_query_limit($sql, 1);
45-
$this->assertEquals('index.php', $db->sql_fetchfield('session_page'), 'Failed asserting that session_page is index.php for admin user');
38+
$this->db->sql_query_limit($sql, 1);
39+
$this->assertEquals('index.php', $this->db->sql_fetchfield('session_page'), 'Failed asserting that session_page is index.php for admin user');
4640

4741
// Request non-existent url
4842
self::request('GET', 'nonexistent.jpg', [], false);
4943
$this->assertEquals(404, self::$client->getInternalResponse()->getStatusCode(), 'Failed asserting that status of non-existent image is 404');
5044

51-
$db->sql_query_limit($sql, 1);
45+
$this->db->sql_query_limit($sql, 1);
5246
// User page should not be updated to non-existent one
53-
$this->assertEquals('index.php', $db->sql_fetchfield('session_page'), 'Failed asserting that session page has not changed after 404');
47+
$this->assertEquals('index.php', $this->db->sql_fetchfield('session_page'), 'Failed asserting that session page has not changed after 404');
5448
}
5549
}

tests/functional/smilies_test.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ public function test_smilies_mode()
2121
$this->login();
2222

2323
// Get smilies data
24-
$db = $this->get_db();
2524
$sql_ary = [
2625
'SELECT' => 's.smiley_url, MIN(s.emotion) AS emotion, MIN(s.code) AS code, s.smiley_width, s.smiley_height, MIN(s.smiley_order) AS min_smiley_order',
2726
'FROM' => [
2827
SMILIES_TABLE => 's',
2928
],
3029
'GROUP_BY' => 's.smiley_url, s.smiley_width, s.smiley_height',
31-
'ORDER_BY' => $db->sql_quote('min_smiley_order'),
30+
'ORDER_BY' => $this->db->sql_quote('min_smiley_order'),
3231
];
33-
$sql = $db->sql_build_query('SELECT', $sql_ary);
34-
$result = $db->sql_query($sql);
35-
$smilies = $db->sql_fetchrowset($result);
36-
$db->sql_freeresult($result);
32+
$sql = $this->db->sql_build_query('SELECT', $sql_ary);
33+
$result = $this->db->sql_query($sql);
34+
$smilies = $this->db->sql_fetchrowset($result);
35+
$this->db->sql_freeresult($result);
3736

3837
// Visit smilies page
3938
$crawler = self::request('GET', 'posting.php?mode=smilies');

tests/functional/switch_permissions_test.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ public function test_switch_permissions_acp()
7373
*/
7474
public function test_switch_permissions_ucp()
7575
{
76-
$db = $this->get_db();
7776
$sql = 'SELECT user_id
7877
FROM ' . USERS_TABLE . "
7978
WHERE username = '" . self::TEST_USER . "'";
80-
$result = $db->sql_query($sql);
81-
$user_id = $db->sql_fetchfield('user_id');
82-
$db->sql_freeresult($result);
79+
$result = $this->db->sql_query($sql);
80+
$user_id = $this->db->sql_fetchfield('user_id');
81+
$this->db->sql_freeresult($result);
8382

8483
// Open memberlist profile page for user
8584
$crawler = self::request('GET', "memberlist.php?mode=viewprofile&u={$user_id}&sid={$this->sid}");

tests/functional/ucp_allow_pm_test.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ public function test_disabled_pm_admin_to_user()
6464
// enable or disable PM for a user, like from ucp
6565
protected function set_user_allow_pm($user_id, $allow)
6666
{
67-
$db = $this->get_db();
6867
$sql = 'UPDATE ' . USERS_TABLE . "
6968
SET user_allow_pm = " . $allow . "
7069
WHERE user_id = " . $user_id;
71-
$result = $db->sql_query($sql);
72-
$db->sql_freeresult($result);
70+
$result = $this->db->sql_query($sql);
71+
$this->db->sql_freeresult($result);
7372
}
7473
}

tests/functional/ucp_profile_test.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function test_autologin_keys_manage()
7373
{
7474
$this->add_lang('ucp');
7575
$this->login('admin', true);
76-
$db = $this->get_db();
7776

7877
$crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=autologin_keys');
7978
$this->assertContainsLang('UCP_PROFILE_AUTOLOGIN_KEYS', $crawler->filter('#cp-main h2')->text());
@@ -87,9 +86,9 @@ public function test_autologin_keys_manage()
8786
'WHERE' => 'sk.user_id = ' . (int) $user_id,
8887
'ORDER_BY' => 'sk.last_login ASC',
8988
];
90-
$result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), 1);
91-
$key_id = substr($db->sql_fetchfield('key_id'), 0, 8);
92-
$db->sql_freeresult($result);
89+
$result = $this->db->sql_query_limit($this->db->sql_build_query('SELECT', $sql_ary), 1);
90+
$key_id = substr($this->db->sql_fetchfield('key_id'), 0, 8);
91+
$this->db->sql_freeresult($result);
9392

9493
$this->assertStringContainsString($key_id, $crawler->filter('label[for="' . $key_id . '"]')->text());
9594

0 commit comments

Comments
 (0)