1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-03-25 01:51:21 +01:00

[ticket/15286] Fix tests

PHPBB3-15286
This commit is contained in:
Rubén Calvo 2017-08-09 14:22:03 +02:00
parent ef43dbdcca
commit a176fa56ef
4 changed files with 25 additions and 35 deletions

View File

@ -71,11 +71,12 @@ class delete
* @param resync $resync
* @param storage $storage
*/
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, $storage)
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, storage $storage)
{
$this->config = $config;
$this->db = $db;
$this->dispatcher = $dispatcher;
$this->resync = $resync;
$this->storage = $storage;
}
@ -411,7 +412,7 @@ class delete
{
if ($this->storage->exists($filename))
{
$this->storage->remove($filename);
$this->storage->delete($filename);
return true;
}
}

View File

@ -27,6 +27,9 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
/** @var \phpbb\attachment\resync */
protected $resync;
/** @var \phpbb\storage\storage */
protected $storage;
/** @var \phpbb\attachment\delete */
protected $attachment_delete;
@ -52,15 +55,13 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
$this->filesystem->expects($this->any())
->method('exists')
->willReturn(true);
$local_adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
$local_adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->getMockBuilder('\phpbb\storage\adapter_factory')
->disableOriginalConstructor()
->getMock();
$adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($local_adapter);
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, 'attachment');
->willReturn($adapter);
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, '');
$this->dispatcher = new \phpbb_mock_event_dispatcher();
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
}
@ -109,24 +110,6 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
*/
public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false)
{
$this->filesystem = $this->createMock('\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->dispatcher, $this->resync, $this->storage);
$this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar'));
}

View File

@ -99,15 +99,13 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
$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);
$local_adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
$local_adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->getMockBuilder('\phpbb\storage\adapter_factory')
->disableOriginalConstructor()
->getMock();
$adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($local_adapter);
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, 'attachment');
->willReturn($adapter);
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, '');
$factory_mock = $this->getMockBuilder('\phpbb\files\factory')
->disableOriginalConstructor()

View File

@ -298,6 +298,14 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
$db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($adapter);
$storage = new \phpbb\storage\storage($adapter_factory_mock, '');
// Create auth mock
$auth = $this->createMock('\phpbb\auth\auth');
$auth->expects($this->any())
@ -309,7 +317,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_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path);
$attachment_delete = new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage);
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();