fix: Fix tests following OC_App migrations to IAppManager

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2024-03-06 18:19:24 +01:00
parent 733a818139
commit a0be3ffdf2
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
6 changed files with 62 additions and 22 deletions

View File

@ -539,11 +539,9 @@ class Factory implements IFactory {
/**
* Get a list of language files that should be loaded
*
* @param string $app
* @param string $lang
* @return string[]
*/
private function getL10nFilesForApp($app, $lang) {
private function getL10nFilesForApp(string $app, string $lang): array {
$languageFiles = [];
$i18nDir = $this->findL10nDir($app);

View File

@ -116,14 +116,22 @@ class AppManagerTest extends TestCase {
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->overwriteService(AppConfig::class, $this->appConfig);
$this->cacheFactory->expects($this->any())
->method('createDistributed')
->with('settings')
->willReturn($this->cache);
$this->config
->method('getSystemValueBool')
->with('installed', false)
->willReturn(true);
$this->manager = new AppManager(
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
@ -267,7 +275,6 @@ class AppManagerTest extends TestCase {
->setConstructorArgs([
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
@ -322,7 +329,6 @@ class AppManagerTest extends TestCase {
->setConstructorArgs([
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
@ -385,7 +391,6 @@ class AppManagerTest extends TestCase {
->setConstructorArgs([
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
@ -589,7 +594,6 @@ class AppManagerTest extends TestCase {
->setConstructorArgs([
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
@ -649,7 +653,6 @@ class AppManagerTest extends TestCase {
->setConstructorArgs([
$this->userSession,
$this->config,
$this->appConfig,
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,

View File

@ -83,7 +83,8 @@ class CoordinatorTest extends TestCase {
$this->dashboardManager,
$this->eventDispatcher,
$this->eventLogger,
$this->logger
$this->appManager,
$this->logger,
);
}

View File

@ -6,6 +6,7 @@ use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Routing\RouteConfig;
use OC\Route\Route;
use OC\Route\Router;
use OCP\App\IAppManager;
use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
use OCP\IRequest;
@ -142,7 +143,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();
@ -169,7 +171,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();
@ -235,7 +238,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();
@ -291,7 +295,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();
@ -324,7 +329,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();
@ -377,7 +383,8 @@ class RoutingTest extends \Test\TestCase {
$this->createMock(IRequest::class),
$this->createMock(IConfig::class),
$this->createMock(IEventLogger::class),
$this->createMock(ContainerInterface::class)
$this->createMock(ContainerInterface::class),
$this->createMock(IAppManager::class),
])
->getMock();

View File

@ -13,6 +13,8 @@ namespace Test\L10N;
use OC\L10N\Factory;
use OC\L10N\LanguageNotFoundException;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
@ -38,6 +40,9 @@ class FactoryTest extends TestCase {
/** @var string */
protected $serverRoot;
/** @var IAppManager|MockObject */
protected IAppManager $appManager;
protected function setUp(): void {
parent::setUp();
@ -45,6 +50,7 @@ class FactoryTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->serverRoot = \OC::$SERVERROOT;
@ -76,12 +82,13 @@ class FactoryTest extends TestCase {
$this->userSession,
$this->cacheFactory,
$this->serverRoot,
$this->appManager,
])
->setMethods($methods)
->getMock();
}
return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot);
return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot, $this->appManager);
}
public function dataFindAvailableLanguages(): array {
@ -402,7 +409,7 @@ class FactoryTest extends TestCase {
public function dataGetL10nFilesForApp(): array {
return [
[null, 'de', [\OC::$SERVERROOT . '/core/l10n/de.json']],
['', 'de', [\OC::$SERVERROOT . '/core/l10n/de.json']],
['core', 'ru', [\OC::$SERVERROOT . '/core/l10n/ru.json']],
['lib', 'ru', [\OC::$SERVERROOT . '/lib/l10n/ru.json']],
['settings', 'de', [\OC::$SERVERROOT . '/apps/settings/l10n/de.json']],
@ -415,17 +422,28 @@ class FactoryTest extends TestCase {
/**
* @dataProvider dataGetL10nFilesForApp
*
* @param string|null $app
* @param string $app
* @param string $expected
*/
public function testGetL10nFilesForApp($app, $lang, $expected): void {
$factory = $this->getFactory();
if (in_array($app, ['settings','files'])) {
$this->appManager
->method('getAppPath')
->with($app)
->willReturn(\OC::$SERVERROOT . '/apps/' . $app);
} else {
$this->appManager
->method('getAppPath')
->with($app)
->willThrowException(new AppPathNotFoundException());
}
self::assertSame($expected, $this->invokePrivate($factory, 'getL10nFilesForApp', [$app, $lang]));
}
public function dataFindL10NDir(): array {
return [
[null, \OC::$SERVERROOT . '/core/l10n/'],
['', \OC::$SERVERROOT . '/core/l10n/'],
['core', \OC::$SERVERROOT . '/core/l10n/'],
['lib', \OC::$SERVERROOT . '/lib/l10n/'],
['settings', \OC::$SERVERROOT . '/apps/settings/l10n/'],
@ -437,11 +455,22 @@ class FactoryTest extends TestCase {
/**
* @dataProvider dataFindL10NDir
*
* @param string|null $app
* @param string $app
* @param string $expected
*/
public function testFindL10NDir($app, $expected): void {
$factory = $this->getFactory();
if (in_array($app, ['settings','files'])) {
$this->appManager
->method('getAppPath')
->with($app)
->willReturn(\OC::$SERVERROOT . '/apps/' . $app);
} else {
$this->appManager
->method('getAppPath')
->with($app)
->willThrowException(new AppPathNotFoundException());
}
self::assertSame($expected, $this->invokePrivate($factory, 'findL10nDir', [$app]));
}

View File

@ -11,6 +11,7 @@ namespace Test\L10N;
use DateTime;
use OC\L10N\Factory;
use OC\L10N\L10N;
use OCP\App\IAppManager;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
@ -34,7 +35,8 @@ class L10nTest extends TestCase {
/** @var IUserSession $userSession */
$userSession = $this->createMock(IUserSession::class);
$cacheFactory = $this->createMock(ICacheFactory::class);
return new Factory($config, $request, $userSession, $cacheFactory, \OC::$SERVERROOT);
$appManager = $this->createMock(IAppManager::class);
return new Factory($config, $request, $userSession, $cacheFactory, \OC::$SERVERROOT, $appManager);
}
public function testSimpleTranslationWithTrailingColon(): void {