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;
|
|
|
|
|
2015-01-16 10:52:52 +03:00
|
|
|
use OCA\Activity\UserSettings;
|
2016-11-10 18:42:46 +03:00
|
|
|
use OCP\Activity\IManager;
|
|
|
|
use OCP\Activity\ISetting;
|
|
|
|
use OCP\IConfig;
|
2014-05-23 20:41:36 +04:00
|
|
|
|
2014-12-09 18:02:11 +03:00
|
|
|
class UserSettingsTest extends TestCase {
|
|
|
|
/** @var UserSettings */
|
|
|
|
protected $userSettings;
|
|
|
|
|
2016-11-10 18:42:46 +03:00
|
|
|
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $activityManager;
|
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2014-12-17 15:35:36 +03:00
|
|
|
protected $config;
|
|
|
|
|
2014-11-11 02:03:47 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
2016-11-10 18:42:46 +03:00
|
|
|
$this->activityManager = $this->createMock(IManager::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->userSettings = new UserSettings($this->activityManager, $this->config);
|
2014-05-23 20:41:36 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 18:25:51 +04:00
|
|
|
public function getDefaultSettingData() {
|
2016-11-10 18:42:46 +03:00
|
|
|
return [
|
|
|
|
['stream', 'type1', true],
|
|
|
|
['email', 'type1', false],
|
|
|
|
['setting', 'self', true],
|
|
|
|
['setting', 'selfemail', false],
|
|
|
|
['setting', 'batchtime', 3600],
|
|
|
|
['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) {
|
2016-11-10 18:42:46 +03:00
|
|
|
if ($method !== 'setting') {
|
|
|
|
if ($type === 'not-exists') {
|
|
|
|
$this->activityManager->expects($this->once())
|
|
|
|
->method('getSettingById')
|
|
|
|
->with($type)
|
|
|
|
->willThrowException(new \InvalidArgumentException());
|
|
|
|
} else {
|
|
|
|
$s = $this->createMock(ISetting::class);
|
|
|
|
$s->expects($method === 'stream' ? $this->once() : $this->never())
|
|
|
|
->method('isDefaultEnabledStream')
|
|
|
|
->willReturn($expected);
|
|
|
|
$s->expects($method === 'email' ? $this->once() : $this->never())
|
|
|
|
->method('isDefaultEnabledMail')
|
|
|
|
->willReturn($expected);
|
|
|
|
$this->activityManager->expects($this->once())
|
|
|
|
->method('getSettingById')
|
|
|
|
->with($type)
|
|
|
|
->willReturn($s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-04-06 11:58:42 +03:00
|
|
|
$this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultFromSetting', [$method, $type]));
|
2014-05-23 20:41:36 +04:00
|
|
|
}
|
|
|
|
}
|