Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.97% |
26 / 124 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functions_user_group_user_attributes_test | |
20.97% |
26 / 124 |
|
66.67% |
2 / 3 |
7.44 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| group_user_attributes_data | |
0.00% |
0 / 98 |
|
0.00% |
0 / 1 |
2 | |||
| test_group_user_attributes | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | require_once __DIR__ . '/../../phpBB/includes/functions_user.php'; |
| 15 | |
| 16 | class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case |
| 17 | { |
| 18 | public function getDataSet() |
| 19 | { |
| 20 | return $this->createXMLDataSet(__DIR__.'/fixtures/group_user_attributes.xml'); |
| 21 | } |
| 22 | |
| 23 | public static function group_user_attributes_data() |
| 24 | { |
| 25 | return array( |
| 26 | array( |
| 27 | 'Setting new default group without settings for user with no settings - no change', |
| 28 | 1, |
| 29 | 2, |
| 30 | array( |
| 31 | 'group_avatar' => '', |
| 32 | 'group_avatar_type' => '', |
| 33 | 'group_avatar_height' => 0, |
| 34 | 'group_avatar_width' => 0, |
| 35 | 'group_rank' => 0, |
| 36 | ), |
| 37 | array( |
| 38 | 'user_avatar' => '', |
| 39 | 'user_rank' => 0, |
| 40 | ), |
| 41 | ), |
| 42 | array( |
| 43 | 'Setting new default group without settings for user with default settings - user settings overwritten', |
| 44 | 2, |
| 45 | 2, |
| 46 | array( |
| 47 | 'group_avatar' => '', |
| 48 | 'group_avatar_type' => '', |
| 49 | 'group_avatar_height' => 0, |
| 50 | 'group_avatar_width' => 0, |
| 51 | 'group_rank' => 0, |
| 52 | ), |
| 53 | array( |
| 54 | 'user_avatar' => '', |
| 55 | 'user_rank' => 0, |
| 56 | ), |
| 57 | ), |
| 58 | array( |
| 59 | 'Setting new default group without settings for user with custom settings - no change', |
| 60 | 3, |
| 61 | 2, |
| 62 | array( |
| 63 | 'group_avatar' => '', |
| 64 | 'group_avatar_type' => '', |
| 65 | 'group_avatar_height' => 0, |
| 66 | 'group_avatar_width' => 0, |
| 67 | 'group_rank' => 0, |
| 68 | ), |
| 69 | array( |
| 70 | 'user_avatar' => 'custom', |
| 71 | 'user_rank' => 2, |
| 72 | ), |
| 73 | ), |
| 74 | array( |
| 75 | 'Setting new default group with settings for user with no settings - user settings overwritten', |
| 76 | 1, |
| 77 | 3, |
| 78 | array( |
| 79 | 'group_avatar' => 'default2', |
| 80 | 'group_avatar_type' => 'avatar.driver.upload', |
| 81 | 'group_avatar_height' => 1, |
| 82 | 'group_avatar_width' => 1, |
| 83 | 'group_rank' => 3, |
| 84 | ), |
| 85 | array( |
| 86 | 'user_avatar' => 'default2', |
| 87 | 'user_rank' => 3, |
| 88 | ), |
| 89 | ), |
| 90 | array( |
| 91 | 'Setting new default group with settings for user with default settings - user settings overwritten', |
| 92 | 2, |
| 93 | 3, |
| 94 | array( |
| 95 | 'group_avatar' => 'default2', |
| 96 | 'group_avatar_type' => 'avatar.driver.upload', |
| 97 | 'group_avatar_height' => 1, |
| 98 | 'group_avatar_width' => 1, |
| 99 | 'group_rank' => 3, |
| 100 | ), |
| 101 | array( |
| 102 | 'user_avatar' => 'default2', |
| 103 | 'user_rank' => 3, |
| 104 | ), |
| 105 | ), |
| 106 | array( |
| 107 | 'Setting new default group with settings for user with custom settings - no change', |
| 108 | 3, |
| 109 | 3, |
| 110 | array( |
| 111 | 'group_avatar' => 'default2', |
| 112 | 'group_avatar_type' => 'avatar.driver.upload', |
| 113 | 'group_avatar_height' => 1, |
| 114 | 'group_avatar_width' => 1, |
| 115 | 'group_rank' => 3, |
| 116 | ), |
| 117 | array( |
| 118 | 'user_avatar' => 'custom', |
| 119 | 'user_rank' => 2, |
| 120 | ), |
| 121 | ), |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @dataProvider group_user_attributes_data |
| 127 | */ |
| 128 | public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) |
| 129 | { |
| 130 | global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container, $phpbb_log, $phpbb_root_path, $phpEx; |
| 131 | |
| 132 | $user = new phpbb_mock_user; |
| 133 | $user->ip = ''; |
| 134 | $user->data['user_id'] = $user_id; |
| 135 | $cache = new phpbb_mock_cache; |
| 136 | $db = $this->new_dbal(); |
| 137 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 138 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 139 | $auth->expects($this->any()) |
| 140 | ->method('acl_clear_prefetch'); |
| 141 | $cache_driver = new \phpbb\cache\driver\dummy(); |
| 142 | $phpbb_container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
| 143 | $phpbb_container |
| 144 | ->expects($this->any()) |
| 145 | ->method('get') |
| 146 | ->with('cache.driver') |
| 147 | ->will($this->returnValue($cache_driver)); |
| 148 | $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
| 149 | |
| 150 | group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); |
| 151 | |
| 152 | $sql = 'SELECT user_avatar, user_rank |
| 153 | FROM ' . USERS_TABLE . ' |
| 154 | WHERE user_id = ' . $user_id; |
| 155 | $result = $db->sql_query($sql); |
| 156 | |
| 157 | $this->assertEquals(array($expected), $db->sql_fetchrowset($result)); |
| 158 | |
| 159 | $db->sql_freeresult($result); |
| 160 | } |
| 161 | } |