You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.5 KiB
PHTML
119 lines
3.5 KiB
PHTML
7 years ago
|
<?php
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
namespace Tests\Richdocuments;
|
||
|
|
||
|
use OCA\Richdocuments\PermissionManager;
|
||
|
use OCP\IConfig;
|
||
|
use OCP\IGroupManager;
|
||
|
use OCP\IUser;
|
||
|
use Test\TestCase;
|
||
|
|
||
|
class PermissionManagerTest extends TestCase {
|
||
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockBuilder */
|
||
|
private $config;
|
||
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockBuilder */
|
||
|
private $groupManager;
|
||
|
/** @var PermissionManager */
|
||
|
private $permissionManager;
|
||
|
|
||
|
public function setUp() {
|
||
|
parent::setUp();
|
||
|
$this->config = $this->createMock(IConfig::class);
|
||
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
||
|
$this->permissionManager = new PermissionManager($this->config, $this->groupManager);
|
||
|
}
|
||
|
|
||
|
public function testIsEnabledForUserEnabledNoRestrictions() {
|
||
|
/** @var IUser|\PHPUnit_Framework_MockObject_MockBuilder $user */
|
||
|
$user = $this->createMock(IUser::class);
|
||
|
|
||
|
$this->config
|
||
|
->expects($this->once())
|
||
|
->method('getAppValue')
|
||
|
->with('richdocuments', 'use_groups', '')
|
||
|
->willReturn('');
|
||
|
|
||
|
$this->assertTrue($this->permissionManager->isEnabledForUser($user));
|
||
|
}
|
||
|
|
||
|
public function testIsEnabledForUserEnabledNotInGroup() {
|
||
|
/** @var IUser|\PHPUnit_Framework_MockObject_MockBuilder $user */
|
||
|
$user = $this->createMock(IUser::class);
|
||
|
$user
|
||
|
->expects($this->once())
|
||
|
->method('getUID')
|
||
|
->willReturn('TestUser');
|
||
|
|
||
|
$this->config
|
||
|
->expects($this->once())
|
||
|
->method('getAppValue')
|
||
|
->with('richdocuments', 'use_groups', '')
|
||
|
->willReturn('Enabled1|Enabled2|Enabled3');
|
||
|
|
||
|
$this->groupManager
|
||
|
->expects($this->at(0))
|
||
|
->method('isInGroup')
|
||
|
->with('TestUser', 'Enabled1')
|
||
|
->willReturn(false);
|
||
|
$this->groupManager
|
||
|
->expects($this->at(1))
|
||
|
->method('isInGroup')
|
||
|
->with('TestUser', 'Enabled2')
|
||
|
->willReturn(false);
|
||
|
$this->groupManager
|
||
|
->expects($this->at(2))
|
||
|
->method('isInGroup')
|
||
|
->with('TestUser', 'Enabled3')
|
||
|
->willReturn(false);
|
||
|
|
||
|
$this->assertFalse($this->permissionManager->isEnabledForUser($user));
|
||
|
}
|
||
|
|
||
|
public function testIsEnabledForUserEnabledInGroup() {
|
||
|
/** @var IUser|\PHPUnit_Framework_MockObject_MockBuilder $user */
|
||
|
$user = $this->createMock(IUser::class);
|
||
|
$user
|
||
|
->expects($this->once())
|
||
|
->method('getUID')
|
||
|
->willReturn('TestUser');
|
||
|
|
||
|
$this->config
|
||
|
->expects($this->once())
|
||
|
->method('getAppValue')
|
||
|
->with('richdocuments', 'use_groups', '')
|
||
|
->willReturn('Enabled1|Enabled2|Enabled3');
|
||
|
|
||
|
$this->groupManager
|
||
|
->expects($this->at(0))
|
||
|
->method('isInGroup')
|
||
|
->with('TestUser', 'Enabled1')
|
||
|
->willReturn(false);
|
||
|
$this->groupManager
|
||
|
->expects($this->at(1))
|
||
|
->method('isInGroup')
|
||
|
->with('TestUser', 'Enabled2')
|
||
|
->willReturn(true);
|
||
|
|
||
|
$this->assertTrue($this->permissionManager->isEnabledForUser($user));
|
||
|
}
|
||
|
}
|