From 9d4d212e0f71789e1f0332046dd852d80ab9c8ba Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 24 Oct 2013 13:55:23 +0200 Subject: [ticket/11525] Only remove group or user prefix from given avatar data Until now, the user data had both user_id and group_id keys in the avatar data. As both group_ and user_ prefixes were removed the group_id was collapsed onto the user_id and therefore all users in the same group had the same prefix for their uploaded avatars. This patch will make sure that the correct id is used depending on whether it's a group's or user's avatar data. PHPBB3-11525 --- tests/avatar/manager_test.php | 44 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'tests/avatar') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 4afa594beb..f687f7bc86 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -201,20 +201,58 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase 'foobar_avatar_height' => '', ), ), + array( + array( + 'user_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 4, + ), + ), + array( + array( + 'user_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 5, + 'group_id' => 4, + ), + 'user', + ), + array( + array( + 'group_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 4, + 'user_id' => 5, + ), + 'group', + ), ); } /** * @dataProvider database_row_data */ - public function test_clean_row(array $input, array $output) + public function test_clean_row(array $input, array $output, $prefix = '') { $cleaned_row = array(); - $cleaned_row = \phpbb\avatar\manager::clean_row($input); - foreach ($output as $key => $null) + $cleaned_row = \phpbb\avatar\manager::clean_row($input, $prefix); + foreach ($output as $key => $value) { $this->assertArrayHasKey($key, $cleaned_row); + $this->assertEquals($output[$key], $value); } } -- cgit v1.2.1 From 32ba402c34922fca9bd0d8a5d02bde62e7334d1a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 11 Nov 2013 00:01:31 +0100 Subject: [ticket/11525] Compare correct array to expected value PHPBB3-11525 --- tests/avatar/manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/avatar') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index f687f7bc86..47d19be66d 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -252,7 +252,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase foreach ($output as $key => $value) { $this->assertArrayHasKey($key, $cleaned_row); - $this->assertEquals($output[$key], $value); + $this->assertEquals($cleaned_row[$key], $value); } } -- cgit v1.2.1 From a74c560ecafc0c6e63f1e0fc8191e85b066a05ef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 11 Nov 2013 00:02:12 +0100 Subject: [ticket/11525] Fix expected value of group avatar test PHPBB3-11525 --- tests/avatar/manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/avatar') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 47d19be66d..e9f622bfde 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -233,7 +233,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase ), array( 'avatar' => '', - 'id' => 4, + 'id' => 'g4', 'user_id' => 5, ), 'group', -- cgit v1.2.1 From 13a4ceedb18ba938d3cd18e2f68707385bc9283a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 13 Nov 2013 18:27:40 +0100 Subject: [ticket/11525] Use foreach instead of array_walk in method clean_row() This approach is cleaner and probably even faster the previous ways that included using array_walk() or array_map() and other helper functions and methods. PHPBB3-11525 --- tests/avatar/manager_test.php | 50 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) (limited to 'tests/avatar') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index e9f622bfde..f29f7aee95 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -152,31 +152,20 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase return array( array( array( - 'user_avatar' => '', - 'user_avatar_type' => '', - 'user_avatar_width' => '', + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '', 'user_avatar_height' => '', + 'group_avatar' => '', ), array( - 'avatar' => '', - 'avatar_type' => '', - 'avatar_width' => '', - 'avatar_height' => '', - ), - ), - array( - array( - 'group_avatar' => '', - 'group_avatar_type' => '', - 'group_avatar_width' => '', - 'group_avatar_height' => '', - ), - array( - 'avatar' => '', - 'avatar_type' => '', - 'avatar_width' => '', - 'avatar_height' => '', + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '', + 'user_avatar_height' => '', + 'group_avatar' => '', ), + 'foobar', ), array( array(), @@ -187,20 +176,6 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase 'avatar_height' => '', ), ), - array( - array( - 'foobar_avatar' => '', - 'foobar_avatar_type' => '', - 'foobar_avatar_width' => '', - 'foobar_avatar_height' => '', - ), - array( - 'foobar_avatar' => '', - 'foobar_avatar_type' => '', - 'foobar_avatar_width' => '', - 'foobar_avatar_height' => '', - ), - ), array( array( 'user_avatar' => '', @@ -208,8 +183,9 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase 'group_id' => 4, ), array( - 'avatar' => '', - 'id' => 4, + 'user_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, ), ), array( -- cgit v1.2.1