You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.0 KiB

9 years ago
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Robin McCorkell <robin@mccorkell.me.uk>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_External\Tests;
  25. use OCA\Files_External\Lib\DefinitionParameter as Param;
  26. class DefinitionParameterTest extends \Test\TestCase {
  27. public function testJsonSerialization() {
  28. $param = new Param('foo', 'bar');
  29. $this->assertEquals([
  30. 'value' => 'bar',
  31. 'flags' => 0,
  32. 'type' => 0,
  33. 'tooltip' => '',
  34. ], $param->jsonSerialize());
  35. $param->setType(Param::VALUE_BOOLEAN);
  36. $param->setDefaultValue(true);
  37. $this->assertEquals([
  38. 'value' => 'bar',
  39. 'flags' => 0,
  40. 'type' => Param::VALUE_BOOLEAN,
  41. 'tooltip' => '',
  42. 'defaultValue' => true,
  43. ], $param->jsonSerialize());
  44. $param->setType(Param::VALUE_PASSWORD);
  45. $param->setFlag(Param::FLAG_OPTIONAL);
  46. $this->assertEquals([
  47. 'value' => 'bar',
  48. 'flags' => Param::FLAG_OPTIONAL,
  49. 'type' => Param::VALUE_PASSWORD,
  50. 'tooltip' => '',
  51. ], $param->jsonSerialize());
  52. $param->setType(Param::VALUE_HIDDEN);
  53. $param->setFlags(Param::FLAG_NONE);
  54. $this->assertEquals([
  55. 'value' => 'bar',
  56. 'flags' => Param::FLAG_NONE,
  57. 'type' => Param::VALUE_HIDDEN,
  58. 'tooltip' => '',
  59. ], $param->jsonSerialize());
  60. }
  61. public function validateValueProvider() {
  62. return [
  63. [Param::VALUE_TEXT, Param::FLAG_NONE, 'abc', true],
  64. [Param::VALUE_TEXT, Param::FLAG_NONE, '', false],
  65. [Param::VALUE_TEXT, Param::FLAG_OPTIONAL, '', true],
  66. [Param::VALUE_BOOLEAN, Param::FLAG_NONE, false, true],
  67. [Param::VALUE_BOOLEAN, Param::FLAG_NONE, 123, false],
  68. // conversion from string to boolean
  69. [Param::VALUE_BOOLEAN, Param::FLAG_NONE, 'false', true, false],
  70. [Param::VALUE_BOOLEAN, Param::FLAG_NONE, 'true', true, true],
  71. [Param::VALUE_PASSWORD, Param::FLAG_NONE, 'foobar', true],
  72. [Param::VALUE_PASSWORD, Param::FLAG_NONE, '', false],
  73. [Param::VALUE_HIDDEN, Param::FLAG_NONE, '', false]
  74. ];
  75. }
  76. /**
  77. * @dataProvider validateValueProvider
  78. */
  79. public function testValidateValue($type, $flags, $value, $success, $expectedValue = null) {
  80. $param = new Param('foo', 'bar');
  81. $param->setType($type);
  82. $param->setFlags($flags);
  83. $this->assertEquals($success, $param->validateValue($value));
  84. if (isset($expectedValue)) {
  85. $this->assertEquals($expectedValue, $value);
  86. }
  87. }
  88. }