2014-05-23 20:41:36 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-02-12 11:14:27 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-07-22 13:37:41 +03:00
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* @license AGPL-3.0
|
2014-05-23 20:41:36 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-05-23 20:41:36 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-05-23 20:41:36 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-02-12 11:14:27 +03:00
|
|
|
* 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-05-23 20:41:36 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Activity\Tests;
|
|
|
|
|
2014-06-04 18:25:51 +04:00
|
|
|
use OCA\Activity\Data;
|
2015-02-16 19:05:26 +03:00
|
|
|
use OCA\Activity\Tests\Mock\Extension;
|
2015-01-16 10:52:52 +03:00
|
|
|
use OCA\Activity\UserSettings;
|
2014-05-23 20:41:36 +04:00
|
|
|
|
2014-12-09 18:02:11 +03:00
|
|
|
class UserSettingsTest extends TestCase {
|
|
|
|
/** @var UserSettings */
|
|
|
|
protected $userSettings;
|
|
|
|
|
2014-12-17 15:35:36 +03:00
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $config;
|
|
|
|
|
2014-11-11 02:03:47 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2015-01-16 10:52:52 +03:00
|
|
|
$activityLanguage = \OCP\Util::getL10N('activity', 'en');
|
2016-05-02 13:01:24 +03:00
|
|
|
$activityManager = new \OC\Activity\Manager(
|
2015-03-25 18:32:14 +03:00
|
|
|
$this->getMock('OCP\IRequest'),
|
|
|
|
$this->getMock('OCP\IUserSession'),
|
|
|
|
$this->getMock('OCP\IConfig')
|
|
|
|
);
|
2015-01-16 10:52:52 +03:00
|
|
|
$activityManager->registerExtension(function() use ($activityLanguage) {
|
2015-02-16 19:05:26 +03:00
|
|
|
return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator'));
|
2015-02-05 17:09:21 +03:00
|
|
|
});
|
2014-12-17 15:35:36 +03:00
|
|
|
$this->config = $this->getMock('OCP\IConfig');
|
2015-08-14 13:32:49 +03:00
|
|
|
$this->userSettings = new UserSettings($activityManager, $this->config, new Data(
|
|
|
|
$activityManager,
|
|
|
|
$this->getMock('\OCP\IDBConnection'),
|
|
|
|
$this->getMock('\OCP\IUserSession')
|
|
|
|
));
|
2014-05-23 20:41:36 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 18:25:51 +04:00
|
|
|
public function getDefaultSettingData() {
|
2014-05-23 20:41:36 +04:00
|
|
|
return array(
|
2015-02-16 19:05:26 +03:00
|
|
|
array('stream', 'type1', true),
|
|
|
|
array('email', 'type1', false),
|
2014-12-12 19:18:57 +03:00
|
|
|
array('setting', 'self', true),
|
|
|
|
array('setting', 'selfemail', false),
|
2014-06-04 18:25:51 +04:00
|
|
|
array('setting', 'batchtime', 3600),
|
2014-12-12 19:18:57 +03:00
|
|
|
array('setting', 'not-exists', false),
|
2014-05-23 20:41:36 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-04 18:25:51 +04:00
|
|
|
* @dataProvider getDefaultSettingData
|
2014-12-17 15:35:36 +03:00
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $type
|
|
|
|
* @param mixed $expected
|
2014-05-23 20:41:36 +04:00
|
|
|
*/
|
2014-06-04 18:25:51 +04:00
|
|
|
public function testGetDefaultSetting($method, $type, $expected) {
|
2014-12-09 18:02:11 +03:00
|
|
|
$this->assertEquals($expected, $this->userSettings->getDefaultSetting($method, $type));
|
2014-05-23 20:41:36 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 18:25:51 +04:00
|
|
|
public function getNotificationTypesData() {
|
|
|
|
return array(
|
2015-07-22 09:26:05 +03:00
|
|
|
//array('test1', 'stream', array('type1')),
|
2015-02-16 19:05:26 +03:00
|
|
|
array('noPreferences', 'email', array('type2')),
|
2014-06-04 18:25:51 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getNotificationTypesData
|
2014-12-17 15:35:36 +03:00
|
|
|
*
|
|
|
|
* @param string $user
|
|
|
|
* @param string $method
|
|
|
|
* @param array $expected
|
2014-06-04 18:25:51 +04:00
|
|
|
*/
|
|
|
|
public function testGetNotificationTypes($user, $method, $expected) {
|
2014-12-17 15:35:36 +03:00
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->anything(), 'activity', $this->stringStartsWith('notify_'), $this->anything())
|
|
|
|
->willReturnMap([
|
2016-04-04 16:59:25 +03:00
|
|
|
['test1', 'activity', 'notify_stream_type1', true, 1],
|
|
|
|
['test1', 'activity', 'notify_stream_type2', true, 0],
|
|
|
|
['noPreferences', 'activity', 'notify_email_type1', false, 0],
|
|
|
|
['noPreferences', 'activity', 'notify_email_type2', true, 1],
|
2014-12-17 15:35:36 +03:00
|
|
|
]);
|
|
|
|
|
2014-12-09 18:02:11 +03:00
|
|
|
$this->assertEquals($expected, $this->userSettings->getNotificationTypes($user, $method));
|
2014-06-04 18:25:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function filterUsersBySettingData() {
|
|
|
|
return array(
|
|
|
|
array(array(), 'stream', 'type1', array()),
|
2016-04-04 16:59:25 +03:00
|
|
|
array(array('test', 'test1', 'test2', 'test3', 'test4'), 'stream', 'type3', array('test1' => 1, 'test4' => 1)),
|
|
|
|
array(array('test', 'test1', 'test2', 'test3', 'test4', 'test5'), 'email', 'type3', array('test1' => '1', 'test4' => '4', 'test5' => 1)),
|
|
|
|
array(array('test', 'test6'), 'stream', 'type1', array('test' => 1, 'test6' => 1)),
|
|
|
|
array(array('test', 'test6'), 'stream', 'type4', array('test6' => 1)),
|
2015-02-16 19:05:26 +03:00
|
|
|
array(array('test6'), 'email', 'type2', array('test6' => '2700')),
|
|
|
|
array(array('test', 'test6'), 'email', 'type2', array('test' => '3600', 'test6' => '2700')),
|
|
|
|
array(array('test', 'test6'), 'email', 'type1', array('test6' => '2700')),
|
2014-06-04 18:25:51 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider filterUsersBySettingData
|
2014-12-17 15:35:36 +03:00
|
|
|
*
|
|
|
|
* @param array $users
|
|
|
|
* @param string $method
|
|
|
|
* @param string $type
|
|
|
|
* @param array $expected
|
2014-06-04 18:25:51 +04:00
|
|
|
*/
|
|
|
|
public function testFilterUsersBySetting($users, $method, $type, $expected) {
|
2014-12-17 15:35:36 +03:00
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getUserValueForUsers')
|
|
|
|
->with($this->anything(), $this->anything(), $this->anything())
|
|
|
|
->willReturnMap([
|
2015-02-16 19:05:26 +03:00
|
|
|
['activity', 'notify_stream_type1', ['test', 'test6'], ['test6' => '1']],
|
|
|
|
['activity', 'notify_stream_type4', ['test', 'test6'], ['test6' => '1']],
|
|
|
|
['activity', 'notify_stream_type3', ['test', 'test1', 'test2', 'test3', 'test4'], ['test1' => '1', 'test2' => '0', 'test3' => '', 'test4' => '1']],
|
|
|
|
|
|
|
|
['activity', 'notify_email_type1', ['test', 'test6'], ['test6' => '1']],
|
|
|
|
['activity', 'notify_email_type2', ['test6'], ['test6' => '1']],
|
|
|
|
['activity', 'notify_email_type2', ['test', 'test6'], ['test6' => '1']],
|
|
|
|
['activity', 'notify_email_type3', ['test', 'test1', 'test2', 'test3', 'test4', 'test5'], ['test1' => '1', 'test2' => '0', 'test3' => '', 'test4' => '3', 'test5' => '1']],
|
2014-12-17 15:35:36 +03:00
|
|
|
|
|
|
|
['activity', 'notify_setting_batchtime', ['test6'], ['test6' => '2700']],
|
|
|
|
['activity', 'notify_setting_batchtime', ['test', 'test6'], ['test6' => '2700']],
|
|
|
|
['activity', 'notify_setting_batchtime', ['test1', 'test4', 'test5'], ['test1' => '1', 'test4' => '4']],
|
|
|
|
]);
|
|
|
|
|
2014-12-09 18:02:11 +03:00
|
|
|
$this->assertEquals($expected, $this->userSettings->filterUsersBySetting($users, $method, $type));
|
2014-05-23 20:41:36 +04:00
|
|
|
}
|
|
|
|
}
|