Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
30.43% covered (danger)
30.43%
7 / 23
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationAlertComponent
30.43% covered (danger)
30.43%
7 / 23
0.00% covered (danger)
0.00%
0 / 1
23.50
0.00% covered (danger)
0.00%
0 / 1
 __construct
30.43% covered (danger)
30.43%
7 / 23
0.00% covered (danger)
0.00%
0 / 1
23.50
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * @file
18 */
19namespace MediaWiki\Skin\WikimediaApiPortal\Component;
20
21use MediaWiki\Registration\ExtensionRegistry;
22use MediaWiki\User\User;
23use OOUI\ButtonWidget;
24
25class NotificationAlertComponent extends Component {
26    /**
27     * @param ExtensionRegistry $extensionRegistry
28     * @param User $user
29     * @param array $notificationAlert
30     */
31    public function __construct(
32        ExtensionRegistry $extensionRegistry,
33        User $user,
34        array $notificationAlert
35    ) {
36        parent::__construct( 'NotificationAlert' );
37
38        if ( !isset( $notificationAlert['data']['counter-num'] ) ||
39            !isset( $notificationAlert['data']['counter-text'] ) ||
40            !isset( $notificationAlert['href'] ) ||
41            !isset( $notificationAlert['text'] )
42        ) {
43            $this->args = null;
44            return;
45        }
46
47        if ( !$user->isRegistered() ) {
48            $this->args = null;
49            return;
50        }
51
52        // Support: Echo extension
53        if ( !$extensionRegistry->isLoaded( 'Echo' ) ) {
54            $this->args = null;
55            return;
56        }
57
58        $this->args = [
59            'hasCount' => $notificationAlert['data']['counter-num'] > 0,
60            'count' => $notificationAlert['data']['counter-text'],
61            'notificationButton' => new ButtonWidget( [
62                'icon' => 'bellOutline',
63                'title' => $notificationAlert['text'],
64                'framed' => false,
65                'href' => $notificationAlert['href']
66            ] )
67        ];
68    }
69}