Skip to content
Snippets Groups Projects
Commit 4f026048 authored by Stein Magne Bjorklund's avatar Stein Magne Bjorklund
Browse files

Make ServiceModuleTest pass

- Make sure Utils::queryFile called from Utils also pass in loadspk settings
since global call is removed.
- Improve ServiceModule guards. Make sure it correctly returns false early.
parent 42470d90
No related branches found
No related tags found
1 merge request!18Resolve "Remove all use of GLOBALS"
...@@ -498,9 +498,9 @@ final class Utils ...@@ -498,9 +498,9 @@ final class Utils
$f[$strippedModelDir] = array(); $f[$strippedModelDir] = array();
} }
Utils::queryFile($modelFile, $e, $r[$strippedModelDir], $f); Utils::queryFile($modelFile, $e, $r[$strippedModelDir], $f, $lodspk);
} else { } else {
Utils::queryFile($modelFile, $e, $r, $f); Utils::queryFile($modelFile, $e, $r, $f, $lodspk);
} }
} }
} }
......
...@@ -98,16 +98,19 @@ final class ServiceModule implements ModuleInterface ...@@ -98,16 +98,19 @@ final class ServiceModule implements ModuleInterface
$lodspk = $this->configuration->getConfigValue('bootstrap', 'lodspk'); $lodspk = $this->configuration->getConfigValue('bootstrap', 'lodspk');
$q = preg_replace('|^' . $conf['basedir'] . '|', '', $localUri); $q = preg_replace('|^' . $conf['basedir'] . '|', '', $localUri);
$qArr = explode('/', $q);
if (sizeof($qArr) == 0) { if ($q === 0 || $q === "") {
return false; return false;
} }
$tokens = explode('/', $q);
if (count($tokens) === 0) {
return false;
}
$extension = Utils::getExtension($acceptContentType, $conf['http_accept']); $extension = Utils::getExtension($acceptContentType, $conf['http_accept']);
$viewFile = null; $viewFile = null;
$tokens = $qArr;
$arguments = array(); $arguments = array();
while (sizeof($tokens) > 0) { while (sizeof($tokens) > 0) {
......
...@@ -4,6 +4,7 @@ namespace uib\ub\loadspeakr\modules; ...@@ -4,6 +4,7 @@ namespace uib\ub\loadspeakr\modules;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use uib\ub\loadspeakr\Configuration; use uib\ub\loadspeakr\Configuration;
use uib\ub\loadspeakr\Endpoint;
use uib\ub\loadspeakr\Utils; use uib\ub\loadspeakr\Utils;
require_once __DIR__ . '/../../../../../common.inc.php'; require_once __DIR__ . '/../../../../../common.inc.php';
...@@ -16,7 +17,7 @@ class ServiceModuleTest extends TestCase ...@@ -16,7 +17,7 @@ class ServiceModuleTest extends TestCase
{ {
parent::setUp(); parent::setUp();
global $conf; global $conf;
$conf['basedir'] = 'https://example.com'; $conf['basedir'] = 'https://example.com/';
$conf['root'] = 'home'; $conf['root'] = 'home';
$lodspk = [ $lodspk = [
'view' => '', 'view' => '',
...@@ -26,27 +27,25 @@ class ServiceModuleTest extends TestCase ...@@ -26,27 +27,25 @@ class ServiceModuleTest extends TestCase
$boostrapConfig = [ $boostrapConfig = [
'localUri' => '', 'localUri' => '',
'uri' => '', 'uri' => 'https://example.combar.jpg',
'acceptContentType' => '', 'acceptContentType' => 'text/html',
'endpoints' => '', 'endpoints' => [],
'extension' => [], 'extension' => [],
'lodspk' => $lodspk, 'lodspk' => $lodspk,
]; ];
$boostrapConfig['endpoints']['local'] = new Endpoint('https://sparql.ub.uib.no/sparql/query', []);
$configuration = new Configuration($conf); $configuration = new Configuration($conf);
$modulesConfig = $configuration->add('bootstrap', $boostrapConfig); $modulesConfig = $configuration->add('bootstrap', $boostrapConfig);
$this->service = new ServiceModule($modulesConfig, new Utils($modulesConfig)); $this->service = new ServiceModule($modulesConfig, new Utils($modulesConfig));
} }
public function testMatch(): void /**
* @covers \uib\ub\loadspeakr\modules\ServiceModule::match
*/
public function testMatchGuards(): void
{ {
$uri = 'bar'; self::assertFalse($this->service->match('bar'), 'Failed matching');
self::assertSame(
'foo',
$this->service->match($uri),
'Failed matching '
);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment