AuthMechanismTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin McCorkell <robin@mccorkell.me.uk>
  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\Auth;
  24. use OCA\Files_External\Lib\Auth\AuthMechanism;
  25. use OCA\Files_External\Lib\Backend\Backend;
  26. use OCA\Files_External\Lib\StorageConfig;
  27. class AuthMechanismTest extends \Test\TestCase {
  28. public function testJsonSerialization() {
  29. $mechanism = $this->getMockBuilder(AuthMechanism::class)
  30. ->setMethods(['jsonSerializeDefinition'])
  31. ->getMock();
  32. $mechanism->expects($this->once())
  33. ->method('jsonSerializeDefinition')
  34. ->willReturn(['foo' => 'bar']);
  35. $mechanism->setScheme('scheme');
  36. $json = $mechanism->jsonSerialize();
  37. $this->assertEquals('bar', $json['foo']);
  38. $this->assertEquals('scheme', $json['scheme']);
  39. }
  40. public function validateStorageProvider() {
  41. return [
  42. [true, 'scheme', true],
  43. [false, 'scheme', false],
  44. [true, 'foobar', true],
  45. [false, 'barfoo', true],
  46. ];
  47. }
  48. /**
  49. * @dataProvider validateStorageProvider
  50. */
  51. public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) {
  52. $mechanism = $this->getMockBuilder(AuthMechanism::class)
  53. ->setMethods(['validateStorageDefinition'])
  54. ->getMock();
  55. $mechanism->expects($this->atMost(1))
  56. ->method('validateStorageDefinition')
  57. ->willReturn($definitionSuccess);
  58. $mechanism->setScheme($scheme);
  59. $backend = $this->getMockBuilder(Backend::class)
  60. ->disableOriginalConstructor()
  61. ->getMock();
  62. $backend->expects($this->once())
  63. ->method('getAuthSchemes')
  64. ->willReturn(['scheme' => true, 'foobar' => true]);
  65. $storageConfig = $this->getMockBuilder(StorageConfig::class)
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $storageConfig->expects($this->once())
  69. ->method('getBackend')
  70. ->willReturn($backend);
  71. $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig));
  72. }
  73. }