Browse Source

Fixed phpunit

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
tags/v14.0.0beta1
John Molakvoæ (skjnldsv) 5 years ago
parent
commit
a349f2a9f5
No account linked to committer's email address
2 changed files with 193 additions and 206 deletions
  1. 12
    72
      apps/files/tests/Controller/ViewControllerTest.php
  2. 181
    134
      tests/lib/NavigationManagerTest.php

+ 12
- 72
apps/files/tests/Controller/ViewControllerTest.php View File

@@ -145,7 +145,7 @@ class ViewControllerTest extends TestCase {
$nav->assign('total_space', '100 B');
//$nav->assign('webdavurl', '');
$nav->assign('navigationItems', [
[
'files' => [
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
@@ -156,7 +156,7 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'recent' => [
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
@@ -167,65 +167,21 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'favorites' => [
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'order' => 5,
'name' => null,
'name' => \OC::$server->getL10N('files')->t('Favorites'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
'sublist' => [],
'defaultExpandedState' => false,
'enableMenuButton' => 0,
'expandedState' => 'show_Quick_Access'
],
[
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with you'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared with others'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => \OC::$server->getL10N('files_sharing')->t('Shared by link', []),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => \OC::$server->getL10N('files_sharing')->t('Deleted shares'),
'active' => false,
'icon' => '',
'type' => 'link',
'classes' => '',
],
[
'systemtagsfilter' => [
'id' => 'systemtagsfilter',
'appname' => 'systemtags',
'script' => 'list.php',
@@ -236,7 +192,7 @@ class ViewControllerTest extends TestCase {
'type' => 'link',
'classes' => '',
],
[
'trashbin' => [
'id' => 'trashbin',
'appname' => 'files_trashbin',
'script' => 'list.php',
@@ -264,39 +220,23 @@ class ViewControllerTest extends TestCase {
'allowShareWithLink' => 'yes',
'appNavigation' => $nav,
'appContents' => [
[
'files' => [
'id' => 'files',
'content' => null,
],
[
'recent' => [
'id' => 'recent',
'content' => null,
],
[
'favorites' => [
'id' => 'favorites',
'content' => null,
],
[
'id' => 'sharingin',
'content' => null,
],
[
'id' => 'sharingout',
'content' => null,
],
[
'id' => 'sharinglinks',
'content' => null,
],
[
'id' => 'deletedshares',
'content' => null,
],
[
'systemtagsfilter' => [
'id' => 'systemtagsfilter',
'content' => null,
],
[
'trashbin' => [
'id' => 'trashbin',
'content' => null,
],

+ 181
- 134
tests/lib/NavigationManagerTest.php View File

@@ -12,10 +12,6 @@

namespace Test;

use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -23,6 +19,10 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;

class NavigationManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject */
@@ -44,12 +44,12 @@ class NavigationManagerTest extends TestCase {
protected function setUp() {
parent::setUp();

$this->appManager = $this->createMock(AppManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFac = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(AppManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFac = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->navigationManager = new NavigationManager(
$this->appManager,
$this->urlGenerator,
@@ -65,46 +65,46 @@ class NavigationManagerTest extends TestCase {
public function addArrayData() {
return [
[
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'type' => 'settings',
'classes' => '',
],
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'active' => false,
'type' => 'settings',
'classes' => '',
'entry id' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'type' => 'settings',
'classes' => ''
],
'entry id2' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'active' => false,
'type' => 'settings',
'classes' => ''
]
],
[
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'entry id' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
//'icon' => 'optional',
'href' => 'url',
'active' => true,
'href' => 'url',
'active' => true
],
[
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => '',
'href' => 'url',
'active' => false,
'type' => 'link',
'classes' => '',
],
],
'entry id2' => [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => '',
'href' => 'url',
'active' => false,
'type' => 'link',
'classes' => ''
]
]
];
}

@@ -120,7 +120,7 @@ class NavigationManagerTest extends TestCase {

$navigationEntries = $this->navigationManager->getAll('all');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);

$this->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()');
@@ -148,12 +148,12 @@ class NavigationManagerTest extends TestCase {
$navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);

$navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is only called once for getAll()');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists');
$this->assertEquals($expectedEntry, $navigationEntries[0]);
$this->assertEquals($expectedEntry, $navigationEntries['entry id']);

$this->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()');
@@ -161,11 +161,11 @@ class NavigationManagerTest extends TestCase {

public function testAddArrayClearGetAll() {
$entry = [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url'
];

$this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
@@ -178,11 +178,11 @@ class NavigationManagerTest extends TestCase {
$this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');

$entry = [
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url',
'id' => 'entry id',
'name' => 'link text',
'order' => 1,
'icon' => 'optional',
'href' => 'url'
];

global $testAddClosureNumberOfCalls;
@@ -208,36 +208,36 @@ class NavigationManagerTest extends TestCase {
public function testWithAppManager($expected, $navigation, $isAdmin = false) {

$l = $this->createMock(IL10N::class);
$l->expects($this->any())->method('t')->willReturnCallback(function($text, $parameters = []) {
$l->expects($this->any())->method('t')->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
});

$this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
$this->l10nFac->expects($this->any())->method('get')->willReturn($l);
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function($appName, $file) {
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) {
return "/apps/$appName/img/$file";
});
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() {
return "/apps/test/";
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function () {
return '/apps/test/';
});
$this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
)
->willReturn('https://example.com/logout');
->expects($this->once())
->method('linkToRouteAbsolute')
->with(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister()
]
)
->willReturn('https://example.com/logout');
$user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn('user001');
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
$this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$this->appManager->expects($this->once())
->method('getEnabledAppsForUser')
->with($user)
->willReturn(['test']);
->method('getEnabledAppsForUser')
->with($user)
->willReturn(['test']);
$this->groupManager->expects($this->any())->method('isAdmin')->willReturn($isAdmin);
$subadmin = $this->createMock(SubAdmin::class);
$subadmin->expects($this->any())->method('isSubAdmin')->with($user)->willReturn(false);
@@ -250,72 +250,119 @@ class NavigationManagerTest extends TestCase {

public function providesNavigationConfig() {
$apps = [
[
'id' => 'core_apps',
'order' => 3,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/apps.svg',
'name' => 'Apps',
'active' => false,
'type' => 'settings',
'classes' => '',
'core_apps' => [
'id' => 'core_apps',
'order' => 3,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/apps.svg',
'name' => 'Apps',
'active' => false,
'type' => 'settings',
'classes' => ''
]
];
$defaults = [
[
'id' => 'settings',
'order' => 1,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/admin.svg',
'name' => 'Settings',
'active' => false,
'type' => 'settings',
'classes' => '',
],
[
'id' => 'logout',
'order' => 99999,
'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,
'type' => 'settings',
'classes' => '',
'settings' => [
'id' => 'settings',
'order' => 1,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/admin.svg',
'name' => 'Settings',
'active' => false,
'type' => 'settings',
'classes' => ''
],
'logout' => [
'id' => 'logout',
'order' => 99999,
'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,
'type' => 'settings',
'classes' => ''
]
];

return [
'minimalistic' => [array_merge([$defaults[0]], [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]],
'minimalistic-settings' => [array_merge([$defaults[0]], [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'settings',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]],
'admin' => [array_merge([$defaults[0]], $apps, [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => '',
]], [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]], true],
'no name' => [array_merge([$defaults[0]], $apps, [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]], true],
'no admin' => [$defaults, ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]]
'minimalistic' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test']
]]
],
'minimalistic-settings' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'settings',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']
]
]],
'admin' => [
array_merge(
['settings' => $defaults['settings']],
$apps,
['test' => [
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
'classes' => ''
]],
['logout' => $defaults['logout']]
),
['navigations' => [
['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']
]],
true
],
'no name' => [
array_merge(
['settings' => $defaults['settings']],
$apps,
['logout' => $defaults['logout']]
),
['navigations' => [
['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']
]],
true
],
'no admin' => [
$defaults,
['navigations' => [[
'@attributes' => ['role' => 'admin'],
'route' => 'test.page.index',
'name' => 'Test'
]]]
]
];
}
}

Loading…
Cancel
Save