Skip to content

Commit e234506

Browse files
committed
Add a test of sorts for the new permissions function
1 parent 944c878 commit e234506

2 files changed

Lines changed: 205 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for 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+
*/
10+
11+
namespace phpbb\ideas\tests\factory;
12+
13+
class permissions_helper_test extends \phpbb_database_test_case
14+
{
15+
protected static function setup_extensions()
16+
{
17+
return array('phpbb/ideas');
18+
}
19+
20+
/** @var \phpbb\auth\auth */
21+
protected $auth;
22+
23+
/** @var \phpbb\config\config */
24+
protected $config;
25+
26+
/** @var \phpbb\db\driver\driver_interface */
27+
protected $db;
28+
29+
public function getDataSet()
30+
{
31+
return $this->createXMLDataSet(__DIR__ . '/../fixtures/permissions.xml');
32+
}
33+
34+
public function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
global $cache, $db, $phpbb_dispatcher;
39+
40+
$cache = $this->createMock('\phpbb\cache\driver\driver_interface');
41+
$cache->method('get')->willReturn(false);
42+
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
43+
44+
$this->auth = new \phpbb\auth\auth;
45+
$this->config = new \phpbb\config\config(['ideas_forum_id' => 2]);
46+
$this->db = $db = $this->new_dbal();
47+
}
48+
49+
public function test_set_ideas_forum_permissions()
50+
{
51+
global $phpbb_root_path, $phpEx;
52+
53+
$permission_helper = new \phpbb\ideas\factory\permission_helper($this->config, $this->db, $phpbb_root_path, $phpEx);
54+
55+
$permission_helper->set_ideas_forum_permissions($this->config['ideas_forum_id']);
56+
57+
$sql = 'SELECT a.auth_setting, b.auth_option
58+
FROM phpbb_acl_groups a
59+
JOIN phpbb_acl_options b
60+
ON a.auth_option_id = b.auth_option_id
61+
WHERE forum_id = ' . $this->config['ideas_forum_id'];
62+
63+
$expected = [
64+
[
65+
'auth_setting' => ACL_YES,
66+
'auth_option' => 'f_post',
67+
],
68+
[
69+
'auth_setting' => ACL_NEVER,
70+
'auth_option' => 'f_announce',
71+
],
72+
[
73+
'auth_setting' => ACL_NEVER,
74+
'auth_option' => 'f_announce_global',
75+
],
76+
[
77+
'auth_setting' => ACL_NEVER,
78+
'auth_option' => 'f_sticky',
79+
],
80+
[
81+
'auth_setting' => ACL_NEVER,
82+
'auth_option' => 'f_poll',
83+
],
84+
[
85+
'auth_setting' => ACL_NEVER,
86+
'auth_option' => 'f_icons',
87+
],
88+
[
89+
'auth_setting' => ACL_NEVER,
90+
'auth_option' => 'f_user_lock',
91+
],
92+
];
93+
94+
$this->assertSqlResultEquals($expected, $sql);
95+
}
96+
}

tests/fixtures/permissions.xml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dataset>
3+
<table name="phpbb_forums">
4+
<column>forum_id</column>
5+
<column>forum_desc</column>
6+
<column>forum_parents</column>
7+
<column>forum_rules</column>
8+
<row>
9+
<value>1</value>
10+
<value></value>
11+
<value></value>
12+
<value></value>
13+
</row>
14+
<row>
15+
<value>2</value>
16+
<value></value>
17+
<value></value>
18+
<value></value>
19+
</row>
20+
</table>
21+
<table name="phpbb_groups">
22+
<column>group_id</column>
23+
<column>group_name</column>
24+
<column>group_desc</column>
25+
<row>
26+
<value>2</value>
27+
<value>REGISTERED</value>
28+
<value></value>
29+
</row>
30+
<row>
31+
<value>4</value>
32+
<value>GLOBAL_MODERATORS</value>
33+
<value></value>
34+
</row>
35+
<row>
36+
<value>5</value>
37+
<value>ADMINISTRATORS</value>
38+
<value></value>
39+
</row>
40+
</table>
41+
<table name="phpbb_acl_options">
42+
<column>auth_option_id</column>
43+
<column>auth_option</column>
44+
<column>is_global</column>
45+
<column>is_local</column>
46+
<column>founder_only</column>
47+
<row>
48+
<value>1</value>
49+
<value>f_post</value>
50+
<value>0</value>
51+
<value>1</value>
52+
<value>0</value>
53+
</row>
54+
<row>
55+
<value>2</value>
56+
<value>f_announce</value>
57+
<value>0</value>
58+
<value>1</value>
59+
<value>0</value>
60+
</row>
61+
<row>
62+
<value>3</value>
63+
<value>f_announce_global</value>
64+
<value>0</value>
65+
<value>1</value>
66+
<value>0</value>
67+
</row>
68+
<row>
69+
<value>4</value>
70+
<value>f_sticky</value>
71+
<value>0</value>
72+
<value>1</value>
73+
<value>0</value>
74+
</row>
75+
<row>
76+
<value>5</value>
77+
<value>f_poll</value>
78+
<value>0</value>
79+
<value>1</value>
80+
<value>0</value>
81+
</row>
82+
<row>
83+
<value>6</value>
84+
<value>f_icons</value>
85+
<value>0</value>
86+
<value>1</value>
87+
<value>0</value>
88+
</row>
89+
<row>
90+
<value>7</value>
91+
<value>f_user_lock</value>
92+
<value>0</value>
93+
<value>1</value>
94+
<value>0</value>
95+
</row>
96+
</table>
97+
<table name="phpbb_acl_groups">
98+
<column>auth_option_id</column>
99+
<column>group_id</column>
100+
<column>forum_id</column>
101+
<column>auth_setting</column>
102+
<row>
103+
<value>1</value>
104+
<value>2</value>
105+
<value>2</value>
106+
<value>0</value>
107+
</row>
108+
</table>
109+
</dataset>

0 commit comments

Comments
 (0)