activity/tests/UserSettingsTest.php

149 строки
5.4 KiB
PHP
Исходник Обычный вид История

<?php
/**
2016-02-12 11:14:27 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
*
2016-02-12 11:14:27 +03:00
* @license AGPL-3.0
*
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.
*
2016-02-12 11:14:27 +03:00
* This program is distributed in the hope that it will be useful,
* 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/>
*
*/
namespace OCA\Activity\Tests;
2014-06-04 18:25:51 +04:00
use OCA\Activity\Data;
use OCA\Activity\Tests\Mock\Extension;
2015-01-16 10:52:52 +03:00
use OCA\Activity\UserSettings;
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');
$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) {
return new Extension($activityLanguage, $this->getMock('\OCP\IURLGenerator'));
});
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-06-04 18:25:51 +04:00
public function getDefaultSettingData() {
return array(
array('stream', 'type1', true),
array('email', 'type1', false),
array('setting', 'self', true),
array('setting', 'selfemail', false),
2014-06-04 18:25:51 +04:00
array('setting', 'batchtime', 3600),
array('setting', 'not-exists', false),
);
}
/**
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-06-04 18:25:51 +04:00
public function testGetDefaultSetting($method, $type, $expected) {
$this->assertEquals($expected, $this->userSettings->getDefaultSetting($method, $type));
}
2014-06-04 18:25:51 +04:00
public function getNotificationTypesData() {
return array(
//array('test1', 'stream', array('type1')),
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([
['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
]);
$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()),
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)),
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([
['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']],
]);
$this->assertEquals($expected, $this->userSettings->filterUsersBySetting($users, $method, $type));
}
}