Merge remote-tracking branch 'marc1706/ticket/11930' into develop

* marc1706/ticket/11930:
  [ticket/11930] Update docblock of avatar driver constructor
  [ticket/11930] Modify order of properties to fit constructor method
  [ticket/11930] Move path_helper in front of optional cache argument
  [ticket/11930] Fix tests after adding phpbb\path_helper to avatar drivers
  [ticket/11930] Use \phpbb\path_helper for avatar URLs
This commit is contained in:
Andreas Fischer 2013-10-21 11:04:23 +02:00
commit ba5b53521a
5 changed files with 25 additions and 5 deletions

View file

@ -5,6 +5,7 @@ services:
- @config - @config
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- @path_helper
- @cache.driver - @cache.driver
calls: calls:
- [set_name, [avatar.driver.gravatar]] - [set_name, [avatar.driver.gravatar]]
@ -17,6 +18,7 @@ services:
- @config - @config
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- @path_helper
- @cache.driver - @cache.driver
calls: calls:
- [set_name, [avatar.driver.local]] - [set_name, [avatar.driver.local]]
@ -29,6 +31,7 @@ services:
- @config - @config
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- @path_helper
- @cache.driver - @cache.driver
calls: calls:
- [set_name, [avatar.driver.remote]] - [set_name, [avatar.driver.remote]]
@ -41,6 +44,7 @@ services:
- @config - @config
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- @path_helper
- @cache.driver - @cache.driver
calls: calls:
- [set_name, [avatar.driver.upload]] - [set_name, [avatar.driver.upload]]

View file

@ -47,6 +47,12 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface
*/ */
protected $php_ext; protected $php_ext;
/**
* Path Helper
* @var \phpbb\path_helper
*/
protected $path_helper;
/** /**
* Cache driver * Cache driver
* @var \phpbb\cache\driver\driver_interface * @var \phpbb\cache\driver\driver_interface
@ -75,13 +81,15 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface
* @param \phpbb\request\request $request Request object * @param \phpbb\request\request $request Request object
* @param string $phpbb_root_path Path to the phpBB root * @param string $phpbb_root_path Path to the phpBB root
* @param string $php_ext PHP file extension * @param string $php_ext PHP file extension
* @param \phpbb_path_helper $path_helper phpBB path helper
* @param \phpbb\cache\driver\driver_interface $cache Cache driver * @param \phpbb\cache\driver\driver_interface $cache Cache driver
*/ */
public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null) public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null)
{ {
$this->config = $config; $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->path_helper = $path_helper;
$this->cache = $cache; $this->cache = $cache;
} }

View file

@ -29,7 +29,7 @@ class local extends \phpbb\avatar\driver\driver
public function get_data($row) public function get_data($row)
{ {
return array( return array(
'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], 'src' => $this->path_helper->get_web_root_path() . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
'width' => $row['avatar_width'], 'width' => $row['avatar_width'],
'height' => $row['avatar_height'], 'height' => $row['avatar_height'],
); );

View file

@ -29,7 +29,7 @@ class upload extends \phpbb\avatar\driver\driver
public function get_data($row, $ignore_config = false) public function get_data($row, $ignore_config = false)
{ {
return array( return array(
'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'], 'src' => $this->path_helper->get_web_root_path() . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'],
'width' => $row['avatar_width'], 'width' => $row['avatar_width'],
'height' => $row['avatar_height'], 'height' => $row['avatar_height'],
); );

View file

@ -25,9 +25,17 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
$config = new \phpbb\config\config(array()); $config = new \phpbb\config\config(array());
$request = $this->getMock('\phpbb\request\request'); $request = $this->getMock('\phpbb\request\request');
$cache = $this->getMock('\phpbb\cache\driver\driver_interface'); $cache = $this->getMock('\phpbb\cache\driver\driver_interface');
$path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->phpbb_root_path,
$this->phpEx
);
// $this->avatar_foobar will be needed later on // $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 = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
$this->avatar_foobar->expects($this->any()) $this->avatar_foobar->expects($this->any())
->method('get_name') ->method('get_name')
->will($this->returnValue('avatar.driver.foobar')); ->will($this->returnValue('avatar.driver.foobar'));
@ -40,7 +48,7 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
foreach ($this->avatar_drivers() as $driver) 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 = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache));
$cur_avatar->expects($this->any()) $cur_avatar->expects($this->any())
->method('get_name') ->method('get_name')
->will($this->returnValue('avatar.driver.' . $driver)); ->will($this->returnValue('avatar.driver.' . $driver));