aboutsummaryrefslogtreecommitdiffstats
path: root/tests/avatar
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2014-08-07 17:19:08 +0200
committerMarc Alexander <admin@m-a-styles.de>2014-08-07 17:29:33 +0200
commite0c2013bb921f04f032744c3bc351c015c759d8d (patch)
treedc9f79569e572646a0ec49e3e81119802701119e /tests/avatar
parent4f23bb711ca457efba370d7ac67394e0db59b578 (diff)
downloadforums-e0c2013bb921f04f032744c3bc351c015c759d8d.tar
forums-e0c2013bb921f04f032744c3bc351c015c759d8d.tar.gz
forums-e0c2013bb921f04f032744c3bc351c015c759d8d.tar.bz2
forums-e0c2013bb921f04f032744c3bc351c015c759d8d.tar.xz
forums-e0c2013bb921f04f032744c3bc351c015c759d8d.zip
[ticket/12822] Add method for deleting avatars and use confirm_box
The method will take care of the actual deletion process in the avatar manager. Additionally, we'll be using a confirm box while deleting the avatar to prevent users from accidentally deleting their avatars. PHPBB3-12822
Diffstat (limited to 'tests/avatar')
-rw-r--r--tests/avatar/fixtures/users.xml33
-rw-r--r--tests/avatar/manager_test.php57
2 files changed, 81 insertions, 9 deletions
diff --git a/tests/avatar/fixtures/users.xml b/tests/avatar/fixtures/users.xml
new file mode 100644
index 0000000000..3e6586e909
--- /dev/null
+++ b/tests/avatar/fixtures/users.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_avatar</column>
+ <column>user_avatar_type</column>
+ <column>user_avatar_width</column>
+ <column>user_avatar_height</column>
+ <row>
+ <value>1</value>
+ <value>barfoo</value>
+ <value></value>
+ <value></value>
+ <value>foobar@example.com</value>
+ <value>avatar.driver.gravatar</value>
+ <value>80</value>
+ <value>80</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>foobar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index d8099b40d4..a63a13ce50 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -13,13 +13,18 @@
require_once dirname(__FILE__) . '/driver/foobar.php';
-class phpbb_avatar_manager_test extends \phpbb_test_case
+class phpbb_avatar_manager_test extends \phpbb_database_test_case
{
/** @var \phpbb\avatar\manager */
protected $manager;
protected $avatar_foobar;
protected $avatar_barfoo;
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/users.xml');
+ }
+
public function setUp()
{
global $phpbb_root_path, $phpEx;
@@ -31,7 +36,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
->will($this->returnArgument(0));
// Prepare dependencies for avatar manager and driver
- $config = new \phpbb\config\config(array());
+ $this->config = new \phpbb\config\config(array());
$cache = $this->getMock('\phpbb\cache\driver\driver_interface');
$path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
@@ -52,7 +57,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
$guesser = new \phpbb\mimetype\guesser($guessers);
// $this->avatar_foobar will be needed later on
- $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
+ $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache));
$this->avatar_foobar->expects($this->any())
->method('get_name')
->will($this->returnValue('avatar.driver.foobar'));
@@ -76,15 +81,17 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
$cur_avatar->expects($this->any())
->method('get_name')
->will($this->returnValue('avatar.driver.' . $driver));
- $config['allow_avatar_' . get_class($cur_avatar)] = false;
+ $this->config['allow_avatar_' . get_class($cur_avatar)] = $driver == 'gravatar';
$avatar_drivers[] = $cur_avatar;
}
- $config['allow_avatar_' . get_class($this->avatar_foobar)] = true;
- $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;
+ $this->config['allow_avatar_' . get_class($this->avatar_foobar)] = true;
+ $this->config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;
// Set up avatar manager
- $this->manager = new \phpbb\avatar\manager($config, $avatar_drivers, $phpbb_container);
+ $this->manager = new \phpbb\avatar\manager($this->config, $avatar_drivers, $phpbb_container);
+ $this->db = $this->new_dbal();
+ $this->user = new \phpbb\user();
}
protected function avatar_drivers()
@@ -122,6 +129,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
{
return array(
array('avatar.driver.foobar', 'avatar.driver.foobar'),
+ array('avatar.driver.gravatar', 'avatar.driver.gravatar'),
array('avatar.driver.foo_wrong', null),
array('avatar.driver.local', null),
array(AVATAR_GALLERY, null),
@@ -196,8 +204,8 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
array(
'avatar' => '',
'avatar_type' => '',
- 'avatar_width' => '',
- 'avatar_height' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
),
),
array(
@@ -287,4 +295,35 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
array('FOOBAR_EXPLAIN', 'foo'),
)));
}
+
+ public function data_handle_avatar_delete()
+ {
+ return array(
+ array(array(
+ 'avatar' => '',
+ 'avatar_type' => '',
+ 'avatar_width' => 0,
+ 'avatar_height' => 0,
+ ), 1, array(
+ 'avatar' => 'foobar@example.com',
+ 'avatar_type' => 'avatar.driver.gravatar',
+ 'avatar_width' => '16',
+ 'avatar_height' => '16',
+ ), USERS_TABLE, 'user_'),
+ );
+ }
+
+ /**
+ * @dataProvider data_handle_avatar_delete
+ */
+ public function test_handle_avatar_delete($expected, $id, $avatar_data, $table, $prefix)
+ {
+ $this->config['allow_avatar_gravatar'] = true;
+ $this->assertNull($this->manager->handle_avatar_delete($this->db, $this->user, $avatar_data, $table, $prefix));
+
+ $sql = 'SELECT * FROM ' . $table . '
+ WHERE ' . $prefix . 'id = ' . $id;
+ $result = $this->db->sql_query($sql);
+ $this->assertSame($expected, $this->manager->clean_row($this->db->sql_fetchrow($result), substr($prefix, -1)));
+ }
}