AppSettingsControllerTest.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace Tests\Settings\Controller;
  23. use OC\App\AppStore\Fetcher\AppFetcher;
  24. use OC\App\AppStore\Fetcher\CategoryFetcher;
  25. use OC\Settings\Controller\AppSettingsController;
  26. use OCP\AppFramework\Http\ContentSecurityPolicy;
  27. use OCP\AppFramework\Http\JSONResponse;
  28. use OCP\AppFramework\Http\TemplateResponse;
  29. use OCP\L10N\IFactory;
  30. use Test\TestCase;
  31. use OCP\IRequest;
  32. use OCP\IL10N;
  33. use OCP\IConfig;
  34. use OCP\INavigationManager;
  35. use OCP\App\IAppManager;
  36. /**
  37. * Class AppSettingsControllerTest
  38. *
  39. * @package Tests\Settings\Controller
  40. */
  41. class AppSettingsControllerTest extends TestCase {
  42. /** @var AppSettingsController */
  43. private $appSettingsController;
  44. /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
  45. private $request;
  46. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  47. private $l10n;
  48. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  49. private $config;
  50. /** @var INavigationManager|\PHPUnit_Framework_MockObject_MockObject */
  51. private $navigationManager;
  52. /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
  53. private $appManager;
  54. /** @var CategoryFetcher|\PHPUnit_Framework_MockObject_MockObject */
  55. private $categoryFetcher;
  56. /** @var AppFetcher|\PHPUnit_Framework_MockObject_MockObject */
  57. private $appFetcher;
  58. /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
  59. private $l10nFactory;
  60. public function setUp() {
  61. parent::setUp();
  62. $this->request = $this->createMock(IRequest::class);
  63. $this->l10n = $this->createMock(IL10N::class);
  64. $this->l10n->expects($this->any())
  65. ->method('t')
  66. ->will($this->returnArgument(0));
  67. $this->config = $this->createMock(IConfig::class);
  68. $this->navigationManager = $this->createMock(INavigationManager::class);
  69. $this->appManager = $this->createMock(IAppManager::class);
  70. $this->categoryFetcher = $this->createMock(CategoryFetcher::class);
  71. $this->appFetcher = $this->createMock(AppFetcher::class);
  72. $this->l10nFactory = $this->createMock(IFactory::class);
  73. $this->appSettingsController = new AppSettingsController(
  74. 'settings',
  75. $this->request,
  76. $this->l10n,
  77. $this->config,
  78. $this->navigationManager,
  79. $this->appManager,
  80. $this->categoryFetcher,
  81. $this->appFetcher,
  82. $this->l10nFactory
  83. );
  84. }
  85. public function testListCategories() {
  86. $expected = new JSONResponse([
  87. [
  88. 'id' => 0,
  89. 'ident' => 'enabled',
  90. 'displayName' => 'Enabled',
  91. ],
  92. [
  93. 'id' => 1,
  94. 'ident' => 'disabled',
  95. 'displayName' => 'Not enabled',
  96. ],
  97. [
  98. 'id' => 'auth',
  99. 'ident' => 'auth',
  100. 'displayName' => 'Authentication & authorization',
  101. ],
  102. [
  103. 'id' => 'customization',
  104. 'ident' => 'customization',
  105. 'displayName' => 'Customization',
  106. ],
  107. [
  108. 'id' => 'files',
  109. 'ident' => 'files',
  110. 'displayName' => 'Files',
  111. ],
  112. [
  113. 'id' => 'integration',
  114. 'ident' => 'integration',
  115. 'displayName' => 'Integration',
  116. ],
  117. [
  118. 'id' => 'monitoring',
  119. 'ident' => 'monitoring',
  120. 'displayName' => 'Monitoring',
  121. ],
  122. [
  123. 'id' => 'multimedia',
  124. 'ident' => 'multimedia',
  125. 'displayName' => 'Multimedia',
  126. ],
  127. [
  128. 'id' => 'office',
  129. 'ident' => 'office',
  130. 'displayName' => 'Office & text',
  131. ],
  132. [
  133. 'id' => 'organization',
  134. 'ident' => 'organization',
  135. 'displayName' => 'Organization',
  136. ],
  137. [
  138. 'id' => 'social',
  139. 'ident' => 'social',
  140. 'displayName' => 'Social & communication',
  141. ],
  142. [
  143. 'id' => 'tools',
  144. 'ident' => 'tools',
  145. 'displayName' => 'Tools',
  146. ],
  147. ]);
  148. $this->categoryFetcher
  149. ->expects($this->once())
  150. ->method('get')
  151. ->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));
  152. $this->assertEquals($expected, $this->appSettingsController->listCategories());
  153. }
  154. public function testViewApps() {
  155. $this->config
  156. ->expects($this->once())
  157. ->method('getSystemValue')
  158. ->with('appstoreenabled', true)
  159. ->will($this->returnValue(true));
  160. $this->navigationManager
  161. ->expects($this->once())
  162. ->method('setActiveEntry')
  163. ->with('core_apps');
  164. $policy = new ContentSecurityPolicy();
  165. $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
  166. $expected = new TemplateResponse('settings', 'apps', ['category' => 'enabled', 'appstoreEnabled' => true], 'user');
  167. $expected->setContentSecurityPolicy($policy);
  168. $this->assertEquals($expected, $this->appSettingsController->viewApps());
  169. }
  170. public function testViewAppsAppstoreNotEnabled() {
  171. $this->config
  172. ->expects($this->once())
  173. ->method('getSystemValue')
  174. ->with('appstoreenabled', true)
  175. ->will($this->returnValue(false));
  176. $this->navigationManager
  177. ->expects($this->once())
  178. ->method('setActiveEntry')
  179. ->with('core_apps');
  180. $policy = new ContentSecurityPolicy();
  181. $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
  182. $expected = new TemplateResponse('settings', 'apps', ['category' => 'enabled', 'appstoreEnabled' => false], 'user');
  183. $expected->setContentSecurityPolicy($policy);
  184. $this->assertEquals($expected, $this->appSettingsController->viewApps());
  185. }
  186. }