Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_group_helper_test_case
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 config_defaults
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 get_test_language_data_set
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 get_test_rank_data_set
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 setup_engine
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
1 / 1
1
 setUp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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_group_helper_test_case extends phpbb_test_case
15{
16    /** @var  \phpbb\group\helper */
17    protected $group_helper;
18
19    protected function config_defaults()
20    {
21        $defaults = array(
22            'ranks_path' => 'images/ranks'
23        );
24        return $defaults;
25    }
26
27    protected function get_test_language_data_set()
28    {
29        return array(
30            'G_BOTS'                    => 'Bots',
31            'G_NEW_GROUP'                => 'Some new group',
32            'G_not_uppercase'            => 'The key does not contain uppercase letters',
33            'G_GROUP_WITH_ÜMLAUTS'        => 'Should work',
34        );
35    }
36
37    protected function get_test_rank_data_set()
38    {
39        return array(
40            'special' => array(
41                1 => array(
42                    'rank_id'        => 1,
43                    'rank_title'    => 'Site admin',
44                    'rank_special'    => 1,
45                    'rank_image'    => 'siteadmin.png',
46                ),
47                2 => array(
48                    'rank_id'        => 2,
49                    'rank_title'    => 'Test member',
50                    'rank_special'    => 1,
51                    'rank_image'    => '',
52                )
53            )
54        );
55    }
56
57    protected function setup_engine(array $new_config = array())
58    {
59        global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
60
61        // Set up authentication data for testing
62        $auth = $this->getMockBuilder('\phpbb\auth\auth')->disableOriginalConstructor()->getMock();
63        $auth->expects($this->any())
64            ->method('acl_get')
65            ->with($this->stringContains('_'), $this->anything())
66            ->will($this->returnValueMap(array(
67                array('u_viewprofile', true),
68            )));
69
70        // Set up database connection for testing
71        $db = $this->getMockBuilder('\phpbb\db\driver\driver_interface')->getMock();
72
73        // Set up cache service
74        $cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock();
75        $cache_service->expects($this->any())
76            ->method('obtain_ranks')
77            ->will($this->returnValue($this->get_test_rank_data_set()));
78
79        // Set up configuration
80        $defaults = $this->config_defaults();
81        $config = new \phpbb\config\config(array_merge($defaults, $new_config));
82
83        // Set up language service
84        $lang = new \phpbb\language\language(
85            new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
86        );
87
88        // Set up language data for testing
89        $reflection_class = new ReflectionClass('\phpbb\language\language');
90
91        // Set default language files loaded flag to true
92        $loaded_flag = $reflection_class->getProperty('common_language_files_loaded');
93        $loaded_flag->setValue($lang, true);
94
95        // Set up test language data
96        $lang_array = $reflection_class->getProperty('lang');
97        $lang_array->setValue($lang, $this->get_test_language_data_set());
98
99        // Set up event dispatcher
100        $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
101
102        // Set up path helper
103        $path_helper = $this->getMockBuilder('\phpbb\path_helper')
104            ->disableOriginalConstructor()
105            ->onlyMethods(['get_phpbb_root_path', 'get_php_ext', 'update_web_root_path'])
106            ->getMock();
107        $path_helper->method('get_phpbb_root_path')
108            ->willReturn($phpbb_root_path);
109        $path_helper->method('get_php_ext')
110            ->willReturn($phpEx);
111        $path_helper->method('update_web_root_path')
112            ->will($this->returnArgument(0));
113
114        $template = $this->getMockBuilder('\phpbb\template\template')->disableOriginalConstructor()->getMock();
115
116        $user = new \phpbb\user($lang, '\phpbb\datetime');
117        $user->data['user_id'] = ANONYMOUS;
118
119        $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper')
120            ->disableOriginalConstructor()
121            ->getMock();
122
123        $this->group_helper = new \phpbb\group\helper($auth, $avatar_helper, $db, $cache_service, $config, $lang, $phpbb_dispatcher, $path_helper, $template, $user);
124    }
125
126    protected function setUp(): void
127    {
128        $this->setup_engine();
129    }
130}