usersettingstest.php
4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* ownCloud - Activity App
*
* @author Joas Schilling
* @copyright 2014 Joas Schilling nickvergessen@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Activity\Tests;
use OCA\Activity\UserSettings;
use OCA\Activity\Data;
class UserSettingsTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$preferences = array(
array('test1', 'activity', 'notify_stream_type1', '1'),
array('test1', 'activity', 'notify_stream_type2', '2'),
array('test2', 'activity', 'notify_stream_type1', '0'),
array('test2', 'activity', 'notify_stream_type2', '0'),
array('test3', 'activity', 'notify_stream_type1', ''),
array('test4', 'activity', 'notify_stream_type1', '3'),
array('test6', 'activity', 'notify_stream_file_nodefault', '1'),
array('test6', 'activity', 'notify_stream_file_created', '1'),
array('test1', 'activity', 'notify_email_type1', '1'),
array('test1', 'activity', 'notify_email_type2', '2'),
array('test2', 'activity', 'notify_email_type1', '0'),
array('test2', 'activity', 'notify_email_type2', '0'),
array('test3', 'activity', 'notify_email_type1', ''),
array('test4', 'activity', 'notify_email_type1', '3'),
array('test5', 'activity', 'notify_email_type1', '1'),
array('test6', 'activity', 'notify_email_shared', '1'),
array('test6', 'activity', 'notify_email_file_created', '1'),
array('test1', 'activity', 'notify_setting_batchtime', '1'),
array('test2', 'activity', 'notify_setting_batchtime', '2'),
array('test3', 'activity', 'notify_setting_batchtime', '3'),
array('test4', 'activity', 'notify_setting_batchtime', '4'),
array('test6', 'activity', 'notify_setting_batchtime', '2700'),
);
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*preferences`(`userid`, `appid`, `configkey`, `configvalue`)' . ' VALUES(?, ?, ?, ?)');
foreach ($preferences as $preference) {
$query->execute($preference);
}
}
public function tearDown() {
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `appid` = ?');
$query->execute(array('activity'));
}
public function getDefaultSettingData() {
return array(
array('stream', Data::TYPE_SHARED, true),
array('stream', Data::TYPE_SHARE_CREATED, true),
array('email', Data::TYPE_SHARED, true),
array('email', Data::TYPE_SHARE_CREATED, false),
array('setting', 'batchtime', 3600),
);
}
/**
* @dataProvider getDefaultSettingData
*/
public function testGetDefaultSetting($method, $type, $expected) {
$this->assertEquals($expected, UserSettings::getDefaultSetting($method, $type));
}
public function getNotificationTypesData() {
return array(
array('test1', 'stream', array('shared', 'file_created', 'file_changed', 'file_deleted')),
array('noPreferences', 'email', array('shared')),
);
}
/**
* @dataProvider getNotificationTypesData
*/
public function testGetNotificationTypes($user, $method, $expected) {
$this->assertEquals($expected, UserSettings::getNotificationTypes($user, $method));
}
public function filterUsersBySettingData() {
return array(
array(array(), 'stream', 'type1', array()),
array(array('test', 'test1', 'test2', 'test3', 'test4'), 'stream', 'type1', array('test1' => true, 'test4' => true)),
array(array('test', 'test1', 'test2', 'test3', 'test4', 'test5'), 'email', 'type1', array('test1' => '1', 'test4' => '4', 'test5' => true)),
array(array('test', 'test6'), 'stream', 'file_created', array('test' => true, 'test6' => true)),
array(array('test', 'test6'), 'stream', 'file_nodefault', array('test6' => true)),
array(array('test6'), 'email', 'shared', array('test6' => '2700')),
array(array('test', 'test6'), 'email', 'shared', array('test' => '3600', 'test6' => '2700')),
array(array('test', 'test6'), 'email', 'file_created', array('test6' => '2700')),
);
}
/**
* @dataProvider filterUsersBySettingData
*/
public function testFilterUsersBySetting($users, $method, $type, $expected) {
$this->assertEquals($expected, UserSettings::filterUsersBySetting($users, $method, $type));
}
}