Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
17.24% covered (danger)
17.24%
20 / 116
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_content_visibility_get_global_visibility_sql_test
17.24% covered (danger)
17.24%
20 / 116
66.67% covered (warning)
66.67%
2 / 3
8.10
0.00% covered (danger)
0.00%
0 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_global_visibility_sql_data
0.00% covered (danger)
0.00%
0 / 96
0.00% covered (danger)
0.00%
0 / 1
2
 test_get_global_visibility_sql
100.00% covered (success)
100.00%
19 / 19
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_content_visibility_get_global_visibility_sql_test extends phpbb_database_test_case
15{
16    public function getDataSet()
17    {
18        return $this->createXMLDataSet(__DIR__ . '/fixtures/get_forums_visibility_sql.xml');
19    }
20
21    public static function get_global_visibility_sql_data()
22    {
23        return array(
24            array(
25                'phpbb_topics',
26                'topic', array(), '',
27                array(
28                    array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
29                ),
30                array(
31                    array('topic_id' => 1),
32                    array('topic_id' => 2),
33                    array('topic_id' => 3),
34                    array('topic_id' => 4),
35                    array('topic_id' => 5),
36                    array('topic_id' => 6),
37                    array('topic_id' => 7),
38                    array('topic_id' => 8),
39                    array('topic_id' => 9),
40                ),
41            ),
42            array(
43                'phpbb_topics',
44                'topic', array(3), '',
45                array(
46                    array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
47                ),
48                array(
49                    array('topic_id' => 1),
50                    array('topic_id' => 2),
51                    array('topic_id' => 3),
52                    array('topic_id' => 4),
53                    array('topic_id' => 5),
54                    array('topic_id' => 6),
55                ),
56            ),
57            array(
58                'phpbb_topics',
59                'topic', array(), '',
60                array(
61                    array('m_approve', true, array(2 => true)),
62                ),
63                array(
64                    array('topic_id' => 2),
65                    array('topic_id' => 4),
66                    array('topic_id' => 5),
67                    array('topic_id' => 6),
68                    array('topic_id' => 8),
69                ),
70            ),
71            array(
72                'phpbb_posts',
73                'post', array(), '',
74                array(
75                    array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
76                ),
77                array(
78                    array('post_id' => 1),
79                    array('post_id' => 2),
80                    array('post_id' => 3),
81                    array('post_id' => 4),
82                    array('post_id' => 5),
83                    array('post_id' => 6),
84                    array('post_id' => 7),
85                    array('post_id' => 8),
86                    array('post_id' => 9),
87                ),
88            ),
89            array(
90                'phpbb_posts',
91                'post', array(3), '',
92                array(
93                    array('m_approve', true, array(1 => true, 2 => true, 3 => true)),
94                ),
95                array(
96                    array('post_id' => 1),
97                    array('post_id' => 2),
98                    array('post_id' => 3),
99                    array('post_id' => 4),
100                    array('post_id' => 5),
101                    array('post_id' => 6),
102                ),
103            ),
104            array(
105                'phpbb_posts',
106                'post', array(), '',
107                array(
108                    array('m_approve', true, array(2 => true)),
109                ),
110                array(
111                    array('post_id' => 2),
112                    array('post_id' => 4),
113                    array('post_id' => 5),
114                    array('post_id' => 6),
115                    array('post_id' => 8),
116                ),
117            ),
118        );
119    }
120
121    /**
122    * @dataProvider get_global_visibility_sql_data
123    */
124    public function test_get_global_visibility_sql($table, $mode, $forum_ids, $table_alias, $permissions, $expected)
125    {
126        global $cache, $db, $auth, $phpbb_root_path, $phpEx;
127
128        $cache = new phpbb_mock_cache;
129        $db = $this->new_dbal();
130
131        // Create auth mock
132        $auth = $this->createMock('\phpbb\auth\auth');
133        $auth->expects($this->any())
134            ->method('acl_getf')
135            ->with($this->stringContains('_'), $this->anything())
136            ->will($this->returnValueMap($permissions));
137        $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
138        $lang = new \phpbb\language\language($lang_loader);
139        $user = new \phpbb\user($lang, '\phpbb\datetime');
140        $config = new phpbb\config\config(array());
141        $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
142        $content_visibility = new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE);
143
144        $result = $db->sql_query('SELECT ' . $mode . '_id
145            FROM ' . $table . '
146            WHERE ' . $content_visibility->get_global_visibility_sql($mode, $forum_ids, $table_alias) . '
147            ORDER BY ' . $mode . '_id ASC');
148
149        $this->assertEquals($expected, $db->sql_fetchrowset($result));
150    }
151}