AuthMechanismTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_External\Tests\Auth;
  23. class AuthMechanismTest extends \Test\TestCase {
  24. public function testJsonSerialization() {
  25. $mechanism = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
  26. ->setMethods(['jsonSerializeDefinition'])
  27. ->getMock();
  28. $mechanism->expects($this->once())
  29. ->method('jsonSerializeDefinition')
  30. ->willReturn(['foo' => 'bar']);
  31. $mechanism->setScheme('scheme');
  32. $json = $mechanism->jsonSerialize();
  33. $this->assertEquals('bar', $json['foo']);
  34. $this->assertEquals('scheme', $json['scheme']);
  35. }
  36. public function validateStorageProvider() {
  37. return [
  38. [true, 'scheme', true],
  39. [false, 'scheme', false],
  40. [true, 'foobar', true],
  41. [false, 'barfoo', true],
  42. ];
  43. }
  44. /**
  45. * @dataProvider validateStorageProvider
  46. */
  47. public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) {
  48. $mechanism = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism')
  49. ->setMethods(['validateStorageDefinition'])
  50. ->getMock();
  51. $mechanism->expects($this->atMost(1))
  52. ->method('validateStorageDefinition')
  53. ->willReturn($definitionSuccess);
  54. $mechanism->setScheme($scheme);
  55. $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend')
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $backend->expects($this->once())
  59. ->method('getAuthSchemes')
  60. ->willReturn(['scheme' => true, 'foobar' => true]);
  61. $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig')
  62. ->disableOriginalConstructor()
  63. ->getMock();
  64. $storageConfig->expects($this->once())
  65. ->method('getBackend')
  66. ->willReturn($backend);
  67. $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig));
  68. }
  69. }