Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue1148-fixParamPlugins' into …
Browse files Browse the repository at this point in the history
…issue1148-order-of-plugin-rendering
  • Loading branch information
Vainonen committed Mar 2, 2022
2 parents f67f20d + 5ce6c74 commit cba30a7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push]
on: [push, pull_request, workflow_dispatch]

jobs:
build-test:
Expand Down
6 changes: 5 additions & 1 deletion dockerfiles/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ COPY dockerfiles/config/000-default.conf /etc/apache2/sites-available/000-defaul
RUN a2enmod rewrite
RUN a2enmod expires

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# set ServerName & redirect error log to stderr for docker logs
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
sed -ri \
-e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/1!g' \
"/etc/apache2/apache2.conf"

WORKDIR /var/www/html
RUN rm index.html
Expand Down
4 changes: 2 additions & 2 deletions model/ConceptSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function getArrayClass()
return null;
}

public function getSearchTerm()
public function getSearchTerm() : string
{
$term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query');
if (!$term && $this->rest)
if ((!isset($term) || strlen(trim($term)) === 0) && $this->rest)
$term = $this->request->getQueryParamRaw('label');
$term = trim($term); // surrounding whitespace is not considered significant
$term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184
Expand Down
8 changes: 7 additions & 1 deletion model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct($resource, $globalPlugins=array())
{
$this->resource = $resource;
$this->globalPlugins = $globalPlugins;
$this->setParameterizedPlugins();
$this->setPropertyLabelOverrides();
$pluginArray = $this->getPluginArray();
$this->pluginRegister = new PluginRegister($pluginArray);
Expand All @@ -45,6 +44,7 @@ public function __construct($resource, $globalPlugins=array())
*/
public function getPluginArray() : array
{
$this->setParameterizedPlugins();
$pluginArray = array();
$vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins');
if (!$vocabularyPlugins instanceof EasyRdf\Collection) {
Expand All @@ -62,6 +62,12 @@ public function getPluginArray() : array
}
$pluginArray = array_merge($pluginArray, $this->globalPlugins);

$paramPlugins = $this->resource->allResources('skosmos:useParamPlugin');
if ($paramPlugins) {
foreach ($paramPlugins as $plugin) {
$pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue();
}
}
$plugins = $this->resource->allLiterals('skosmos:usePlugin');
if ($plugins) {
foreach ($plugins as $pluginlit) {
Expand Down
20 changes: 20 additions & 0 deletions tests/ConceptSearchParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public function testGetSearchTerm() {
$this->assertEquals('test', $params->getSearchTerm());
}

/**
* For https://github.com/NatLibFi/Skosmos/issues/1275, to verify
* that querying for `0` (zero) does not evaluate it as a boolean
* value, causing issues in the SKOSMOS search functionality.
*
* @covers ConceptSearchParameters::getSearchTerm
*/
public function testGetSearchTermZeroes() {
$params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl'), true);
$this->assertEquals('', $params->getSearchTerm());
$this->request->method('getQueryParamRaw')->will(
$this->returnValueMap([
['q', '0'],
['query', '0'],
['label', '10']
])
);
$this->assertEquals('0', $params->getSearchTerm());
}

/**
* @covers ConceptSearchParameters::getTypeLimit
* @covers ConceptSearchParameters::getDefaultTypeLimit
Expand Down
2 changes: 1 addition & 1 deletion tests/VocabularyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public function testGetPluginParameters() {
public function testGetOrderedPlugins() {
$vocab = $this->model->getVocabulary('paramPluginTest');
$plugins = $vocab->getConfig()->getPluginArray();
$this->assertEquals(["plugin2", "Bravo", "imaginaryPlugin", "plugin1", "alpha", "charlie", "plugin3"], $plugins);
$this->assertEquals(["plugin2", "Bravo", "plugin1", "alpha", "charlie", "imaginaryPlugin", "plugin3"], $plugins);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
skosmos:feedbackRecipient "developer@vocabulary.org";
skosmos:groupClass skos:Collection;
skosmos:language "en";
skosmos:vocabularyPlugins ("plugin2" "Bravo" :parameterizedPlugin "plugin1");
skosmos:vocabularyPlugins ("plugin2" "Bravo" "plugin1");
skosmos:usePlugin "plugin1" ;
skosmos:usePlugin "plugin3" ;
skosmos:useParamPlugin :parameterizedPlugin ;
Expand Down

0 comments on commit cba30a7

Please sign in to comment.