1
0

LegacyBackendTest.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Tests\Backend;
  8. use OCA\Files_External\Lib\Backend\LegacyBackend;
  9. use OCA\Files_External\Lib\DefinitionParameter;
  10. use OCA\Files_External\Lib\MissingDependency;
  11. class LegacyBackendTest extends \Test\TestCase {
  12. /**
  13. * @return MissingDependency[]
  14. */
  15. public static function checkDependencies() {
  16. return [
  17. (new MissingDependency('abc'))->setMessage('foobar')
  18. ];
  19. }
  20. public function testConstructor(): void {
  21. $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
  22. ->disableOriginalConstructor()
  23. ->getMock();
  24. $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
  25. $definition = [
  26. 'configuration' => [
  27. 'textfield' => 'Text field',
  28. 'passwordfield' => '*Password field',
  29. 'checkbox' => '!Checkbox',
  30. 'hiddenfield' => '#Hidden field',
  31. 'optionaltext' => '&Optional text field',
  32. 'optionalpassword' => '&*Optional password field',
  33. ],
  34. 'backend' => 'Backend text',
  35. 'priority' => 123,
  36. 'custom' => 'foo/bar.js',
  37. 'has_dependencies' => true,
  38. ];
  39. $backend = new LegacyBackend($class, $definition, $auth);
  40. $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
  41. $this->assertEquals('Backend text', $backend->getText());
  42. $this->assertEquals(123, $backend->getPriority());
  43. $this->assertContains('foo/bar.js', $backend->getCustomJs());
  44. $this->assertArrayHasKey('builtin', $backend->getAuthSchemes());
  45. $this->assertEquals($auth, $backend->getLegacyAuthMechanism());
  46. $dependencies = $backend->checkDependencies();
  47. $this->assertCount(1, $dependencies);
  48. $this->assertEquals('abc', $dependencies[0]->getDependency());
  49. $this->assertEquals('foobar', $dependencies[0]->getMessage());
  50. $parameters = $backend->getParameters();
  51. $this->assertEquals('Text field', $parameters['textfield']->getText());
  52. $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['textfield']->getType());
  53. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['textfield']->getFlags());
  54. $this->assertEquals('Password field', $parameters['passwordfield']->getText());
  55. $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['passwordfield']->getType());
  56. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['passwordfield']->getFlags());
  57. $this->assertEquals('Checkbox', $parameters['checkbox']->getText());
  58. $this->assertEquals(DefinitionParameter::VALUE_BOOLEAN, $parameters['checkbox']->getType());
  59. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['checkbox']->getFlags());
  60. $this->assertEquals('Hidden field', $parameters['hiddenfield']->getText());
  61. $this->assertEquals(DefinitionParameter::VALUE_HIDDEN, $parameters['hiddenfield']->getType());
  62. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['hiddenfield']->getFlags());
  63. $this->assertEquals('Optional text field', $parameters['optionaltext']->getText());
  64. $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['optionaltext']->getType());
  65. $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionaltext']->getFlags());
  66. $this->assertEquals('Optional password field', $parameters['optionalpassword']->getText());
  67. $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['optionalpassword']->getType());
  68. $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionalpassword']->getFlags());
  69. }
  70. public function testNoDependencies(): void {
  71. $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
  75. $definition = [
  76. 'configuration' => [
  77. ],
  78. 'backend' => 'Backend text',
  79. ];
  80. $backend = new LegacyBackend($class, $definition, $auth);
  81. $dependencies = $backend->checkDependencies();
  82. $this->assertCount(0, $dependencies);
  83. }
  84. }