activity/tests/UserSettingsTest.php

89 строки
2.6 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;
2015-01-16 10:52:52 +03:00
use OCA\Activity\UserSettings;
use OCP\Activity\IManager;
use OCP\Activity\ISetting;
use OCP\IConfig;
class UserSettingsTest extends TestCase {
/** @var UserSettings */
protected $userSettings;
/** @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();
$this->activityManager = $this->createMock(IManager::class);
$this->config = $this->createMock(IConfig::class);
$this->userSettings = new UserSettings($this->activityManager, $this->config);
}
2014-06-04 18:25:51 +04:00
public function getDefaultSettingData() {
return [
['stream', 'type1', true],
['email', 'type1', false],
['setting', 'self', true],
['setting', 'selfemail', false],
['setting', 'batchtime', 3600],
['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) {
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);
}
}
$this->assertEquals($expected, self::invokePrivate($this->userSettings, 'getDefaultFromSetting', [$method, $type]));
}
}