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 1642e66c7aSAndreas Gohr * @something else 1742e66c7aSAndreas Gohr * @something other 1842e66c7aSAndreas Gohr * @another tag 1942e66c7aSAndreas Gohr * @return string The return 2042e66c7aSAndreas Gohr */ 2142e66c7aSAndreas Gohr public function dummyMethod1($foo, $bar) 2242e66c7aSAndreas Gohr { 2342e66c7aSAndreas Gohr return 'dummy'; 2442e66c7aSAndreas Gohr } 2542e66c7aSAndreas Gohr 2642e66c7aSAndreas Gohr public function testMethodDocBlock() 2742e66c7aSAndreas Gohr { 2842e66c7aSAndreas Gohr $call = new ApiCall([$this, 'dummyMethod1']); 2942e66c7aSAndreas Gohr 3042e66c7aSAndreas Gohr $this->assertEquals('This is a test', $call->getSummary()); 3142e66c7aSAndreas Gohr $this->assertEquals("With more information\nin several lines", $call->getDescription()); 3242e66c7aSAndreas Gohr 3342e66c7aSAndreas Gohr $this->assertEquals( 3442e66c7aSAndreas Gohr [ 3542e66c7aSAndreas Gohr 'foo' => [ 3642e66c7aSAndreas Gohr 'type' => 'string', 3742e66c7aSAndreas Gohr 'description' => 'First variable', 3842e66c7aSAndreas Gohr ], 3942e66c7aSAndreas Gohr 'bar' => [ 4042e66c7aSAndreas Gohr 'type' => 'int', 4142e66c7aSAndreas Gohr 'description' => '', 4242e66c7aSAndreas Gohr ] 4342e66c7aSAndreas Gohr ], 4442e66c7aSAndreas Gohr $call->getArgs() 4542e66c7aSAndreas Gohr ); 4642e66c7aSAndreas Gohr 4742e66c7aSAndreas Gohr $this->assertEquals( 4842e66c7aSAndreas Gohr [ 4942e66c7aSAndreas Gohr 'type' => 'string', 5042e66c7aSAndreas Gohr 'description' => 'The return' 5142e66c7aSAndreas Gohr ], 5242e66c7aSAndreas Gohr $call->getReturn() 5342e66c7aSAndreas Gohr ); 5442e66c7aSAndreas Gohr 5542e66c7aSAndreas Gohr // remove one parameter 5642e66c7aSAndreas Gohr $call->limitArgs(['foo']); 5742e66c7aSAndreas Gohr $this->assertEquals( 5842e66c7aSAndreas Gohr [ 5942e66c7aSAndreas Gohr 'foo' => [ 6042e66c7aSAndreas Gohr 'type' => 'string', 6142e66c7aSAndreas Gohr 'description' => 'First variable', 6242e66c7aSAndreas Gohr ], 6342e66c7aSAndreas Gohr ], 6442e66c7aSAndreas Gohr $call->getArgs() 6542e66c7aSAndreas Gohr ); 6642e66c7aSAndreas Gohr } 6742e66c7aSAndreas Gohr 6842e66c7aSAndreas Gohr public function testFunctionDocBlock() 6942e66c7aSAndreas Gohr { 70*5b379b50SAndreas Gohr $call = new ApiCall('inlineSVG'); 71*5b379b50SAndreas Gohr $call->setArgDescription('file', 'overwritten description'); 7242e66c7aSAndreas Gohr 7342e66c7aSAndreas Gohr $this->assertEquals( 7442e66c7aSAndreas Gohr [ 75*5b379b50SAndreas Gohr 'file' => [ 7642e66c7aSAndreas Gohr 'type' => 'string', 77*5b379b50SAndreas Gohr 'description' => 'overwritten description', 7842e66c7aSAndreas Gohr ], 79*5b379b50SAndreas Gohr 'maxsize' => [ 8042e66c7aSAndreas Gohr 'type' => 'int', 81*5b379b50SAndreas Gohr 'description' => 'maximum allowed size for the SVG to be embedded', 8242e66c7aSAndreas Gohr ] 8342e66c7aSAndreas Gohr ], 8442e66c7aSAndreas Gohr $call->getArgs() 8542e66c7aSAndreas Gohr ); 8642e66c7aSAndreas Gohr } 8742e66c7aSAndreas Gohr 8842e66c7aSAndreas Gohr public function testExecution() 8942e66c7aSAndreas Gohr { 9042e66c7aSAndreas Gohr $call = new ApiCall([$this, 'dummyMethod1']); 9142e66c7aSAndreas Gohr $this->assertEquals('dummy', $call(['bar', 1]), 'positional parameters'); 9242e66c7aSAndreas Gohr $this->assertEquals('dummy', $call(['foo' => 'bar', 'bar' => 1]), 'named parameters'); 9342e66c7aSAndreas Gohr 9442e66c7aSAndreas Gohr $call = new ApiCall('date'); 9542e66c7aSAndreas Gohr $this->assertEquals('2023-11-30', $call(['Y-m-d', 1701356591]), 'positional parameters'); 9642e66c7aSAndreas Gohr $this->assertEquals('2023-11-30', $call(['format' => 'Y-m-d', 'timestamp' => 1701356591]), 'named parameters'); 9742e66c7aSAndreas Gohr } 9842e66c7aSAndreas Gohr} 99