diff options
-rw-r--r-- | lib/private/L10N/Factory.php | 4 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 15 | ||||
-rw-r--r-- | tests/lib/AppFramework/Bootstrap/CoordinatorTest.php | 3 | ||||
-rw-r--r-- | tests/lib/AppFramework/Routing/RoutingTest.php | 19 | ||||
-rw-r--r-- | tests/lib/L10N/FactoryTest.php | 39 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 4 |
6 files changed, 62 insertions, 22 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 16595ad9385..785915fc82b 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -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); diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index dfbaedff957..88f2bd9873b 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -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, diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index a706abecc4f..193f9295551 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -83,7 +83,8 @@ class CoordinatorTest extends TestCase { $this->dashboardManager, $this->eventDispatcher, $this->eventLogger, - $this->logger + $this->appManager, + $this->logger, ); } diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php index c9812a5dfb7..c5e6f70cdc6 100644 --- a/tests/lib/AppFramework/Routing/RoutingTest.php +++ b/tests/lib/AppFramework/Routing/RoutingTest.php @@ -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(); diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index 20eb355f6f4..4f12cb8d53c 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -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])); } diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 9817f8b0141..a6d74256212 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -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 { |