142e66c7aSAndreas Gohr<?php 242e66c7aSAndreas Gohr 342e66c7aSAndreas Gohrnamespace dokuwiki\test\Remote; 442e66c7aSAndreas Gohr 542e66c7aSAndreas Gohruse dokuwiki\Remote\ApiCall; 642e66c7aSAndreas Gohr 742e66c7aSAndreas Gohrclass ApiCallTest extends \DokuWikiTest 842e66c7aSAndreas Gohr{ 942e66c7aSAndreas Gohr /** 1042e66c7aSAndreas Gohr * This is a test 1142e66c7aSAndreas Gohr * 1242e66c7aSAndreas Gohr * With more information 1342e66c7aSAndreas Gohr * in several lines 1442e66c7aSAndreas Gohr * @param string $foo First variable 1542e66c7aSAndreas Gohr * @param int $bar 16*b05603abSAndreas Gohr * @param string[] $baz 1742e66c7aSAndreas Gohr * @something else 1842e66c7aSAndreas Gohr * @something other 1942e66c7aSAndreas Gohr * @another tag 2042e66c7aSAndreas Gohr * @return string The return 2142e66c7aSAndreas Gohr */ 22*b05603abSAndreas Gohr public function dummyMethod1($foo, $bar, $baz) 2342e66c7aSAndreas Gohr { 2442e66c7aSAndreas Gohr return 'dummy'; 2542e66c7aSAndreas Gohr } 2642e66c7aSAndreas Gohr 2742e66c7aSAndreas Gohr public function testMethodDocBlock() 2842e66c7aSAndreas Gohr { 2942e66c7aSAndreas Gohr $call = new ApiCall([$this, 'dummyMethod1']); 3042e66c7aSAndreas Gohr 3142e66c7aSAndreas Gohr $this->assertEquals('This is a test', $call->getSummary()); 3242e66c7aSAndreas Gohr $this->assertEquals("With more information\nin several lines", $call->getDescription()); 3342e66c7aSAndreas Gohr 3442e66c7aSAndreas Gohr $this->assertEquals( 3542e66c7aSAndreas Gohr [ 3642e66c7aSAndreas Gohr 'foo' => [ 3742e66c7aSAndreas Gohr 'type' => 'string', 3842e66c7aSAndreas Gohr 'description' => 'First variable', 3942e66c7aSAndreas Gohr ], 4042e66c7aSAndreas Gohr 'bar' => [ 4142e66c7aSAndreas Gohr 'type' => 'int', 4242e66c7aSAndreas Gohr 'description' => '', 43*b05603abSAndreas Gohr ], 44*b05603abSAndreas Gohr 'baz' => [ 45*b05603abSAndreas Gohr 'type' => 'array', 46*b05603abSAndreas Gohr 'description' => '', 47*b05603abSAndreas Gohr ], 4842e66c7aSAndreas Gohr ], 4942e66c7aSAndreas Gohr $call->getArgs() 5042e66c7aSAndreas Gohr ); 5142e66c7aSAndreas Gohr 5242e66c7aSAndreas Gohr $this->assertEquals( 5342e66c7aSAndreas Gohr [ 5442e66c7aSAndreas Gohr 'type' => 'string', 5542e66c7aSAndreas Gohr 'description' => 'The return' 5642e66c7aSAndreas Gohr ], 5742e66c7aSAndreas Gohr $call->getReturn() 5842e66c7aSAndreas Gohr ); 5942e66c7aSAndreas Gohr 6042e66c7aSAndreas Gohr // remove one parameter 6142e66c7aSAndreas Gohr $call->limitArgs(['foo']); 6242e66c7aSAndreas Gohr $this->assertEquals( 6342e66c7aSAndreas Gohr [ 6442e66c7aSAndreas Gohr 'foo' => [ 6542e66c7aSAndreas Gohr 'type' => 'string', 6642e66c7aSAndreas Gohr 'description' => 'First variable', 6742e66c7aSAndreas Gohr ], 6842e66c7aSAndreas Gohr ], 6942e66c7aSAndreas Gohr $call->getArgs() 7042e66c7aSAndreas Gohr ); 7142e66c7aSAndreas Gohr } 7242e66c7aSAndreas Gohr 7342e66c7aSAndreas Gohr public function testFunctionDocBlock() 7442e66c7aSAndreas Gohr { 755b379b50SAndreas Gohr $call = new ApiCall('inlineSVG'); 765b379b50SAndreas Gohr $call->setArgDescription('file', 'overwritten description'); 7742e66c7aSAndreas Gohr 7842e66c7aSAndreas Gohr $this->assertEquals( 7942e66c7aSAndreas Gohr [ 805b379b50SAndreas Gohr 'file' => [ 8142e66c7aSAndreas Gohr 'type' => 'string', 825b379b50SAndreas Gohr 'description' => 'overwritten description', 8342e66c7aSAndreas Gohr ], 845b379b50SAndreas Gohr 'maxsize' => [ 8542e66c7aSAndreas Gohr 'type' => 'int', 865b379b50SAndreas Gohr 'description' => 'maximum allowed size for the SVG to be embedded', 8742e66c7aSAndreas Gohr ] 8842e66c7aSAndreas Gohr ], 8942e66c7aSAndreas Gohr $call->getArgs() 9042e66c7aSAndreas Gohr ); 9142e66c7aSAndreas Gohr } 9242e66c7aSAndreas Gohr 9342e66c7aSAndreas Gohr public function testExecution() 9442e66c7aSAndreas Gohr { 9542e66c7aSAndreas Gohr $call = new ApiCall([$this, 'dummyMethod1']); 9642e66c7aSAndreas Gohr $this->assertEquals('dummy', $call(['bar', 1]), 'positional parameters'); 9742e66c7aSAndreas Gohr $this->assertEquals('dummy', $call(['foo' => 'bar', 'bar' => 1]), 'named parameters'); 9842e66c7aSAndreas Gohr 9942e66c7aSAndreas Gohr $call = new ApiCall('date'); 10042e66c7aSAndreas Gohr $this->assertEquals('2023-11-30', $call(['Y-m-d', 1701356591]), 'positional parameters'); 10142e66c7aSAndreas Gohr $this->assertEquals('2023-11-30', $call(['format' => 'Y-m-d', 'timestamp' => 1701356591]), 'named parameters'); 10242e66c7aSAndreas Gohr } 10342e66c7aSAndreas Gohr} 104