Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListWidget: Remove usage of $this->mFormat (not taken into account anymore by parent class) #462

Merged
merged 5 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions formats/widget/SRF_ListWidget.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use SMW\ListResultPrinter;
use SMW\Query\ResultPrinters\ListResultPrinter\ListResultBuilder;
use SMW\Query\ResultPrinters\ResultPrinter;

/**
* Extends the list result printer (SMW_QP_List.php) with a JavaScript
Expand All @@ -13,7 +14,7 @@
* @ingroup SemanticResultFormats
* @file SRF_ListWidget.php
*/
class SRFListWidget extends ListResultPrinter {
class SRFListWidget extends ResultPrinter {

/**
* Get a human readable label for this printer.
Expand All @@ -38,11 +39,20 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) {
static $statNr = 0;
//$this->isHTML = true;

// Set output type for the parent
$this->mFormat = $this->params['listtype'] == 'ordered' || $this->params['listtype'] == 'ol' ? 'ol' : 'ul';
$listType = $this->params[ 'listtype' ] === 'ordered' || $this->params[ 'listtype' ] === 'ol' ? 'ol' : 'ul';

$builder = new ListResultBuilder( $res, $this->mLinker );

$builder->set( $this->params );
$builder->set( [
'format' => $listType,
'link-first' => $this->mLinkFirst,
'link-others' => $this->mLinkOthers,
'show-headers' => $this->mShowHeaders,
] );

// Get results from SMWListResultPrinter
$result = parent::getResultText( $res, $outputmode );
$result = $builder->getResultText();

// Count widgets
$listwidgetID = 'listwidget-' . ++$statNr;
Expand Down Expand Up @@ -70,7 +80,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) {
'div',
[
'class' => 'srf-listwidget ' . htmlspecialchars( $this->params['class'] ),
'data-listtype' => $this->mFormat,
'data-listtype' => $listType,
'data-widget' => $this->params['widget'],
'data-pageitems' => $this->params['pageitems'],
],
Expand Down
95 changes: 95 additions & 0 deletions tests/phpunit/Integration/JSONScript/TestCases/listwidget-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"description": "Listwidget format: widgets - unordered (#449 - `wgContLang=fr`, `wgLang=en`)",
"setup": [
{
"namespace": "NS_CATEGORY",
"page": "Listwidget example",
"contents": "Holds listwidget examples."
},
{
"page": "May 2000",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2001",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2002",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2003",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2004",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2005",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "May 2006",
"contents": "[[Category:Listwidget example]]"
},
{
"page": "Listwidget - alphabet - unordered",
"contents": "{{#ask: [[Category:Listwidget example]] |format=listwidget |link=all |headers=show |listtype=unordered |widget=alphabet |pageitems=6}}"
},
{
"page": "Listwidget - menu - listtype unspecified",
"contents": "{{#ask: [[Category:Listwidget example]] |format=listwidget |link=all |headers=show |widget=menu }}"
},
{
"page": "Listwidget - pagination - ordered",
"contents": "{{#ask: [[Category:Listwidget example]] |format=listwidget |link=all |headers=show |listtype=ordered |widget=pagination }}"
}
],
"tests": [
{
"type": "parser-html",
"about": "#0 Listwidget - alphabet - unordered",
"subject": "Listwidget - alphabet - unordered",
"assert-output": {
"to-contain": [
".srf-listwidget[data-listtype=\"ul\"][data-widget=\"alphabet\"][data-pageitems=\"6\"] .listwidget-container[id]"
]
}
},
{
"type": "parser-html",
"about": "#1 Listwidget - menu - listtype unspecified",
"subject": "Listwidget - menu - listtype unspecified",
"assert-output": {
"to-contain": [
".srf-listwidget[data-listtype=\"ul\"][data-widget=\"menu\"][data-pageitems=\"5\"] .listwidget-container[id]"
]
}
},
{
"type": "parser-html",
"about": "#2 Listwidget - pagination - ordered",
"subject": "Listwidget - pagination - ordered",
"assert-output": {
"to-contain": [
".srf-listwidget[data-listtype=\"ol\"][data-widget=\"pagination\"][data-pageitems=\"5\"] .listwidget-container[id]"
]
}
}

],
"settings": {
"wgContLang": "fr",
"wgLang": "en",
"smwgNamespacesWithSemanticLinks": {
"NS_MAIN": true
}
},
"meta": {
"version": "2",
"is-incomplete": false,
"debug": true
}
}