Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
85 / 85
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_notification_group_request_test
100.00% covered (success)
100.00%
85 / 85
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_notification_types
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 test_notifications
100.00% covered (success)
100.00%
77 / 77
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
14require_once __DIR__ . '/base.php';
15
16class phpbb_notification_group_request_test extends phpbb_tests_notification_base
17{
18    public function getDataSet()
19    {
20        return $this->createXMLDataSet(__DIR__ . '/fixtures/group_request.xml');
21    }
22
23    protected function get_notification_types()
24    {
25        return array_merge(
26            parent::get_notification_types(),
27            array(
28                'notification.type.group_request',
29                'notification.type.group_request_approved',
30            )
31        );
32    }
33
34    public function test_notifications()
35    {
36        global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log;
37
38        include_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
39        include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
40        include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx);
41
42        $this->container->set('groupposition.legend', new \phpbb\groupposition\legend(
43            $this->db
44        ));
45        $this->container->set('groupposition.teampage', new \phpbb\groupposition\teampage(
46            $this->db,
47            $this->cache->get_driver()
48        ));
49        $this->container->set('group_helper', new \phpbb\group\helper(
50            $this->getMockBuilder('\phpbb\auth\auth')->disableOriginalConstructor()->getMock(),
51            $this->getMockBuilder('\phpbb\avatar\helper')->disableOriginalConstructor()->getMock(),
52            $this->db,
53            $this->cache,
54            $this->config,
55            new \phpbb\language\language(
56                new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
57            ),
58            new phpbb_mock_event_dispatcher(),
59            new \phpbb\path_helper(
60                new \phpbb\symfony_request(
61                    new phpbb_mock_request()
62                ),
63                $this->getMockBuilder('\phpbb\request\request')->disableOriginalConstructor()->getMock(),
64                $phpbb_root_path,
65                $phpEx
66            ),
67            $this->getMockBuilder('\phpbb\template\template')->disableOriginalConstructor()->getMock(),
68            $this->user
69        ));
70        $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
71        $phpbb_log = new \phpbb\log\dummy();
72        $this->get_test_case_helpers()->set_s9e_services();
73
74        // Now on to the actual test
75
76        $group_id = false;
77        group_create($group_id, GROUP_OPEN, 'test', 'test group', array());
78
79        // Add user 2 as group leader
80        group_user_add($group_id, 2, false, false, false, true, false);
81
82        // Add user 3 as pending
83        group_user_add($group_id, 3, false, false, false, false, true);
84
85        $this->assert_notifications(
86            array(
87                // user 3 pending notification
88                array(
89                    'item_id'                => 3, // user_id of requesting join
90                    'item_parent_id'        => $group_id,
91                    'user_id'                   => 2,
92                    'notification_read'        => 0,
93                    'notification_data'           => array(
94                        'group_name'            => 'test',
95                    ),
96                ),
97            ),
98            array(
99                'user_id'        => 2,
100            )
101        );
102
103        // Approve user 3 joining the group
104        group_user_attributes('approve', $group_id, array(3));
105
106        // user 3 pending notification should have been deleted
107        $this->assert_notifications(
108            array(),
109            array(
110                'user_id'        => 2,
111            )
112        );
113
114        $this->assert_notifications(
115            array(
116                // user 3 approved notification
117                array(
118                    'item_id'                => $group_id, // user_id of requesting join
119                    'user_id'                   => 3,
120                    'notification_read'        => 0,
121                    'notification_data'           => array(
122                        'group_name'            => 'test',
123                    ),
124                ),
125            ),
126            array(
127                'user_id'        => 3,
128            )
129        );
130    }
131}