ViewControllerTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Files\Tests\Controller;
  22. use OCA\Files\Controller\ViewController;
  23. use OCP\AppFramework\Http;
  24. use OCP\Template;
  25. use Test\TestCase;
  26. use OCP\IRequest;
  27. use OCP\IURLGenerator;
  28. use OCP\AppFramework\Http\RedirectResponse;
  29. use OCP\INavigationManager;
  30. use OCP\IL10N;
  31. use OCP\IConfig;
  32. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  33. /**
  34. * Class ViewControllerTest
  35. *
  36. * @package OCA\Files\Tests\Controller
  37. */
  38. class ViewControllerTest extends TestCase {
  39. /** @var IRequest */
  40. private $request;
  41. /** @var IURLGenerator */
  42. private $urlGenerator;
  43. /** @var INavigationManager */
  44. private $navigationManager;
  45. /** @var IL10N */
  46. private $l10n;
  47. /** @var IConfig */
  48. private $config;
  49. /** @var EventDispatcherInterface */
  50. private $eventDispatcher;
  51. /** @var ViewController */
  52. private $viewController;
  53. public function setUp() {
  54. parent::setUp();
  55. $this->request = $this->getMock('\OCP\IRequest');
  56. $this->urlGenerator = $this->getMock('\OCP\IURLGenerator');
  57. $this->navigationManager = $this->getMock('\OCP\INavigationManager');
  58. $this->l10n = $this->getMock('\OCP\IL10N');
  59. $this->config = $this->getMock('\OCP\IConfig');
  60. $this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
  61. $this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
  62. ->setConstructorArgs([
  63. 'files',
  64. $this->request,
  65. $this->urlGenerator,
  66. $this->navigationManager,
  67. $this->l10n,
  68. $this->config,
  69. $this->eventDispatcher
  70. ])
  71. ->setMethods([
  72. 'getStorageInfo',
  73. 'renderScript'
  74. ])
  75. ->getMock();
  76. }
  77. public function testIndexWithIE8RedirectAndDirDefined() {
  78. $this->request
  79. ->expects($this->once())
  80. ->method('isUserAgent')
  81. ->with(['/MSIE 8.0/'])
  82. ->will($this->returnValue(true));
  83. $this->urlGenerator
  84. ->expects($this->once())
  85. ->method('linkToRoute')
  86. ->with('files.view.index')
  87. ->will($this->returnValue('/apps/files/'));
  88. $expected = new Http\RedirectResponse('/apps/files/#?dir=MyDir');
  89. $this->assertEquals($expected, $this->viewController->index('MyDir'));
  90. }
  91. public function testIndexWithIE8RedirectAndViewDefined() {
  92. $this->request
  93. ->expects($this->once())
  94. ->method('isUserAgent')
  95. ->with(['/MSIE 8.0/'])
  96. ->will($this->returnValue(true));
  97. $this->urlGenerator
  98. ->expects($this->once())
  99. ->method('linkToRoute')
  100. ->with('files.view.index')
  101. ->will($this->returnValue('/apps/files/'));
  102. $expected = new Http\RedirectResponse('/apps/files/#?dir=/&view=MyView');
  103. $this->assertEquals($expected, $this->viewController->index('', 'MyView'));
  104. }
  105. public function testIndexWithIE8RedirectAndViewAndDirDefined() {
  106. $this->request
  107. ->expects($this->once())
  108. ->method('isUserAgent')
  109. ->with(['/MSIE 8.0/'])
  110. ->will($this->returnValue(true));
  111. $this->urlGenerator
  112. ->expects($this->once())
  113. ->method('linkToRoute')
  114. ->with('files.view.index')
  115. ->will($this->returnValue('/apps/files/'));
  116. $expected = new RedirectResponse('/apps/files/#?dir=MyDir&view=MyView');
  117. $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
  118. }
  119. public function testIndexWithRegularBrowser() {
  120. $this->request
  121. ->expects($this->once())
  122. ->method('isUserAgent')
  123. ->with(['/MSIE 8.0/'])
  124. ->will($this->returnValue(false));
  125. $this->viewController
  126. ->expects($this->once())
  127. ->method('getStorageInfo')
  128. ->will($this->returnValue([
  129. 'relative' => 123,
  130. 'owner' => 'MyName',
  131. 'ownerDisplayName' => 'MyDisplayName',
  132. ]));
  133. $this->config
  134. ->expects($this->any())
  135. ->method('getAppValue')
  136. ->will($this->returnArgument(2));
  137. $nav = new Template('files', 'appnavigation');
  138. $nav->assign('navigationItems', [
  139. 0 => [
  140. 'id' => 'files',
  141. 'appname' => 'files',
  142. 'script' => 'list.php',
  143. 'order' => 0,
  144. 'name' => new \OC_L10N_String(new \OC_L10N('files'), 'All files', []),
  145. 'active' => false,
  146. 'icon' => '',
  147. ],
  148. 1 => [
  149. 'id' => 'favorites',
  150. 'appname' => 'files',
  151. 'script' => 'simplelist.php',
  152. 'order' => 5,
  153. 'name' => null,
  154. 'active' => false,
  155. 'icon' => '',
  156. ],
  157. 2 => [
  158. 'id' => 'systemtagsfilter',
  159. 'appname' => 'systemtags',
  160. 'script' => 'list.php',
  161. 'order' => 9,
  162. 'name' => new \OC_L10N_String(new \OC_L10N('systemtags'), 'Tags', []),
  163. 'active' => false,
  164. 'icon' => '',
  165. ],
  166. 3 => [
  167. 'id' => 'sharingin',
  168. 'appname' => 'files_sharing',
  169. 'script' => 'list.php',
  170. 'order' => 10,
  171. 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with you', []),
  172. 'active' => false,
  173. 'icon' => '',
  174. ],
  175. 4 => [
  176. 'id' => 'sharingout',
  177. 'appname' => 'files_sharing',
  178. 'script' => 'list.php',
  179. 'order' => 15,
  180. 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with others', []),
  181. 'active' => false,
  182. 'icon' => '',
  183. ],
  184. 5 => [
  185. 'id' => 'sharinglinks',
  186. 'appname' => 'files_sharing',
  187. 'script' => 'list.php',
  188. 'order' => 20,
  189. 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared by link', []),
  190. 'active' => false,
  191. 'icon' => '',
  192. ],
  193. 6 => [
  194. 'id' => 'trashbin',
  195. 'appname' => 'files_trashbin',
  196. 'script' => 'list.php',
  197. 'order' => 50,
  198. 'name' => new \OC_L10N_String(new \OC_L10N('files_trashbin'), 'Deleted files', []),
  199. 'active' => false,
  200. 'icon' => '',
  201. ],
  202. ]);
  203. $expected = new Http\TemplateResponse(
  204. 'files',
  205. 'index',
  206. [
  207. 'usedSpacePercent' => 123,
  208. 'owner' => 'MyName',
  209. 'ownerDisplayName' => 'MyDisplayName',
  210. 'isPublic' => false,
  211. 'mailNotificationEnabled' => 'no',
  212. 'mailPublicNotificationEnabled' => 'no',
  213. 'allowShareWithLink' => 'yes',
  214. 'appNavigation' => $nav,
  215. 'appContents' => [
  216. 0 => [
  217. 'id' => 'files',
  218. 'content' => null,
  219. ],
  220. 1 => [
  221. 'id' => 'favorites',
  222. 'content' => null,
  223. ],
  224. 2 => [
  225. 'id' => 'systemtagsfilter',
  226. 'content' => null,
  227. ],
  228. 3 => [
  229. 'id' => 'sharingin',
  230. 'content' => null,
  231. ],
  232. 4 => [
  233. 'id' => 'sharingout',
  234. 'content' => null,
  235. ],
  236. 5 => [
  237. 'id' => 'sharinglinks',
  238. 'content' => null,
  239. ],
  240. 6 => [
  241. 'id' => 'trashbin',
  242. 'content' => null,
  243. ],
  244. ],
  245. ]
  246. );
  247. $policy = new Http\ContentSecurityPolicy();
  248. $policy->addAllowedFrameDomain('\'self\'');
  249. $expected->setContentSecurityPolicy($policy);
  250. $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
  251. }
  252. }