Cleanup ManagerTest

* Fix deprecated getMock call
* No longer requires DB
This commit is contained in:
Roeland Jago Douma 2016-07-14 13:49:18 +02:00
parent a6c23a1f8b
commit a3fa0d00c3
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
1 changed files with 32 additions and 12 deletions

View File

@ -17,7 +17,6 @@ use Test\TestCase;
* Class Manager * Class Manager
* *
* @package Test\App * @package Test\App
* @group DB
*/ */
class ManagerTest extends TestCase { class ManagerTest extends TestCase {
/** /**
@ -85,12 +84,22 @@ class ManagerTest extends TestCase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->userSession = $this->getMock('\OCP\IUserSession'); $this->userSession = $this->getMockBuilder('\OCP\IUserSession')
$this->groupManager = $this->getMock('\OCP\IGroupManager'); ->disableOriginalConstructor()
->getMock();
$this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')
->disableOriginalConstructor()
->getMock();
$this->appConfig = $this->getAppConfig(); $this->appConfig = $this->getAppConfig();
$this->cacheFactory = $this->getMock('\OCP\ICacheFactory'); $this->cacheFactory = $this->getMockBuilder('\OCP\ICacheFactory')
$this->cache = $this->getMock('\OCP\ICache'); ->disableOriginalConstructor()
$this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface'); ->getMock();
$this->cache = $this->getMockBuilder('\OCP\ICache')
->disableOriginalConstructor()
->getMock();
$this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface')
->disableOriginalConstructor()
->getMock();
$this->cacheFactory->expects($this->any()) $this->cacheFactory->expects($this->any())
->method('create') ->method('create')
->with('settings') ->with('settings')
@ -228,20 +237,31 @@ class ManagerTest extends TestCase {
$this->assertTrue($this->manager->isInstalled('test')); $this->assertTrue($this->manager->isInstalled('test'));
} }
private function newUser($uid) {
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock();
return new User($uid, null, null, $config, $urlgenerator);
}
public function testIsEnabledForUserEnabled() { public function testIsEnabledForUserEnabled() {
$this->appConfig->setValue('test', 'enabled', 'yes'); $this->appConfig->setValue('test', 'enabled', 'yes');
$user = new User('user1', null); $user = $this->newUser('user1');
$this->assertTrue($this->manager->isEnabledForUser('test', $user)); $this->assertTrue($this->manager->isEnabledForUser('test', $user));
} }
public function testIsEnabledForUserDisabled() { public function testIsEnabledForUserDisabled() {
$this->appConfig->setValue('test', 'enabled', 'no'); $this->appConfig->setValue('test', 'enabled', 'no');
$user = new User('user1', null); $user = $this->newUser('user1');
$this->assertFalse($this->manager->isEnabledForUser('test', $user)); $this->assertFalse($this->manager->isEnabledForUser('test', $user));
} }
public function testIsEnabledForUserEnabledForGroup() { public function testIsEnabledForUserEnabledForGroup() {
$user = new User('user1', null); $user = $this->newUser('user1');
$this->groupManager->expects($this->once()) $this->groupManager->expects($this->once())
->method('getUserGroupIds') ->method('getUserGroupIds')
->with($user) ->with($user)
@ -252,7 +272,7 @@ class ManagerTest extends TestCase {
} }
public function testIsEnabledForUserDisabledForGroup() { public function testIsEnabledForUserDisabledForGroup() {
$user = new User('user1', null); $user = $this->newUser('user1');
$this->groupManager->expects($this->once()) $this->groupManager->expects($this->once())
->method('getUserGroupIds') ->method('getUserGroupIds')
->with($user) ->with($user)
@ -268,7 +288,7 @@ class ManagerTest extends TestCase {
} }
public function testIsEnabledForUserLoggedIn() { public function testIsEnabledForUserLoggedIn() {
$user = new User('user1', null); $user = $this->newUser('user1');
$this->userSession->expects($this->once()) $this->userSession->expects($this->once())
->method('getUser') ->method('getUser')
@ -290,7 +310,7 @@ class ManagerTest extends TestCase {
} }
public function testGetAppsForUser() { public function testGetAppsForUser() {
$user = new User('user1', null); $user = $this->newUser('user1');
$this->groupManager->expects($this->any()) $this->groupManager->expects($this->any())
->method('getUserGroupIds') ->method('getUserGroupIds')
->with($user) ->with($user)