diff options
author | Marc Alexander <admin@m-a-styles.de> | 2015-09-23 10:17:38 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2015-10-09 10:18:31 +0200 |
commit | 04786313892df25f5adce555ebae6b2e5ad4d222 (patch) | |
tree | f02c037a6c853945f384c31169494236172ad4f6 /tests | |
parent | 8d03b9e001526fb237cdb744dd832c1dd4182d01 (diff) | |
download | forums-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')
-rw-r--r-- | tests/attachment/delete_test.php | 55 | ||||
-rw-r--r-- | tests/attachment/fixtures/resync.xml | 15 | ||||
-rw-r--r-- | tests/content_visibility/delete_post_test.php | 2 | ||||
-rw-r--r-- | tests/functions_user/delete_user_test.php | 4 | ||||
-rw-r--r-- | tests/privmsgs/delete_user_pms_test.php | 4 |
5 files changed, 72 insertions, 8 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"> diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index bb609b6ab7..c383ebfa2f 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -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(); diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index b877164629..f28c7286e3 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -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() diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index 7345721d8b..1da4b76f9f 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -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); |