Fixed phpunit

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-07-13 14:47:00 +02:00
parent 34368cc031
commit a349f2a9f5
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
2 changed files with 193 additions and 206 deletions

View File

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

View File

@ -12,10 +12,6 @@
namespace Test; namespace Test;
use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IL10N; use OCP\IL10N;
@ -23,6 +19,10 @@ use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
class NavigationManagerTest extends TestCase { class NavigationManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject */
@ -65,16 +65,16 @@ class NavigationManagerTest extends TestCase {
public function addArrayData() { public function addArrayData() {
return [ return [
[ [
[ 'entry id' => [
'id' => 'entry id', 'id' => 'entry id',
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
'icon' => 'optional', 'icon' => 'optional',
'href' => 'url', 'href' => 'url',
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
], ],
[ 'entry id2' => [
'id' => 'entry id', 'id' => 'entry id',
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
@ -82,19 +82,19 @@ class NavigationManagerTest extends TestCase {
'href' => 'url', 'href' => 'url',
'active' => false, 'active' => false,
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
], ]
], ],
[ [
[ 'entry id' => [
'id' => 'entry id', 'id' => 'entry id',
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
//'icon' => 'optional', //'icon' => 'optional',
'href' => 'url', 'href' => 'url',
'active' => true, 'active' => true
], ],
[ 'entry id2' => [
'id' => 'entry id', 'id' => 'entry id',
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
@ -102,9 +102,9 @@ class NavigationManagerTest extends TestCase {
'href' => 'url', 'href' => 'url',
'active' => false, 'active' => false,
'type' => 'link', 'type' => 'link',
'classes' => '', 'classes' => ''
], ]
], ]
]; ];
} }
@ -120,7 +120,7 @@ class NavigationManagerTest extends TestCase {
$navigationEntries = $this->navigationManager->getAll('all'); $navigationEntries = $this->navigationManager->getAll('all');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists'); $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->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()'); $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'); $navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()'); $this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()');
$this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists'); $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'); $navigationEntries = $this->navigationManager->getAll('all');
$this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is only called once for getAll()'); $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->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->navigationManager->clear(false);
$this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()'); $this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()');
@ -165,7 +165,7 @@ class NavigationManagerTest extends TestCase {
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
'icon' => 'optional', 'icon' => 'optional',
'href' => 'url', 'href' => 'url'
]; ];
$this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists'); $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists');
@ -182,7 +182,7 @@ class NavigationManagerTest extends TestCase {
'name' => 'link text', 'name' => 'link text',
'order' => 1, 'order' => 1,
'icon' => 'optional', 'icon' => 'optional',
'href' => 'url', 'href' => 'url'
]; ];
global $testAddClosureNumberOfCalls; global $testAddClosureNumberOfCalls;
@ -208,17 +208,17 @@ class NavigationManagerTest extends TestCase {
public function testWithAppManager($expected, $navigation, $isAdmin = false) { public function testWithAppManager($expected, $navigation, $isAdmin = false) {
$l = $this->createMock(IL10N::class); $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); return vsprintf($text, $parameters);
}); });
$this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation); $this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
$this->l10nFac->expects($this->any())->method('get')->willReturn($l); $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"; return "/apps/$appName/img/$file";
}); });
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() { $this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function () {
return "/apps/test/"; return '/apps/test/';
}); });
$this->urlGenerator $this->urlGenerator
->expects($this->once()) ->expects($this->once())
@ -226,7 +226,7 @@ class NavigationManagerTest extends TestCase {
->with( ->with(
'core.login.logout', 'core.login.logout',
[ [
'requesttoken' => \OCP\Util::callRegister(), 'requesttoken' => \OCP\Util::callRegister()
] ]
) )
->willReturn('https://example.com/logout'); ->willReturn('https://example.com/logout');
@ -250,7 +250,7 @@ class NavigationManagerTest extends TestCase {
public function providesNavigationConfig() { public function providesNavigationConfig() {
$apps = [ $apps = [
[ 'core_apps' => [
'id' => 'core_apps', 'id' => 'core_apps',
'order' => 3, 'order' => 3,
'href' => '/apps/test/', 'href' => '/apps/test/',
@ -258,11 +258,11 @@ class NavigationManagerTest extends TestCase {
'name' => 'Apps', 'name' => 'Apps',
'active' => false, 'active' => false,
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
] ]
]; ];
$defaults = [ $defaults = [
[ 'settings' => [
'id' => 'settings', 'id' => 'settings',
'order' => 1, 'order' => 1,
'href' => '/apps/test/', 'href' => '/apps/test/',
@ -270,9 +270,9 @@ class NavigationManagerTest extends TestCase {
'name' => 'Settings', 'name' => 'Settings',
'active' => false, 'active' => false,
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
], ],
[ 'logout' => [
'id' => 'logout', 'id' => 'logout',
'order' => 99999, 'order' => 99999,
'href' => 'https://example.com/logout', 'href' => 'https://example.com/logout',
@ -280,11 +280,15 @@ class NavigationManagerTest extends TestCase {
'name' => 'Log out', 'name' => 'Log out',
'active' => false, 'active' => false,
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
], ]
]; ];
return [ return [
'minimalistic' => [array_merge([$defaults[0]], [[ 'minimalistic' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test', 'id' => 'test',
'order' => 100, 'order' => 100,
'href' => '/apps/test/', 'href' => '/apps/test/',
@ -292,9 +296,18 @@ class NavigationManagerTest extends TestCase {
'name' => 'Test', 'name' => 'Test',
'active' => false, 'active' => false,
'type' => 'link', 'type' => 'link',
'classes' => '', 'classes' => ''
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]], ]],
'minimalistic-settings' => [array_merge([$defaults[0]], [[ ['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test']
]]
],
'minimalistic-settings' => [
array_merge(
['settings' => $defaults['settings']],
['test' => [
'id' => 'test', 'id' => 'test',
'order' => 100, 'order' => 100,
'href' => '/apps/test/', 'href' => '/apps/test/',
@ -302,9 +315,19 @@ class NavigationManagerTest extends TestCase {
'name' => 'Test', 'name' => 'Test',
'active' => false, 'active' => false,
'type' => 'settings', 'type' => 'settings',
'classes' => '', 'classes' => ''
]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]], ]],
'admin' => [array_merge([$defaults[0]], $apps, [[ ['logout' => $defaults['logout']]
),
['navigations' => [
['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']
]
]],
'admin' => [
array_merge(
['settings' => $defaults['settings']],
$apps,
['test' => [
'id' => 'test', 'id' => 'test',
'order' => 100, 'order' => 100,
'href' => '/apps/test/', 'href' => '/apps/test/',
@ -312,10 +335,34 @@ class NavigationManagerTest extends TestCase {
'name' => 'Test', 'name' => 'Test',
'active' => false, 'active' => false,
'type' => 'link', 'type' => 'link',
'classes' => '', '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], ['logout' => $defaults['logout']]
'no admin' => [$defaults, ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]] ),
['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'
]]]
]
]; ];
} }
} }