ValidatorTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\RichObjectStrings;
  7. use OC\RichObjectStrings\Validator;
  8. use OCP\RichObjectStrings\Definitions;
  9. use OCP\RichObjectStrings\InvalidObjectExeption;
  10. use Test\TestCase;
  11. class ValidatorTest extends TestCase {
  12. public function test(): void {
  13. $v = new Validator(new Definitions());
  14. $v->validate('test', []);
  15. $v->validate('test {string1} test {foo} test {bar}.', [
  16. 'string1' => [
  17. 'type' => 'user',
  18. 'id' => 'johndoe',
  19. 'name' => 'John Doe',
  20. ],
  21. 'foo' => [
  22. 'type' => 'user-group',
  23. 'id' => 'sample',
  24. 'name' => 'Sample Group',
  25. ],
  26. 'bar' => [
  27. 'type' => 'file',
  28. 'id' => '42',
  29. 'name' => 'test.txt',
  30. 'path' => 'path/to/test.txt',
  31. ],
  32. ]);
  33. $this->addToAssertionCount(2);
  34. $this->expectException(InvalidObjectExeption::class);
  35. $this->expectExceptionMessage('Object is invalid, value 123 is not a string');
  36. $v->validate('test {string1} test.', [
  37. 'string1' => [
  38. 'type' => 'user',
  39. 'id' => 'johndoe',
  40. 'name' => 'John Doe',
  41. 'key' => 123,
  42. ],
  43. ]);
  44. $this->expectExceptionMessage('Object is invalid, key 456 is not a string');
  45. $v->validate('test {string1} test.', [
  46. 'string1' => [
  47. 'type' => 'user',
  48. 'id' => 'johndoe',
  49. 'name' => 'John Doe',
  50. 456 => 'value',
  51. ],
  52. ]);
  53. }
  54. }