ListCommandTest.php 3.2 KB

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