[ticket/14168] Fix tabs in manager and add test file

PHPBB3-14168
This commit is contained in:
Marc Alexander 2015-10-09 12:14:19 +02:00
parent 88033feb85
commit 53008c8782
2 changed files with 140 additions and 71 deletions

View file

@ -18,82 +18,82 @@ namespace phpbb\attachment;
*/ */
class manager class manager
{ {
/** @var delete Attachment delete class */ /** @var delete Attachment delete class */
protected $delete; protected $delete;
/** @var resync Attachment resync class */ /** @var resync Attachment resync class */
protected $resync; protected $resync;
/** @var upload Attachment upload class */ /** @var upload Attachment upload class */
protected $upload; protected $upload;
/** /**
* Constructor for attachment manager * Constructor for attachment manager
* *
* @param delete $delete Attachment delete class * @param delete $delete Attachment delete class
* @param resync $resync Attachment resync class * @param resync $resync Attachment resync class
* @param upload $upload Attachment upload class * @param upload $upload Attachment upload class
*/ */
public function __construct(delete $delete, resync $resync, upload $upload) public function __construct(delete $delete, resync $resync, upload $upload)
{ {
$this->delete = $delete; $this->delete = $delete;
$this->resync = $resync; $this->resync = $resync;
$this->upload = $upload; $this->upload = $upload;
} }
/** /**
* Wrapper method for deleting attachments * Wrapper method for deleting attachments
* *
* @param string $mode can be: post|message|topic|attach|user * @param string $mode can be: post|message|topic|attach|user
* @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids * @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids
* @param bool $resync set this to false if you are deleting posts or topics * @param bool $resync set this to false if you are deleting posts or topics
* *
* @return int|bool Number of deleted attachments or false if something * @return int|bool Number of deleted attachments or false if something
* went wrong during attachment deletion * went wrong during attachment deletion
*/ */
public function delete($mode, $id, $resync = true) public function delete($mode, $id, $resync = true)
{ {
$this->delete->delete($mode, $id, $resync); return $this->delete->delete($mode, $id, $resync);
} }
/** /**
* Wrapper method for deleting attachments from filesystem * Wrapper method for deleting attachments from filesystem
* *
* @param string $filename Filename of attachment * @param string $filename Filename of attachment
* @param string $mode Delete mode * @param string $mode Delete mode
* @param bool $entry_removed Whether entry was removed. Defaults to false * @param bool $entry_removed Whether entry was removed. Defaults to false
* @return bool True if file was removed, false if not * @return bool True if file was removed, false if not
*/ */
public function unlink($filename, $mode = 'file', $entry_removed = false) public function unlink($filename, $mode = 'file', $entry_removed = false)
{ {
$this->delete->unlink_attachment($filename, $mode, $entry_removed); return $this->delete->unlink_attachment($filename, $mode, $entry_removed);
} }
/** /**
* Wrapper method for resyncing specified type * Wrapper method for resyncing specified type
* *
* @param string $type Type of resync * @param string $type Type of resync
* @param array $ids IDs to resync * @param array $ids IDs to resync
*/ */
public function resync($type, $ids) public function resync($type, $ids)
{ {
$this->resync->resync($type, $ids); $this->resync->resync($type, $ids);
} }
/** /**
* Wrapper method for uploading attachment * Wrapper method for uploading attachment
* *
* @param string $form_name The form name of the file upload input * @param string $form_name The form name of the file upload input
* @param int $forum_id The id of the forum * @param int $forum_id The id of the forum
* @param bool $local Whether the file is local or not * @param bool $local Whether the file is local or not
* @param string $local_storage The path to the local file * @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not * @param bool $is_message Whether it is a PM or not
* @param array $local_filedata An file data object created for the local file * @param array $local_filedata An file data object created for the local file
* *
* @return object filespec * @return object filespec
*/ */
public function upload($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = []) public function upload($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = [])
{ {
$this->upload->upload($form_name, $forum_id, $local, $local_storage, $is_message, $local_filedata); return $this->upload->upload($form_name, $forum_id, $local, $local_storage, $is_message, $local_filedata);
} }
} }

View file

@ -0,0 +1,69 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
class phpbb_attachment_manager_test extends \phpbb_test_case
{
protected $delete;
protected $resync;
protected $upload;
public function setUp()
{
$this->delete = $this->getMockBuilder('\phpbb\attachment\delete')
->disableOriginalConstructor()
->setMethods(['delete', 'unlink'])
->getMock();
$this->resync = $this->getMockBuilder('\phpbb\attachment\resync')
->disableOriginalConstructor()
->setMethods(['resync'])
->getMock();
$this->upload = $this->getMockBuilder('\phpbb\attachment\upload')
->disableOriginalConstructor()
->setMethods(['upload'])
->getMock();
}
protected function get_manager()
{
return new \phpbb\attachment\manager($this->delete, $this->resync, $this->upload);
}
public function data_delete()
{
return array(
[
['foo', [1, 2, 3], false],
['foo', [1, 2, 3], false],
true,
],
[
['foo', [1, 2, 3], true],
['foo', [1, 2, 3]],
true,
],
);
}
/**
* @dataProvider data_delete
*/
public function test_delete($input, $input_manager, $output)
{
$mock = $this->delete->expects($this->atLeastOnce())
->method('delete');
$mock = call_user_func_array([$mock, 'with'], $input);
$mock->willReturn($output);
$manager = $this->get_manager();
$this->assertSame($output, call_user_func_array([$manager, 'delete'], $input_manager));
}
}