1
0

UserPlaceholderHandlerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\files_external\tests\Config;
  27. use OCA\Files_External\Config\UserPlaceholderHandler;
  28. use OCP\IRequest;
  29. use OCP\IUser;
  30. use OCP\IUserManager;
  31. use OCP\IUserSession;
  32. use OCP\Share\Exceptions\ShareNotFound;
  33. use OCP\Share\IManager;
  34. class UserPlaceholderHandlerTest extends \Test\TestCase {
  35. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  36. protected $user;
  37. /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
  38. protected $session;
  39. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  40. private $shareManager;
  41. /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
  42. private $request;
  43. /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
  44. private $userManager;
  45. /** @var UserPlaceholderHandler */
  46. protected $handler;
  47. protected function setUp(): void {
  48. parent::setUp();
  49. $this->user = $this->createMock(IUser::class);
  50. $this->user->expects($this->any())
  51. ->method('getUid')
  52. ->willReturn('alice');
  53. $this->session = $this->createMock(IUserSession::class);
  54. $this->shareManager = $this->createMock(IManager::class);
  55. $this->request = $this->createMock(IRequest::class);
  56. $this->userManager = $this->createMock(IUserManager::class);
  57. $this->handler = new UserPlaceholderHandler($this->session, $this->shareManager, $this->request, $this->userManager);
  58. }
  59. protected function setUser() {
  60. $this->session->expects($this->any())
  61. ->method('getUser')
  62. ->willReturn($this->user);
  63. }
  64. public function optionProvider() {
  65. return [
  66. ['/foo/bar/$user/foobar', '/foo/bar/alice/foobar'],
  67. [['/foo/bar/$user/foobar'], ['/foo/bar/alice/foobar']],
  68. [['/FOO/BAR/$USER/FOOBAR'], ['/FOO/BAR/alice/FOOBAR']],
  69. ];
  70. }
  71. /**
  72. * @dataProvider optionProvider
  73. */
  74. public function testHandle($option, $expected) {
  75. $this->setUser();
  76. $this->assertSame($expected, $this->handler->handle($option));
  77. }
  78. /**
  79. * @dataProvider optionProvider
  80. */
  81. public function testHandleNoUser($option) {
  82. $this->shareManager->expects($this->once())
  83. ->method('getShareByToken')
  84. ->willThrowException(new ShareNotFound());
  85. $this->assertSame($option, $this->handler->handle($option));
  86. }
  87. }