Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
74 / 74 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_notification_convert_test | |
100.00% |
74 / 74 |
|
100.00% |
4 / 4 |
10 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
2 | |||
| test_convert | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
| create_expected | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
6 | |||
| 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 | require_once __DIR__ . '/../mock/sql_insert_buffer.php'; |
| 14 | |
| 15 | class phpbb_notification_convert_test extends phpbb_database_test_case |
| 16 | { |
| 17 | protected $db; |
| 18 | protected $doctrine_db; |
| 19 | protected $migration; |
| 20 | |
| 21 | public function getDataSet() |
| 22 | { |
| 23 | return $this->createXMLDataSet(__DIR__ . '/fixtures/convert.xml'); |
| 24 | } |
| 25 | |
| 26 | protected function setUp(): void |
| 27 | { |
| 28 | parent::setUp(); |
| 29 | |
| 30 | global $phpbb_root_path, $phpEx; |
| 31 | |
| 32 | $this->db = $this->new_dbal(); |
| 33 | $this->doctrine_db = $this->new_doctrine_dbal(); |
| 34 | $factory = new \phpbb\db\tools\factory(); |
| 35 | $db_tools = $factory->get($this->doctrine_db); |
| 36 | $core_tables = self::get_core_tables(); |
| 37 | |
| 38 | // Add user_notify_type column for testing this migration and set type |
| 39 | $db_tools->sql_column_add($core_tables['users'], 'user_notify_type', ['TINT:4', 0]); |
| 40 | $user_notify_type_map = [ |
| 41 | 1 => 0, |
| 42 | 2 => 0, |
| 43 | 3 => 1, |
| 44 | 4 => 1, |
| 45 | 5 => 2, |
| 46 | 6 => 2, |
| 47 | ]; |
| 48 | |
| 49 | foreach ($user_notify_type_map as $user_id => $notify_type) |
| 50 | { |
| 51 | $this->db->sql_query('UPDATE ' . $core_tables['users'] . ' SET user_notify_type = ' . (int) $notify_type . ' WHERE user_id = ' . (int) $user_id); |
| 52 | } |
| 53 | |
| 54 | $this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert( |
| 55 | new \phpbb\config\config(array()), |
| 56 | $this->db, |
| 57 | $db_tools, |
| 58 | $phpbb_root_path, |
| 59 | $phpEx, |
| 60 | 'phpbb_', |
| 61 | $core_tables |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | public function test_convert() |
| 66 | { |
| 67 | $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); |
| 68 | $this->migration->perform_conversion($buffer, 0); |
| 69 | |
| 70 | $expected = array_merge( |
| 71 | $this->create_expected('post', 1, 'email'), |
| 72 | $this->create_expected('topic', 1, 'email'), |
| 73 | |
| 74 | $this->create_expected('post', 2, 'email'), |
| 75 | $this->create_expected('topic', 2, 'email'), |
| 76 | $this->create_expected('pm', 2, 'email'), |
| 77 | |
| 78 | $this->create_expected('post', 3, 'jabber'), |
| 79 | $this->create_expected('topic', 3, 'jabber'), |
| 80 | |
| 81 | $this->create_expected('post', 4, 'jabber'), |
| 82 | $this->create_expected('topic', 4, 'jabber'), |
| 83 | $this->create_expected('pm', 4, 'jabber'), |
| 84 | |
| 85 | $this->create_expected('post', 5, 'both'), |
| 86 | $this->create_expected('topic', 5, 'both'), |
| 87 | |
| 88 | $this->create_expected('post', 6, 'both'), |
| 89 | $this->create_expected('topic', 6, 'both'), |
| 90 | $this->create_expected('pm', 6, 'both') |
| 91 | ); |
| 92 | |
| 93 | $this->assertEquals($expected, $buffer->get_buffer()); |
| 94 | } |
| 95 | |
| 96 | protected function create_expected($type, $user_id, $method = '') |
| 97 | { |
| 98 | $return = array(); |
| 99 | |
| 100 | if ($method !== '') |
| 101 | { |
| 102 | $return[] = array( |
| 103 | 'item_type' => $type, |
| 104 | 'item_id' => 0, |
| 105 | 'user_id' => $user_id, |
| 106 | 'method' => '', |
| 107 | 'notify' => 1, |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | if ($method === 'email' || $method === 'both') |
| 112 | { |
| 113 | $return[] = array( |
| 114 | 'item_type' => $type, |
| 115 | 'item_id' => 0, |
| 116 | 'user_id' => $user_id, |
| 117 | 'method' => 'email', |
| 118 | 'notify' => 1, |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | if ($method === 'jabber' || $method === 'both') |
| 123 | { |
| 124 | $return[] = array( |
| 125 | 'item_type' => $type, |
| 126 | 'item_id' => 0, |
| 127 | 'user_id' => $user_id, |
| 128 | 'method' => 'jabber', |
| 129 | 'notify' => 1, |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | return $return; |
| 134 | } |
| 135 | } |