aboutsummaryrefslogtreecommitdiffstats
path: root/tests/attachment
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2015-09-23 10:17:38 +0200
committerMarc Alexander <admin@m-a-styles.de>2015-10-09 10:18:31 +0200
commit04786313892df25f5adce555ebae6b2e5ad4d222 (patch)
treef02c037a6c853945f384c31169494236172ad4f6 /tests/attachment
parent8d03b9e001526fb237cdb744dd832c1dd4182d01 (diff)
downloadforums-04786313892df25f5adce555ebae6b2e5ad4d222.tar
forums-04786313892df25f5adce555ebae6b2e5ad4d222.tar.gz
forums-04786313892df25f5adce555ebae6b2e5ad4d222.tar.bz2
forums-04786313892df25f5adce555ebae6b2e5ad4d222.tar.xz
forums-04786313892df25f5adce555ebae6b2e5ad4d222.zip
[ticket/14168] Move phpbb_unlink() into attachment delete class
PHPBB3-14168
Diffstat (limited to 'tests/attachment')
-rw-r--r--tests/attachment/delete_test.php55
-rw-r--r--tests/attachment/fixtures/resync.xml15
2 files changed, 67 insertions, 3 deletions
diff --git a/tests/attachment/delete_test.php b/tests/attachment/delete_test.php
index df7e305dc5..8db6487542 100644
--- a/tests/attachment/delete_test.php
+++ b/tests/attachment/delete_test.php
@@ -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'));
+ }
}
diff --git a/tests/attachment/fixtures/resync.xml b/tests/attachment/fixtures/resync.xml
index 132f62382c..d15f6d17f9 100644
--- a/tests/attachment/fixtures/resync.xml
+++ b/tests/attachment/fixtures/resync.xml
@@ -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">