Skip to content

Commit a176fa5

Browse files
committed
[ticket/15286] Fix tests
PHPBB3-15286
1 parent ef43dbd commit a176fa5

4 files changed

Lines changed: 25 additions & 35 deletions

File tree

phpBB/phpbb/attachment/delete.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ class delete
7171
* @param resync $resync
7272
* @param storage $storage
7373
*/
74-
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, $storage)
74+
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, storage $storage)
7575
{
7676
$this->config = $config;
7777
$this->db = $db;
7878
$this->dispatcher = $dispatcher;
79+
$this->resync = $resync;
7980
$this->storage = $storage;
8081
}
8182

@@ -411,7 +412,7 @@ public function unlink_attachment($filename, $mode = 'file', $entry_removed = fa
411412
{
412413
if ($this->storage->exists($filename))
413414
{
414-
$this->storage->remove($filename);
415+
$this->storage->delete($filename);
415416
return true;
416417
}
417418
}

tests/attachment/delete_test.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
2727
/** @var \phpbb\attachment\resync */
2828
protected $resync;
2929

30+
/** @var \phpbb\storage\storage */
31+
protected $storage;
32+
3033
/** @var \phpbb\attachment\delete */
3134
protected $attachment_delete;
3235

@@ -52,15 +55,13 @@ public function setUp()
5255
$this->filesystem->expects($this->any())
5356
->method('exists')
5457
->willReturn(true);
55-
$local_adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
56-
$local_adapter->configure(['path' => 'files']);
57-
$adapter_factory_mock = $this->getMockBuilder('\phpbb\storage\adapter_factory')
58-
->disableOriginalConstructor()
59-
->getMock();
58+
$adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
59+
$adapter->configure(['path' => 'files']);
60+
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
6061
$adapter_factory_mock->expects($this->any())
6162
->method('get')
62-
->willReturn($local_adapter);
63-
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, 'attachment');
63+
->willReturn($adapter);
64+
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, '');
6465
$this->dispatcher = new \phpbb_mock_event_dispatcher();
6566
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
6667
}
@@ -109,24 +110,6 @@ public function data_attachment_unlink()
109110
*/
110111
public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false)
111112
{
112-
$this->filesystem = $this->createMock('\phpbb\filesystem\filesystem', array('remove', 'exists'));
113-
if ($throw_exception)
114-
{
115-
$this->filesystem->expects($this->any())
116-
->method('remove')
117-
->willThrowException(new \phpbb\filesystem\exception\filesystem_exception);;
118-
}
119-
else
120-
{
121-
$this->filesystem->expects($this->any())
122-
->method('remove')
123-
->willReturn($remove_success);
124-
}
125-
126-
$this->filesystem->expects($this->any())
127-
->method('exists')
128-
->willReturn($exists_success);
129-
130113
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
131114
$this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar'));
132115
}

tests/attachment/upload_test.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ public function setUp()
9999
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
100100
$this->plupload = new \phpbb\plupload\plupload($phpbb_root_path, $this->config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), $this->php_ini, $this->mimetype_guesser);
101101

102-
$local_adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
103-
$local_adapter->configure(['path' => 'files']);
104-
$adapter_factory_mock = $this->getMockBuilder('\phpbb\storage\adapter_factory')
105-
->disableOriginalConstructor()
106-
->getMock();
102+
$adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
103+
$adapter->configure(['path' => 'files']);
104+
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
107105
$adapter_factory_mock->expects($this->any())
108106
->method('get')
109-
->willReturn($local_adapter);
110-
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, 'attachment');
107+
->willReturn($adapter);
108+
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, '');
111109

112110
$factory_mock = $this->getMockBuilder('\phpbb\files\factory')
113111
->disableOriginalConstructor()

tests/content_visibility/delete_post_test.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft
298298
$db = $this->new_dbal();
299299
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
300300

301+
$adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
302+
$adapter->configure(['path' => 'files']);
303+
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
304+
$adapter_factory_mock->expects($this->any())
305+
->method('get')
306+
->willReturn($adapter);
307+
$storage = new \phpbb\storage\storage($adapter_factory_mock, '');
308+
301309
// Create auth mock
302310
$auth = $this->createMock('\phpbb\auth\auth');
303311
$auth->expects($this->any())
@@ -309,7 +317,7 @@ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft
309317
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
310318
$lang = new \phpbb\language\language($lang_loader);
311319
$user = new \phpbb\user($lang, '\phpbb\datetime');
312-
$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path);
320+
$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage);
313321

314322
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
315323

0 commit comments

Comments
 (0)