ListCommandTest.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@owncloud.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  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, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Files_External\Tests\Command;
  27. use OCA\Files_External\Command\ListCommand;
  28. use OCA\Files_External\Lib\Auth\NullMechanism;
  29. use OCA\Files_External\Lib\Auth\Password\Password;
  30. use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
  31. use OCA\Files_External\Lib\Backend\Local;
  32. use OCA\Files_External\Lib\StorageConfig;
  33. use OCA\Files_External\Service\GlobalStoragesService;
  34. use OCA\Files_External\Service\UserStoragesService;
  35. use OCP\Authentication\LoginCredentials\IStore;
  36. use OCP\IL10N;
  37. use OCP\ISession;
  38. use OCP\IUserManager;
  39. use OCP\IUserSession;
  40. use OCP\Security\ICrypto;
  41. use PHPUnit_Framework_MockObject_MockObject;
  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. }