diff options
author | Nils Adermann <naderman@naderman.de> | 2014-08-11 17:37:56 +0200 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2014-08-11 17:37:56 +0200 |
commit | bad90dafbfe8a093a518b90b82a01d4e63e757f2 (patch) | |
tree | e97a0d694ba8926910f8afb512302907fb1d6e32 /tests/avatar | |
parent | 91df95a90dd3266f4beeb7df7534f75882909581 (diff) | |
parent | 70978e96d34ddf3bea24c363800e9fc920c3120b (diff) | |
download | forums-bad90dafbfe8a093a518b90b82a01d4e63e757f2.tar forums-bad90dafbfe8a093a518b90b82a01d4e63e757f2.tar.gz forums-bad90dafbfe8a093a518b90b82a01d4e63e757f2.tar.bz2 forums-bad90dafbfe8a093a518b90b82a01d4e63e757f2.tar.xz forums-bad90dafbfe8a093a518b90b82a01d4e63e757f2.zip |
Merge remote-tracking branch 'github-marc1706/ticket/12822' into develop-ascraeus
* github-marc1706/ticket/12822:
[ticket/12822] Fix test runs of avatar manager_test
[ticket/12822] Add method for deleting avatars and use confirm_box
[ticket/12822] Remove "None" option from avatar select boxes
Diffstat (limited to 'tests/avatar')
-rw-r--r-- | tests/avatar/fixtures/users.xml | 33 | ||||
-rw-r--r-- | tests/avatar/manager_test.php | 68 |
2 files changed, 90 insertions, 11 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 8463cdb6c2..9f89968f36 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')); @@ -67,24 +72,26 @@ class phpbb_avatar_manager_test extends \phpbb_test_case { if ($driver !== 'upload') { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache)); } else { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache)); } $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,42 @@ 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_limit($sql, 1); + + $row = $this->manager->clean_row($this->db->sql_fetchrow($result), substr($prefix, 0, -1)); + $this->db->sql_freeresult($result); + + foreach ($expected as $key => $value) + { + $this->assertEquals($value, $row[$key]); + } + } } |