aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/OCS/ApiHelperTest.php
blob: fdbc1f4c53890d600a9a2b5d8f080618bf69c50f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace Test\OCS;

use OC\OCS\ApiHelper;
use OCP\IRequest;

class ApiHelperTest extends \Test\TestCase {
	/**
	 * @return array
	 */
	public function versionDataScriptNameProvider(): array {
		return [
			// Valid script name
			[
				'/master/ocs/v2.php', true,
			],

			// Invalid script names
			[
				'/master/ocs/v2.php/someInvalidPathName', false,
			],
			[
				'/master/ocs/v1.php', false,
			],
			[
				'', false,
			],
		];
	}

	/**
	 * @dataProvider versionDataScriptNameProvider
	 */
	public function testIsV2(string $scriptName, bool $expected): void {
		$request = $this->getMockBuilder(IRequest::class)
			->disableOriginalConstructor()
			->getMock();
		$request
			->expects($this->once())
			->method('getScriptName')
			->willReturn($scriptName);

		$this->assertEquals($expected, $this->invokePrivate(new ApiHelper, 'isV2', [$request]));
	}
}