1
0

ApiHelperTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-or-later
  7. */
  8. namespace Test\OCS;
  9. use OC\OCS\ApiHelper;
  10. use OCP\IRequest;
  11. class ApiHelperTest extends \Test\TestCase {
  12. /**
  13. * @return array
  14. */
  15. public function versionDataScriptNameProvider(): array {
  16. return [
  17. // Valid script name
  18. [
  19. '/master/ocs/v2.php', true,
  20. ],
  21. // Invalid script names
  22. [
  23. '/master/ocs/v2.php/someInvalidPathName', false,
  24. ],
  25. [
  26. '/master/ocs/v1.php', false,
  27. ],
  28. [
  29. '', false,
  30. ],
  31. ];
  32. }
  33. /**
  34. * @dataProvider versionDataScriptNameProvider
  35. */
  36. public function testIsV2(string $scriptName, bool $expected): void {
  37. $request = $this->getMockBuilder(IRequest::class)
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. $request
  41. ->expects($this->once())
  42. ->method('getScriptName')
  43. ->willReturn($scriptName);
  44. $this->assertEquals($expected, $this->invokePrivate(new ApiHelper, 'isV2', [$request]));
  45. }
  46. }