Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
68.97% |
20 / 29 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_attachment_resync_test | |
68.97% |
20 / 29 |
|
75.00% |
3 / 4 |
5.75 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| data_resync | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| test_resync | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_attachment_resync_test extends \phpbb_database_test_case |
| 15 | { |
| 16 | /** @var \phpbb\db\driver\driver_interface */ |
| 17 | protected $db; |
| 18 | |
| 19 | /** @var \phpbb\attachment\resync */ |
| 20 | protected $resync; |
| 21 | |
| 22 | public function getDataSet() |
| 23 | { |
| 24 | return $this->createXMLDataSet(__DIR__ . '/fixtures/resync.xml'); |
| 25 | } |
| 26 | |
| 27 | protected function setUp(): void |
| 28 | { |
| 29 | parent::setUp(); |
| 30 | |
| 31 | $this->db = $this->new_dbal(); |
| 32 | $this->resync = new \phpbb\attachment\resync($this->db); |
| 33 | } |
| 34 | |
| 35 | public static function data_resync() |
| 36 | { |
| 37 | return array( |
| 38 | array('', array(1), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '1')), |
| 39 | array('post', array(1), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '1')), |
| 40 | array('post', array(2), 'post_id', POSTS_TABLE, array('post_attachment' => '1'), array('post_attachment' => '0')), |
| 41 | array('topic', array(1), 'topic_id', TOPICS_TABLE, array('topic_attachment' => '1'), array('topic_attachment' => '1')), |
| 42 | array('topic', array(2), 'topic_id', TOPICS_TABLE, array('topic_attachment' => '1'), array('topic_attachment' => '0')), |
| 43 | array('message', array(1), 'msg_id', PRIVMSGS_TABLE, array('message_attachment' => '1'), array('message_attachment' => '1')), |
| 44 | array('message', array(2), 'msg_id', PRIVMSGS_TABLE, array('message_attachment' => '1'), array('message_attachment' => '0')), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @dataProvider data_resync |
| 50 | */ |
| 51 | public function test_resync($type, $ids, $sql_id, $exist_table, $exist_data, $resync_data) |
| 52 | { |
| 53 | $sql_prefix = ($type) ?: 'post'; |
| 54 | $sql = 'SELECT ' . $sql_prefix . '_attachment |
| 55 | FROM ' . $exist_table . ' |
| 56 | WHERE ' . $sql_id . ' = ' . $ids[0]; |
| 57 | $result = $this->db->sql_query($sql); |
| 58 | $data = $this->db->sql_fetchrow($result); |
| 59 | $this->db->sql_freeresult($result); |
| 60 | |
| 61 | $this->assertEquals($exist_data, $data); |
| 62 | |
| 63 | $this->resync->resync($type, $ids); |
| 64 | |
| 65 | $sql = 'SELECT ' . $sql_prefix . '_attachment |
| 66 | FROM ' . $exist_table . ' |
| 67 | WHERE ' . $sql_id . ' = ' . $ids[0]; |
| 68 | $result = $this->db->sql_query($sql); |
| 69 | $data = $this->db->sql_fetchrow($result); |
| 70 | $this->db->sql_freeresult($result); |
| 71 | |
| 72 | $this->assertEquals($resync_data, $data); |
| 73 | } |
| 74 | } |