forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_test.php
More file actions
120 lines (104 loc) · 3.25 KB
/
Copy pathdelete_test.php
File metadata and controls
120 lines (104 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
require_once(dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php');
class phpbb_attachment_delete_test extends \phpbb_database_test_case
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\event\dispatcher_interface */
protected $dispatcher;
/** @var \phpbb\attachment\resync */
protected $resync;
/** @var \phpbb\storage\storage */
protected $storage;
/** @var \phpbb\attachment\delete */
protected $attachment_delete;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml');
}
public function setUp(): void
{
parent::setUp();
$this->config = new \phpbb\config\config(array());
$this->db = $this->new_dbal();
$this->resync = new \phpbb\attachment\resync($this->db);
$this->storage = $this->createMock('\phpbb\storage\storage');
$this->storage->expects($this->any())
->method('exists')
->willReturn(true);
$this->dispatcher = new \phpbb_mock_event_dispatcher();
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
}
public function data_attachment_delete()
{
return array(
array('attach', '', false, false),
array('meh', 5, false, 0),
array('attach', array(5), false, 0),
array('attach', array(1,2), false, 2),
array('attach', array(1,2), true, 2),
array('post', 5, false, 0),
array('topic', 5, false, 0),
array('topic', 1, true, 3),
array('user', 1, false, 0),
);
}
/**
* @dataProvider data_attachment_delete
*/
public function test_attachment_delete($mode, $ids, $resync, $expected)
{
// We need to reset the attachment ID sequence to properly test this
if ($this->db->get_sql_layer() === 'postgres')
{
$sql = 'ALTER SEQUENCE phpbb_attachments_seq RESTART WITH 1';
$this->db->sql_query($sql);
}
$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->storage = $this->createMock('\phpbb\storage\storage', array('delete', 'exists'));
if ($throw_exception)
{
$this->storage->expects($this->any())
->method('delete')
->willThrowException(new \phpbb\storage\exception\exception);
}
else
{
$this->storage->expects($this->any())
->method('delete')
->willReturn($remove_success);
}
$this->storage->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'));
}
}