1
0

APITest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Tom Needham <tom@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. use OCP\IRequest;
  10. class APITest extends \Test\TestCase {
  11. // Helps build a response variable
  12. /**
  13. * @param string $message
  14. */
  15. public function buildResponse($shipped, $data, $code, $message = null) {
  16. $resp = new \OC\OCS\Result($data, $code, $message);
  17. $resp->addHeader('KEY', 'VALUE');
  18. return [
  19. 'shipped' => $shipped,
  20. 'response' => $resp,
  21. 'app' => $this->getUniqueID('testapp_'),
  22. ];
  23. }
  24. // Validate details of the result
  25. /**
  26. * @param \OC\OCS\Result $result
  27. */
  28. public function checkResult($result, $success) {
  29. // Check response is of correct type
  30. $this->assertInstanceOf(\OC\OCS\Result::class, $result);
  31. // Check if it succeeded
  32. /** @var $result \OC\OCS\Result */
  33. $this->assertEquals($success, $result->succeeded());
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function versionDataScriptNameProvider() {
  39. return [
  40. // Valid script name
  41. [
  42. '/master/ocs/v2.php',
  43. true,
  44. ],
  45. // Invalid script names
  46. [
  47. '/master/ocs/v2.php/someInvalidPathName',
  48. false,
  49. ],
  50. [
  51. '/master/ocs/v1.php',
  52. false,
  53. ],
  54. [
  55. '',
  56. false,
  57. ],
  58. ];
  59. }
  60. /**
  61. * @dataProvider versionDataScriptNameProvider
  62. * @param string $scriptName
  63. * @param bool $expected
  64. */
  65. public function testIsV2($scriptName, $expected) {
  66. $request = $this->getMockBuilder(IRequest::class)
  67. ->disableOriginalConstructor()
  68. ->getMock();
  69. $request
  70. ->expects($this->once())
  71. ->method('getScriptName')
  72. ->willReturn($scriptName);
  73. $this->assertEquals($expected, $this->invokePrivate(new \OC_API, 'isV2', [$request]));
  74. }
  75. }