AppSettingsControllerTest.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  4. * @copyright Copyright (c) 2015, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\Settings\Tests\Controller;
  30. use OC\App\AppStore\Bundles\BundleFetcher;
  31. use OC\App\AppStore\Fetcher\AppFetcher;
  32. use OC\App\AppStore\Fetcher\CategoryFetcher;
  33. use OC\Installer;
  34. use OCA\Settings\Controller\AppSettingsController;
  35. use OCP\App\IAppManager;
  36. use OCP\AppFramework\Http\ContentSecurityPolicy;
  37. use OCP\AppFramework\Http\JSONResponse;
  38. use OCP\AppFramework\Http\TemplateResponse;
  39. use OCP\IConfig;
  40. use OCP\IL10N;
  41. use OCP\INavigationManager;
  42. use OCP\IRequest;
  43. use OCP\IURLGenerator;
  44. use OCP\L10N\IFactory;
  45. use PHPUnit\Framework\MockObject\MockObject;
  46. use Psr\Log\LoggerInterface;
  47. use Test\TestCase;
  48. /**
  49. * Class AppSettingsControllerTest
  50. *
  51. * @package Tests\Settings\Controller
  52. *
  53. * @group DB
  54. */
  55. class AppSettingsControllerTest extends TestCase {
  56. /** @var AppSettingsController */
  57. private $appSettingsController;
  58. /** @var IRequest|MockObject */
  59. private $request;
  60. /** @var IL10N|MockObject */
  61. private $l10n;
  62. /** @var IConfig|MockObject */
  63. private $config;
  64. /** @var INavigationManager|MockObject */
  65. private $navigationManager;
  66. /** @var IAppManager|MockObject */
  67. private $appManager;
  68. /** @var CategoryFetcher|MockObject */
  69. private $categoryFetcher;
  70. /** @var AppFetcher|MockObject */
  71. private $appFetcher;
  72. /** @var IFactory|MockObject */
  73. private $l10nFactory;
  74. /** @var BundleFetcher|MockObject */
  75. private $bundleFetcher;
  76. /** @var Installer|MockObject */
  77. private $installer;
  78. /** @var IURLGenerator|MockObject */
  79. private $urlGenerator;
  80. /** @var LoggerInterface|MockObject */
  81. private $logger;
  82. protected function setUp(): void {
  83. parent::setUp();
  84. $this->request = $this->createMock(IRequest::class);
  85. $this->l10n = $this->createMock(IL10N::class);
  86. $this->l10n->expects($this->any())
  87. ->method('t')
  88. ->willReturnArgument(0);
  89. $this->config = $this->createMock(IConfig::class);
  90. $this->navigationManager = $this->createMock(INavigationManager::class);
  91. $this->appManager = $this->createMock(IAppManager::class);
  92. $this->categoryFetcher = $this->createMock(CategoryFetcher::class);
  93. $this->appFetcher = $this->createMock(AppFetcher::class);
  94. $this->l10nFactory = $this->createMock(IFactory::class);
  95. $this->bundleFetcher = $this->createMock(BundleFetcher::class);
  96. $this->installer = $this->createMock(Installer::class);
  97. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  98. $this->logger = $this->createMock(LoggerInterface::class);
  99. $this->appSettingsController = new AppSettingsController(
  100. 'settings',
  101. $this->request,
  102. $this->l10n,
  103. $this->config,
  104. $this->navigationManager,
  105. $this->appManager,
  106. $this->categoryFetcher,
  107. $this->appFetcher,
  108. $this->l10nFactory,
  109. $this->bundleFetcher,
  110. $this->installer,
  111. $this->urlGenerator,
  112. $this->logger
  113. );
  114. }
  115. public function testListCategories() {
  116. $this->installer->expects($this->any())
  117. ->method('isUpdateAvailable')
  118. ->willReturn(false);
  119. $expected = new JSONResponse([
  120. [
  121. 'id' => 'auth',
  122. 'ident' => 'auth',
  123. 'displayName' => 'Authentication & authorization',
  124. ],
  125. [
  126. 'id' => 'customization',
  127. 'ident' => 'customization',
  128. 'displayName' => 'Customization',
  129. ],
  130. [
  131. 'id' => 'files',
  132. 'ident' => 'files',
  133. 'displayName' => 'Files',
  134. ],
  135. [
  136. 'id' => 'integration',
  137. 'ident' => 'integration',
  138. 'displayName' => 'Integration',
  139. ],
  140. [
  141. 'id' => 'monitoring',
  142. 'ident' => 'monitoring',
  143. 'displayName' => 'Monitoring',
  144. ],
  145. [
  146. 'id' => 'multimedia',
  147. 'ident' => 'multimedia',
  148. 'displayName' => 'Multimedia',
  149. ],
  150. [
  151. 'id' => 'office',
  152. 'ident' => 'office',
  153. 'displayName' => 'Office & text',
  154. ],
  155. [
  156. 'id' => 'organization',
  157. 'ident' => 'organization',
  158. 'displayName' => 'Organization',
  159. ],
  160. [
  161. 'id' => 'social',
  162. 'ident' => 'social',
  163. 'displayName' => 'Social & communication',
  164. ],
  165. [
  166. 'id' => 'tools',
  167. 'ident' => 'tools',
  168. 'displayName' => 'Tools',
  169. ],
  170. ]);
  171. $this->categoryFetcher
  172. ->expects($this->once())
  173. ->method('get')
  174. ->willReturn(json_decode('[{"id":"auth","translations":{"cs":{"name":"Autentizace & autorizace","description":"Aplikace poskytující služby dodatečného ověření nebo přihlášení"},"hu":{"name":"Azonosítás és hitelesítés","description":"Apps that provide additional authentication or authorization services"},"de":{"name":"Authentifizierung & Authorisierung","description":"Apps die zusätzliche Autentifizierungs- oder Autorisierungsdienste bereitstellen"},"nl":{"name":"Authenticatie & authorisatie","description":"Apps die aanvullende authenticatie- en autorisatiediensten bieden"},"nb":{"name":"Pålogging og tilgangsstyring","description":"Apper for å tilby ekstra pålogging eller tilgangsstyring"},"it":{"name":"Autenticazione e autorizzazione","description":"Apps that provide additional authentication or authorization services"},"fr":{"name":"Authentification et autorisations","description":"Applications qui fournissent des services d\'authentification ou d\'autorisations additionnels."},"ru":{"name":"Аутентификация и авторизация","description":"Apps that provide additional authentication or authorization services"},"en":{"name":"Authentication & authorization","description":"Apps that provide additional authentication or authorization services"}}},{"id":"customization","translations":{"cs":{"name":"Přizpůsobení","description":"Motivy a aplikace měnící rozvržení a uživatelské rozhraní"},"it":{"name":"Personalizzazione","description":"Applicazioni di temi, modifiche della disposizione e UX"},"de":{"name":"Anpassung","description":"Apps zur Änderung von Themen, Layout und Benutzererfahrung"},"hu":{"name":"Személyre szabás","description":"Témák, elrendezések felhasználói felület módosító alkalmazások"},"nl":{"name":"Maatwerk","description":"Thema\'s, layout en UX aanpassingsapps"},"nb":{"name":"Tilpasning","description":"Apper for å endre Tema, utseende og brukeropplevelse"},"fr":{"name":"Personalisation","description":"Thèmes, apparence et applications modifiant l\'expérience utilisateur"},"ru":{"name":"Настройка","description":"Themes, layout and UX change apps"},"en":{"name":"Customization","description":"Themes, layout and UX change apps"}}},{"id":"files","translations":{"cs":{"name":"Soubory","description":"Aplikace rozšiřující správu souborů nebo aplikaci Soubory"},"it":{"name":"File","description":"Applicazioni di gestione dei file ed estensione dell\'applicazione FIle"},"de":{"name":"Dateien","description":"Dateimanagement sowie Erweiterungs-Apps für die Dateien-App"},"hu":{"name":"Fájlok","description":"Fájl kezelő és kiegészítő alkalmazások"},"nl":{"name":"Bestanden","description":"Bestandebeheer en uitbreidingen van bestand apps"},"nb":{"name":"Filer","description":"Apper for filhåndtering og filer"},"fr":{"name":"Fichiers","description":"Applications de gestion de fichiers et extensions à l\'application Fichiers"},"ru":{"name":"Файлы","description":"Расширение: файлы и управление файлами"},"en":{"name":"Files","description":"File management and Files app extension apps"}}},{"id":"integration","translations":{"it":{"name":"Integrazione","description":"Applicazioni che collegano Nextcloud con altri servizi e piattaforme"},"hu":{"name":"Integráció","description":"Apps that connect Nextcloud with other services and platforms"},"nl":{"name":"Integratie","description":"Apps die Nextcloud verbinden met andere services en platformen"},"nb":{"name":"Integrasjon","description":"Apper som kobler Nextcloud med andre tjenester og plattformer"},"de":{"name":"Integration","description":"Apps die Nextcloud mit anderen Diensten und Plattformen verbinden"},"cs":{"name":"Propojení","description":"Aplikace propojující NextCloud s dalšími službami a platformami"},"fr":{"name":"Intégration","description":"Applications qui connectent Nextcloud avec d\'autres services et plateformes"},"ru":{"name":"Интеграция","description":"Приложения, соединяющие Nextcloud с другими службами и платформами"},"en":{"name":"Integration","description":"Apps that connect Nextcloud with other services and platforms"}}},{"id":"monitoring","translations":{"nb":{"name":"Overvåking","description":"Apper for statistikk, systemdiagnose og aktivitet"},"it":{"name":"Monitoraggio","description":"Applicazioni di statistiche, diagnostica di sistema e attività"},"de":{"name":"Überwachung","description":"Datenstatistiken-, Systemdiagnose- und Aktivitäten-Apps"},"hu":{"name":"Megfigyelés","description":"Data statistics, system diagnostics and activity apps"},"nl":{"name":"Monitoren","description":"Gegevensstatistiek, systeem diagnose en activiteit apps"},"cs":{"name":"Kontrola","description":"Datové statistiky, diagnózy systému a aktivity aplikací"},"fr":{"name":"Surveillance","description":"Applications de statistiques sur les données, de diagnostics systèmes et d\'activité."},"ru":{"name":"Мониторинг","description":"Статистика данных, диагностика системы и активность приложений"},"en":{"name":"Monitoring","description":"Data statistics, system diagnostics and activity apps"}}},{"id":"multimedia","translations":{"nb":{"name":"Multimedia","description":"Apper for lyd, film og bilde"},"it":{"name":"Multimedia","description":"Applicazioni per audio, video e immagini"},"de":{"name":"Multimedia","description":"Audio-, Video- und Bilder-Apps"},"hu":{"name":"Multimédia","description":"Hang, videó és kép alkalmazások"},"nl":{"name":"Multimedia","description":"Audio, video en afbeelding apps"},"en":{"name":"Multimedia","description":"Audio, video and picture apps"},"cs":{"name":"Multimédia","description":"Aplikace audia, videa a obrázků"},"fr":{"name":"Multimédia","description":"Applications audio, vidéo et image"},"ru":{"name":"Мультимедиа","description":"Приложение аудио, видео и изображения"}}},{"id":"office","translations":{"nb":{"name":"Kontorstøtte og tekst","description":"Apper for Kontorstøtte og tekstbehandling"},"it":{"name":"Ufficio e testo","description":"Applicazione per ufficio ed elaborazione di testi"},"de":{"name":"Büro & Text","description":"Büro- und Textverarbeitungs-Apps"},"hu":{"name":"Iroda és szöveg","description":"Irodai és szöveg feldolgozó alkalmazások"},"nl":{"name":"Office & tekst","description":"Office en tekstverwerkingsapps"},"cs":{"name":"Kancelář a text","description":"Aplikace pro kancelář a zpracování textu"},"fr":{"name":"Bureautique & texte","description":"Applications de bureautique et de traitement de texte"},"en":{"name":"Office & text","description":"Office and text processing apps"}}},{"id":"organization","translations":{"nb":{"name":"Organisering","description":"Apper for tidsstyring, oppgaveliste og kalender"},"it":{"name":"Organizzazione","description":"Applicazioni di gestione del tempo, elenco delle cose da fare e calendario"},"hu":{"name":"Szervezet","description":"Időbeosztás, teendő lista és naptár alkalmazások"},"nl":{"name":"Organisatie","description":"Tijdmanagement, takenlijsten en agenda apps"},"cs":{"name":"Organizace","description":"Aplikace pro správu času, plánování a kalendáře"},"de":{"name":"Organisation","description":"Time management, Todo list and calendar apps"},"fr":{"name":"Organisation","description":"Applications de gestion du temps, de listes de tâches et d\'agendas"},"ru":{"name":"Организация","description":"Приложения по управлению временем, список задач и календарь"},"en":{"name":"Organization","description":"Time management, Todo list and calendar apps"}}},{"id":"social","translations":{"nb":{"name":"Sosialt og kommunikasjon","description":"Apper for meldinger, kontakthåndtering og sosiale medier"},"it":{"name":"Sociale e comunicazione","description":"Applicazioni di messaggistica, gestione dei contatti e reti sociali"},"de":{"name":"Kommunikation","description":"Nachrichten-, Kontaktverwaltungs- und Social-Media-Apps"},"hu":{"name":"Közösségi és kommunikáció","description":"Üzenetküldő, kapcsolat kezelő és közösségi média alkalmazások"},"nl":{"name":"Sociaal & communicatie","description":"Messaging, contactbeheer en social media apps"},"cs":{"name":"Sociální sítě a komunikace","description":"Aplikace pro zasílání zpráv, správu kontaktů a sociální sítě"},"fr":{"name":"Social & communication","description":"Applications de messagerie, de gestion de contacts et de réseaux sociaux"},"ru":{"name":"Социальное и связь","description":"Общение, управление контактами и социальное медиа-приложение"},"en":{"name":"Social & communication","description":"Messaging, contact management and social media apps"}}},{"id":"tools","translations":{"nb":{"name":"Verktøy","description":"Alt annet"},"it":{"name":"Strumenti","description":"Tutto il resto"},"hu":{"name":"Eszközök","description":"Minden más"},"nl":{"name":"Tools","description":"De rest"},"de":{"name":"Werkzeuge","description":"Alles Andere"},"en":{"name":"Tools","description":"Everything else"},"cs":{"name":"Nástroje","description":"Vše ostatní"},"fr":{"name":"Outils","description":"Tout le reste"},"ru":{"name":"Приложения","description":"Что-то еще"}}}]', true));
  175. $this->assertEquals($expected, $this->appSettingsController->listCategories());
  176. }
  177. public function testViewApps() {
  178. $this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
  179. $this->installer->expects($this->any())
  180. ->method('isUpdateAvailable')
  181. ->willReturn(false);
  182. $this->config
  183. ->expects($this->once())
  184. ->method('getSystemValueBool')
  185. ->with('appstoreenabled', true)
  186. ->willReturn(true);
  187. $this->navigationManager
  188. ->expects($this->once())
  189. ->method('setActiveEntry')
  190. ->with('core_apps');
  191. $policy = new ContentSecurityPolicy();
  192. $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
  193. $expected = new TemplateResponse('settings',
  194. 'settings-vue',
  195. [
  196. 'serverData' => [
  197. 'updateCount' => 0,
  198. 'appstoreEnabled' => true,
  199. 'bundles' => [],
  200. 'developerDocumentation' => ''
  201. ]
  202. ],
  203. 'user');
  204. $expected->setContentSecurityPolicy($policy);
  205. $this->assertEquals($expected, $this->appSettingsController->viewApps());
  206. }
  207. public function testViewAppsAppstoreNotEnabled() {
  208. $this->installer->expects($this->any())
  209. ->method('isUpdateAvailable')
  210. ->willReturn(false);
  211. $this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
  212. $this->config
  213. ->expects($this->once())
  214. ->method('getSystemValueBool')
  215. ->with('appstoreenabled', true)
  216. ->willReturn(false);
  217. $this->navigationManager
  218. ->expects($this->once())
  219. ->method('setActiveEntry')
  220. ->with('core_apps');
  221. $policy = new ContentSecurityPolicy();
  222. $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
  223. $expected = new TemplateResponse('settings',
  224. 'settings-vue',
  225. [
  226. 'serverData' => [
  227. 'updateCount' => 0,
  228. 'appstoreEnabled' => false,
  229. 'bundles' => [],
  230. 'developerDocumentation' => ''
  231. ]
  232. ],
  233. 'user');
  234. $expected->setContentSecurityPolicy($policy);
  235. $this->assertEquals($expected, $this->appSettingsController->viewApps());
  236. }
  237. }