Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
68.18% covered (warning)
68.18%
30 / 44
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_migrator_convert_timezones_test
68.18% covered (warning)
68.18%
30 / 44
60.00% covered (warning)
60.00%
3 / 5
7.16
0.00% covered (danger)
0.00%
0 / 1
 getDataSet
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 revert_schema
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 update_schema
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 setUp
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 test_convert
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
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
14class phpbb_migrator_convert_timezones_test extends phpbb_database_test_case
15{
16    protected $db;
17    protected $db_doctrine;
18    protected $migration;
19
20    public function getDataSet()
21    {
22        $this->db = $this->new_dbal();
23        $this->db_doctrine = $this->new_doctrine_dbal();
24        $factory = new \phpbb\db\tools\factory();
25        $db_tools = $factory->get($this->db_doctrine);
26
27        // user_dst doesn't exist anymore, must re-add it to test this
28        $db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1));
29
30        return $this->createXMLDataSet(__DIR__ . '/fixtures/convert_timezones.xml');
31    }
32
33    public function revert_schema()
34    {
35        return array(
36            'drop_columns'    => array(
37                $this->table_prefix . 'users'            => array(
38                    'user_dst',
39                ),
40            ),
41        );
42    }
43
44    public function update_schema()
45    {
46        return array(
47            'add_columns'    => array(
48                $this->table_prefix . 'users'            => array(
49                    'user_dst'        => array('BOOL', 0),
50                ),
51            ),
52        );
53    }
54
55    protected function setUp(): void
56    {
57        parent::setUp();
58
59        global $phpbb_root_path, $phpEx;
60
61        $this->db = $this->new_dbal();
62        $this->db_doctrine = $this->new_doctrine_dbal();
63        $factory = new \phpbb\db\tools\factory();
64
65        $this->migration = new \phpbb\db\migration\data\v310\timezone(
66            new \phpbb\config\config(array()),
67            $this->db,
68            $factory->get($this->db_doctrine),
69            $phpbb_root_path,
70            $phpEx,
71            'phpbb_',
72            self::get_core_tables()
73        );
74    }
75
76    protected $expected_results = array(
77        //user_id => user_timezone
78        1 => 'Etc/GMT+12',
79        2 => 'Etc/GMT+11',
80        3 => 'Etc/GMT-3',
81        4 => 'Etc/GMT-4',
82        5 => 'America/St_Johns',
83        6 => 'Australia/Eucla',
84    );
85
86    public function test_convert()
87    {
88        $this->migration->update_timezones(0);
89
90        $sql = 'SELECT user_id, user_timezone
91            FROM phpbb_users
92            ORDER BY user_id ASC';
93        $result = $this->db->sql_query($sql);
94        while ($row = $this->db->sql_fetchrow($result))
95        {
96            $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']);
97        }
98        $this->db->sql_freeresult($result);
99
100        $factory = new \phpbb\db\tools\factory();
101        $db_tools = $factory->get($this->db_doctrine);
102
103        // Remove the user_dst field again
104        $db_tools->sql_column_remove('phpbb_users', 'user_dst');
105    }
106}