aboutsummaryrefslogtreecommitdiffstats
path: root/tests/avatar/manager_test.php
diff options
context:
space:
mode:
authorAndy Chase <asperous2@gmail.com>2013-07-22 11:29:36 -0700
committerAndy Chase <asperous2@gmail.com>2013-07-22 11:29:36 -0700
commite2a769ac79ad408e94935c97a5fc1325fb838c4f (patch)
tree5f56bbc9d9290f49a6c88987561f345df49f8a3c /tests/avatar/manager_test.php
parentcc1aef47fb4f5d37415436c62067ad2dcde768bb (diff)
parentb71038486e067daf0c608d73aabeb60a56e86840 (diff)
downloadforums-e2a769ac79ad408e94935c97a5fc1325fb838c4f.tar
forums-e2a769ac79ad408e94935c97a5fc1325fb838c4f.tar.gz
forums-e2a769ac79ad408e94935c97a5fc1325fb838c4f.tar.bz2
forums-e2a769ac79ad408e94935c97a5fc1325fb838c4f.tar.xz
forums-e2a769ac79ad408e94935c97a5fc1325fb838c4f.zip
Merge branch 'develop' into ticket/11620
Diffstat (limited to 'tests/avatar/manager_test.php')
-rw-r--r--tests/avatar/manager_test.php130
1 files changed, 108 insertions, 22 deletions
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index cb895b521a..4ebe79c9cd 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -19,24 +19,35 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$this->phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$this->phpbb_container->expects($this->any())
->method('get')
- ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar'));
+ ->will($this->returnArgument(0));
// Prepare dependencies for avatar manager and driver
$config = new phpbb_config(array());
$request = $this->getMock('phpbb_request');
$cache = $this->getMock('phpbb_cache_driver_interface');
+ // $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, $cache));
$this->avatar_foobar->expects($this->any())
- ->method('get_name')
- ->will($this->returnValue('avatar.driver.foobar'));
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.foobar'));
+ // barfoo driver can't be mocked with constructor arguments
$this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name'));
$this->avatar_barfoo->expects($this->any())
- ->method('get_name')
- ->will($this->returnValue('avatar.driver.barfoo'));
-
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.barfoo'));
$avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo);
+ foreach ($this->avatar_drivers() as $driver)
+ {
+ $cur_avatar = $this->getMock('phpbb_avatar_driver_' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache));
+ $cur_avatar->expects($this->any())
+ ->method('get_name')
+ ->will($this->returnValue('avatar.driver.' . $driver));
+ $config['allow_avatar_' . get_class($cur_avatar)] = false;
+ $avatar_drivers[] = $cur_avatar;
+ }
+
$config['allow_avatar_' . get_class($this->avatar_foobar)] = true;
$config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;
@@ -44,28 +55,27 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container);
}
- public function test_get_driver()
+ protected function avatar_drivers()
{
- $driver = $this->manager->get_driver('avatar.driver.foobar', false);
- $this->assertEquals('avatar.driver.foobar', $driver);
-
- $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false);
- $this->assertNull($driver);
-
- $driver = $this->manager->get_driver('avatar.driver.foobar');
- $this->assertEquals('avatar.driver.foobar', $driver);
-
- $driver = $this->manager->get_driver('avatar.driver.foo_wrong');
- $this->assertNull($driver);
+ return array(
+ 'local',
+ 'upload',
+ 'remote',
+ 'gravatar',
+ );
}
public function test_get_all_drivers()
{
$drivers = $this->manager->get_all_drivers();
- $this->assertArrayHasKey('avatar.driver.foobar', $drivers);
- $this->assertArrayHasKey('avatar.driver.barfoo', $drivers);
- $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);
- $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']);
+ $this->assertEquals(array(
+ 'avatar.driver.barfoo' => 'avatar.driver.barfoo',
+ 'avatar.driver.foobar' => 'avatar.driver.foobar',
+ 'avatar.driver.local' => 'avatar.driver.local',
+ 'avatar.driver.remote' => 'avatar.driver.remote',
+ 'avatar.driver.upload' => 'avatar.driver.upload',
+ 'avatar.driver.gravatar' => 'avatar.driver.gravatar',
+ ), $drivers);
}
public function test_get_enabled_drivers()
@@ -76,6 +86,48 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']);
}
+ public function get_driver_data_enabled()
+ {
+ return array(
+ array('avatar.driver.foobar', 'avatar.driver.foobar'),
+ array('avatar.driver.foo_wrong', null),
+ array('avatar.driver.local', null),
+ array(AVATAR_GALLERY, null),
+ array(AVATAR_UPLOAD, null),
+ array(AVATAR_REMOTE, null),
+ );
+ }
+
+ /**
+ * @dataProvider get_driver_data_enabled
+ */
+ public function test_get_driver_enabled($driver_name, $expected)
+ {
+ $driver = $this->manager->get_driver($driver_name);
+ $this->assertEquals($expected, $driver);
+ }
+
+ public function get_driver_data_all()
+ {
+ return array(
+ array('avatar.driver.foobar', 'avatar.driver.foobar'),
+ array('avatar.driver.foo_wrong', null),
+ array('avatar.driver.local', 'avatar.driver.local'),
+ array(AVATAR_GALLERY, 'avatar.driver.local'),
+ array(AVATAR_UPLOAD, 'avatar.driver.upload'),
+ array(AVATAR_REMOTE, 'avatar.driver.remote'),
+ );
+ }
+
+ /**
+ * @dataProvider get_driver_data_all
+ */
+ public function test_get_driver_all($driver_name, $expected)
+ {
+ $driver = $this->manager->get_driver($driver_name, false);
+ $this->assertEquals($expected, $driver);
+ }
+
public function test_get_avatar_settings()
{
$avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar);
@@ -157,4 +209,38 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey($key, $cleaned_row);
}
}
+
+ public function test_clean_driver_name()
+ {
+ $this->assertEquals('avatar.driver.local', $this->manager->clean_driver_name('avatar_driver_local'));
+ }
+
+ public function test_prepare_driver_name()
+ {
+ $this->assertEquals('avatar_driver_local', $this->manager->prepare_driver_name('avatar.driver.local'));
+ }
+
+ public function test_localize_errors()
+ {
+ $user = $this->getMock('phpbb_user');
+ $lang_array = array(
+ array('FOOBAR_OFF', 'foobar_off'),
+ array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'),
+ );
+ $user->expects($this->any())
+ ->method('lang')
+ ->will($this->returnValueMap($lang_array));
+
+ // Pass error as string
+ $this->assertEquals(array('foobar_off'), $this->manager->localize_errors($user, array('FOOBAR_OFF')));
+
+ // Pass error as array for vsprintf()
+ $this->assertEquals(array('FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(array('FOOBAR_EXPLAIN', 'foo'))));
+
+ // Pass both types
+ $this->assertEquals(array('foobar_off', 'FOOBAR_EXPLAIN foo'), $this->manager->localize_errors($user, array(
+ 'FOOBAR_OFF',
+ array('FOOBAR_EXPLAIN', 'foo'),
+ )));
+ }
}