LegacyBackendTest.php 4.6 KB

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