mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 18:26:32 +02:00
[ticket/14168] Move phpbb_unlink() into attachment delete class
PHPBB3-14168
This commit is contained in:
@@ -21,12 +21,17 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\filesystem\filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var \phpbb\attachment\resync */
|
||||
protected $resync;
|
||||
|
||||
/** @var \phpbb\attachment\delete */
|
||||
protected $attachment_delete;
|
||||
|
||||
protected $phpbb_root_path;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml');
|
||||
@@ -34,7 +39,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $db;
|
||||
global $db, $phpbb_root_path;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@@ -42,7 +47,15 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
$this->db = $this->new_dbal();
|
||||
$db = $this->db;
|
||||
$this->resync = new \phpbb\attachment\resync($this->db);
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->resync);
|
||||
$this->filesystem = $this->getMock('\phpbb\filesystem\filesystem', array('remove', 'exists'));
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('remove')
|
||||
->willReturn(false);
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('exists')
|
||||
->willReturn(true);
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->filesystem, $this->resync, $phpbb_root_path);
|
||||
}
|
||||
|
||||
public function data_attachment_delete()
|
||||
@@ -55,7 +68,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
array('attach', array(1,2), true, 2),
|
||||
array('post', 5, false, 0),
|
||||
array('topic', 5, false, 0),
|
||||
array('topic', 1, true, 2),
|
||||
array('topic', 1, true, 3),
|
||||
array('user', 1, false, 0),
|
||||
);
|
||||
}
|
||||
@@ -74,4 +87,40 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
|
||||
$this->assertSame($expected, $this->attachment_delete->delete($mode, $ids, $resync));
|
||||
}
|
||||
|
||||
public function data_attachment_unlink()
|
||||
{
|
||||
return array(
|
||||
array(true, true, true),
|
||||
array(true, false, false),
|
||||
array(true, true, false, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_attachment_unlink
|
||||
*/
|
||||
public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false)
|
||||
{
|
||||
$this->filesystem = $this->getMock('\phpbb\filesystem\filesystem', array('remove', 'exists'));
|
||||
if ($throw_exception)
|
||||
{
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('remove')
|
||||
->willThrowException(new \phpbb\filesystem\exception\filesystem_exception);;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('remove')
|
||||
->willReturn($remove_success);
|
||||
}
|
||||
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('exists')
|
||||
->willReturn($exists_success);
|
||||
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->filesystem, $this->resync, $this->phpbb_root_path);
|
||||
$this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar'));
|
||||
}
|
||||
}
|
||||
|
@@ -6,12 +6,16 @@
|
||||
<column>in_message</column>
|
||||
<column>is_orphan</column>
|
||||
<column>attach_comment</column>
|
||||
<column>physical_filename</column>
|
||||
<column>thumbnail</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
<value>foo</value>
|
||||
<value>foo</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
@@ -19,6 +23,17 @@
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>foo2</value>
|
||||
<value>foo2</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>foo2</value>
|
||||
<value>foo2</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
|
@@ -312,7 +312,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
|
||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||
$lang = new \phpbb\language\language($lang_loader);
|
||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb\attachment\resync($db));
|
||||
$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path);
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
|
||||
|
@@ -25,7 +25,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container;
|
||||
global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path;
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$config = new \phpbb\config\config(array(
|
||||
@@ -36,7 +36,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||
$phpbb_container->set('attachment.delete', new \phpbb\attachment\delete($config, $db, new \phpbb\attachment\resync($db)));
|
||||
$phpbb_container->set('attachment.delete', new \phpbb\attachment\delete($config, $db, new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path));
|
||||
$phpbb_container->set(
|
||||
'auth.provider.db',
|
||||
new phpbb_mock_auth_provider()
|
||||
|
@@ -85,13 +85,13 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
|
||||
*/
|
||||
public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to)
|
||||
{
|
||||
global $db, $phpbb_container;
|
||||
global $db, $phpbb_container, $phpbb_root_path;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||
$phpbb_container->set('attachment.delete', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb\attachment\resync($db)));
|
||||
$phpbb_container->set('attachment.delete', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path));
|
||||
|
||||
phpbb_delete_user_pms($delete_user);
|
||||
|
||||
|
Reference in New Issue
Block a user