|
| 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 | +} |
0 commit comments