LegacyBackendTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. * @author Roeland Jago Douma <roeland@famdouma.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\Backend;
  24. use OCA\Files_External\Lib\Backend\LegacyBackend;
  25. use OCA\Files_External\Lib\DefinitionParameter;
  26. use OCA\Files_External\Lib\MissingDependency;
  27. class LegacyBackendTest extends \Test\TestCase {
  28. /**
  29. * @return MissingDependency[]
  30. */
  31. public static function checkDependencies() {
  32. return [
  33. (new MissingDependency('abc'))->setMessage('foobar')
  34. ];
  35. }
  36. public function testConstructor() {
  37. $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
  41. $definition = [
  42. 'configuration' => [
  43. 'textfield' => 'Text field',
  44. 'passwordfield' => '*Password field',
  45. 'checkbox' => '!Checkbox',
  46. 'hiddenfield' => '#Hidden field',
  47. 'optionaltext' => '&Optional text field',
  48. 'optionalpassword' => '&*Optional password field',
  49. ],
  50. 'backend' => 'Backend text',
  51. 'priority' => 123,
  52. 'custom' => 'foo/bar.js',
  53. 'has_dependencies' => true,
  54. ];
  55. $backend = new LegacyBackend($class, $definition, $auth);
  56. $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
  57. $this->assertEquals('Backend text', $backend->getText());
  58. $this->assertEquals(123, $backend->getPriority());
  59. $this->assertContains('foo/bar.js', $backend->getCustomJs());
  60. $this->assertArrayHasKey('builtin', $backend->getAuthSchemes());
  61. $this->assertEquals($auth, $backend->getLegacyAuthMechanism());
  62. $dependencies = $backend->checkDependencies();
  63. $this->assertCount(1, $dependencies);
  64. $this->assertEquals('abc', $dependencies[0]->getDependency());
  65. $this->assertEquals('foobar', $dependencies[0]->getMessage());
  66. $parameters = $backend->getParameters();
  67. $this->assertEquals('Text field', $parameters['textfield']->getText());
  68. $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['textfield']->getType());
  69. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['textfield']->getFlags());
  70. $this->assertEquals('Password field', $parameters['passwordfield']->getText());
  71. $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['passwordfield']->getType());
  72. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['passwordfield']->getFlags());
  73. $this->assertEquals('Checkbox', $parameters['checkbox']->getText());
  74. $this->assertEquals(DefinitionParameter::VALUE_BOOLEAN, $parameters['checkbox']->getType());
  75. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['checkbox']->getFlags());
  76. $this->assertEquals('Hidden field', $parameters['hiddenfield']->getText());
  77. $this->assertEquals(DefinitionParameter::VALUE_HIDDEN, $parameters['hiddenfield']->getType());
  78. $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['hiddenfield']->getFlags());
  79. $this->assertEquals('Optional text field', $parameters['optionaltext']->getText());
  80. $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['optionaltext']->getType());
  81. $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionaltext']->getFlags());
  82. $this->assertEquals('Optional password field', $parameters['optionalpassword']->getText());
  83. $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['optionalpassword']->getType());
  84. $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionalpassword']->getFlags());
  85. }
  86. public function testNoDependencies() {
  87. $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin')
  88. ->disableOriginalConstructor()
  89. ->getMock();
  90. $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest';
  91. $definition = [
  92. 'configuration' => [
  93. ],
  94. 'backend' => 'Backend text',
  95. ];
  96. $backend = new LegacyBackend($class, $definition, $auth);
  97. $dependencies = $backend->checkDependencies();
  98. $this->assertCount(0, $dependencies);
  99. }
  100. }