ListCommandTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_External\Tests\Command;
  28. use OCA\Files_External\Command\ListCommand;
  29. use OCA\Files_External\Lib\Auth\NullMechanism;
  30. use OCA\Files_External\Lib\Auth\Password\Password;
  31. use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
  32. use OCA\Files_External\Lib\Backend\Local;
  33. use OCA\Files_External\Lib\StorageConfig;
  34. use OCA\Files_External\Service\GlobalStoragesService;
  35. use OCA\Files_External\Service\UserStoragesService;
  36. use OCP\Authentication\LoginCredentials\IStore;
  37. use OCP\IL10N;
  38. use OCP\ISession;
  39. use OCP\IUserManager;
  40. use OCP\IUserSession;
  41. use OCP\Security\ICrypto;
  42. use Symfony\Component\Console\Output\BufferedOutput;
  43. class ListCommandTest extends CommandTest {
  44. /**
  45. * @return ListCommand|\PHPUnit\Framework\MockObject\MockObject
  46. */
  47. private function getInstance() {
  48. /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject $globalService */
  49. $globalService = $this->createMock(GlobalStoragesService::class);
  50. /** @var UserStoragesService|\PHPUnit\Framework\MockObject\MockObject $userService */
  51. $userService = $this->createMock(UserStoragesService::class);
  52. /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
  53. $userManager = $this->createMock(IUserManager::class);
  54. /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
  55. $userSession = $this->createMock(IUserSession::class);
  56. return new ListCommand($globalService, $userService, $userSession, $userManager);
  57. }
  58. public function testListAuthIdentifier() {
  59. $l10n = $this->createMock(IL10N::class);
  60. $session = $this->createMock(ISession::class);
  61. $crypto = $this->createMock(ICrypto::class);
  62. $instance = $this->getInstance();
  63. $mount1 = new StorageConfig();
  64. $mount1->setAuthMechanism(new Password($l10n));
  65. $mount1->setBackend(new Local($l10n, new NullMechanism($l10n)));
  66. $mount2 = new StorageConfig();
  67. $credentialStore = $this->createMock(IStore::class);
  68. $mount2->setAuthMechanism(new SessionCredentials($l10n, $credentialStore));
  69. $mount2->setBackend(new Local($l10n, new NullMechanism($l10n)));
  70. $input = $this->getInput($instance, [], [
  71. 'output' => 'json'
  72. ]);
  73. $output = new BufferedOutput();
  74. $instance->listMounts('', [$mount1, $mount2], $input, $output);
  75. $output = json_decode($output->fetch(), true);
  76. $this->assertNotEquals($output[0]['authentication_type'], $output[1]['authentication_type']);
  77. }
  78. }