Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functional_notification_test
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 user_subscription_data
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_user_subscriptions
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 test_mark_notifications_read
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
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
14/**
15* @group functional
16*/
17class phpbb_functional_notification_test extends phpbb_functional_test_case
18{
19    public static function user_subscription_data()
20    {
21        return array(
22            // Rows inserted by phpBB/install/schemas/schema_data.sql
23            // Also see PHPBB3-11460
24            array('notification.type.post_notification.method.board', true),
25            array('notification.type.topic_notification.method.board', true),
26            array('notification.type.post_notification.method.email', true),
27            array('notification.type.topic_notification.method.email', true),
28
29            // Default behaviour for in-board notifications:
30            // If user did not opt-out, in-board notifications are on.
31            array('notification.type.bookmark_notification.method.board', true),
32            array('notification.type.quote_notification.method.board', true),
33
34            // Default behaviour for email notifications:
35            // If user did not opt-in, email notifications are off.
36            array('notification.type.bookmark_notification.method.email', false),
37            array('notification.type.quote_notification.method.email', false),
38        );
39    }
40
41    /**
42    * @dataProvider user_subscription_data
43    */
44    public function test_user_subscriptions($checkbox_name, $expected_status)
45    {
46        $this->login();
47        $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
48
49        $cplist = $crawler->filter('.table1');
50        if ($expected_status)
51        {
52            $this->assert_checkbox_is_checked($cplist, $checkbox_name);
53        }
54        else
55        {
56            $this->assert_checkbox_is_unchecked($cplist, $checkbox_name);
57        }
58    }
59
60    public function test_mark_notifications_read()
61    {
62        // Create a new standard user
63        $this->create_user('notificationtestuser');
64        $this->add_user_group('NEWLY_REGISTERED', array('notificationtestuser'));
65        $this->login('notificationtestuser');
66
67        // Post a new post that needs approval
68        $this->create_post(2, 1, 'Re: Welcome to phpBB', 'This is a test [b]post[/b] posted by notificationtestuser.', array(), 'POST_STORED_MOD');
69        $crawler = self::request('GET', "viewtopic.php?t=1&sid={$this->sid}");
70        $this->assertStringNotContainsString('This is a test post posted by notificationtestuser.', $crawler->filter('html')->text());
71
72        // Login as admin
73        $this->logout();
74        $this->login();
75        $this->add_lang('ucp');
76
77        $crawler = self::request('GET', 'ucp.php?i=ucp_notifications');
78
79        // At least one notification should exist
80        $this->assertGreaterThan(0, $crawler->filter('#notification-button strong')->text());
81
82        // Get form token
83        $link = $crawler->selectLink($this->lang('NOTIFICATIONS_MARK_ALL_READ'))->link()->getUri();
84        $crawler = self::request('GET', substr($link, strpos($link, 'ucp.')));
85        $this->assertCount(1, $crawler->filter('#notification-button strong.badge.hidden'));
86        $this->assertEquals("0", $crawler->filter('#notification-button strong.badge.hidden')->text());
87    }
88}