diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/SemanticResultFormats/tests |
first commit
Diffstat (limited to 'www/wiki/extensions/SemanticResultFormats/tests')
92 files changed, 8062 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticResultFormats/tests/bootstrap.php b/www/wiki/extensions/SemanticResultFormats/tests/bootstrap.php new file mode 100644 index 00000000..b8d09067 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/bootstrap.php @@ -0,0 +1,20 @@ +<?php + +if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) { + die( 'Not an entry point' ); +} + +if ( !is_readable( $path = __DIR__ . '/../../SemanticMediaWiki/tests/autoloader.php' ) ) { + die( 'The SemanticMediaWiki test autoloader is not available' ); +} + +print sprintf( "\n%-20s%s\n", "Semantic Result Formats: ", SRF_VERSION ); + +$autoloader = require $path; +$autoloader->addPsr4( 'SRF\\Tests\\', __DIR__ . '/phpunit' ); +$autoloader->addPsr4( 'SMW\\Test\\', __DIR__ . '/../../SemanticMediaWiki/tests/phpunit' ); +$autoloader->addPsr4( 'SMW\\Tests\\', __DIR__ . '/../../SemanticMediaWiki/tests/phpunit' ); + +$autoloader->addClassMap( [ + 'SRF\Tests\ResultPrinterReflector' => __DIR__ . '/phpunit/ResultPrinterReflector.php', +] ); diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php new file mode 100644 index 00000000..a676f6b7 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php @@ -0,0 +1,52 @@ +<?php + +namespace SRF\Tests\Integration; + +use SMW\Tests\Utils\UtilityFactory; + +/** + * @group SRF + * @group SMWExtension + * + * @license GNU GPL v2+ + * @since 2.5 + * + * @author mwjames + */ +class I18nJsonFileIntegrityTest extends \PHPUnit_Framework_TestCase { + + /** + * @dataProvider i18nFileProvider + */ + public function testI18NJsonDecodeEncode( $file ) { + + $jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file ); + + $this->assertInternalType( + 'integer', + $jsonFileReader->getModificationTime() + ); + + $this->assertInternalType( + 'array', + $jsonFileReader->read() + ); + } + + public function i18nFileProvider() { + + $provider = []; + $location = $GLOBALS['wgMessagesDirs']['SemanticResultFormats']; + + $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location ); + $bulkFileProvider->searchByFileExtension( 'json' ); + + foreach ( $bulkFileProvider->getFiles() as $file ) { + $provider[basename( $file )] = [ $file ]; + } + + asort( $provider ); + return $provider; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-0.bib b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-0.bib new file mode 100644 index 00000000..6f076aef --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-0.bib @@ -0,0 +1,2 @@ +@Book{, +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-1.bib b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-1.bib new file mode 100644 index 00000000..8c65f8f1 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-1.bib @@ -0,0 +1,10 @@ +@Incollection{maskin1985ttoiineas, + address = "Cambridge", + author = "Eric S. Maskin", + booktitle = "Social Goals and Social Organization", + editor = "Leonid Hurwicz, David Schmeidler and Hugo Sonnenschein", + pages = "173-204", + publisher = "Cambridge University Press", + title = "The theory of implementation in nash equilibrium: a survey", + year = "1985", +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-2.bib b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-2.bib new file mode 100644 index 00000000..5a1d6c5a --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-2.bib @@ -0,0 +1,8 @@ +@Book{abramowitz1964homf, + address = "New York", + author = "Milton Abramowitz and Irene A. Stegun", + edition = "ninth Dover printing, tenth GPO printing", + publisher = "Dover", + title = "Handbook of Mathematical Functions", + year = "1964", +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-3.bib b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-3.bib new file mode 100644 index 00000000..b5602c23 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/bibtex-01-3.bib @@ -0,0 +1,16 @@ +@Book{maskin1985ttoiineas, + address = "Cambridge", + author = "Eric S. Maskin", + publisher = "Cambridge University Press", + title = "The theory of implementation in nash equilibrium: a survey", + year = "1985", +} + +@Book{abramowitz1964homf, + address = "New York", + author = "Milton Abramowitz and Irene A. Stegun", + edition = "ninth Dover printing, tenth GPO printing", + publisher = "Dover", + title = "Handbook of Mathematical Functions", + year = "1964", +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-01.1.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-01.1.txt new file mode 100644 index 00000000..5537abc5 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-01.1.txt @@ -0,0 +1,14 @@ +BEGIN:VCALENDAR +PRODID:-//SMW Project//Semantic Result Formats +VERSION:2.0 +METHOD:PUBLISH +X-WR-CALNAME:.* +X-WR-CALDESC:Simple description +BEGIN:VEVENT +SUMMARY:Example/ICalendar-01/1 +URL:.*/Example/ICalendar-01/1 +UID:.*/Example/ICalendar-01/1 +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +END:VCALENDAR
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-02.0.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-02.0.txt new file mode 100644 index 00000000..63ef744e --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-02.0.txt @@ -0,0 +1,28 @@ +BEGIN:VCALENDAR +PRODID:-//SMW Project//Semantic Result Formats +VERSION:2.0 +METHOD:PUBLISH +X-WR-CALNAME:.* +X-WR-CALDESC:Simple description +BEGIN:VEVENT +SUMMARY:A +URL:.*/Example/ICalendar-02/1 +UID:.*/Example/ICalendar-02/1 +DTSTART:19700101 +LOCATION:LOC-A +DESCRIPTION:Something about A +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +BEGIN:VEVENT +SUMMARY:B +URL:.*/Example/ICalendar-02/2 +UID:.*/Example/ICalendar-02/2 +DTSTART:19700102T120000 +DTEND:19700102T150000 +LOCATION:LOC-B +DESCRIPTION:Something about B +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +END:VCALENDAR diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.0.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.0.txt new file mode 100644 index 00000000..f942fbec --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.0.txt @@ -0,0 +1,37 @@ +BEGIN:VCALENDAR +PRODID:-//SMW Project//Semantic Result Formats +VERSION:2.0 +METHOD:PUBLISH +X-WR-CALNAME:.* +X-WR-CALDESC:Simple description +BEGIN:VTIMEZONE +TZID:UTC +BEGIN:STANDARD +DTSTART:.* +TZOFFSETFROM:+0000 +TZOFFSETTO:+0000 +TZNAME:UTC +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +SUMMARY:A +URL:.*/Example/ICalendar-03/1 +UID:.*/Example/ICalendar-03/1 +DTSTART:19700101 +LOCATION:LOC-A +DESCRIPTION:Something about A +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +BEGIN:VEVENT +SUMMARY:B +URL:.*/Example/ICalendar-03/2 +UID:.*/Example/ICalendar-03/2 +DTSTART:19700102T120000 +DTEND:19700102T150000 +LOCATION:LOC-B +DESCRIPTION:Something about B +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +END:VCALENDAR diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt new file mode 100644 index 00000000..b1821b39 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt @@ -0,0 +1,46 @@ +BEGIN:VCALENDAR +PRODID:-//SMW Project//Semantic Result Formats +VERSION:2.0 +METHOD:PUBLISH +X-WR-CALNAME:.* +X-WR-CALDESC:Simple description +BEGIN:VTIMEZONE +TZID:UTC +BEGIN:STANDARD +DTSTART:.* +TZOFFSETFROM:+0000 +TZOFFSETTO:+0000 +TZNAME:UTC +END:STANDARD +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:America/New_York +BEGIN:STANDARD +DTSTART:.* +TZOFFSETFROM:-0500 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +SUMMARY:A +URL:.*/Example/ICalendar-03/1 +UID:.*/Example/ICalendar-03/1 +DTSTART:19700101 +LOCATION:LOC-A +DESCRIPTION:Something about A +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +BEGIN:VEVENT +SUMMARY:B +URL:.*/Example/ICalendar-03/2 +UID:.*/Example/ICalendar-03/2 +DTSTART:19700102T120000 +DTEND:19700102T150000 +LOCATION:LOC-B +DESCRIPTION:Something about B +DTSTAMP:.* +SEQUENCE:.* +END:VEVENT +END:VCALENDAR diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/image-upload-480.png b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/image-upload-480.png Binary files differnew file mode 100644 index 00000000..4353df8e --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/image-upload-480.png diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.0.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.0.txt new file mode 100644 index 00000000..263d5669 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.0.txt @@ -0,0 +1,12 @@ +BEGIN:VCARD +VERSION:3.0 +N;CHARSET=UTF-8:Example/Vcard-01/0;;;; +FN;CHARSET=UTF-8:Example/Vcard-01/0 +CLASS:PUBLIC +CATEGORIES;CHARSET=UTF-8:Category:Vcard-00 +SOURCE;CHARSET=UTF-8:.*/Example/Vcard-01/0 +PRODID:-////Semantic MediaWiki +REV:.* +URL:.*/Example/Vcard-01/0 +UID:.*/Example/Vcard-01/0 +END:VCARD
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.1.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.1.txt new file mode 100644 index 00000000..15117522 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.1.txt @@ -0,0 +1,17 @@ +BEGIN:VCARD +VERSION:3.0 +N;CHARSET=UTF-8:Doe;John;;; +FN;CHARSET=UTF-8:John Doe +CLASS:PUBLIC +BDAY:1952-01-01 +EMAIL;TYPE=INTERNET:johnDoe@example.org +ADR;TYPE=HOME;CHARSET=UTF-8:;;Example Avenue;Anytown;;; +TEL;TYPE=CELL:+1 781 555 1212 +TEL;TYPE=HOME:+1 202 555 1212 +NOTE;CHARSET=UTF-8:John Doe has a long and varied history\, being documented on more ... +SOURCE;CHARSET=UTF-8:.*/Example/Vcard-01/1 +PRODID:-////Semantic MediaWiki +REV:.* +URL:http://www.example/com/doe +UID:.*/Example/Vcard-01/1 +END:VCARD
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.2.txt b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.2.txt new file mode 100644 index 00000000..7c536b1c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/Fixtures/vcard-01.2.txt @@ -0,0 +1,17 @@ +BEGIN:VCARD +VERSION:3.0 +N;CHARSET=UTF-8:Doe;John;;; +FN;CHARSET=UTF-8:John Doe +CLASS:PUBLIC +BDAY:1952-01-01 +EMAIL;TYPE=INTERNET:johnDoe@example.org +ADR;TYPE=HOME;CHARSET=UTF-8:;;Example Avenue;Anytown;;; +TEL;TYPE=CELL:+1 781 555 1212 +TEL;TYPE=HOME:+1 202 555 1212 +NOTE;CHARSET=UTF-8:John Doe has a long and varied history\, being documented on more ... +SOURCE;CHARSET=UTF-8:.*/Example/Vcard-01/2#_f8bae6eae7468315094dd5c6a509e2c4 +PRODID:-////Semantic MediaWiki +REV:.* +URL:http://www.example/com/doe +UID:.*/Example/Vcard-01/2#_f8bae6eae7468315094dd5c6a509e2c4 +END:VCARD
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php new file mode 100644 index 00000000..63e740fc --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/JsonTestCaseScriptRunnerTest.php @@ -0,0 +1,63 @@ +<?php +namespace SRF\Tests\Integration\JSONScript; +use SMW\Tests\Integration\JSONScript\JsonTestCaseScriptRunnerTest as SMWJsonTestCaseScriptRunnerTest; +/** + * @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests#write-integration-tests-using-json-script + * + * `JsonTestCaseScriptRunner` provisioned by SMW is a base class allowing to use a JSON + * format to create test definitions with the objective to compose "real" content + * and test integration with MediaWiki, Semantic MediaWiki, and Scribunto. + * + * @group SRF + * @group SMWExtension + * + * @license GNU GPL v2+ + * @since 2.5 + * + * @author Stephan Gambke + */ +class JsonTestCaseScriptRunnerTest extends SMWJsonTestCaseScriptRunnerTest { + /** + * @see \SMW\Tests\JsonTestCaseScriptRunner::getTestCaseLocation + * @return string + */ + protected function getTestCaseLocation() { + return __DIR__ . '/TestCases'; + } + /** + * @return string[] + * @since 3.0 + */ + protected function getPermittedSettings() { + $settings = parent::getPermittedSettings(); + $settings[] = 'srfgMapProvider'; + return $settings; + } + + /** + * @see JsonTestCaseScriptRunner::getDependencyDefinitions + */ + protected function getDependencyDefinitions() { + return [ + 'Mermaid' => [ $this, 'checkMermaidDependency' ] + ]; + } + public function checkMermaidDependency( $val, &$reason ) { + + if ( !defined( 'MERMAID_VERSION' ) ) { + $reason = "Dependency: Mermaid as requirement is not available!"; + return false; + } + + list( $compare, $requiredVersion ) = explode( ' ', $val ); + $version = MERMAID_VERSION; + + if ( !version_compare( $version, $requiredVersion, $compare ) ) { + $reason = "Dependency: Required version of Mermaid($requiredVersion $compare $version) is not available!"; + return false; + } + + return true; + } + +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/README.md b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/README.md new file mode 100644 index 00000000..0888a4b9 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/README.md @@ -0,0 +1,82 @@ + +<!-- Begin of generated contents by readmeContentsBuilder.php --> + +## TestCases + +Contains 21 files with a total of 62 tests: + +### D +* [datatables-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/datatables-01.json) Test `format=datatables` html output (no JS validation) + +### E +* [earliest-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/earliest-01.json) Test for `format=earliest` +* [eventcalendar-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/eventcalendar-01.json) Test `format=eventcalendar` html output (no JS validation) + +### F +* [filtered-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/filtered-01.json) Filtered format: ... +* [filtered-02.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/filtered-02.json) Filtered format: ... + +### G +* [gallery-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/gallery-01.json) Test `format=gallery` with file upload + +### I +* [icalendar-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/icalendar-01.json) Test `format=icalendar` +* [icalendar-02.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/icalendar-02.json) Test `format=icalendar` on iCalendar specific labels using `Special:Ask` +* [icalendar-03.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/icalendar-03.json) Test `format=icalendar` with timezone using `Special:Ask` + +### L +* [latest-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/latest-01.json) Test for `format=latest` + +### M +* [math-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/math-01.json) Test for math/sum result format in pt-br lang + +### T +* [tagcloud-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-01.json) Test `format=tagcloud` html output +* [timeline-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/timeline-01.json) Test for timeline result format +* [tree-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-01.json) Tree format: Multi-page results +* [tree-02.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-02.json) Tree format: Simple one-page result +* [tree-03.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-03.json) Tree format: Raising error: Missing 'parent' parameter +* [tree-04.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-04.json) Tree format: Empty resultset does not produce tree +* [tree-05.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-05.json) Tree format: Loop detection +* [tree-06.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-06.json) Tree format: Insert elements with multiple parents multiple times +* [tree-07.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/tree-07.json) Tree format: Simple one-page result + +### V +* [vcard-01.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/TestCases/vcard-01.json) Test `format=vcard` + +-- Last updated on 2017-11-11 by `readmeContentsBuilder.php` + +<!-- End of generated contents by readmeContentsBuilder.php --> + +## Writing a test case + +Have a look at the [bootstrap.json](https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Integration/JSONScript/bootstrap.json) example test case and the [introduction video](https://youtu.be/7fDKjPFaTaY). For further assistance, please read the following [document](https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests/phpunit/Integration/JSONScript#designing-an-integration-test). + +## Running a test + +The `composer integration` command can be used the quickly execute the integration tests and in +combination with the `--filter` option allows to select a single specific case. + +<pre> +$ composer integration -- --filter vcard +Using PHP 7.1.1 + +Semantic Result Formats: 3.0.0-alpha + +Semantic MediaWiki: 3.0.0-alpha (c352b6a, SMWSQLStore3, mysql) +MediaWiki: 1.31.0-alpha (44c06df, MediaWiki vendor autoloader) +Site language: en + +Execution time: 2017-01-01 12:00 +Debug logs: Disabled +Xdebug: Disabled (or not installed) + +PHPUnit 4.8.35 by Sebastian Bergmann and contributors. + +Runtime: PHP 7.1.1 +Configuration: /var/www/html/w/extensions/SemanticResultFormats/phpunit.xml.dist + +. + +Time: 18.38 seconds, Memory: 38.00MB +</pre> diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/bibtex-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/bibtex-01.json new file mode 100644 index 00000000..2966fbe0 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/bibtex-01.json @@ -0,0 +1,159 @@ +{ + "description": "Test `format=bibtex`", + "setup": [ + { + "page": "Has author", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has title", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has publisher", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has year", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has address", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has edition", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has email", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Email]]" + }, + { + "page": "BibTex/00", + "contents": "[[Category:Bibtex-00]]" + }, + { + "page": "BibTex/01", + "contents": "[[Category:Bibtex-01]] [[Type::incollection]] [[Has author:: Eric S. Maskin]] [[Has editor::Leonid Hurwicz]] [[Has editor::David Schmeidler]] [[Has editor::Hugo Sonnenschein]] [[Has title::The theory of implementation in nash equilibrium: a survey]] [[Has booktitle::Social Goals and Social Organization]] [[Has year::1985]] [[Has publisher::Cambridge University Press]] [[Has address::Cambridge]] [[Has pages::173-204]]" + }, + { + "page": "BibTex/02", + "contents": "[[Category:Bibtex-02]] [[Has author::Milton Abramowitz]] [[Has author::Irene A. Stegun]] [[Has title::Handbook of Mathematical Functions]] [[Has year::1964]] [[Has publisher::Dover]] [[Has address::New York]] [[Has edition::ninth Dover printing, tenth GPO printing]]" + } + ], + "tests": [ + { + "type": "special", + "about": "#0 `format=bibtex` empty (bibtex-01-0.bib)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "bibtex" + }, + "q": "[[Category:Bibtex-00]]", + "po": "?Has author=author|?Has title=title|?Has publisher=publisher|?Has year=year|?Has address=address|?Has edition=edition" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/bibtex-01-0.bib" + } + } + }, + { + "type": "special", + "about": "#1 `format=bibtex` single author, editor (bibtex-01-1.bib)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "bibtex" + }, + "q": "[[Category:Bibtex-01]]", + "po": "?Type=type|?Has author=author|?Has title=title|?Has publisher=publisher|?Has year=year|?Has address=address|?Has edition=edition|?Has editor=editor|?Has pages=pages|?Has booktitle=booktitle" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/bibtex-01-1.bib" + } + } + }, + { + "type": "special", + "about": "#2 `format=bibtex` multiple authors (bibtex-01-2.bib)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "bibtex" + }, + "q": "[[Category:Bibtex-02]]", + "po": "?Has author=author|?Has title=title|?Has publisher=publisher|?Has year=year|?Has address=address|?Has edition=edition" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/bibtex-01-2.bib" + } + } + }, + { + "type": "special", + "about": "#3 `format=bibtex` multiple records (bibtex-01-3.bib)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "bibtex" + }, + "q": "[[Category:Bibtex-02]] OR [[Category:Bibtex-01]]", + "po": "?Has author=author|+order=desc|?Has title=title|?Has publisher=publisher|?Has year=year|?Has address=address|?Has edition=edition" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/bibtex-01-3.bib" + } + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/datatables-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/datatables-01.json new file mode 100644 index 00000000..2ea26ebf --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/datatables-01.json @@ -0,0 +1,47 @@ +{ + "description": "Test `format=datatables` html output (no JS validation)", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/Datatables/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Datatables]]" + }, + { + "page": "Example/Datatables/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Datatables]]" + }, + { + "page": "Test/Datatables/Q.1", + "contents": "{{#ask: [[Category:Datatables]] |?Has date |format=datatables }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0", + "subject": "Test/Datatables/Q.1", + "assert-output": { + "to-contain": [ + "<div class=\"srf-datatables\" data-theme=\"bootstrap\"><div class=\"top\">" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/earliest-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/earliest-01.json new file mode 100644 index 00000000..700e5265 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/earliest-01.json @@ -0,0 +1,61 @@ +{ + "description": "Test for `format=earliest`", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/Earliest/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Earliest]]" + }, + { + "page": "Example/Earliest/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Earliest]]" + }, + { + "page": "Example/Earliest/Q.1", + "contents": "{{#ask: [[Category:Earliest]] |?Has date |format=earliest }}" + }, + { + "page": "Example/Earliest/Q.2", + "contents": "{{#ask: [[Category:Earliest/default]] |?Has date |format=earliest |default=No date }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0", + "subject": "Example/Earliest/Q.1", + "assert-output": { + "to-contain": [ + "1 January 1970" + ] + } + }, + { + "type": "parser", + "about": "#1 default output", + "subject": "Example/Earliest/Q.2", + "assert-output": { + "to-contain": [ + "No date" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/eventcalendar-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/eventcalendar-01.json new file mode 100644 index 00000000..681ed40d --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/eventcalendar-01.json @@ -0,0 +1,47 @@ +{ + "description": "Test `format=eventcalendar` html output (no JS validation)", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/Eventcalendar/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Eventcalendar]]" + }, + { + "page": "Example/Eventcalendar/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Eventcalendar]]" + }, + { + "page": "Test/Eventcalendar/Q.1", + "contents": "{{#ask: [[Category:Eventcalendar]] |?Has date |format=eventcalendar }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0", + "subject": "Test/Eventcalendar/Q.1", + "assert-output": { + "to-contain": [ + "<div class=\"srf-eventcalendar\" data-external-class=\"\">" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-01.json new file mode 100644 index 00000000..d86ba5fe --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-01.json @@ -0,0 +1,330 @@ +{ + "description": "Filtered format: ...", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/City name", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Location", + "contents": "[[Has type::Geographic coordinates]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Country code", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Population", + "contents": "[[Has type::Number]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Elevation", + "contents": "[[Has type::Quantity]][[Corresponds to::1 m]][[Corresponds to::0.001 km]][[Corresponds to::3.28084 ft]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Timezone", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Modification date", + "contents": "[[Has type::Date]]" + }, + + { + "namespace": "NS_TEMPLATE", + "page": "City", + "contents": "[[Category:Filtered test]][[Category:City]][[Filtered test/City name::{{{name|}}}]][[Filtered test/Location:: {{{latitude|}}}°, {{{longitude|}}}°]][[Filtered test/Country code::{{{country code|}}}]][[Filtered test/Population::{{{population|}}}]][[Filtered test/Elevation::{{{dem|}}} m]][[Filtered test/Timezone::{{{timezone|}}}]][[Filtered test/Modification date::{{{modification date|}}}]]" + }, + + { + "page": "Filtered test/Berlin", + "contents": "{{City |name=Berlin |latitude=52.52437 |longitude=13.41053 |country code=DE |population=3426354 |dem=43 |timezone=Europe/Berlin |modification date=2016-09-26 }}" + }, + { + "page": "Filtered test/Cairo", + "contents": "{{City |name=Cairo |latitude=30.06263 |longitude=31.24967 |country code=EG |population=7734614 |dem=23 |timezone=Africa/Cairo |modification date=2015-06-03 }}" + }, + { + "page": "Filtered test/London", + "contents": "{{City |name=London |latitude=51.50853 |longitude=-0.12574 |country code=GB |population=7556900 |dem=25 |timezone=Europe/London |modification date=2016-09-14 }}" + }, + { + "page": "Filtered test/Madrid", + "contents": "{{City |name=Madrid |latitude=40.4165 |longitude=-3.70256 |country code=ES |population=3255944 |dem=665 |timezone=Europe/Madrid |modification date=2015-06-03 }}" + }, + { + "page": "Filtered test/Paris", + "contents": "{{City |name=Paris |latitude=48.85341 |longitude=2.3488 |country code=FR |population=2138551 |dem=42 |timezone=Europe/Paris |modification date=2016-02-18 }}" + }, + { + "page": "Filtered test/Sofia", + "contents": "{{City |name=Sofia |latitude=42.69751 |longitude=23.32415 |country code=BG |population=1152556 |dem=562 |timezone=Europe/Sofia |modification date=2011-06-16 }}" + }, + { + "page": "Filtered test/Vienna", + "contents": "{{City |name=Vienna |latitude=48.20849 |longitude=16.37208 |country code=AT |population=1691468 |dem=193 |timezone=Europe/Vienna |modification date=2015-07-29 }}" + }, + { + "page": "Filtered test/Yerevan", + "contents": "{{City |name=Yerevan |latitude=40.18111 |longitude=44.51361 |country code=AM |population=1093485 |dem=994 |timezone=Asia/Yerevan |modification date=2016-03-10 }}" + }, + { + "page": "Example/Filtered 01-01", + "contents": "{{#ask:[[Category:Filtered test]]|format=filtered}}" + }, + { + "page": "Example/Filtered 01-02", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=list}}" + }, + { + "page": "Example/Filtered 01-03", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=calendar}}" + }, + { + "page": "Example/Filtered 01-04", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=table}}" + }, + { + "page": "Example/Filtered 01-05", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=map}}" + }, + { + "page": "Example/Filtered 01-06", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |+filter=value |format=filtered }}" + }, + { + "page": "Example/Filtered 01-07", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/Elevation |+filter=number |format=filtered }}" + }, + { + "page": "Example/Filtered 01-08", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/Location |+filter=distance |+distance filter origin=52.52437° 13.41053° |format=filtered }}" + }, + { + "page": "Example/Filtered 01-09", + "contents": "{{#ask:[[Category:Filtered test]] |format=filtered |filter position=top }}" + }, + { + "page": "Example/Filtered 01-10", + "contents": "{{#ask:[[Category:Filtered test]] |format=filtered |filter position=bottom }}" + }, + { + "page": "Example/Filtered 01-11", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=list |list view type=ul }}" + }, + { + "page": "Example/Filtered 01-12", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=list |list view type=ol }}" + }, + { + "page": "Example/Filtered 01-17", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/Location |+filter=distance |format=filtered }}" + }, + { + "page": "Example/Filtered 01-18", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/Elevation |+filter=distance |format=filtered }}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Filtered 01-01 (Empty response)", + "subject": "Example/Filtered 01-01", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + [ "div.filtered", 1 ], + "div.filtered > div.filtered-filters > div.filtered-filter-spinner", + "div.filtered > div.filtered-views > div.filtered-views-selectors-container:empty", + "div.filtered > div.filtered-views > div.filtered-views-container:empty" + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-02 (List view)", + "subject": "Example/Filtered 01-02", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter-spinner", + [ "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-list", 1 ], + "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-list:contains('List')", + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-list", 1 ], + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-list > div.filtered-list-item:not(:empty)", 8 ] + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-03 (Calendar view)", + "subject": "Example/Filtered 01-03", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter-spinner", + [ "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-calendar", 1 ], + "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-calendar:contains('Calendar')", + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-calendar", 1 ] + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-04 (Table view)", + "subject": "Example/Filtered 01-04", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter-spinner", + [ "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-table", 1 ], + "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-table:contains('Table')", + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-table", 1 ], + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-table > table tr > th:not(:empty)", 3 ], + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-table > table tr.filtered-table-item:not(:empty)", 8 ], + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-table > table tr.filtered-table-item > td", 24 ] + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-05 (Map view)", + "subject": "Example/Filtered 01-05", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter-spinner", + [ "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-map", 1 ], + "div.filtered > div.filtered-views > div.filtered-views-selectors-container > div.filtered-view-selector.filtered-map:contains('Map')", + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-map", 1 ] + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-06 (Value filter)", + "subject": "Example/Filtered 01-06", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter.filtered-value", + "div.filtered > div.filtered-views > div.filtered-views-selectors-container:empty", + "div.filtered > div.filtered-views > div.filtered-views-container:empty" + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-07 (Number filter)", + "subject": "Example/Filtered 01-07", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter.filtered-number", + "div.filtered > div.filtered-views > div.filtered-views-selectors-container:empty", + "div.filtered > div.filtered-views > div.filtered-views-container:empty" + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-08 (Distance filter)", + "subject": "Example/Filtered 01-08", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered > div.filtered-filters > div.filtered-filter.filtered-distance", + "div.filtered > div.filtered-views > div.filtered-views-selectors-container:empty", + "div.filtered > div.filtered-views > div.filtered-views-container:empty" + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-09 (Filters on top)", + "subject": "Example/Filtered 01-09", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + [ "div.filtered", 1 ], + "div.filtered > div.filtered-filters + div.filtered-views" + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-10 (Filters at bottom)", + "subject": "Example/Filtered 01-10", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + [ "div.filtered", 1 ], + "div.filtered > div.filtered-views + div.filtered-filters " + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-11 (List view: Type ul)", + "subject": "Example/Filtered 01-11", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-list > ul > li.filtered-list-item:not(:empty)", 8 ] + ] + } + }, + { + "type": "parser-html", + "about": "Filtered 01-12 (List view: Type ul)", + "subject": "Example/Filtered 01-12", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + [ "div.filtered > div.filtered-views > div.filtered-views-container > div.filtered-view.filtered-list > ol > li.filtered-list-item:not(:empty)", 8 ] + ] + } + }, + { + "type": "parser", + "about": "Filtered 01-17 (Distance filter: Missing origin)", + "subject": "Example/Filtered 01-17", + "assert-output": { + "to-contain": [ + "Missing origin for distance filter on 'Filtered test/Location'." + ] + } + }, + { + "type": "parser", + "about": "Filtered 01-18 (Distance filter: Wrong printout type)", + "subject": "Example/Filtered 01-18", + "assert-output": { + "to-contain": [ + "The 'distance' filter can not be used on the 'Filtered test/Elevation' printout." + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "srfgMapProvider": "OpenStreetMap.Mapnik", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-02.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-02.json new file mode 100644 index 00000000..03512762 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/filtered-02.json @@ -0,0 +1,56 @@ +{ + "description": "Filtered format: ...", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/City name", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Filtered test/Location", + "contents": "[[Has type::Geographic coordinates]]" + }, + + { + "namespace": "NS_TEMPLATE", + "page": "City", + "contents": "[[Category:Filtered test]][[Category:City]][[Filtered test/City name::{{{name|}}}]][[Filtered test/Location:: {{{latitude|}}}°, {{{longitude|}}}°]]" + }, + + { + "page": "Filtered test/Berlin", + "contents": "{{City |name=Berlin |latitude=52.52437 |longitude=13.41053 }}" + }, + { + "page": "Example/Filtered 02-01", + "contents": "{{#ask:[[Category:Filtered test]] |?Filtered test/City name |?Filtered test/Location |format=filtered |views=map}}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Filtered 02-01 (Map view: No srfgMapProvider specified)", + "subject": "Example/Filtered 02-01", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + "div.filtered + span.smw-highlighter[data-title=\"Warning\"][title='No map provider specified for \"map\" view.'], div.filtered + p span.smw-highlighter[data-title=\"Warning\"][title='No map provider specified for \"map\" view.']" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gallery-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gallery-01.json new file mode 100644 index 00000000..0be9e237 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gallery-01.json @@ -0,0 +1,60 @@ +{ + "description": "Test `format=gallery` with file upload", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has text", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "NS_FILE", + "page": "Gallery01.png", + "contents": { + "upload": { + "file" : "/../Fixtures/image-upload-480.png", + "text" : "[[Has file::{{FULLPAGENAME}}]] [[Has caption::123]]" + } + } + }, + { + "page": "Example/Gallery-01/Q.1", + "contents": "{{#ask: [[Has caption::123]] |?Has file |format=gallery |limit=1 }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 (simple)", + "subject": "Example/Gallery-01/Q.1", + "assert-output": { + "to-contain": [ + "<div class=\"srf-gallery\" data-redirect-type=\"_wpg\">", + "<div class=\"thumb\" style=\"width: 150px;\"><div style=\"margin:15px auto;\"><a href=\".*File:Gallery01.png\" class=\"image\">" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "wgEnableUploads": true, + "wgFileExtensions": [ + "png" + ], + "wgDefaultUserOptions": { + "thumbsize": 5 + }, + "smwgPageSpecialProperties": [ + "_MDAT" + ], + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "NS_FILE": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gantt-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gantt-01.json new file mode 100644 index 00000000..b35e5d3e --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/gantt-01.json @@ -0,0 +1,167 @@ +{ + "description": "Test the gantt format", + "requires": { + "Mermaid": ">= 2.0" + }, + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Display Title", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Start Date", + "contents": "[[Has type::Date]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "End Date", + "contents": "[[Has type::Date]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Status", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Priority", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Related To Section", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "NS_TEMPLATE", + "page": "Task", + "contents": "[[Category:Task]][[Display Title::{{{title|}}}]][[Start Date::{{{start|}}}]][[End Date::{{{end|}}}]][[Status::{{{status|}}}]][[Priority::{{{priority|}}}]][[Related To Section::{{{section|}}}]]" + }, + { + "page": "Gantt Test/Task1", + "contents": "{{Task |title=Task01 |start=2019-01-01 |end=2019-01-15 |status=completed |priority=high |section=First Section }}" + }, + { + "page": "Gantt Test/Task2", + "contents": "{{Task |title=Task02 |start=2019-01-15 |end=2019-01-31 |status=backlog |priority=low |section=Second Section }}" + }, + { + "page": "Gantt Test/Task3", + "contents": "{{Task |title=Task03 |start=2019-02-01 |end=2019-02-15 |status=open |priority=critical |section=First Section }}" + }, + { + "page": "Gantt Test/Task4", + "contents": "{{Task |title=Task04 |start=2019-02-15 |end=2019-02-28 |status=done |priority=very high |section=First Section }}" + }, + { + "page": "Example/Gantt Diagram min config", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt }}" + }, + { + "page": "Example/Gantt Diagram config all", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt |theme=forest |sortkey=title |bargap=15 |barheight=40 |titletopmargin=30 |leftpadding=130}}" + }, + { + "page": "Example/Gantt Diagram test axis format 1", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt | axisformat=%m/%d/%Y}}" + }, + { + "page": "Example/Gantt Diagram test axis format 2", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt | axisformat=%m/%Y}}" + }, + { + "page": "Example/Gantt Diagram test axis format 3", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt | axisformat=%B-%Y}}" + }, + { + "page": "Example/Gantt Diagram mapping test 1", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Status=status |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Priority=priority| format=gantt |theme=forest |sortkey=title |bargap=15 |barheight=40 |titletopmargin=30 |leftpadding=130}}" + }, + { + "page": "Example/Gantt priority mapping test", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Status=status |?Priority=priority| |prioritymapping=critical=>crit; very high=>crit| format=gantt |theme=forest |sortkey=title |bargap=15 |barheight=40 |titletopmargin=30 |leftpadding=130}}" + }, + { + "page": "Example/Gantt status mapping test", + "contents": "{{#ask:[[Category:Task]] |?Display Title=task |?Start Date=startdate |?End Date=enddate |?Related To Section=section |?Status=status |?Priority=priority| |statusmapping=backlog=>active;open=>active;done=>done| format=gantt |theme=forest |sortkey=title |bargap=15 |barheight=40 |titletopmargin=30 |leftpadding=130}}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Test Selector of created SVG", + "subject": "Example/Gantt Diagram min config", + "assert-output": { + "to-be-valid-html": 1, + "to-contain": [ + ["div.mw-parser-output > div.srf-gantt",1] + ] + } + }, + { + "type": "parser", + "about": "Test gantt min config", + "subject": "Example/Gantt Diagram min config", + "assert-output": { + "to-contain": [ + "data-mermaid=\"{"content":"gantt\\ndateFormat YYYY-MM-DD\\naxisFormat %m\\/%d\\/%Y\\nsection First Section\\nTask01\\t :2019-01-01, 2019-01-15\\nTask03\\t :2019-02-01, 2019-02-15\\nTask04\\t :2019-02-15, 2019-02-28\\nsection Second Section\\nTask02\\t :2019-01-15, 2019-01-31\\n","config":{"theme":"default","gantt":{"leftPadding":75,"titleTopMargin":25,"barHeight":20,"barGap":4}}}\"><div class=\"mermaid-dots\"></div></div>" + ] + } + }, + { + "type": "parser", + "about": "Test gantt when all config params set", + "subject": "Example/Gantt Diagram config all", + "assert-output": { + "to-contain": [ + "data-mermaid=\"{"content":"gantt\\ndateFormat YYYY-MM-DD\\naxisFormat %m\\/%d\\/%Y\\nsection First Section\\nTask01\\t :2019-01-01, 2019-01-15\\nTask03\\t :2019-02-01, 2019-02-15\\nTask04\\t :2019-02-15, 2019-02-28\\nsection Second Section\\nTask02\\t :2019-01-15, 2019-01-31\\n","config":{"theme":"forest","gantt":{"leftPadding":130,"titleTopMargin":30,"barHeight":40,"barGap":15}}}\"><div class=\"mermaid-dots\"></div></div>" + ] + } + }, + { + "type": "parser", + "about": "Test axis forma %m/%d/%Y", + "subject": "Example/Gantt Diagram test axis format 1", + "assert-output": { + "to-contain": [ + "axisFormat %m\\/%d\\/%Y" + ] + } + }, + { + "type": "parser", + "about": "Test priority mapping", + "subject": "Example/Gantt priority mapping test", + "assert-output": { + "to-contain": [ + "data-mermaid=\"{"content":"gantt\\ndateFormat YYYY-MM-DD\\naxisFormat %m\\/%d\\/%Y\\nsection First Section\\nTask01\\t :2019-01-01, 2019-01-15\\nTask03\\t :crit, 2019-02-01, 2019-02-15\\nTask04\\t :crit, 2019-02-15, 2019-02-28\\nsection Second Section\\nTask02\\t :2019-01-15, 2019-01-31\\n","config":{"theme":"forest","gantt":{"leftPadding":130,"titleTopMargin":30,"barHeight":40,"barGap":15}}}\"><div class=\"mermaid-dots\"></div></div>" + ] + } + }, + { + "type": "parser", + "about": "Test priority mapping", + "subject": "Example/Gantt status mapping test", + "assert-output": { + "to-contain": [ + "data-mermaid=\"{"content":"gantt\\ndateFormat YYYY-MM-DD\\naxisFormat %m\\/%d\\/%Y\\nsection First Section\\nTask01\\t :2019-01-01, 2019-01-15\\nTask03\\t :active, 2019-02-01, 2019-02-15\\nTask04\\t :done, 2019-02-15, 2019-02-28\\nsection Second Section\\nTask02\\t :active, 2019-01-15, 2019-01-31\\n","config":{"theme":"forest","gantt":{"leftPadding":130,"titleTopMargin":30,"barHeight":40,"barGap":15}}}\"><div class=\"mermaid-dots\"></div></div>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": true + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-01.json new file mode 100644 index 00000000..068d5dc5 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-01.json @@ -0,0 +1,68 @@ +{ + "description": "Test `format=icalendar`", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/ICalendar-01/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:ICalendar-01]]" + }, + { + "page": "Example/ICalendar/Q.1", + "contents": "{{#ask: [[Category:ICalendar-01]] |?Has date |title=SRF integration |description=Simple description |format=icalendar }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 `format=icalendar` embedded", + "subject": "Example/ICalendar/Q.1", + "assert-output": { + "to-contain": [ + "Special:Ask/-5B-5BCategory:ICalendar-2D01-5D-5D/-3FHas-20date/mainlabel%3D/limit%3D50/offset%3D0/format%3Dicalendar/title%3DSRF-20integration/description%3DSimple-20description" + ] + } + }, + { + "type": "special", + "about": "#1 `format=icalendar` raw output via `Special:Ask`", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "icalendar", + "title": "SRF integration", + "description": "Simple description" + }, + "q": "[[Category:ICalendar-01]]", + "po": "?Has date" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/icalendar-01.1.txt" + } + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-02.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-02.json new file mode 100644 index 00000000..10691946 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-02.json @@ -0,0 +1,78 @@ +{ + "description": "Test `format=icalendar` on iCalendar specific labels using `Special:Ask`", + "setup": [ + { + "page": "Has planned start", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has planned finish", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has conference", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has description", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has location", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Page]]" + }, + { + "page": "Example/ICalendar-02/1", + "contents": "[[Has conference::A]] [[Has planned start::1 Jan 1970]] [[Has location::LOC-A]] [[Has description::Something about A]] [[Category:ICalendar-02]]" + }, + { + "page": "Example/ICalendar-02/2", + "contents": "[[Has conference::B]] [[Has planned start::2 Jan 1970 12:00]] [[Has planned finish::2 Jan 1970 15:00]] [[Has location::LOC-B]] [[Has description::Something about B]] [[Category:ICalendar-02]]" + } + ], + "tests": [ + { + "type": "special", + "about": "#0 `format=icalendar`, match iCalendar specific labels", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "icalendar", + "title": "SRF integration", + "description": "Simple description" + }, + "q": "[[Category:ICalendar-02]]", + "po": "?Has conference=summary|?Has planned start=start|?Has planned finish=end|?Has location=location|?Has description=description" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/icalendar-02.0.txt" + } + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-03.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-03.json new file mode 100644 index 00000000..0904c17f --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/icalendar-03.json @@ -0,0 +1,131 @@ +{ + "description": "Test `format=icalendar` with timezone using `Special:Ask`", + "setup": [ + { + "page": "Has planned start", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has planned finish", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has conference", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has description", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has location", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Page]]" + }, + { + "page": "Example/ICalendar-03/1", + "contents": "[[Has conference::A]] [[Has planned start::1 Jan 1970]] [[Has location::LOC-A]] [[Has description::Something about A]] [[Category:ICalendar-03]]" + }, + { + "page": "Example/ICalendar-03/2", + "contents": "[[Has conference::B]] [[Has planned start::2 Jan 1970 12:00]] [[Has planned finish::2 Jan 1970 15:00]] [[Has location::LOC-B]] [[Has description::Something about B]] [[Category:ICalendar-03]]" + } + ], + "tests": [ + { + "type": "special", + "about": "#0 single timezone (UTC)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "icalendar", + "title": "SRF integration", + "timezone": "UTC", + "description": "Simple description" + }, + "q": "[[Category:ICalendar-03]]", + "po": "?Has conference=summary|?Has planned start=start|?Has planned finish=end|?Has location=location|?Has description=description" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/icalendar-03.0.txt" + } + } + }, + { + "type": "special", + "about": "#1 multiple timezones (UTC,America/New_York)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "icalendar", + "title": "SRF integration", + "timezone": "UTC,America/New_York", + "description": "Simple description" + }, + "q": "[[Category:ICalendar-03]]", + "po": "?Has conference=summary|?Has planned start=start|?Has planned finish=end|?Has location=location|?Has description=description" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/icalendar-03.1.txt" + } + } + }, + { + "type": "special", + "about": "#2 unknown timezone", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "icalendar", + "title": "SRF integration", + "timezone": "UTC,Foo", + "description": "Simple description" + }, + "q": "[[Category:ICalendar-03]]", + "po": "?Has conference=summary|?Has planned start=start|?Has planned finish=end|?Has location=location|?Has description=description" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/icalendar-03.0.txt" + } + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/latest-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/latest-01.json new file mode 100644 index 00000000..c8b7b759 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/latest-01.json @@ -0,0 +1,61 @@ +{ + "description": "Test for `format=latest`", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/Latest/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Latest]]" + }, + { + "page": "Example/Latest/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Latest]]" + }, + { + "page": "Example/Latest/Q.1", + "contents": "{{#ask: [[Category:Latest]] |?Has date |format=latest }}" + }, + { + "page": "Example/Latest/Q.2", + "contents": "{{#ask: [[Category:Latest/default]] |?Has date |format=latest |default=No date }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0", + "subject": "Example/Latest/Q.1", + "assert-output": { + "to-contain": [ + "3 January 1970" + ] + } + }, + { + "type": "parser", + "about": "#1 default output", + "subject": "Example/Latest/Q.2", + "assert-output": { + "to-contain": [ + "No date" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/listwidget-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/listwidget-01.json new file mode 100644 index 00000000..2a55ca24 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/listwidget-01.json @@ -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 + } +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/math-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/math-01.json new file mode 100644 index 00000000..0a0258c6 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/math-01.json @@ -0,0 +1,113 @@ +{ + "description": "Test for math/sum result format in pt-br lang", + "setup": [ + { + "page": "Has number", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Number]]" + }, + { + "page": "Example/Math/1", + "contents": "[[Has number::30000000]] [[Has number::15000]] [[Has number::15000,25]] [[Has number::25,50]] " + }, + { + "page": "Example/Math/Q.1", + "contents": "{{#show: Example/Math/1 |?Has number|format=sum }}" + }, + { + "page": "Example/Math/Q.2", + "contents": "{{#show: Example/Math/1 |?Has number|format=max }}" + }, + { + "page": "Example/Math/Q.3", + "contents": "{{#show: Example/Math/1 |?Has number|format=min }}" + }, + { + "page": "Example/Math/Q.4", + "contents": "{{#show: Example/Math/1 |?Has number|format=product }}" + }, + { + "page": "Example/Math/Q.5", + "contents": "{{#show: Example/Math/1 |?Has number|format=average }}" + }, + { + "page": "Example/Math/Q.6", + "contents": "{{#show: Example/Math/1 |?Has number|format=median }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 format=sum (kilo and decimal separators)", + "subject": "Example/Math/Q.1", + "assert-output": { + "to-contain": [ + "30.030.025,75" + ] + } + }, + { + "type": "parser", + "about": "#1 format=max (kilo and decimal separators)", + "subject": "Example/Math/Q.2", + "assert-output": { + "to-contain": [ + "30.000.000" + ] + } + }, + { + "type": "parser", + "about": "#2 format=min (kilo and decimal separators)", + "subject": "Example/Math/Q.3", + "assert-output": { + "to-contain": [ + "25,5" + ] + } + }, + { + "type": "parser", + "about": "#3 format=product (kilo and decimal separators)", + "subject": "Example/Math/Q.4", + "assert-output": { + "to-contain": [ + "1,721279e+17" + ] + } + }, + { + "type": "parser", + "about": "#4 format=average (kilo and decimal separators)", + "subject": "Example/Math/Q.5", + "assert-output": { + "to-contain": [ + "7.507.506,438" + ] + } + }, + { + "type": "parser", + "about": "#5 format=median (kilo and decimal separators)", + "subject": "Example/Math/Q.6", + "assert-output": { + "to-contain": [ + "15.000,125" + ] + } + } + ], + "settings": { + "wgContLang": "pt-br", + "wgLang": "pt-br", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-01.json new file mode 100644 index 00000000..f29c8e30 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-01.json @@ -0,0 +1,101 @@ +{ + "description": "Test `format=outline` template output", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Assigned to", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Severity", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "NS_TEMPLATE", + "page": "outline-test-header", + "contents": "<includeonly> #outlinelevel: {{{#outlinelevel}}}, #itemcount: {{{#itemcount}}}, Severity: {{{Severity}}}</includeonly>" + }, + { + "namespace": "NS_TEMPLATE", + "page": "outline-test-item", + "contents": "<includeonly> #itemsubject: {{{#itemsubject}}}, #itemsection: {{{#itemsection}}}, #itemnumber: {{{#itemnumber}}}, Assigned to: {{{Assigned to}}}</includeonly>" + }, + { + "page": "SRF/Outline/1", + "contents": "[[Assigned to::John]] [[Severity::Normal]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/2", + "contents": "[[Assigned to::Jane]] [[Severity::Urgent]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/3", + "contents": "[[Assigned to::ç”°ä¸]] [[Severity::Urgent]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/Q.1", + "contents": "{{#ask: [[Category:Outline]] |?Severity |?Assigned to |format=outline |template=outline-test |sort=Severity,Assigned to |outlineproperties=Severity |link=none }}" + }, + { + "page": "SRF/Outline/Q.2", + "contents": "{{#ask: [[Category:Outline]] |?Severity |?Assigned to |format=outline |template=outline-test |sort=Severity,Assigned to |outlineproperties=Severity,Assigned to |link=none }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 (`outlineproperties=Severity`)", + "subject": "SRF/Outline/Q.1", + "assert-output": { + "to-contain": [ + "<div class=\"outline-test-section-severity\"> #outlinelevel: 0, #itemcount: 1, Severity: Normal", + "<div class=\"outline-test-items\"><div class=\"outline-test-item\">", + "#itemsubject: SRF/Outline/1, #itemsection: 0, #itemnumber: 0, Assigned to: {{{Assigned to}}}", + "#itemsubject: {{{#itemsubject}}}, #itemsection: 0, #itemnumber: 1, Assigned to: John</div></div></div>", + "<div class=\"outline-test-section-severity\"> #outlinelevel: 0, #itemcount: 2, Severity: Urgent", + "<div class=\"outline-test-items\"><div class=\"outline-test-item\">", + "#itemsubject: SRF/Outline/2, #itemsection: 0, #itemnumber: 0, Assigned to: {{{Assigned to}}}", + "#itemsubject: {{{#itemsubject}}}, #itemsection: 0, #itemnumber: 1, Assigned to: Jane</div>", + "#itemsubject: SRF/Outline/3, #itemsection: 1, #itemnumber: 0, Assigned to: {{{Assigned to}}}", + "#itemsubject: {{{#itemsubject}}}, #itemsection: 1, #itemnumber: 1, Assigned to: ç”°ä¸</div></div></div>" + ] + } + }, + { + "type": "parser", + "about": "#1 (`outlineproperties=Severity,Assigned to`)", + "subject": "SRF/Outline/Q.2", + "assert-output": { + "to-contain": [ + "<div class=\"outline-test-section-severity\"> #outlinelevel: 0, #itemcount: 1, Severity: Normal", + "<div class=\"outline-test-items\"><div class=\"outline-test-section-assigned-to\">", + "#outlinelevel: 1, #itemcount: 1, Severity: {{{Severity}}}", + "<div class=\"outline-test-items\"><div class=\"outline-test-item\">", + "#itemsubject: SRF/Outline/1, #itemsection: 0, #itemnumber: 0, Assigned to: {{{Assigned to}}}</div></div></div></div></div>", + "<div class=\"outline-test-section-severity\"> #outlinelevel: 0, #itemcount: 2, Severity: Urgent", + "<div class=\"outline-test-items\"><div class=\"outline-test-section-assigned-to\">", + "#outlinelevel: 1, #itemcount: 1, Severity: {{{Severity}}}", + "<div class=\"outline-test-items\"><div class=\"outline-test-item\">", + "#itemsubject: SRF/Outline/2, #itemsection: 0, #itemnumber: 0, Assigned to: {{{Assigned to}}}</div></div></div>", + "<div class=\"outline-test-section-assigned-to\"> #outlinelevel: 1, #itemcount: 1, Severity: {{{Severity}}}", + "<div class=\"outline-test-items\"><div class=\"outline-test-item\">", + "#itemsubject: SRF/Outline/3, #itemsection: 0, #itemnumber: 0, Assigned to: {{{Assigned to}}}</div></div></div></div></div>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-02.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-02.json new file mode 100644 index 00000000..d9122f8d --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/outline-02.json @@ -0,0 +1,105 @@ +{ + "description": "Test `format=outline` list output", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Assigned to", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Severity", + "contents": "[[Has type::Text]]" + }, + { + "page": "SRF/Outline/1", + "contents": "[[Assigned to::John]] [[Severity::Normal]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/2", + "contents": "[[Assigned to::Jane]] [[Severity::Urgent]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/3", + "contents": "[[Assigned to::ç”°ä¸]] [[Severity::Urgent]] [[Category:Outline]]" + }, + { + "page": "SRF/Outline/Q.1", + "contents": "{{#ask: [[Category:Outline]] |?Severity |?Assigned to |format=outline |sort=Severity,Assigned to |outlineproperties=Severity |link=none }}" + }, + { + "page": "SRF/Outline/Q.2", + "contents": "{{#ask: [[Category:Outline]] |?Severity |?Assigned to |format=outline |sort=Severity,Assigned to |outlineproperties=Severity,Assigned to |link=none }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 (`outlineproperties=Severity`)", + "subject": "SRF/Outline/Q.1", + "assert-output": { + "to-contain": [ + "<p style=\"font-size: small; font-weight: bold;\">Normal</p>", + "<ul>", + "<li>SRF/Outline/1 (Assigned to John)</li>", + "</ul>", + "<ul>", + "</ul>", + "<p style=\"font-size: small; font-weight: bold;\">Urgent</p>", + "<ul>", + "<li>SRF/Outline/2 (Assigned to Jane)</li>", + "<li>SRF/Outline/3 (Assigned to ç”°ä¸)</li>", + "</ul>", + "<ul>", + "</ul>" + ] + } + }, + { + "type": "parser", + "about": "#1 (`outlineproperties=Severity,Assigned to`)", + "subject": "SRF/Outline/Q.2", + "assert-output": { + "to-contain": [ + "<p style=\"font-size: medium; font-weight: regular;\">Normal</p>", + "<ul>", + "<p style=\"font-size: small; font-weight: bold;\">John</p>", + "<ul>", + "<li>SRF/Outline/1</li>", + "</ul>", + "<ul>", + "</ul>", + "</ul>", + "<p style=\"font-size: medium; font-weight: regular;\">Urgent</p>", + "<ul>", + "<p style=\"font-size: small; font-weight: bold;\">Jane</p>", + "<ul>", + "<li>SRF/Outline/2</li>", + "</ul>", + "<ul>", + "</ul>", + "<p style=\"font-size: small; font-weight: bold;\">ç”°ä¸</p>", + "<ul>", + "<li>SRF/Outline/3</li>", + "</ul>", + "<ul>", + "</ul>", + "</ul>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-01.json new file mode 100644 index 00000000..c2800225 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-01.json @@ -0,0 +1,70 @@ +{ + "description": "Test `format=tagcloud` html output", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "TagcloudTemplate", + "namespace": "NS_TEMPLATE", + "contents": "<includeonly>T: {{{1}}}</includeonly>" + }, + { + "page": "Example/Tagcloud/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Tagcloud]]" + }, + { + "page": "Example/Tagcloud/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Tagcloud]]" + }, + { + "page": "Example/Tagcloud/3", + "contents": "[[Has date::3 Jan 1970]] [[Has date::4 Jan 1970]] [[Category:Tagcloud]]" + }, + { + "page": "Test/Tagcloud/Q.1", + "contents": "{{#ask: [[Category:Tagcloud]] |?Has date |format=tagcloud }}" + }, + { + "page": "Test/Tagcloud/Q.2", + "contents": "{{#ask: [[Category:Tagcloud]] |?Has date |template=TagcloudTemplate |format=tagcloud }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0", + "subject": "Test/Tagcloud/Q.1", + "assert-output": { + "to-contain": [ + "<div class=\"srf-tagcloud\" data-version=\"0.4.1\"><span style=\"font-size:77%\">1 January 1970</span> <span style=\"font-size:242%\">3 January 1970</span> <span style=\"font-size:77%\">4 January 1970</span></div>" + ] + } + }, + { + "type": "parser", + "about": "#0 with template", + "subject": "Test/Tagcloud/Q.2", + "assert-output": { + "to-contain": [ + "<div class=\"srf-tagcloud\" data-version=\"0.4.1\"><span style=\"font-size:77%\">T: 1 January 1970</span> <span style=\"font-size:242%\">T: 3 January 1970</span> <span style=\"font-size:77%\">T: 4 January 1970</span></div>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-02.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-02.json new file mode 100644 index 00000000..525b867a --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tagcloud-02.json @@ -0,0 +1,78 @@ +{ + "description": "Test `format=tagcloud` html output, namespaced", + "setup": [ + { + "page": "Has page", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Page]]" + }, + { + "page": "TagcloudTemplate", + "namespace": "NS_TEMPLATE", + "contents": "<includeonly>{{{1}}}</includeonly>" + }, + { + "page": "Example/Tagcloud/1", + "namespace": "NS_HELP", + "contents": "[[Has page::Help:Test1]] [[Category:Tagcloud-2]]" + }, + { + "page": "Example/Tagcloud/2", + "namespace": "NS_HELP", + "contents": "[[Has page::Help:Test2]] [[Category:Tagcloud-2]]" + }, + { + "page": "Example/Tagcloud/3", + "namespace": "NS_HELP", + "contents": "[[Has page::Help:Test3]] [[Category:Tagcloud-2]]" + }, + { + "page": "Test/Tagcloud/Q.1", + "contents": "{{#ask: [[Category:Tagcloud-2]] |?Has page |format=tagcloud }}" + }, + { + "page": "Test/Tagcloud/Q.2", + "contents": "{{#ask: [[Category:Tagcloud-2]] |?Has page |template=TagcloudTemplate |format=tagcloud }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 (namespaced page value)", + "subject": "Test/Tagcloud/Q.1", + "assert-output": { + "to-contain": [ + "<a href=.* class=\"new\" title=\"Help:Test1.*\">Help:Test1</a>", + "<a href=.* class=\"new\" title=\"Help:Test2.*\">Help:Test2</a>", + "<a href=.* class=\"new\" title=\"Help:Test3.*\">Help:Test3</a>" + ] + } + }, + { + "type": "parser", + "about": "#1 (#355, template namespaced page value)", + "subject": "Test/Tagcloud/Q.2", + "assert-output": { + "to-contain": [ + "<span style=\"font-size:77%\">Help:Test1</span>", + "<span style=\"font-size:77%\">Help:Test2</span>", + "<span style=\"font-size:77%\">Help:Test3</span>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "NS_HELP":true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/timeline-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/timeline-01.json new file mode 100644 index 00000000..fc0e475c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/timeline-01.json @@ -0,0 +1,50 @@ +{ + "description": "Test for timeline result format", + "setup": [ + { + "page": "Has date", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Example/Timeline/1", + "contents": "[[Has date::1 Jan 1970]] [[Category:Timeline]]" + }, + { + "page": "Example/Timeline/2", + "contents": "[[Has date::3 Jan 1970]] [[Category:Timeline]]" + }, + { + "page": "Example/Timeline/Q.1", + "contents": "{{#ask: [[Category:Timeline]] |?Has date |format=timeline }}" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 default bands", + "subject": "Example/Timeline/Q.1", + "assert-output": { + "to-contain": [ + "<div id=\"smwtimeline.* class=\"smwtimeline is-disabled\" style=\"height: 300px\">", + "<span class=\"smwtlband\" style=\"display:none;\">MONTH</span><span class=\"smwtlband\" style=\"display:none;\">YEAR</span>", + "<span class=\"smwtlurl\"><a .* title=\"Example/Timeline/1\">Example/Timeline/1</a></span><span class=\"smwtlstart\">1970-01-01</span>", + "<span class=\"smwtlurl\"><a .* title=\"Example/Timeline/2\">Example/Timeline/2</a></span><span class=\"smwtlstart\">1970-01-03</span>" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-01.json new file mode 100644 index 00000000..df5288c0 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-01.json @@ -0,0 +1,222 @@ +{ + "description": "Tree format: Multi-page results", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "page": "Example/Tree 1", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 2", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 3", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 11", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 12", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 13", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 21", + "contents": "[[Has parent::Example/Tree 2]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 22", + "contents": "[[Has parent::Example/Tree 2]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 31", + "contents": "[[Has parent::Example/Tree 3]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 32", + "contents": "[[Has parent::Example/Tree 3]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 33", + "contents": "[[Has parent::Example/Tree 3]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 121", + "contents": "[[Has parent::Example/Tree 12]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 321", + "contents": "[[Has parent::Example/Tree 32]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 01-01", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent}}</div>" + }, + { + "page": "Example/Tree 01-02", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent|root=Example/Tree 1}}</div>" + }, + { + "page": "Example/Tree 01-03", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=ultree|parent=Has parent}}</div>" + }, + { + "page": "Example/Tree 01-04", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=ultree|parent=Has parent|root=Example/Tree 3}}</div>" + }, + { + "page": "Example/Tree 01-05", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=oltree|parent=Has parent}}</div>" + }, + { + "page": "Example/Tree 01-06", + "contents": "<div>{{#ask:[[Part of::Tree test]]|format=oltree|parent=Has parent|root=Example/Tree 2}}</div>" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Tree 01-01 (Multi-page result)", + "subject": "Example/Tree 01-01", + "assert-output": { + "to-contain": [ + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 21\"]:only-child", + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 22\"]:only-child", + + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 31\"]:only-child", + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 32\"] + ul > li:only-child > a[title=\"Example/Tree 321\"]:only-child", + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 33\"]:only-child", + + [ "div > ul:only-child", 1 ], + [ "div > ul > li", 3 ], + [ "div > ul > li > ul > li", 8 ], + [ "div > ul > li > ul > li > ul > li", 2 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 01-02 (Multi-page result with root specified)", + "subject": "Example/Tree 01-02", + "assert-output": { + "to-contain": [ + "div > ul > li:only-child > a[title=\"Example/Tree 1\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ul > li:only-child > a[title=\"Example/Tree 1\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ul > li:only-child > a[title=\"Example/Tree 1\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + [ "div > ul > li", 1 ], + [ "div > ul > li > ul > li", 3 ], + [ "div > ul > li > ul > li > ul > li", 1 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 01-03 (Multi-page result (ultree))", + "subject": "Example/Tree 01-03", + "assert-output": { + "to-contain": [ + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 21\"]:only-child", + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 22\"]:only-child", + + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 31\"]:only-child", + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 32\"] + ul > li:only-child > a[title=\"Example/Tree 321\"]:only-child", + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 33\"]:only-child", + + [ "div > ul > li", 3 ], + [ "div > ul > li > ul > li", 8 ], + [ "div > ul > li > ul > li > ul > li", 2 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 01-04 (Multi-page result with root specified (ultree))", + "subject": "Example/Tree 01-04", + "assert-output": { + "to-contain": [ + "div > ul > li:only-child > a[title=\"Example/Tree 3\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 31\"]:only-child", + "div > ul > li:only-child > a[title=\"Example/Tree 3\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 32\"] + ul > li:only-child > a[title=\"Example/Tree 321\"]:only-child", + "div > ul > li:only-child > a[title=\"Example/Tree 3\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 33\"]:only-child", + + [ "div > ul > li", 1 ], + [ "div > ul > li > ul > li", 3 ], + [ "div > ul > li > ul > li > ul > li", 1 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 01-05 (Multi-page result (oltree))", + "subject": "Example/Tree 01-05", + "assert-output": { + "to-contain": [ + "div > ol > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ol > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ol > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ol > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ol > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ol > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ol > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + "div > ol > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ol > li:nth-child(1) > a[title=\"Example/Tree 21\"]:only-child", + "div > ol > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ol > li:nth-child(2) > a[title=\"Example/Tree 22\"]:only-child", + + "div > ol > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ol > li:nth-child(1) > a[title=\"Example/Tree 31\"]:only-child", + "div > ol > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ol > li:nth-child(2) > a[title=\"Example/Tree 32\"] + ol > li:only-child > a[title=\"Example/Tree 321\"]:only-child", + "div > ol > li:nth-child(3) > a[title=\"Example/Tree 3\"] + ol > li:nth-child(3) > a[title=\"Example/Tree 33\"]:only-child", + + [ "div > ol > li", 3 ], + [ "div > ol > li > ol > li", 8 ], + [ "div > ol > li > ol > li > ol > li", 2 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 01-06 (Multi-page result with root specified (oltree))", + "subject": "Example/Tree 01-06", + "assert-output": { + "to-contain": [ + "div > ol > li:only-child > a[title=\"Example/Tree 2\"] + ol > li:nth-child(1) > a[title=\"Example/Tree 21\"]:only-child", + "div > ol > li:only-child > a[title=\"Example/Tree 2\"] + ol > li:nth-child(2) > a[title=\"Example/Tree 22\"]:only-child", + + [ "div > ol > li", 1 ], + [ "div > ol > li > ol > li", 2 ] + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": true + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-02.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-02.json new file mode 100644 index 00000000..721c363a --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-02.json @@ -0,0 +1,91 @@ +{ + "description": "Tree format: Simple one-page result", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "NS_TEMPLATE", + "page": "Example/Tree format template", + "contents": "FOO{{{1|}}}BAR" + }, + { + "page": "Example/Tree 1", + "contents": "[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 02-01", + "contents": "{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent}}" + }, + { + "page": "Example/Tree 02-02", + "contents": "{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent|template=Example/Tree format template }}" + }, + { + "page": "Example/Tree 02-03", + "contents": "{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent|class=some-class}}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Tree 02-01 (Simple one-page result)", + "subject": "Example/Tree 02-01", + "assert-output": { + "to-contain": [ + "ul > li:only-child > a[title=\"Example/Tree 1\"]:only-child" + ] + } + }, + { + "type": "parser-html", + "about": "Tree 02-02-1 (Simple one-page result with template - structure)", + "subject": "Example/Tree 02-02", + "assert-output": { + "to-contain": [ + "ul > li:only-child > a[title=\"Example/Tree 1\"]:only-child" + ] + } + }, + { + "type": "parser", + "about": "Tree 02-02-2 (Simple one-page result with template - content)", + "subject": "Example/Tree 02-02", + "assert-output": { + "to-contain": [ + "FOO.*Example/Tree 1.*BAR" + ] + } + }, + { + "type": "parser-html", + "about": "Tree 02-03 (Simple one-page result with class parameter)", + "subject": "Example/Tree 02-03", + "assert-output": { + "to-contain": [ + "div.some-class > ul > li:only-child > a[title=\"Example/Tree 1\"]:only-child" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-03.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-03.json new file mode 100644 index 00000000..c90493d5 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-03.json @@ -0,0 +1,43 @@ +{ + "description": "Tree format: Raising error: Missing 'parent' parameter", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "page": "Example/Boostrap", + "contents": "[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 03-01", + "contents": "{{#ask:[[Part of::Tree test]]|format=tree}}" + } + ], + "tests": [ + { + "type": "parser", + "about": "Tree 03-01 (Raising error: Missing 'parent' parameter)", + "subject": "Example/Tree 03-01", + "assert-output": { + "to-contain": [ + "No parent property given. The tree can not be built without a specified parent property." + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-04.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-04.json new file mode 100644 index 00000000..c1176503 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-04.json @@ -0,0 +1,44 @@ +{ + "description": "Tree format: Empty resultset does not produce tree", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "page": "Example/Tree 04-01", + "contents": "{{#ask:[[Part of::+]]|format=tree|parent=Has example}}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Tree 04-01 (Empty resultset does not produce tree)", + "subject": "Example/Tree 04-01", + "assert-output": { + "to-contain": [ + [ "div.srf-tree", 0 ] + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-05.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-05.json new file mode 100644 index 00000000..c9d82e6d --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-05.json @@ -0,0 +1,76 @@ +{ + "description": "Tree format: Loop detection", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "page": "Example/Tree 1", + "contents": "[[Has parent::Example/Tree 121]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 2", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 3", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 11", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 12", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 31", + "contents": "[[Has parent::Example/Tree 3]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 32", + "contents": "[[Has parent::Example/Tree 3]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 121", + "contents": "[[Has parent::Example/Tree 12]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 05-01", + "contents": "{{#ask:[[Part of::Tree test]]|format=tree|parent=Has parent}}" + } + ], + "tests": [ + { + "type": "parser", + "about": "Tree 05-01 (Loop detection)", + "subject": "Example/Tree 05-01", + "assert-output": { + "to-contain": [ + "Circle detected when trying to insert Example/Tree 121 into the tree." + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": true + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-06.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-06.json new file mode 100644 index 00000000..c6bc3184 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-06.json @@ -0,0 +1,127 @@ +{ + "description": "Tree format: Insert elements with multiple parents multiple times", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "NS_TEMPLATE", + "page": "Example/Tree format template", + "contents": "FOO{{{1|}}}BAR" + }, + { + "page": "Example/Tree 1", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 2", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 3", + "contents": "<!-- No parent -->[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 11", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 12", + "contents": "[[Has parent::Example/Tree 1]][[Has parent::Example/Tree 2]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 13", + "contents": "[[Has parent::Example/Tree 1]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 121", + "contents": "[[Has parent::Example/Tree 12]][[Part of::Tree test]]" + }, + { + "page": "Example/Tree 06-01", + "contents": "<div>{{#ask:[[Part of::Tree test]] |format=tree |parent=Has parent }}</div>" + }, + { + "page": "Example/Tree 06-02", + "contents": "<div>{{#ask:[[Part of::Tree test]] |format=tree |parent=Has parent |template=Example/Tree format template }}</div>" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Tree 06-01 (Insert elements with multiple parents multiple times)", + "subject": "Example/Tree 06-01", + "assert-output": { + "to-contain": [ + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:only-child > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"]:only-child", + + [ "div > ul > li", 3 ], + [ "div > ul > li > ul > li", 4 ], + [ "div > ul > li > ul > li > ul > li", 2 ] + ] + } + }, + { + "type": "parser-html", + "about": "Tree 06-02-1 (Insert elements with multiple parents multiple times (with template)) - structure", + "subject": "Example/Tree 06-02", + "assert-output": { + "to-contain": [ + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(1) > a[title=\"Example/Tree 11\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(2) > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + "div > ul > li:nth-child(1) > a[title=\"Example/Tree 1\"] + ul > li:nth-child(3) > a[title=\"Example/Tree 13\"]:only-child", + + "div > ul > li:nth-child(2) > a[title=\"Example/Tree 2\"] + ul > li:only-child > a[title=\"Example/Tree 12\"] + ul > li:only-child > a[title=\"Example/Tree 121\"]:only-child", + + "div > ul > li:nth-child(3) > a[title=\"Example/Tree 3\"]:only-child", + + [ "div > ul > li", 3 ], + [ "div > ul > li > ul > li", 4 ], + [ "div > ul > li > ul > li > ul > li", 2 ] + ] + } + }, + { + "type": "parser", + "about": "Tree 06-02-2 (Insert elements with multiple parents multiple times (with template)) - content", + "subject": "Example/Tree 06-02", + "assert-output": { + "to-contain": [ + "FOO.*Example/Tree 1.*BAR", + "FOO.*Example/Tree 11.*BAR", + "FOO.*Example/Tree 12.*BAR", + "FOO.*Example/Tree 121.*BAR", + "FOO.*Example/Tree 13.*BAR", + "FOO.*Example/Tree 2.*BAR", + "FOO.*Example/Tree 3.*BAR" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": true + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-07.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-07.json new file mode 100644 index 00000000..8b09e758 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/tree-07.json @@ -0,0 +1,139 @@ +{ + "description": "Tree format: Simple one-page result", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has parent", + "contents": "[[Has type::Page]]" + }, + { + "namespace": "SMW_NS_PROPERTY", + "page": "Part of", + "contents": "[[Has type::Text]]" + }, + { + "namespace": "NS_TEMPLATE", + "page": "Example/Tree format template", + "contents": "FOO{{{1|}}}BAR{{{userparam|}}}BAZ" + }, + { + "page": "Example/Tree 1", + "contents": "[[Part of::Tree test]]" + }, + { + "page": "Example/Tree 11", + "contents": "[[Part of::Tree test]][[Has parent::Example/Tree 1]]" + }, + { + "page": "Example/Tree 07-01", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent }}" + }, + { + "page": "Example/Tree 07-02", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent |link=all}}" + }, + { + "page": "Example/Tree 07-03", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent |link=subject}}" + }, + { + "page": "Example/Tree 07-04", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent |link=none}}" + }, + { + "page": "Example/Tree 07-05", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent |template=Example/Tree format template |userparam=someparam }}" + }, + { + "page": "Example/Tree 07-06", + "contents": "{{#ask:[[Part of::Tree test]] |?Has parent |format=tree |parent=Has parent |template=Example/Tree format template |userparam=someparam |link=none}}" + } + ], + "tests": [ + { + "type": "parser-html", + "about": "Tree 07-01 (Default linking)", + "subject": "Example/Tree 07-01", + "assert-output": { + "to-contain": [ + "ul > li > a[title=\"Example/Tree 1\"] + ul > li > a[title=\"Example/Tree 11\"] + a[title=\"Property:Has parent\"] + a[title=\"Example/Tree 1\"]" + ] + } + }, + { + "type": "parser-html", + "about": "Tree 07-02 (link=all)", + "subject": "Example/Tree 07-02", + "assert-output": { + "to-contain": [ + "ul > li > a[title=\"Example/Tree 1\"] + ul > li > a[title=\"Example/Tree 11\"] + a[title=\"Property:Has parent\"] + a[title=\"Example/Tree 1\"]" + ] + } + }, + { + "type": "parser-html", + "about": "Tree 07-03 (link=subject)", + "subject": "Example/Tree 07-03", + "assert-output": { + "to-contain": [ + "ul > li > a[title=\"Example/Tree 1\"] + ul > li > a[title=\"Example/Tree 11\"]:first-of-type + a[title=\"Property:Has parent\"]:last-of-type" + + ] + } + }, + { + "type": "parser-html", + "about": "Tree 07-04 (link=none)", + "subject": "Example/Tree 07-04", + "assert-output": { + "to-contain": [ + "ul > li > ul:only-child > li > a[title=\"Property:Has parent\"]:only-child" + ] + } + }, + { + "type": "parser", + "about": "Tree 07-05-1 (template with userparam)", + "subject": "Example/Tree 07-05", + "assert-output": { + "to-contain": [ + "BARsomeparamBAZ" + ] + } + }, + { + "type": "parser-html", + "about": "Tree 07-05-2 (template with userparam: assert intact default linking)", + "subject": "Example/Tree 07-05", + "assert-output": { + "to-contain": [ + "ul > li > a[title=\"Example/Tree 1\"] + ul > li > a[title=\"Example/Tree 11\"]" + ] + } + }, + { + "type": "parser", + "about": "Tree 07-06 (template with userparam and link=none)", + "subject": "Example/Tree 07-06", + "assert-output": { + "to-contain": [ + "FOOExample/Tree 1BARsomeparamBAZ", + "FOOExample/Tree 11BARsomeparamBAZ" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/vcard-01.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/vcard-01.json new file mode 100644 index 00000000..536f5a8d --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/TestCases/vcard-01.json @@ -0,0 +1,136 @@ +{ + "description": "Test `format=vcard`", + "setup": [ + { + "page": "Has birthday", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Date]]" + }, + { + "page": "Has address", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has cellphone", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Phone]]" + }, + { + "page": "Has homephone", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Phone]]" + }, + { + "page": "Has note", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Text]]" + }, + { + "page": "Has homepage", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::URL]]" + }, + { + "page": "Has email", + "namespace": "SMW_NS_PROPERTY", + "contents": "[[Has type::Email]]" + }, + { + "page": "Example/Vcard-01/0", + "contents": "[[Category:Vcard-00]]" + }, + { + "page": "Example/Vcard-01/1", + "contents": "[[Category:Vcard-01]] [[Has name::John Doe]] [[Has birthday::1 Jan 1952]] [[Has email::johnDoe@example.org]] [[Has homepage::http://www.example/com/doe]] [[Has address::Example Avenue]] [[Has town::Anytown]] [[Has cellphone::+1 781 555 1212]] [[Has homephone::+1 202 555 1212]] [[Has note::John Doe has a long and varied history, being documented on more ...]]" + }, + { + "page": "Example/Vcard-01/2", + "contents": "{{#subobject: |Has name=John Doe |Has birthday=1 Jan 1952 |Has email=johnDoe@example.org |Has homepage=http://www.example/com/doe |Has address=Example Avenue |Has town=Anytown |Has cellphone=+1 781 555 1212 |Has homephone=+1 202 555 1212 |Has note=John Doe has a long and varied history, being documented on more ... |@category=Vcard-02}}" + } + ], + "tests": [ + { + "type": "special", + "about": "#0 `format=vcard` empty", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "vcard" + }, + "q": "[[Category:Vcard-00]]", + "po": "?Category=category" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/vcard-01.0.txt" + } + } + }, + { + "type": "special", + "about": "#1 `format=vcard` name + address", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "vcard" + }, + "q": "[[Category:Vcard-01]]", + "po": "?Has name=name|?Has birthday=birthday|?Has email=email|?Has homepage=homepage|?Has address=homestreet|?has town=homelocality|?Has cellphone=cellphone|?Has homephone=homephone|?Has note=note" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/vcard-01.1.txt" + } + } + }, + { + "type": "special", + "about": "#2 `format=vcard` name + address (subobject)", + "special-page": { + "page": "Ask", + "request-parameters": { + "p": { + "link": "none", + "limit": "10", + "offset": "0", + "mainlabel": "", + "format": "vcard" + }, + "q": "[[Category:Vcard-02]]", + "po": "?Has name=name|?Has birthday=birthday|?Has email=email|?Has homepage=homepage|?Has address=homestreet|?has town=homelocality|?Has cellphone=cellphone|?Has homephone=homephone|?Has note=note" + } + }, + "assert-output": { + "to-contain": { + "contents-file" : "/../Fixtures/vcard-01.2.txt" + } + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/bootstrap.json b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/bootstrap.json new file mode 100644 index 00000000..da01021e --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/JSONScript/bootstrap.json @@ -0,0 +1,53 @@ +{ + "description": "Example bootstrap test case (see https://youtu.be/7fDKjPFaTaY)", + "setup": [ + { + "namespace": "SMW_NS_PROPERTY", + "page": "Has example", + "contents": "[[Has type::Page]]" + }, + { + "page": "Example/Boostrap", + "contents": "[[Has example::Example123]]" + } + ], + "tests": [ + { + "type": "parser", + "about": "#0 (page type annotation)", + "subject": "Example/Boostrap", + "assert-store": { + "semantic-data": { + "strictPropertyValueMatch": false, + "propertyCount": 3, + "propertyKeys": [ + "_SKEY", + "_MDAT", + "Has example" + ], + "propertyValues": [ + "Example123" + ] + } + }, + "assert-output": { + "to-contain": [ + "Example123" + ] + } + } + ], + "settings": { + "wgContLang": "en", + "wgLang": "en", + "smwgNamespacesWithSemanticLinks": { + "NS_MAIN": true, + "SMW_NS_PROPERTY": true + } + }, + "meta": { + "version": "2", + "is-incomplete": false, + "debug": false + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/ResourcesTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/ResourcesTest.php new file mode 100644 index 00000000..20b55c40 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Integration/ResourcesTest.php @@ -0,0 +1,81 @@ +<?php + +namespace SRF\Tests\Integration; + +use ResourceLoader; +use ResourceLoaderContext; +use ResourceLoaderModule; + +/** + * Tests for resource definitions and files + * + * @file + * @since 1.9 + * + * @ingroup SRF + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class ResourcesTest extends \PHPUnit_Framework_TestCase { + + /** + * Helper method to load resources only valid for this extension + * + * @return array + */ + private function getSRFResourceModules() { + global $srfgIP; + return include $srfgIP . '/' . 'Resources.php'; + } + + public function moduleDataProvider() { + + // #501 + // MW 1.33+ + if ( class_exists( '\MediaWiki\MediaWikiServices' ) && method_exists( '\MediaWiki\MediaWikiServices', 'getResourceLoader' ) ) { + $resourceLoader = \MediaWiki\MediaWikiServices::getInstance()->getResourceLoader(); + } else { + $resourceLoader = new ResourceLoader(); + } + + $context = ResourceLoaderContext::newDummyContext(); + $modules = $this->getSRFResourceModules(); + + return [ [ $modules, $resourceLoader, $context ] ]; + } + + /** + * @dataProvider moduleDataProvider + */ + public function testModulesScriptsFilesAreAccessible( $modules, ResourceLoader $resourceLoader, $context ) { + foreach ( $modules as $name => $values ) { + $module = $resourceLoader->getModule( $name ); + $scripts = $module->getScript( $context ); + $this->assertInternalType( 'string', $scripts ); + } + } + + /** + * Test styles accessibility + * + * @dataProvider moduleDataProvider + */ + public function testModulesStylesFilesAreAccessible( $modules, ResourceLoader $resourceLoader, $context ) { + + foreach ( $modules as $name => $values ) { + + // Get module details + $module = $resourceLoader->getModule( $name ); + + // Get styles per module + $styles = $module->getStyles( $context ); + $this->assertContainsOnly( 'string', $styles ); + } + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/ResultPrinterReflector.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/ResultPrinterReflector.php new file mode 100644 index 00000000..5b9f3ae6 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/ResultPrinterReflector.php @@ -0,0 +1,55 @@ +<?php + +namespace SRF\Tests; + +use ReflectionClass; +use SMW\Query\ResultPrinter; + +/** + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class ResultPrinterReflector { + + /** + * Helper method sets result printer parameters + * + * @param ResultPrinter $instance + * @param array $parameters + * + * @return ResultPrinter + */ + public function addParameters( ResultPrinter $instance, array $parameters ) { + + $reflector = new ReflectionClass( $instance ); + $params = $reflector->getProperty( 'params' ); + $params->setAccessible( true ); + $params->setValue( $instance, $parameters ); + + if ( isset( $parameters['searchlabel'] ) ) { + $searchlabel = $reflector->getProperty( 'mSearchlabel' ); + $searchlabel->setAccessible( true ); + $searchlabel->setValue( $instance, $parameters['searchlabel'] ); + } + + if ( isset( $parameters['headers'] ) ) { + $searchlabel = $reflector->getProperty( 'mShowHeaders' ); + $searchlabel->setAccessible( true ); + $searchlabel->setValue( $instance, $parameters['headers'] ); + } + + return $instance; + } + + public function invoke( ResultPrinter $instance, $queryResult, $outputMode ) { + + $reflector = new ReflectionClass( $instance ); + $method = $reflector->getMethod( 'getResultText' ); + $method->setAccessible( true ); + + return $method->invoke( $instance, $queryResult, $outputMode ); + } + +}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php new file mode 100644 index 00000000..86432d11 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php @@ -0,0 +1,149 @@ +<?php + +namespace SRF\Tests\BibTex; + +use PHPUnit\Framework\MockObject\MockObject; +use SMWInfolink; +use SMWQueryResult; +use SRF\BibTex\BibTexFileExportPrinter; +use SRF\Tests\ResultPrinterReflector; + +/** + * @covers \SRF\BibTex\BibTexFileExportPrinter + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class BibTexFileExportPrinterTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + BibTexFileExportPrinter::class, + new BibTexFileExportPrinter( 'bibtex' ) + ); + } + + /** + * @dataProvider filenameProvider + */ + public function testGetFileName( $filename, $searchlabel, $expected ) { + + $parameters = [ + 'filename' => $filename, + 'searchlabel' => $searchlabel + ]; + + $bibTexPrinter = new BibTexFileExportPrinter( 'bibtex' ); + + ( new ResultPrinterReflector() )->addParameters( $bibTexPrinter, $parameters ); + + $this->assertEquals( + $expected, + $bibTexPrinter->getFileName( $this->newQueryResultDummy() ) + ); + } + + public function filenameProvider() { + + yield[ + '', + '', + 'BibTeX.bib' + ]; + + yield[ + '', + 'foo bar', + 'foo_bar.bib' + ]; + + yield[ + 'foo', + '', + 'foo.bib' + ]; + + yield[ + 'foo.bib', + '', + 'foo.bib' + ]; + + yield[ + 'foo bar.bib', + '', + 'foo_bar.bib' + ]; + } + + /** + * @return MockObject|SMWQueryResult + */ + private function newQueryResultDummy() { + return $this->getMockBuilder( SMWQueryResult::class ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testGetMimeType() { + + $instance = new BibTexFileExportPrinter( + 'bibtex' + ); + + $this->assertEquals( + 'text/bibtex', + $instance->getMimeType( $this->newQueryResultDummy() ) + ); + } + + public function testGetResult_LinkOnNonFileOutput() { + $bibTexPrinter = new BibTexFileExportPrinter( + 'bibtex' + ); + + $this->assertEquals( + 'foo_link', + $bibTexPrinter->getResult( + $this->newMockQueryResultWithLink(), + [], + SMW_OUTPUT_HTML + ) + ); + } + + private function newMockQueryResultWithLink() { + $queryResult = $this->newQueryResultDummy(); + + $queryResult->expects( $this->any() ) + ->method( 'getErrors' ) + ->will( $this->returnValue( [] ) ); + + $queryResult->expects( $this->any() ) + ->method( 'getCount' ) + ->will( $this->returnValue( 1 ) ); + + $queryResult->expects( $this->once() ) + ->method( 'getQueryLink' ) + ->will( $this->returnValue( $this->newInfoLinkStub() ) ); + + return $queryResult; + } + + private function newInfoLinkStub() { + $link = $this->getMockBuilder( SMWInfolink::class ) + ->disableOriginalConstructor() + ->getMock(); + + $link->expects( $this->any() ) + ->method( 'getText' ) + ->will( $this->returnValue( 'foo_link' ) ); + + return $link; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/ItemTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/ItemTest.php new file mode 100644 index 00000000..b2102f6a --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/BibTex/ItemTest.php @@ -0,0 +1,111 @@ +<?php + +namespace SRF\Tests\BibTex; + +use SRF\BibTex\Item; + +/** + * @covers \SRF\BibTex\Item + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class ItemTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + Item::class, + new Item() + ); + } + + /** + * @dataProvider fieldsProvider + */ + public function testText( $fields, $expected ) { + + $instance = new Item(); + + foreach ( $fields as $key => $value ) { + $instance->set( $key, $value ); + } + + $this->assertEquals( + $expected, + $instance->text() + ); + } + + /** + * @dataProvider formatterCallbackFieldsProvider + */ + public function testFormatterCallback( $fields, $expected ) { + + $instance = new Item(); + $instance->setFormatterCallback( function( $key, $values ) { + return implode( '#', $values ); + } ); + + foreach ( $fields as $key => $value ) { + $instance->set( $key, $value ); + } + + $this->assertEquals( + $expected, + $instance->text() + ); + } + + /** + * @dataProvider replaceTextProvider + */ + public function testReplace( $key, $text, $expected ) { + + $instance = new Item(); + + $this->assertEquals( + $expected, + $instance->replace( 'uri', $text ) + ); + } + + public function fieldsProvider() { + + yield [ + [ 'foo' => 'test', 'author' => [ 'abc', 'def', '123' ] ], + "@Book{abc,\r\n author = \"abc, def, 123\", \r\n}" + ]; + + yield [ + [ 'foo' => 'test', 'title' => 'foo bar', 'editor' => [ 'abc', 'def', '123' ] ], + "@Book{fb,\r\n editor = \"abc, def, 123\", \r\n title = \"foo bar\", \r\n}" + ]; + } + + public function formatterCallbackFieldsProvider() { + + yield [ + [ 'foo' => 'test', 'author' => [ 'abc', 'def', '123' ] ], + "@Book{abc,\r\n author = \"abc#def#123\", \r\n}" + ]; + + yield [ + [ 'foo' => 'test', 'title' => 'foo bar', 'editor' => [ 'abc', 'def', '123' ] ], + "@Book{fb,\r\n editor = \"abc#def#123\", \r\n title = \"foo bar\", \r\n}" + ]; + } + + public function replaceTextProvider() { + + yield [ + 'uri', + 'abc-_+ÄäÖ', + 'abcAeaeOe' + ]; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ArrayTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ArrayTest.php new file mode 100644 index 00000000..69900f34 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ArrayTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Array class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ArrayTest extends QueryPrinterRegistryTestCase { + + /** + * @see ResultPrinterTest::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'array' ]; + } + + /** + * @see ResultPrinterTest::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFArray'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DataTablesTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DataTablesTest.php new file mode 100644 index 00000000..1e0826fd --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DataTablesTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\DataTables class. + * + * @file + * @since 1.9 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class DataTablesTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.9 + * + * @return array + */ + public function getFormats() { + return [ 'datatables' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.9 + * + * @return string + */ + public function getClass() { + return 'SRF\DataTables'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DygraphsTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DygraphsTest.php new file mode 100644 index 00000000..f078b44c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/DygraphsTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Dygraphs class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class DygraphsTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'dygraphs' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return 'SRFDygraphs'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/EventCalendarTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/EventCalendarTest.php new file mode 100644 index 00000000..44a52bae --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/EventCalendarTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\EventCalendar class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class EventCalendarTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'eventcalendar' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return 'SRF\EventCalendar'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GalleryTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GalleryTest.php new file mode 100644 index 00000000..91eeeca7 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GalleryTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Gallery class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class GalleryTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'gallery' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return 'SRF\Gallery'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GanttTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GanttTest.php new file mode 100644 index 00000000..8eda6159 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GanttTest.php @@ -0,0 +1,30 @@ +<?php
+
+namespace SRF\Tests\Gantt;
+
+use SMW\Test\QueryPrinterRegistryTestCase;
+
+class GanttTest extends QueryPrinterRegistryTestCase{
+
+ /**
+ * @see QueryPrinterRegistryTestCase::getFormats
+ *
+ * @since 1.8
+ *
+ * @return array
+ */
+ public function getFormats() {
+ return [ 'gantt' ];
+ }
+
+ /**
+ * @see QueryPrinterRegistryTestCase::getClass
+ *
+ * @since 1.8
+ *
+ * @return string
+ */
+ public function getClass() {
+ return '\SRF\Gantt\GanttPrinter';
+ }
+}
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GraphTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GraphTest.php new file mode 100644 index 00000000..f55ef3df --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/GraphTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Array class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class GraphTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'graph' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRF\Graph\GraphPrinter'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/IncomingTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/IncomingTest.php new file mode 100644 index 00000000..c38f5a33 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/IncomingTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Incoming class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class IncomingTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'incoming' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFIncoming'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ListWidgetTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ListWidgetTest.php new file mode 100644 index 00000000..d7e737a4 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/ListWidgetTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\ListWidget class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class ListWidgetTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'listwidget' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFListWidget'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MathTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MathTest.php new file mode 100644 index 00000000..fb6b1cf6 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MathTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Math class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class MathTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'max', 'min', 'sum', 'product', 'average', 'median' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFMath'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MediaPlayerTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MediaPlayerTest.php new file mode 100644 index 00000000..469e48e1 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/MediaPlayerTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\MediaPlayer class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class MediaPlayerTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'media' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return 'SRF\MediaPlayer'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/PageWidgetTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/PageWidgetTest.php new file mode 100644 index 00000000..34ae814c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/PageWidgetTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\PageWidget class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class PageWidgetTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'pagewidget' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFPageWidget'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SparklineTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SparklineTest.php new file mode 100644 index 00000000..48ed8add --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SparklineTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Sparkline class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class SparklineTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'sparkline' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFSparkline'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SpreadsheetTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SpreadsheetTest.php new file mode 100644 index 00000000..15783478 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/SpreadsheetTest.php @@ -0,0 +1,51 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; +use SRF\SpreadsheetPrinter; + +/** + * @ingroup SemanticResultFormats + * @ingroup Test + * @group SRF + * @group SMWExtension + * @group ResultPrinters + */ +class SpreadsheetTest extends QueryPrinterRegistryTestCase { + + public function getFormats() { + return [ 'spreadsheet' ]; + } + + public function getClass() { + return 'SRF\SpreadsheetPrinter'; + } + + public function testLink() { + + $link = $this->getMockBuilder( '\SMWInfolink' ) + ->disableOriginalConstructor() + ->getMock(); + + $queryResult = $this->getMockBuilder( '\SMWQueryResult' ) + ->disableOriginalConstructor() + ->getMock(); + + $queryResult->expects( $this->once() ) + ->method( 'getQueryLink' ) + ->will( $this->returnValue( $link ) ); + + $queryResult->expects( $this->any() ) + ->method( 'getCount' ) + ->will( $this->returnValue( 1 ) ); + + $queryResult->expects( $this->any() ) + ->method( 'getErrors' ) + ->will( $this->returnValue( [] ) ); + + $instance = new SpreadsheetPrinter( 'csv' ); + $instance->getResult( $queryResult, [], SMW_OUTPUT_WIKI ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TagCloudTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TagCloudTest.php new file mode 100644 index 00000000..f78b0c1c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TagCloudTest.php @@ -0,0 +1,52 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\TagCloud class. + * + * @since 1.8 + * + * @file + * + * @ingroup SRF + * @ingroup Test + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ + +/** + * Tests for the SRF\TagCloud class. + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + */ +class TagCloudTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'tagcloud' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRF\TagCloud'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TimeseriesTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TimeseriesTest.php new file mode 100644 index 00000000..495a7522 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TimeseriesTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Sparkline class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class TimeseriesTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'timeseries' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFTimeseries'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TreeTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TreeTest.php new file mode 100644 index 00000000..8b4135db --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/TreeTest.php @@ -0,0 +1,173 @@ +<?php + +namespace SRF\Test; + +use SMW\Test\QueryPrinterRegistryTestCase; +use SMW\Tests\Utils\Mock\CoreMockObjectRepository; +use SMW\Tests\Utils\Mock\MockObjectBuilder; +use SMWQueryProcessor; +use SRF\Formats\Tree\TreeResultPrinter; + +/** + * Class TreeTest + * + * @since 2.5 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @author Stephan Gambke + */ +class TreeTest extends QueryPrinterRegistryTestCase { + + private $parser; + private $title; + + private static $initial_parser; + private static $initial_title; + + /** + * Keep the global state and restore it on tearDown to avoid influencing + * other tests in case this one fails in between. + */ + public static function setUpBeforeClass() { + self::$initial_parser = $GLOBALS['wgParser']; + self::$initial_title = $GLOBALS['wgTitle']; + } + + protected function tearDown() { + $GLOBALS['wgParser'] = self::$initial_parser; + $GLOBALS['wgTitle'] = self::$initial_title; + + parent::tearDown(); + } + + /** + * Returns the names of the formats being tested. + * + * @return string[] + */ + public function getFormats() { + return [ 'tree' ]; + } + + /** + * Returns the name of the class being tested. + * + * @return string + */ + public function getClass() { + return '\SRF\Formats\Tree\TreeResultPrinter'; + } + + /** + */ + public function testGetResult_NoParentProperty() { + + $this->prepareGlobalState(); + + $mockBuilder = new MockObjectBuilder(); + $mockBuilder->registerRepository( new CoreMockObjectRepository() ); + + /** @var \PHPUnit_Framework_MockObject_MockObject $queryResult */ + $queryResult = $mockBuilder->newObject( 'QueryResult', [ 'getCount' => 1 ] ); + + $queryResult->expects( $this->once() ) + ->method( 'addErrors' ) + ->will( $this->returnValue( null ) ); + + $params = SMWQueryProcessor::getProcessedParams( [ 'format' => 'tree' ], [] ); + + $testObject = new TreeResultPrinter( 'tree' ); + + $this->assertEquals( + '', + $testObject->getResult( $queryResult, $params, SMW_OUTPUT_HTML ), + 'Result should be empty.' + ); + + // Restore GLOBAL state to ensure that preceding tests do not use a + // mocked instance + $GLOBALS['wgParser'] = $this->parser; + $GLOBALS['wgTitle'] = $this->title; + } + + protected function prepareGlobalState() { + + // Store current state + $this->parser = $GLOBALS['wgParser']; + $this->title = $GLOBALS['wgTitle']; + + $parserOutput = $this->getMockBuilder( '\ParserOutput' ) + ->disableOriginalConstructor() + ->getMock(); + + $parserOutput->expects( $this->any() ) + ->method( 'getHeadItems' ) + ->will( $this->returnValue( [] ) ); + + $parser = $this->getMockBuilder( '\Parser' ) + ->disableOriginalConstructor() + ->getMock(); + + $parser->expects( $this->any() ) + ->method( 'parse' ) + ->will( $this->returnValue( $parserOutput ) ); + + $title = $this->getMockBuilder( '\Title' ) + ->disableOriginalConstructor() + ->getMock(); + + // Careful!! + $GLOBALS['wgParser'] = $parser; + $GLOBALS['wgTitle'] = $title; + } + + /** + * @return array + */ + protected function provideQueryParamsAndResults() { + $mockBuilder = new MockObjectBuilder(); + $mockBuilder->registerRepository( new CoreMockObjectRepository() ); + + /** @var \SMWResultArray[]|false $resultRow */ + $resultRow = $mockBuilder->newObject( 'ResultArray' ); + + //$resultRow->add( $resultCell ); + + $resultSet[] = []; + + $resultSet[] = $resultRow; + + /** @var array(SMWResultArray[]|false) $resultSet */ + $resultSet[] = false; + + $queryResult = $mockBuilder->newObject( + 'QueryResult', + [ + 'getCount' => 1, + ] + ); + + $queryResult->expects( $this->any() ) + ->method( 'getNext' ) + ->will( call_user_func( [ $this, 'onConsecutiveCalls' ], $resultSet ) ); + + $queryResult = $mockBuilder->newObject( + 'QueryResult', + [ + 'getCount' => 1, + ] + ); + + $params = SMWQueryProcessor::getProcessedParams( [ 'format' => 'tree' ], [] ); + + $expected = ''; + + return [ $queryResult, $params, $expected ]; + } +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotChartTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotChartTest.php new file mode 100644 index 00000000..b51ee365 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotChartTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\jqPlotChart class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class jqPlotChartTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'jqplotchart' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFjqPlotChart'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotSeriesTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotSeriesTest.php new file mode 100644 index 00000000..6ab2e5e8 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/jqPlotSeriesTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\jqPlotSeries class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author mwjames + */ +class jqPlotSeriesTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'jqplotseries' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRFjqPlotSeries'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/vCardTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/vCardTest.php new file mode 100644 index 00000000..565d4955 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Formats/vCardTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\Unit\Formats; + +use SMW\Test\QueryPrinterRegistryTestCase; + +/** + * Tests for the SRF\Gallery class. + * + * @file + * @since 1.8 + * + * @ingroup SemanticResultFormats + * @ingroup Test + * + * @group SRF + * @group SMWExtension + * @group ResultPrinters + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class vCardTest extends QueryPrinterRegistryTestCase { + + /** + * @see QueryPrinterRegistryTestCase::getFormats + * + * @since 1.8 + * + * @return array + */ + public function getFormats() { + return [ 'vcard' ]; + } + + /** + * @see QueryPrinterRegistryTestCase::getClass + * + * @since 1.8 + * + * @return string + */ + public function getClass() { + return '\SRF\vCard\vCardFileExportPrinter'; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/ListTreeBuilderTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/ListTreeBuilderTest.php new file mode 100644 index 00000000..80679e90 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/ListTreeBuilderTest.php @@ -0,0 +1,41 @@ +<?php + +namespace SRF\Tests\Outline; + +use SRF\Outline\ListTreeBuilder; +use SRF\Outline\OutlineTree; + +/** + * @covers \SRF\Outline\ListTreeBuilder + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class ListTreeBuilderTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + ListTreeBuilder::class, + new ListTreeBuilder( [] ) + ); + } + + public function testBuildForEmptyTree() { + + $params = [ + 'outlineproperties' => [ 'Foo' ] + ]; + + $instance = new ListTreeBuilder( $params ); + + $this->assertInternalType( + 'string', + $instance->build( new OutlineTree() ) + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineItemTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineItemTest.php new file mode 100644 index 00000000..6819ee10 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineItemTest.php @@ -0,0 +1,36 @@ +<?php + +namespace SRF\Tests\Outline; + +use SRF\Outline\OutlineItem; + +/** + * @covers \SRF\Outline\OutlineItem + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class OutlineItemTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + OutlineItem::class, + new OutlineItem( [] ) + ); + } + + public function testPropertyAccess() { + + $instance = new OutlineItem( [ 'Foo' ] ); + + $this->assertEquals( + [ 'Foo' ], + $instance->row + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php new file mode 100644 index 00000000..523ecf9b --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineResultPrinterTest.php @@ -0,0 +1,96 @@ +<?php + +namespace SRF\Tests\Outline; + +use SRF\Outline\OutlineResultPrinter; + +/** + * @covers \SRF\Outline\OutlineResultPrinter + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class OutlineResultPrinterTest extends \PHPUnit_Framework_TestCase { + + private $queryResult; + + protected function setUp() { + parent::setUp(); + + $this->queryResult = $this->getMockBuilder( '\SMWQueryResult' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + OutlineResultPrinter::class, + new OutlineResultPrinter( 'outline' ) + ); + } + + public function testGetResult_LinkOnNonFileOutput() { + + $link = $this->getMockBuilder( '\SMWInfolink' ) + ->disableOriginalConstructor() + ->getMock(); + + $link->expects( $this->any() ) + ->method( 'getText' ) + ->will( $this->returnValue( 'foo_link' ) ); + + $this->queryResult->expects( $this->any() ) + ->method( 'getErrors' ) + ->will( $this->returnValue( [] ) ); + + $this->queryResult->expects( $this->any() ) + ->method( 'getCount' ) + ->will( $this->returnValue( 1 ) ); + + $instance = new OutlineResultPrinter( + 'outline' + ); + + // IParam is an empty interface !!! so we use stdClass + $outlineproperties = $this->getMockBuilder( '\stdClass' ) + ->disableOriginalConstructor() + ->setMethods( [ 'getName', 'getValue' ] ) + ->getMock(); + + $outlineproperties->expects( $this->any() ) + ->method( 'getName' ) + ->will( $this->returnValue( 'outlineproperties' ) ); + + $outlineproperties->expects( $this->any() ) + ->method( 'getValue' ) + ->will( $this->returnValue( [] ) ); + + $template = $this->getMockBuilder( '\stdClass' ) + ->disableOriginalConstructor() + ->setMethods( [ 'getName', 'getValue' ] ) + ->getMock(); + + $template->expects( $this->any() ) + ->method( 'getName' ) + ->will( $this->returnValue( 'template' ) ); + + $template->expects( $this->any() ) + ->method( 'getValue' ) + ->will( $this->returnValue( '' ) ); + + $parameters = [ + $outlineproperties, + $template + ]; + + $this->assertContains( + "<ul>\n</ul>\n", + $instance->getResult( $this->queryResult, $parameters, SMW_OUTPUT_HTML ) + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineTreeTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineTreeTest.php new file mode 100644 index 00000000..3af491c0 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/OutlineTreeTest.php @@ -0,0 +1,49 @@ +<?php + +namespace SRF\Tests\Outline; + +use SRF\Outline\OutlineTree; + +/** + * @covers \SRF\Outline\OutlineTree + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class OutlineTreeTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + OutlineTree::class, + new OutlineTree( [] ) + ); + } + + public function testPropertyAccess() { + + $instance = new OutlineTree(); + + $this->assertEmpty( + $instance->tree + ); + + $this->assertEmpty( + $instance->items + ); + + $this->assertEquals( + 0, + $instance->itemCount + ); + + $this->assertEquals( + 0, + $instance->leafCount + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/TemplateBuilderTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/TemplateBuilderTest.php new file mode 100644 index 00000000..ac00d67c --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/Outline/TemplateBuilderTest.php @@ -0,0 +1,43 @@ +<?php + +namespace SRF\Tests\Outline; + +use SRF\Outline\TemplateBuilder; +use SRF\Outline\OutlineTree; + +/** + * @covers \SRF\Outline\TemplateBuilder + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class TemplateBuilderTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + TemplateBuilder::class, + new TemplateBuilder( [] ) + ); + } + + public function testBuildForEmptyTree() { + + $params = [ + 'outlineproperties' => [ 'Foo' ], + 'template' => 'Bar', + 'userparam' => '' + ]; + + $instance = new TemplateBuilder( $params ); + + $this->assertInternalType( + 'string', + $instance->build( new OutlineTree() ) + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/ResourceFormatterTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/ResourceFormatterTest.php new file mode 100644 index 00000000..9443b94a --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/ResourceFormatterTest.php @@ -0,0 +1,34 @@ +<?php + +namespace SRF\Tests; + +use SRF\ResourceFormatter; + +/** + * @covers \SRF\ResourceFormatter + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class ResourceFormatterTest extends \PHPUnit_Framework_TestCase { + + public function testSession() { + + $this->assertContains( + 'smw-', + ResourceFormatter::session() + ); + } + + public function testPlaceholder() { + + $this->assertInternalType( + 'string', + ResourceFormatter::placeholder() + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php new file mode 100644 index 00000000..858af78b --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php @@ -0,0 +1,89 @@ +<?php + +namespace SRF\Tests\iCalendar; + +use SMW\Tests\TestEnvironment; +use SRF\iCalendar\IcalTimezoneFormatter; + +/** + * @covers \SRF\iCalendar\IcalTimezoneFormatter + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class IcalTimezoneFormatterTest extends \PHPUnit_Framework_TestCase { + + private $stringValidator; + + protected function setUp() { + parent::setUp(); + + $this->stringValidator = TestEnvironment::newValidatorFactory()->newStringValidator(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + IcalTimezoneFormatter::class, + new IcalTimezoneFormatter() + ); + } + + /** + * @dataProvider transitionsProvider + */ + public function testGetTransitions( $tz, $from, $to, $expected ) { + + $instance = new IcalTimezoneFormatter(); + $instance->setLocalTimezones( $tz ); + $instance->calcTransitions( $from, $to ); + + $this->stringValidator->assertThatStringContains( + $expected, + $instance->getTransitions() + ); + } + + public function transitionsProvider() { + + // DTSTART can be different pending the OS hence use .* + + yield [ + 'UTC', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:UTC\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:+0000\r\nTZOFFSETTO:+0000\r\nTZNAME:UTC\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'Asia/Bangkok', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:Asia/Bangkok\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + // Travis-CI PHP 7 issue, outputs `TZNAME:+07` + // "TZOFFSETFROM:+0700\r\nTZOFFSETTO:+0700\r\nTZNAME:ICT\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + "TZOFFSETFROM:+0700\r\nTZOFFSETTO:+0700\r\nTZNAME:.*\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'Asia/Tokyo', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:Asia/Tokyo\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:+0900\r\nTZOFFSETTO:+0900\r\nTZNAME:JST\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'America/New_York', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:America/New_York\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:-0500\r\nTZOFFSETTO:-0500\r\nTZNAME:EST\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/AddressTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/AddressTest.php new file mode 100644 index 00000000..0b4855b2 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/AddressTest.php @@ -0,0 +1,56 @@ +<?php + +namespace SRF\Tests\vCard; + +use SRF\vCard\Address; + +/** + * @covers \SRF\vCard\Address + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class AddressTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + Address::class, + new Address( '', [] ) + ); + } + + public function testHasAddress() { + + $instance = new Address( '', [] ); + + $this->assertFalse( + $instance->hasAddress() + ); + } + + public function testText() { + + $adr = [ + 'pobox' => '', + 'ext' => '', + 'street' => '2 Example Avenue', + 'locality' => 'Anytown', + 'region' => 'Foo', + 'code' => '01111', + 'country' => 'Bar' + ]; + + $instance = new Address( '', $adr ); + $instance->set( 'region', 'Bar0042' ); + + $this->assertSame( + "ADR;TYPE=WORK;CHARSET=UTF-8:;;2 Example Avenue;Anytown;Bar0042;01111;Bar\r\n", + $instance->text() + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/EmailTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/EmailTest.php new file mode 100644 index 00000000..51dfe2d5 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/EmailTest.php @@ -0,0 +1,36 @@ +<?php + +namespace SRF\Tests\vCard; + +use SRF\vCard\Email; + +/** + * @covers \SRF\vCard\Email + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class EmailTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + Email::class, + new Email( '', '' ) + ); + } + + public function testText() { + + $instance = new Email( '', 'johnDoe@example.org' ); + + $this->assertSame( + "EMAIL;TYPE=INTERNET:johnDoe@example.org\r\n", + $instance->text() + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/TelTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/TelTest.php new file mode 100644 index 00000000..58ed6022 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/TelTest.php @@ -0,0 +1,36 @@ +<?php + +namespace SRF\Tests\vCard; + +use SRF\vCard\Tel; + +/** + * @covers \SRF\vCard\Tel + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class TelTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + Tel::class, + new Tel( '', '' ) + ); + } + + public function testText() { + + $instance = new Tel( '', '+1 781 555 1212' ); + + $this->assertSame( + "TEL;TYPE=WORK:+1 781 555 1212\r\n", + $instance->text() + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php new file mode 100644 index 00000000..f094268f --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php @@ -0,0 +1,133 @@ +<?php + +namespace SRF\Tests\vCard; + +use SRF\vCard\vCardFileExportPrinter; +use SRF\Tests\ResultPrinterReflector; + +/** + * @covers \SRF\vCard\vCardFileExportPrinter + * @group semantic-result-formats + * + * @license GNU GPL v2+ + * @since 3.1 + * + * @author mwjames + */ +class vCardFileExportPrinterTest extends \PHPUnit_Framework_TestCase { + + private $queryResult; + private $resultPrinterReflector; + + protected function setUp() { + parent::setUp(); + + $this->resultPrinterReflector = new ResultPrinterReflector(); + + $this->queryResult = $this->getMockBuilder( '\SMWQueryResult' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + vCardFileExportPrinter::class, + new vCardFileExportPrinter( 'vcard' ) + ); + } + + /** + * @dataProvider filenameProvider + */ + public function testGetFileName( $filename, $searchlabel, $expected ) { + + $parameters = [ + 'filename' => $filename, + 'searchlabel' => $searchlabel + ]; + + $instance = new vCardFileExportPrinter( + 'vcard' + ); + + $this->resultPrinterReflector->addParameters( $instance, $parameters ); + + $this->assertEquals( + $expected, + $instance->getFileName( $this->queryResult ) + ); + } + + public function testGetMimeType() { + + $instance = new vCardFileExportPrinter( + 'vcard' + ); + + $this->assertEquals( + 'text/x-vcard', + $instance->getMimeType( $this->queryResult ) + ); + } + + public function testGetResult_LinkOnNonFileOutput() { + + $link = $this->getMockBuilder( '\SMWInfolink' ) + ->disableOriginalConstructor() + ->getMock(); + + $link->expects( $this->any() ) + ->method( 'getText' ) + ->will( $this->returnValue( 'foo_link' ) ); + + $this->queryResult->expects( $this->any() ) + ->method( 'getErrors' ) + ->will( $this->returnValue( [] ) ); + + $this->queryResult->expects( $this->any() ) + ->method( 'getCount' ) + ->will( $this->returnValue( 1 ) ); + + $this->queryResult->expects( $this->once() ) + ->method( 'getQueryLink' ) + ->will( $this->returnValue( $link ) ); + + $instance = new vCardFileExportPrinter( + 'vcard' + ); + + $this->assertEquals( + 'foo_link', + $instance->getResult( $this->queryResult, [], SMW_OUTPUT_HTML ) + ); + } + + public function filenameProvider() { + + yield[ + '', + 'foo bar', + 'foo_bar.vcf' + ]; + + yield[ + 'foo', + '', + 'foo.vcf' + ]; + + yield[ + 'foo.vcf', + '', + 'foo.vcf' + ]; + + yield[ + 'foo bar.vcf', + '', + 'foo_bar.vcf' + ]; + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardTest.php b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardTest.php new file mode 100644 index 00000000..2467df95 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/phpunit/Unit/vCard/vCardTest.php @@ -0,0 +1,47 @@ +<?php + +namespace SRF\Tests\vCard; + +use SRF\vCard\vCard; + +/** + * @covers \SRF\vCard\vCard + * @group semantic-result-formats + * + * @license GNU GPL v2" + * @since 3.0 + * + * @author mwjames + */ +class vCardTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + vCard::class, + new vCard( '', '', [] ) + ); + } + + public function testEmptyCard() { + + $instance = new vCard( 'http://example.org/Foo', 'Foo', [] ); + $instance->set( 'url', 'http://example.org/Bar' ); + + $this->assertSame( + "BEGIN:VCARD\r\n" . + "VERSION:3.0\r\n" . + "N;CHARSET=UTF-8:Foo;;;;\r\n" . + "FN;CHARSET=UTF-8:Foo\r\n" . + "CLASS:PUBLIC\r\n" . + "SOURCE;CHARSET=UTF-8:http://example.org/Foo\r\n" . + "PRODID:-////Semantic MediaWiki\r\n" . + "REV:\r\n" . + "URL:http://example.org/Bar\r\n" . + "UID:http://example.org/Foo\r\n" . + "END:VCARD\r\n", + $instance->text() + ); + } + +} diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.test.js new file mode 100644 index 00000000..7b2f24e3 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.test.js @@ -0,0 +1,79 @@ +/** + * This file is part of the Semantic Result Formats QUnit Suite + * @see https://www.semantic-mediawiki.org/wiki/QUnit + * + * @section LICENSE + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + * @file + * + * @since 1.9 + * @ingroup SMW + * + * @licence GNU GPL v2+ + * @author mwjames + */ + +/** + * QUnit tests for the srf base class + * + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf', QUnit.newMwEnvironment() ); + + /** + * Test initialization and accessibility + * + * @since: 1.9 + */ + QUnit.test( 'init', 6, function ( assert ) { + + assert.ok( srf instanceof Object, 'srf namespace and instance was accessible' ); + assert.equal( $.type( srf.log ), 'function', '.log() was accessible' ); + assert.equal( $.type( srf.msg ), 'function', '.msg() was accessible' ); + assert.equal( $.type( srf.settings.getList ), 'function', '.settings.getList() was accessible' ); + assert.equal( $.type( srf.settings.get ), 'function', '.settings.get() was accessible' ); + assert.equal( $.type( srf.version ), 'function', '.version() was accessible' ); + + } ); + + /** + * Test settings function + * + * @since: 1.9 + */ + QUnit.test( 'settings', 4, function ( assert ) { + + assert.equal( $.type( srf.settings.getList() ), 'object', '.getList() returned a list of objects' ); + assert.equal( $.type( srf.settings.get( 'srfgScriptPath' ) ), 'string', '.get( "srfgScriptPath" ) returned a value' ); + assert.equal( srf.settings.get( 'lula' ), undefined, '.get( "lula" ) returned undefined for an unknown key' ); + assert.equal( srf.settings.get(), undefined, '.get() returned undefined for an empty key' ); + + } ); + + /** + * Test version function + * + * @since: 1.9 + */ + QUnit.test( 'version', 1, function ( assert ) { + + assert.equal( $.type( srf.version() ), 'string', '.version() returned a string' ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.util.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.util.test.js new file mode 100644 index 00000000..caac7d2d --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/ext.srf.util.test.js @@ -0,0 +1,119 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.util', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( '.prototype', 1, function ( assert ) { + var util; + + util = new srf.util(); + + assert.ok( util instanceof srf.util, pass + 'the srf.util.prototype instance was accessible' ); + + } ); + + /** + * Object testing + * + * @since 1.9 + */ + QUnit.test( '.message', 3, function ( assert ) { + var util; + var fixture = $( '#qunit-fixture' ); + + util = new srf.util(); + + assert.equal( $.type( util.message ), 'object', pass + 'the message object was accessible' ); + + util.message.set( { context: fixture, message: 'Test' } ); + assert.equal( $( '.ui-widget', fixture ).length, 1, pass + 'message.set() created an object' ); + + QUnit.raises( function() { + util.message.exception( { context: fixture, message: 'Test' } ); + }, pass + 'message.exception() thrown an exception' ); + + + } ); + + /** + * Test spinner + * + * @since 1.9 + */ + QUnit.test( 'spinner', 2, function ( assert ) { + var context; + var util = new srf.util(); + + context = $( '<div><div id="spinner1" class="srf-spinner"></div></div>', '#qunit-fixture' ); + util.spinner.hide( context ); + assert.equal( context.find( '#' + 'spinner1' ).css( 'display' ), 'none', '.hide( context ) was successful' ); + + context = $( '<div><div><div id="spinner2" class="srf-spinner"></div></div></div>', '#qunit-fixture' ); + util.spinner.hide( { context: context } ); + assert.equal( context.find( '#' + 'spinner2' ).css( 'display' ), 'none', '.hide( { context: ... } ) was successful' ); + + } ); + + /** + * Test notification + * + * @since 1.9 + */ + QUnit.test( 'notification', 3, function ( assert ) { + var util; + + util = new srf.util(); + + assert.equal( $.type( util.notification ), 'object', pass + 'the notification object was accessible' ); + assert.equal( $.type( util.notification.create ), 'function', pass + 'notification.create() was accessible' ); + assert.equal( $.type( $.blockUI ), 'function', pass + '$.blockUI() was accessible' ); + + } ); + + /** + * Method testing + * + * @since 1.9 + */ + QUnit.test( '.getImageURL()', 1, function ( assert ) { + var util; + + util = new srf.util(); + + assert.equal( $.type( util.getImageURL ), 'function', pass + '.getImageURL() was accessible' ); + + } ); + + /** + * Method testing + * + * @since 1.9 + */ + QUnit.test( '.getTitleURL()', 1, function ( assert ) { + var util; + + util = new srf.util(); + + assert.equal( $.type( util.getTitleURL ), 'function', pass + '.getTitleURL() was accessible' ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.datatables.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.datatables.test.js new file mode 100644 index 00000000..de7ae30f --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.datatables.test.js @@ -0,0 +1,119 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.formats.datatables', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + var context = $( '<div class="srf-datatables"><div id="smw-test" class="container"></div></div>', '#qunit-fixture' ), + container = context.find( '.container' ); + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( 'instance', 1, function ( assert ) { + + var datatables = new srf.formats.datatables(); + assert.ok( datatables instanceof srf.formats.datatables, pass + 'the srf.formats.datatables instance was accessible' ); + + } ); + + /** + * SMWAPI parse testing + * + * @since 1.9 + */ + QUnit.test( 'parse', 3, function ( assert ) { + var datatables = new srf.formats.datatables(); + + var _uriTestCase = '{\"query\":{\"result\":{\"printrequests\":[{\"label\":\"\",\"typeid\":\"_wpg\",\"mode\":2},{\"label\":\"Has url\",\"typeid\":\"_uri\",\"mode\":1}],\"results\":{\"Data\\/1\":{\"printouts\":{\"Has url\":[\"http:\\/\\/localhost\\/mw\\/index.php?title=Data\\/\"]},\"fulltext\":\"Data\\/1\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Data\\/1\"},\"Main Page\":{\"printouts\":{\"Has url\":[\"http:\\/\\/localhost\\/mw\\/test\\/testcase\"]},\"fulltext\":\"Main Page\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Main_Page\"}},\"meta\":{\"hash\":\"c957c73b571d202b08f1385faf7550ec\",\"count\":2,\"offset\":0}},\"ask\":{\"conditions\":\"[[Has url::+]]\",\"parameters\":{\"limit\":50,\"offset\":0,\"format\":\"datatables\",\"link\":\"all\",\"headers\":\"show\",\"mainlabel\":\"\",\"intro\":\"\",\"outro\":\"\",\"searchlabel\":\"\\u2026 further results\",\"default\":\"\",\"class\":\"sortable wikitable smwtable\",\"theme\":\"bootstrap\"},\"printouts\":[\"?Has url\"]}},\"version\":\"0.1\"}'; + assert.equal( $.type( datatables.test._parse ), 'object', pass + 'the parse object was accessible' ); + + var smwAPI = new smw.api(); + var data = smwAPI.parse( _uriTestCase ); + var result = datatables.test._parse.results( context, data ); + assert.equal( result.aaData.length, 2, pass + 'the result parsing returned an aaData array' ); + assert.equal( data.aoColumnDefs.length, 2, pass + 'the result parsing returned an aoColumnDefs array' ); + + } ); + + /** + * Update testing + * + * @since 1.9 + */ + QUnit.test( 'table init and update test', 3, function ( assert ) { + var datatables = new srf.formats.datatables(); + + assert.equal( $.type( datatables.update ), 'function', pass + 'the function was accessible' ); + + var _modDateCase= '{\"query\":{\"result\":{\"printrequests\":[{\"label\":\"\",\"typeid\":\"_wpg\",\"mode\":2},{\"label\":\"Modification date\",\"typeid\":\"_dat\",\"mode\":1}],\"results\":{\"File:5025159-view-of-the-golden-gate-bridge-san-francisco.jpg\":{\"printouts\":{\"Modification date\":[\"1360064258\"]},\"fulltext\":\"File:5025159-view-of-the-golden-gate-bridge-san-francisco.jpg\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/File:5025159-view-of-the-golden-gate-bridge-san-francisco.jpg\",\"namespace\":6,\"exists\":true},\"Concepttest3\":{\"printouts\":{\"Modification date\":[\"1358906761\"]},\"fulltext\":\"Concepttest3\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Concepttest3\",\"namespace\":0,\"exists\":true},\"Concepttest4\":{\"printouts\":{\"Modification date\":[\"1358905485\"]},\"fulltext\":\"Concepttest4\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Concepttest4\",\"namespace\":0,\"exists\":true}},\"meta\":{\"hash\":\"f790045e40c932332c73b3c8bf7139a8\",\"count\":3,\"offset\":0}},\"ask\":{\"conditions\":\"[[Modification date::+]]\",\"parameters\":{\"limit\":3,\"offset\":0,\"format\":\"datatables\",\"link\":\"all\",\"headers\":\"show\",\"mainlabel\":\"\",\"intro\":\"\",\"outro\":\"\",\"searchlabel\":\"\\u2026 further results\",\"default\":\"\",\"class\":\"\",\"theme\":\"bootstrap\"},\"printouts\":[\"?Modification date\"]}},\"version\":\"0.1\"}'; + + var smwAPI = new smw.api(); + var data = smwAPI.parse( _modDateCase ); + + datatables.init( context, container, data ); + assert.ok( container.find( 'table' ) , pass + 'table was created' ); + + datatables.update( context, data ); + assert.ok( container.find( 'table' ) , pass + 'table was updated' ); + + } ); + + QUnit.test( 'Issue#172: table with subject printout', 1, function ( assert ) { + var oldAlert = window.alert; + try { + var alerts = []; + window.alert = function( msg ) { + alerts.push( msg ); + }; + var datatables = new srf.formats.datatables(); + + var parameters = {"limit":50,"offset":0,"sortkeys":{"":"ASC"},"mainlabel":"-","querymode":1,"format":"datatables","source":"","link":"all","headers":"show","intro":"","outro":"","searchlabel":"... further results","default":"","class":"","theme":"bootstrap"}; + var data1 = new smw.dataItem.wikiPage( "Data/1", "http://localhost/wiki/Data/1", 0, "1", "Data 1" ); + data1.printouts = { + "Has value":{"0":new smw.dataItem.wikiPage( "Value 1","http://localhost/wiki/Value_1",0,"1",null),"property":"Has value"} + }; + var data2 = new smw.dataItem.wikiPage( "Data/2", "http://localhost/wiki/Data/2", 0, "1", "Data 2" ); + data2.printouts = { + "Has value":{"0":new smw.dataItem.wikiPage( "Value 2","http://localhost/wiki/Value_2",0,"1",null),"property":"Has value"} + }; + var results = { + "Data/1": data1, + "Data/2": data2 + }; + var printReqs = [{"label":"Has value","key":"Has_value","redi":"","typeid":"_wpg","mode":1,"format":""},{"label":"Data","key":"","redi":"","typeid":"_wpg","mode":2,"format":""}]; + + var data = { + "query" : { + "ask" : { + "parameters" : parameters + }, + "result" : { + "results" : results, + "printrequests" : printReqs + } + } + }; + assert.strictEqual( alerts.length, 0, "Shouldn't generate any alerts" ); + var actual = datatables.test._parse.results( context, data ); + var expected = {"aaData":[{"Has value":"<a href=\"http://localhost/wiki/Value_1\">Value 1</a>","Data":"<a href=\"http://localhost/wiki/Data/1\">Data 1</a>"},{"Has value":"<a href=\"http://localhost/wiki/Value_2\">Value 2</a>","Data":"<a href=\"http://localhost/wiki/Data/2\">Data 2</a>"}]}; + assert.deepEqual( actual, expected, 'Generated results should look right' ); + } finally { + window.alert = oldAlert; + } + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.eventcalendar.tests.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.eventcalendar.tests.js new file mode 100644 index 00000000..f3c0d053 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.eventcalendar.tests.js @@ -0,0 +1,160 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.formats.eventcalendar', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + var context = $( '<div class="srf-eventcalendar"><div id="smw-test" class="container"></div></div>', '#qunit-fixture' ), + container = context.find( '.container' ); + + var testJSON1 = {"smw-test":"{\"query\":{\"result\":{\"printrequests\":[{\"label\":\"\",\"typeid\":\"_wpg\",\"mode\":2},{\"label\":\"title\",\"typeid\":\"_wpg\",\"mode\":1},{\"label\":\"Has event start\",\"typeid\":\"_dat\",\"mode\":1},{\"label\":\"Has event end\",\"typeid\":\"_dat\",\"mode\":1}],\"results\":{\"Event\\/1\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1325390400\"],\"Has event end\":[\"1325563200\"]},\"fulltext\":\"Event\\/1\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/1\"},\"Event\\/2\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1325300400\"],\"Has event end\":[]},\"fulltext\":\"Event\\/2\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/2\"},\"Event\\/4\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1357304400\"],\"Has event end\":[\"1357308000\"]},\"fulltext\":\"Event\\/4\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/4\"}},\"meta\":{\"hash\":\"ddf5e7e1558d010bf1a1e9ab5c2fa54b\",\"count\":3,\"offset\":0}},\"ask\":{\"conditions\":\"[[Has event start::+]]\",\"parameters\":{\"limit\":50,\"offset\":0,\"format\":\"eventcalendar\",\"link\":\"all\",\"headers\":\"show\",\"mainlabel\":\"\",\"intro\":\"\",\"outro\":\"\",\"searchlabel\":\"\\u2026 further results\",\"default\":\"\",\"defaultview\":\"month\",\"firstday\":\"Sunday\",\"start\":\"earliest\",\"legend\":\"none\",\"class\":\"\",\"theme\":\"basic\",\"dayview\":false},\"printouts\":[\"?Has event=title\",\"?Has event start\",\"?Has event end\"]}},\"version\":\"0.7.4\"}"}; + var testJSON2 = {"smw-test":"{\"query\":{\"result\":{\"printrequests\":[{\"label\":\"\",\"typeid\":\"_wpg\",\"mode\":2},{\"label\":\"title\",\"typeid\":\"_wpg\",\"mode\":1},{\"label\":\"Has event start\",\"typeid\":\"_dat\",\"mode\":1},{\"label\":\"Has event end\",\"typeid\":\"_dat\",\"mode\":1},{\"label\":\"Has event type\",\"typeid\":\"_wpg\",\"mode\":1},{\"label\":\"color\",\"typeid\":\"_str\",\"mode\":1}],\"results\":{\"Event\\/1# c39a574c835d239ebf85019eeb91e4bb\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1325390400\"],\"Has event end\":[\"1325563200\"],\"Has event type\":[{\"fulltext\":\"Meeting\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Meeting\"}],\"color\":[\"green\"]},\"fulltext\":\"Event\\/1# c39a574c835d239ebf85019eeb91e4bb\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/1#_c39a574c835d239ebf85019eeb91e4bb\"},\"Event\\/2# 17423f0168b2fd7d113dbd843224884a\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1325300400\"],\"Has event end\":[],\"Has event type\":[{\"fulltext\":\"Talk\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Talk\"}],\"color\":[\"yellow\"]},\"fulltext\":\"Event\\/2# 17423f0168b2fd7d113dbd843224884a\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/2#_17423f0168b2fd7d113dbd843224884a\"},\"Event\\/3# 4e920606589bc542048086b8913edb9c\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1358910000\"],\"Has event end\":[\"1358913600\"],\"Has event type\":[{\"fulltext\":\"Meeting\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Meeting\"}],\"color\":[]},\"fulltext\":\"Event\\/3# 4e920606589bc542048086b8913edb9c\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/3#_4e920606589bc542048086b8913edb9c\"},\"Event\\/4# 48bff722d643b0c550e6dcdf09699c47\":{\"printouts\":{\"title\":[{\"fulltext\":\"Demo 230\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Demo_230\"}],\"Has event start\":[\"1357304400\"],\"Has event end\":[\"1357308000\"],\"Has event type\":[{\"fulltext\":\"Meeting\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Meeting\"}],\"color\":[]},\"fulltext\":\"Event\\/4# 48bff722d643b0c550e6dcdf09699c47\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event\\/4#_48bff722d643b0c550e6dcdf09699c47\"}},\"meta\":{\"hash\":\"4f7be8ca26f266b1d36fcae82cdbe21c\",\"count\":4,\"offset\":0}},\"ask\":{\"conditions\":\"[[Has event start::+]]\",\"parameters\":{\"limit\":50,\"offset\":0,\"format\":\"eventcalendar\",\"link\":\"all\",\"headers\":\"show\",\"mainlabel\":\"\",\"intro\":\"\",\"outro\":\"\",\"searchlabel\":\"\\u2026 further results\",\"default\":\"\",\"defaultview\":\"month\",\"firstday\":\"Sunday\",\"start\":\"earliest\",\"legend\":\"tooltip\",\"class\":\"\",\"theme\":\"basic\",\"dayview\":true},\"printouts\":[\"?Has event=title\",\"?Has event start\",\"?Has event end\",\"?Has event type\",\"?Has event color=color\"]}},\"version\":\"0.7.4\"}"}; + var testJSON3 = {"smw-test":"{\"query\":{\"result\":{\"printrequests\":[{\"label\":\"\",\"typeid\":\"_wpg\",\"mode\":2},{\"label\":\"title\",\"typeid\":\"_str\",\"mode\":1},{\"label\":\"Has event start\",\"typeid\":\"_dat\",\"mode\":1},{\"label\":\"Has event end\",\"typeid\":\"_dat\",\"mode\":1},{\"label\":\"Description\",\"typeid\":\"_txt\",\"mode\":1},{\"label\":\"icon\",\"typeid\":\"_str\",\"mode\":1},{\"label\":\"color\",\"typeid\":\"_str\",\"mode\":1},{\"label\":\"Has event location\",\"typeid\":\"_wpg\",\"mode\":1}],\"results\":{\"Event calendar test\\/1# dd20ac429f9cec8c9e0fb69719753261\":{\"printouts\":{\"title\":[\"Pellentesque dui pretiu\"],\"Has event start\":[\"1360886400\"],\"Has event end\":[],\"Description\":[\"\\u0432\\u0442\\u043e\\u0440\\u043e\\u0435\"],\"icon\":[\"File:Event-presentation-icon.png\"],\"color\":[\"\\n#A0D8F1\"],\"Has event location\":[]},\"fulltext\":\"Event calendar test\\/1# dd20ac429f9cec8c9e0fb69719753261\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event_calendar_test\\/1#_dd20ac429f9cec8c9e0fb69719753261\",\"namespace\":0,\"exists\":true},\"Event calendar test\\/2# 9040bf1853edcb06d47891ed0760bb35\":{\"printouts\":{\"title\":[\"Lorem ipsum dolor ... nascetur ipsum.\"],\"icon\":[\"File:Event-meeting-icon.gif\"],\"color\":[\"\\n#E9AF32\"],\"Has event location\":[{\"fulltext\":\"Eveline Hall\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Eveline_Hall\",\"namespace\":0,\"exists\":false}]},\"fulltext\":\"Event calendar test\\/2# 9040bf1853edcb06d47891ed0760bb35\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event_calendar_test\\/2#_9040bf1853edcb06d47891ed0760bb35\",\"namespace\":0,\"exists\":true},\"Event calendar test\\/3# b37ba5543d4fd3485d86576a3cbddf48\":{\"printouts\":{\"title\":[\"Condimentum ut ... amet Cras tempus.\"],\"icon\":[\"File:Event-presentation-icon.png\"],\"color\":[\"\\n#A0D8F1\"],\"Has event location\":[]},\"fulltext\":\"Event calendar test\\/3# b37ba5543d4fd3485d86576a3cbddf48\",\"fullurl\":\"http:\\/\\/localhost\\/mw\\/index.php\\/Event_calendar_test\\/3#_b37ba5543d4fd3485d86576a3cbddf48\",\"namespace\":0,\"exists\":true}},\"meta\":{\"hash\":\"5c7f3ce435d3918537e4090289716bda\",\"count\":3,\"offset\":0}},\"ask\":{\"conditions\":\"[[Has project::test 2]]\",\"parameters\":{\"limit\":50,\"offset\":0,\"format\":\"eventcalendar\",\"link\":\"subject\",\"headers\":\"show\",\"mainlabel\":\"\",\"intro\":\"\",\"outro\":\"\",\"searchlabel\":\"\\u2026 further results\",\"default\":\"\",\"defaultview\":\"month\",\"firstday\":\"Monday\",\"start\":\"earliest\",\"legend\":\"pane\",\"class\":\"\",\"theme\":\"vector\",\"dayview\":true},\"printouts\":[\"?Has event=title\",\"?Has event start\",\"?Has event end\",\"?Has event description=Description\",\"?Has event icon=icon\",\"?Has event color=color\",\"?Has event location\"]}},\"version\":\"0.7.4\"}"}; + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( 'instance', 1, function ( assert ) { + + var calendar = new srf.formats.eventcalendar(); + assert.ok( calendar instanceof srf.formats.eventcalendar, pass + 'the srf.formats.eventcalendar instance was accessible' ); + + } ); + + /** + * SMWAPI parse testing + * + * @since 1.9 + */ + QUnit.test( 'parse', 8, function ( assert ) { + var calendar = new srf.formats.eventcalendar(); + + assert.equal( $.type( calendar.test._parse ), 'object', pass + 'the parse object was accessible' ); + + // Base data set + mw.config.set( testJSON1 ); + assert.equal( $.type( calendar.test._getData( container ) ), 'object', pass + 'getData() returned an object' ); + + // Check api is available + var testData = calendar.test._getData( container ); + assert.equal( $.type( calendar.test._parse.api( testData ) ), 'object', pass + 'api() was accessible' ); + + var expected = { + "dates": [ + "1325390400", + "1325563200", + "1325300400", + "1357304400", + "1357308000" + ] + } + + // Check for parsed dates array + var results = calendar.test._parse.api( testData ); + assert.deepEqual( results.dates, expected.dates , pass + 'dates [] did match' ); + + // Second test data contains type data for colorFilter settings + mw.config.set( testJSON2 ); + var testData = calendar.test._getData( container ); + + results = calendar.test._parse.api( testData ); + assert.deepEqual( results.legend, {} , pass + 'filterProperty was empty and therefore an empty {} was returned' ); + + testData.query.ask.parameters.filterProperty = 'Has event type'; + var results = calendar.test._parse.api( testData ), + expected = { "legend": { + "Meeting": {"color": ["green"],"filter": false}, + "Talk": {"color": ["yellow"],"filter": false} } + }; + + assert.deepEqual( results.legend, expected.legend , pass + 'filterProperty was set and a legend {} was returned' ); + + // Id101d97fc69a: title test (typeof _wpg) + assert.equal( results.events[0].title, 'Demo 230' , pass + 'correct title (typeof _wpg) was returned' ); + + // Id101d97fc69a: title test (typeof _str) + mw.config.set( testJSON3 ); + var testData = calendar.test._getData( container ); + results = calendar.test._parse.api( testData ); + assert.equal( results.events[0].title, 'Pellentesque dui pretiu' , pass + 'correct title (typeof _str) was returned' ); + + } ); + + /** + * startDate testing + * + * @since 1.9 + */ + QUnit.test( 'startDate', 10, function ( assert ) { + + var calendar = new srf.formats.eventcalendar(); + + var testData = [ '1325390400', '1325563200', '1357304400', '1357308000' ]; + + assert.equal( $.type( calendar.test._startDate() ) , 'object', pass + 'the object was accessible' ); + assert.equal( $.type( calendar.test._startDate( testData ).minmax() ), 'object', pass + 'minmax() was accessible' ); + assert.equal( $.type( calendar.test._startDate( testData ).get() ), 'date', pass + 'get() was accessible' ); + + var results = calendar.test._startDate( testData ).minmax(); + assert.deepEqual( results, {"max": "1357308000","min": "1325390400"}, pass + 'minmax() returned an object' ); + + var results = calendar.test._startDate( testData ).get(); + assert.deepEqual( results, new Date() , pass + 'get() returned new Date()' ); + + var results = calendar.test._startDate( testData ).get( 'foo' ); + assert.deepEqual( results, new Date() , pass + 'get( "foo" ) returned new Date()' ); + + var results = calendar.test._startDate( testData ).get( 'earliest' ); + assert.equal( results.getDate(), '1' , pass + 'get( "earliest" ) returned 4' ); + + var results = calendar.test._startDate( testData ).get( 'latest' ); + assert.equal( results.getDate(), '4' , pass + 'get( "latest" ) returned 1' ); + + var testData = [ '633830400', '634176000', '1262563200' ]; + var results = calendar.test._startDate( testData ).minmax(); + assert.deepEqual( results, {"max": "1262563200","min": "633830400"}, pass + 'minmax() returned the correct object' ); + + // I7156d76086b62: Regression test + var testData = ["1360886400", "1347753600", "1347753600", "1347926400", "1347926400"]; + var results = calendar.test._startDate( testData ).minmax(); + assert.deepEqual( results, {"max": "1360886400","min": "1347753600"}, pass + 'minmax() returned the correct object' ); + + } ); + + /** + * Update testing + * + * @since 1.9 + */ + QUnit.test( 'update', 2, function ( assert ) { + var calendar = new srf.formats.eventcalendar(); + + assert.equal( $.type( calendar.update ), 'function', pass + 'the function was accessible' ); + + mw.config.set( testJSON1 ); + var testData = calendar.test._getData( container ); + + // Wait for an asynchronous action to complete + calendar.update( context, container, testData ); + stop(); + container.on( "srf.eventcalendar.updateAfterParse", function() { + assert.ok( true, pass + 'the "srf.eventcalendar.updateAfterParse" event was triggered' ); + start(); + } ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.filtered.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.filtered.test.js new file mode 100644 index 00000000..874e346b --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.filtered.test.js @@ -0,0 +1,1404 @@ +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ +"use strict"; +/// <reference types="jquery" /> +exports.__esModule = true; +var View_1 = require("./View/View"); +var Controller = /** @class */ (function () { + function Controller(target, data, printRequests) { + this.target = undefined; + this.filterSpinner = undefined; + this.views = {}; + this.filters = {}; + this.currentView = undefined; + this.target = target; + if (this.target !== undefined) { + this.filterSpinner = this.target.find('div.filtered-filter-spinner'); + } + this.data = data; + this.printRequests = printRequests; + for (var rowId in this.data) { + if (!this.data[rowId].hasOwnProperty('visible')) { + this.data[rowId].visible = {}; + } + } + } + Controller.prototype.getData = function () { + return this.data; + }; + Controller.prototype.getPrintRequests = function () { + return this.printRequests; + }; + Controller.prototype.getPath = function () { + return srf.settings.get('srfgScriptPath') + '/formats/filtered/resources/'; + }; + Controller.prototype.attachView = function (viewid, view) { + this.views[viewid] = view; + if (this.currentView === undefined) { + this.currentView = view; + view.show(); + } + else { + view.hide(); + } + return this; + }; + Controller.prototype.getView = function (viewId) { + return this.views[viewId]; + }; + Controller.prototype.attachFilter = function (filter) { + var filterId = filter.getId(); + this.filters[filterId] = filter; + filter.init(); + return this.onFilterUpdated(filterId); + }; + Controller.prototype.getFilter = function (filterId) { + return this.filters[filterId]; + }; + Controller.prototype.show = function () { + this.initializeFilters(); + this.target.children('.filtered-spinner').remove(); + this.target.children().show(); + this.switchToView(this.currentView); + }; + Controller.prototype.switchToView = function (view) { + if (this.currentView instanceof View_1.View) { + this.currentView.hide(); + } + this.currentView = view; + if (this.currentView instanceof View_1.View) { + view.show(); + } + }; + Controller.prototype.initializeFilters = function () { + var toShow = []; + var toHide = []; + for (var rowId in this.data) { + for (var filterId in this.filters) { + this.data[rowId].visible[filterId] = this.filters[filterId].isDisabled() || this.filters[filterId].isVisible(rowId); + } + if (this.isVisible(rowId)) { + toShow.push(rowId); + } + else { + toHide.push(rowId); + } + } + this.hideRows(toHide); + this.showRows(toShow); + }; + Controller.prototype.onViewSelected = function (viewID) { + this.switchToView(this.views[viewID]); + }; + Controller.prototype.onFilterUpdated = function (filterId) { + var _this = this; + return this.showSpinner() + .then(function () { + var toShow = []; + var toHide = []; + var disabled = _this.filters[filterId].isDisabled(); + for (var rowId in _this.data) { + var newVisible = disabled || _this.filters[filterId].isVisible(rowId); + if (_this.data[rowId].visible[filterId] !== newVisible) { + _this.data[rowId].visible[filterId] = newVisible; + if (newVisible && _this.isVisible(rowId)) { + toShow.push(rowId); + } + else { + toHide.push(rowId); + } + } + } + _this.hideRows(toHide); + _this.showRows(toShow); + }) + .then(function () { _this.hideSpinner(); }); + }; + Controller.prototype.isVisible = function (rowId) { + for (var filterId in this.data[rowId].visible) { + if (!this.data[rowId].visible[filterId]) { + return false; + } + } + return true; + }; + Controller.prototype.hideRows = function (rowIds) { + if (rowIds.length === 0) { + return; + } + for (var viewId in this.views) { + this.views[viewId].hideRows(rowIds); + } + }; + Controller.prototype.showRows = function (rowIds) { + if (rowIds.length === 0) { + return; + } + for (var viewId in this.views) { + this.views[viewId].showRows(rowIds); + } + }; + Controller.prototype.showSpinner = function () { + return this.animateSpinner(); + }; + Controller.prototype.hideSpinner = function () { + return this.animateSpinner(false); + }; + Controller.prototype.animateSpinner = function (show) { + if (show === void 0) { show = true; } + if (this.filterSpinner === undefined) { + return jQuery.when(); + } + if (show) { + return this.filterSpinner.fadeIn(200).promise(); + } + return this.filterSpinner.fadeOut(200).promise(); + }; + return Controller; +}()); +exports.Controller = Controller; + +},{"./View/View":5}],2:[function(require,module,exports){ +"use strict"; +exports.__esModule = true; +var Filter = /** @class */ (function () { + function Filter(filterId, target, printrequestId, controller, options) { + this.outerTarget = undefined; + this.target = undefined; + this.options = undefined; + this.disabled = false; + this.collapsed = false; + this.target = target; + this.outerTarget = target; + this.filterId = filterId; + this.printrequestId = printrequestId; + this.controller = controller; + this.options = options || {}; + } + Filter.prototype.init = function () { }; + ; + Filter.prototype.isDisabled = function () { + return this.disabled; + }; + Filter.prototype.disable = function () { + var _this = this; + this.disabled = true; + this.outerTarget + .removeClass('enabled') + .addClass('disabled'); + this.collapse(); + this.target.promise().then(function () { return _this.controller.onFilterUpdated(_this.filterId); }); + }; + Filter.prototype.enable = function () { + var _this = this; + this.disabled = false; + this.outerTarget + .removeClass('disabled') + .addClass('enabled'); + if (!this.collapsed) { + this.uncollapse(); + } + this.target.promise().then(function () { return _this.controller.onFilterUpdated(_this.filterId); }); + }; + Filter.prototype.collapse = function (duration) { + var _this = this; + if (duration === void 0) { duration = 400; } + if (!this.collapsed) { + this.outerTarget.promise() + .then(function () { + _this.target.slideUp(duration); + _this.outerTarget.animate({ + 'padding-top': 0, + 'padding-bottom': 0, + 'margin-bottom': '2em' + }, duration); + }); + } + }; + Filter.prototype.uncollapse = function () { + var _this = this; + this.outerTarget.promise() + .then(function () { + _this.target.slideDown(); + var style = _this.outerTarget.attr('style'); + _this.outerTarget.removeAttr('style'); + var uncollapsedCss = _this.outerTarget.css(['padding-top', 'padding-bottom', 'margin-bottom']); + _this.outerTarget.attr('style', style); + _this.outerTarget.animate(uncollapsedCss); + }); + }; + Filter.prototype.isVisible = function (rowId) { + return this.options.hasOwnProperty('show if undefined') && this.options['show if undefined'] === true; + }; + Filter.prototype.getId = function () { + return this.filterId; + }; + Filter.prototype.buildEmptyControl = function () { + this.target = $('<div class="filtered-filter-container">'); + this.outerTarget + .append(this.target) + .addClass('enabled'); + this.addOnOffSwitch(); + this.addLabel(); + this.addControlForCollapsing(); + return this.target; + }; + Filter.prototype.addLabel = function () { + // insert the label of the printout this filter filters on + this.target.before("<div class=\"filtered-filter-label\">" + this.options['label'] + "</div>"); + }; + Filter.prototype.addOnOffSwitch = function () { + var _this = this; + if (this.options.hasOwnProperty('switches')) { + var switches = this.options['switches']; + if (switches.length > 0 && $.inArray('on off', switches) >= 0) { + var onOffControl = $("<div class=\"filtered-filter-onoff on\"></div>"); + this.target.before(onOffControl); + onOffControl.click(function () { + if (_this.outerTarget.hasClass('enabled')) { + _this.disable(); + } + else { + _this.enable(); + } + }); + } + } + }; + Filter.prototype.addControlForCollapsing = function () { + var _this = this; + var collapsible = this.options.hasOwnProperty('collapsible') ? this.options['collapsible'] : undefined; + if (collapsible === 'collapsed' || collapsible === 'uncollapsed') { + var collapseControl_1 = $('<span class="filtered-filter-collapse">'); + this.target.before(collapseControl_1); + collapseControl_1.click(function () { + if (collapseControl_1.hasClass('collapsed')) { + _this.uncollapse(); + _this.collapsed = false; + collapseControl_1 + .removeClass('collapsed') + .addClass('uncollapsed'); + } + else { + _this.collapse(); + _this.collapsed = true; + collapseControl_1 + .removeClass('uncollapsed') + .addClass('collapsed'); + } + }); + if (collapsible === 'collapsed') { + this.collapse(0); + this.collapsed = true; + collapseControl_1.addClass('collapsed'); + } + else { + collapseControl_1.addClass('uncollapsed'); + } + } + }; + return Filter; +}()); +exports.Filter = Filter; + +},{}],3:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Filter_1 = require("./Filter"); +var ValueFilter = /** @class */ (function (_super) { + __extends(ValueFilter, _super); + function ValueFilter() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.values = {}; + _this.visibleValues = []; + _this._useOr = true; + return _this; + } + ValueFilter.prototype.init = function () { + this.values = this.getSortedValues(); + this.buildControl(); + }; + ValueFilter.prototype.useOr = function (useOr) { + this._useOr = useOr; + this.controller.onFilterUpdated(this.getId()); + }; + ValueFilter.prototype.getSortedValues = function () { + /** Map of value => label distinct values */ + var distinctValues = {}; + /** Map of value => sort value distinct values */ + var distinctSortValues = {}; + if (this.options.hasOwnProperty('values')) { + return this.options['values'].map(function (item) { + return { + printoutValue: item, + formattedValue: item + }; + }); + } + else { + // build filter values from available values in result set + var data = this.controller.getData(); + var sortedEntries = []; + for (var id in data) { + var printoutValues = data[id]['printouts'][this.printrequestId]['values']; + var printoutFormattedValues = data[id]['printouts'][this.printrequestId]['formatted values']; + var printoutSortValues = data[id]['printouts'][this.printrequestId]['sort values']; + for (var i in printoutValues) { + var printoutFormattedValue = printoutFormattedValues[i]; + if (printoutFormattedValue.indexOf('<a') > -1) { + printoutFormattedValue = /<a.*>(.*?)<\/a>/.exec(printoutFormattedValue)[1]; + } + distinctValues[printoutValues[i]] = printoutFormattedValue; + distinctSortValues[printoutValues[i]] = printoutSortValues[i]; + } + } + for (var printoutValue in distinctSortValues) { + sortedEntries.push({ + printoutValue: printoutValue, + sortValue: distinctSortValues[printoutValue], + formattedValue: distinctValues[printoutValue] + }); + } + sortedEntries.sort(function (a, b) { + return a.sortValue.localeCompare(b.sortValue); + }); + return sortedEntries; + } + }; + ValueFilter.prototype.buildControl = function () { + var filtercontrols = this.buildEmptyControl(); + filtercontrols = this.addControlForSwitches(filtercontrols); + var maxCheckboxes = this.options.hasOwnProperty('max checkboxes') ? this.options['max checkboxes'] : 5; + if (this.values.length > maxCheckboxes) { + filtercontrols.append(this.getSelected2Control()); + } + else { + filtercontrols.append(this.getCheckboxesControl()); + } + }; + ValueFilter.prototype.getCheckboxesControl = function () { + var _this = this; + var checkboxes = $('<div class="filtered-value-checkboxes" style="width: 100%;">'); + // insert options (checkboxes and labels) + for (var _i = 0, _a = this.values; _i < _a.length; _i++) { + var value = _a[_i]; + checkboxes.append("<div class=\"filtered-value-option\"><label><input type=\"checkbox\" value=\"" + value.printoutValue + "\" ><div class=\"filtered-value-option-label\">" + (value.formattedValue || value.printoutValue) + "</div></label></div>"); + } + // attach event handler + checkboxes + .on('change', ':checkbox', function (eventObject) { + var checkboxElement = eventObject.currentTarget; + _this.onFilterUpdated(checkboxElement.value, checkboxElement.checked); + }); + return checkboxes; + }; + ValueFilter.prototype.getSelected2Control = function () { + var _this = this; + var select = $('<select class="filtered-value-select" style="width: 100%;">'); + var data = []; + // insert options (checkboxes and labels) and attach event handlers + for (var _i = 0, _a = this.values; _i < _a.length; _i++) { + var value = _a[_i]; + // Try to get label, if not fall back to value id + var label = value.formattedValue || value.printoutValue; + data.push({ id: value.printoutValue, text: label }); + } + mw.loader.using('ext.srf.filtered.value-filter.select').then(function () { + select.select2({ + multiple: true, + placeholder: mw.message('srf-filtered-value-filter-placeholder').text(), + data: data + }); + select.on("select2:select", function (e) { + _this.onFilterUpdated(e.params.data.id, true); + }); + select.on("select2:unselect", function (e) { + _this.onFilterUpdated(e.params.data.id, false); + }); + }); + return select; + }; + ValueFilter.prototype.addControlForSwitches = function (filtercontrols) { + // insert switches + var switches = this.options.hasOwnProperty('switches') ? this.options['switches'] : undefined; + if (switches !== undefined && $.inArray('and or', switches) >= 0) { + var switchControls = $('<div class="filtered-value-switches">'); + var andorControl = $('<div class="filtered-value-andor">'); + var orControl = this.getRadioControl('or', true); + var andControl = this.getRadioControl('and'); + andorControl + .append(orControl) + .append(andControl) + .appendTo(switchControls); + andorControl + .find('input') + .on('change', undefined, { 'filter': this }, function (eventObject) { + return eventObject.data.filter.useOr(eventObject.target.getAttribute('value') === 'or'); + }); + filtercontrols.append(switchControls); + } + return filtercontrols; + }; + ValueFilter.prototype.getRadioControl = function (type, isChecked) { + if (isChecked === void 0) { isChecked = false; } + var checkedAttr = isChecked ? 'checked' : ''; + var labelText = mw.message('srf-filtered-value-filter-' + type).text(); + var controlText = "<label for=\"filtered-value-" + type + "-" + this.printrequestId + "\">" + + ("<input type=\"radio\" name=\"filtered-value-" + this.printrequestId + "\" class=\"filtered-value-" + type + "\" id=\"filtered-value-" + type + "-" + this.printrequestId + "\" value=\"" + type + "\" " + checkedAttr + ">") + + (labelText + "</label>"); + return $(controlText); + }; + ValueFilter.prototype.isVisible = function (rowId) { + if (this.visibleValues.length === 0) { + return true; + } + var values = this.controller.getData()[rowId].printouts[this.printrequestId].values; + if (values.length === 0) { + return _super.prototype.isVisible.call(this, rowId); + } + if (this._useOr) { + for (var _i = 0, _a = this.visibleValues; _i < _a.length; _i++) { + var expectedValue = _a[_i]; + if (values.indexOf(expectedValue) >= 0) { + return true; + } + } + return false; + } + else { + for (var _b = 0, _c = this.visibleValues; _b < _c.length; _b++) { + var expectedValue = _c[_b]; + if (values.indexOf(expectedValue) < 0) { + return false; + } + } + return true; + } + }; + ValueFilter.prototype.onFilterUpdated = function (value, isChecked) { + var index = this.visibleValues.indexOf(value); + if (isChecked && index === -1) { + this.visibleValues.push(value); + } + else if (!isChecked && index >= 0) { + this.visibleValues.splice(index, 1); + } + this.controller.onFilterUpdated(this.getId()); + }; + return ValueFilter; +}(Filter_1.Filter)); +exports.ValueFilter = ValueFilter; + +},{"./Filter":2}],4:[function(require,module,exports){ +"use strict"; +/// <reference types="leaflet" /> +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var View_1 = require("./View"); +var MapView = /** @class */ (function (_super) { + __extends(MapView, _super); + function MapView() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.map = undefined; + _this.icon = undefined; + _this.markers = undefined; + _this.markerClusterGroup = undefined; + _this.bounds = undefined; + _this.initialized = false; + _this.zoom = -1; + _this.minZoom = -1; + _this.maxZoom = -1; + _this.leafletPromise = undefined; + return _this; + } + MapView.prototype.init = function () { + var _this = this; + var data = this.controller.getData(); + var markers = {}; + if (this.options.hasOwnProperty('height')) { + this.target.height(this.options.height); + } + this.leafletPromise = mw.loader.using('ext.srf.filtered.map-view.leaflet') + .then(function () { + var bounds = undefined; + var disableClusteringAtZoom = _this.getZoomForUnclustering(); + var clusterOptions = { + animateAddingMarkers: true, + disableClusteringAtZoom: disableClusteringAtZoom, + spiderfyOnMaxZoom: disableClusteringAtZoom === null + }; + clusterOptions = _this.getOptions(['maxClusterRadius', 'zoomToBoundsOnClick'], clusterOptions); + var markerClusterGroup = L.markerClusterGroup(clusterOptions); + for (var rowId in data) { + if (data[rowId]['data'].hasOwnProperty(_this.id)) { + var positions = data[rowId]['data'][_this.id]['positions']; + markers[rowId] = []; + for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) { + var pos = positions_1[_i]; + bounds = (bounds === undefined) ? new L.LatLngBounds(pos, pos) : bounds.extend(pos); + var marker = _this.getMarker(pos, data[rowId]); + markers[rowId].push(marker); + markerClusterGroup.addLayer(marker); + } + } + } + _this.markerClusterGroup = markerClusterGroup; + _this.markers = markers; + _this.bounds = (bounds === undefined) ? new L.LatLngBounds([-180, -90], [180, 90]) : bounds; + }); + return this.leafletPromise; + }; + MapView.prototype.getZoomForUnclustering = function () { + if (this.options.hasOwnProperty('marker cluster') && this.options['marker cluster'] === false) { + return 0; + } + if (this.options.hasOwnProperty('marker cluster max zoom')) { + return this.options['marker cluster max zoom'] + 1; + } + return null; + }; + MapView.prototype.getIcon = function (row) { + if (this.icon === undefined) { + this.buildIconList(); + } + if (this.options.hasOwnProperty('marker icon property')) { + var vals = row['printouts'][this.options['marker icon property']]['values']; + if (vals.length > 0 && this.icon.hasOwnProperty(vals[0])) { + return this.icon[vals[0]]; + } + } + return this.icon['default']; + }; + MapView.prototype.buildIconList = function () { + this.icon = {}; + var iconPath = this.controller.getPath() + 'css/images/'; + this.icon['default'] = new L.Icon({ + 'iconUrl': iconPath + 'marker-icon.png', + 'iconRetinaUrl': iconPath + 'marker-icon-2x.png', + 'shadowUrl': iconPath + 'marker-shadow.png', + 'iconSize': [25, 41], + 'iconAnchor': [12, 41], + 'popupAnchor': [1, -34], + // 'tooltipAnchor': [16, -28], + 'shadowSize': [41, 41] + }); + if (this.options.hasOwnProperty('marker icons')) { + for (var value in this.options['marker icons']) { + this.icon[value] = new L.Icon({ + 'iconUrl': this.options['marker icons'][value], + // 'iconRetinaUrl': iconPath + 'marker-icon-2x.png', + 'shadowUrl': iconPath + 'marker-shadow.png', + 'iconSize': [32, 32], + 'iconAnchor': [16, 32], + 'popupAnchor': [1, -30], + // 'tooltipAnchor': [16, -28], + 'shadowSize': [41, 41], + 'shadowAnchor': [12, 41] + }); + } + } + }; + MapView.prototype.getMarker = function (latLng, row) { + var title = undefined; + var popup = []; + // TODO: Use <div> instead of <b> and do CSS styling + for (var prId in row['printouts']) { + var printrequest = (this.controller.getPrintRequests())[prId]; + if (!printrequest.hasOwnProperty('hide') || printrequest.hide === false) { + var printouts = row['printouts'][prId]; + if (title === undefined) { + title = printouts['values'].join(', '); + popup.push('<b>' + printouts['formatted values'].join(', ') + '</b>'); + } + else { + popup.push((printouts.label ? '<b>' + printouts.label + ':</b> ' : '') + printouts['formatted values'].join(', ')); + } + } + } + var marker = L.marker(latLng, { title: title, alt: title }); + marker.bindPopup(popup.join('<br>')); + marker.setIcon(this.getIcon(row)); + return marker; + }; + MapView.prototype.lateInit = function () { + var _this = this; + if (this.initialized) { + return; + } + this.initialized = true; + var that = this; + this.leafletPromise.then(function () { + var mapOptions = { + center: _this.bounds !== undefined ? _this.bounds.getCenter() : [0, 0] + }; + mapOptions = that.getOptions(['zoom', 'minZoom', 'maxZoom'], mapOptions); + // TODO: Limit zoom values to map max zoom + that.map = L.map(that.getTargetElement().get(0), mapOptions); + that.map.addLayer(that.markerClusterGroup); + if (_this.options.hasOwnProperty('map provider')) { + L.tileLayer.provider(_this.options['map provider']).addTo(that.map); + } + if (!mapOptions.hasOwnProperty('zoom')) { + that.map.fitBounds(that.bounds); + } + }); + }; + MapView.prototype.getOptions = function (keys, defaults) { + if (defaults === void 0) { defaults = {}; } + for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { + var key = keys_1[_i]; + if (this.options.hasOwnProperty(key)) { + defaults[key] = this.options[key]; + } + } + return defaults; + }; + MapView.prototype.showRows = function (rowIds) { + var _this = this; + this.leafletPromise.then(function () { + _this.manipulateLayers(rowIds, function (layers) { + _this.markerClusterGroup.addLayers(layers); + }); + }); + }; + MapView.prototype.hideRows = function (rowIds) { + var _this = this; + this.leafletPromise.then(function () { + _this.manipulateLayers(rowIds, function (layers) { + _this.markerClusterGroup.removeLayers(layers); + }); + }); + }; + MapView.prototype.manipulateLayers = function (rowIds, cb) { + var layersFromRowIds = this.getLayersFromRowIds(rowIds); + if (layersFromRowIds.length > 0) { + cb(layersFromRowIds); + } + }; + MapView.prototype.getLayersFromRowIds = function (rowIds) { + return this.flatten(this.getLayersFromRowIdsRaw(rowIds)); + }; + MapView.prototype.getLayersFromRowIdsRaw = function (rowIds) { + var _this = this; + return rowIds.map(function (rowId) { return _this.markers[rowId] ? _this.markers[rowId] : []; }); + }; + MapView.prototype.flatten = function (markers) { + return markers.reduce(function (result, layers) { return result.concat(layers); }, []); + }; + MapView.prototype.show = function () { + _super.prototype.show.call(this); + this.lateInit(); + }; + return MapView; +}(View_1.View)); +exports.MapView = MapView; + +},{"./View":5}],5:[function(require,module,exports){ +"use strict"; +exports.__esModule = true; +var View = /** @class */ (function () { + function View(id, target, c, options) { + if (options === void 0) { options = {}; } + this.id = undefined; + this.target = undefined; + this.controller = undefined; + this.options = undefined; + this.visible = false; + this.rows = {}; + this.id = id; + this.target = target; + this.controller = c; + this.options = options; + } + View.prototype.init = function () { + var _this = this; + var rowIds = Object.keys(this.controller.getData()); + var rows = this.target.find(this.getItemClassName()); + rows.each(function (index, elem) { + var classes = elem.classList; + for (var i = 0; i < classes.length; i++) { + if (rowIds.indexOf(classes[i]) >= 0) { + _this.rows[classes[i]] = $(rows[index]); + } + } + }); + }; + View.prototype.getItemClassName = function () { + return '.filtered-item'; + }; + View.prototype.getTargetElement = function () { + return this.target; + }; + View.prototype.showRows = function (rowIds) { + var _this = this; + if (this.visible && rowIds.length < 200) { + rowIds.forEach(function (rowId) { + _this.rows[rowId].slideDown(400); + }); + } + else { + rowIds.forEach(function (rowId) { + _this.rows[rowId].css('display', ''); + }); + } + }; + View.prototype.hideRows = function (rowIds) { + var _this = this; + if (this.visible && rowIds.length < 200) { + rowIds.forEach(function (rowId) { + _this.rows[rowId].slideUp(400); + }); + } + else { + rowIds.forEach(function (rowId) { + _this.rows[rowId].css('display', 'none'); + }); + } + }; + View.prototype.show = function () { + this.target.show(); + this.visible = true; + }; + View.prototype.hide = function () { + this.target.hide(); + this.visible = false; + }; + return View; +}()); +exports.View = View; + +},{}],6:[function(require,module,exports){ +"use strict"; +exports.__esModule = true; +var ViewSelector = /** @class */ (function () { + function ViewSelector(target, viewIDs, controller) { + this.target = undefined; + this.viewIDs = undefined; + this.controller = undefined; + this.target = target; + this.viewIDs = viewIDs; + this.controller = controller; + } + ViewSelector.prototype.init = function () { + var _this = this; + if (this.viewIDs.length > 1) { + this.viewIDs.forEach(function (id) { _this.target.on('click', '.' + id, { 'target': id, 'controller': _this.controller }, ViewSelector.onSelectorSelected); }); + this.target.children().first().addClass('selected'); + this.target.show(); + } + }; + ViewSelector.onSelectorSelected = function (event) { + event.data.controller.onViewSelected(event.data.target); + $(event.target) + .addClass('selected') + .siblings().removeClass('selected'); + event.stopPropagation(); + event.preventDefault(); + }; + return ViewSelector; +}()); +exports.ViewSelector = ViewSelector; + +},{}],7:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +exports.__esModule = true; +var Controller_1 = require("../../../resources/ts/Filtered/Controller"); +var MockedFilter_1 = require("../Util/MockedFilter"); +var View_1 = require("../../../resources/ts/Filtered/View/View"); +var ControllerTest = /** @class */ (function () { + function ControllerTest() { + } + ControllerTest.prototype.runTests = function () { + QUnit.test('Controller: Can construct and attach data', this.testConstructAndAttachData); + QUnit.test('Controller: Attaching 3 views (foo, bar, baz) and switch between them', this.testAttachViewsAndSwitchToViews); + QUnit.test('Controller: Show', this.testShow); + QUnit.test('Controller: Attaching 3 filters (foo, bar, baz)', this.testAttachFilter); + return true; + }; + /** + * @covers Controller.constructor + * @covers Controller.getData + */ + ControllerTest.prototype.testConstructAndAttachData = function (assert) { + // Setup + var data = { 'foo': {} }; + // Run + var c = new Controller_1.Controller(undefined, data, {}); + // Assert: Can construct + assert.ok(c instanceof Controller_1.Controller, 'Can construct Controller.'); + // Assert: Data correctly attached and retained + assert.deepEqual(c.getData(), data, 'Returns result data as given to constructor.'); + }; + /** + * @covers Controller.attachView + * @covers Controller.getView + * @covers Controller.onViewSelected + */ + ControllerTest.prototype.testAttachViewsAndSwitchToViews = function (assert) { + // Setup + var c = new Controller_1.Controller(undefined, undefined, undefined); + var viewIds = ['foo', 'bar', 'baz']; + var viewsShown = []; + var viewsHidden = []; + var views = {}; + viewIds.forEach(function (viewId) { + var v = new View_1.View(viewId, undefined, c, {}); + v.show = function () { + if (viewsShown.indexOf(v) === -1) { + viewsShown.push(v); + } + var index = viewsHidden.indexOf(v); + if (index >= 0) { + viewsHidden.splice(index, 1); + } + }; + v.hide = function () { + if (viewsHidden.indexOf(v) === -1) { + viewsHidden.push(v); + } + var index = viewsShown.indexOf(v); + if (index >= 0) { + viewsShown.splice(index, 1); + } + }; + views[viewId] = v; + // Run + c.attachView(viewId, v); + }); + // Assert: One view visible, all others hidden, i.e. none has undefined + // visibility + assert.strictEqual(viewsShown.length, 1, 'One view visible.'); + assert.strictEqual(viewsHidden.length, viewIds.length - 1, 'All but one view hidden.'); + for (var viewId in views) { + // Assert: View correctly attached and retained + assert.deepEqual(c.getView(viewId), views[viewId], "Controller knows \"" + viewId + "\" view."); + } + for (var viewId in views) { + // Run: Select view + c.onViewSelected(viewId); + // Assert: Only selected view visible, all others hidden, i.e. none + // has undefined visibility + assert.ok(viewsShown.length === 1 && viewsShown.indexOf(views[viewId]) >= 0, 'Selected view visible.'); + assert.strictEqual(viewsHidden.length, viewIds.length - 1, 'All other views hidden.'); + } + }; + /** + * @covers Controller.show + */ + ControllerTest.prototype.testShow = function (assert) { + // Setup + var targetElement = $(); + var targetShown = false; + targetElement.children = function (selector) { + var targetChild = $(); + targetChild.show = function () { + targetShown = true; + return targetChild; + }; + return targetChild; + }; + // Run + new Controller_1.Controller(targetElement, undefined, undefined).show(); + // Assert + assert.ok(targetShown, 'Container made visible.'); + }; + /** + * @covers Controller.attachFilter + * @covers Controller.getFilter + */ + ControllerTest.prototype.testAttachFilter = function (assert) { + // Setup + var data = { 'foo': {} }; + var controller = new Controller_1.Controller(undefined, data, {}); + var filterIds = ['foo', 'bar', 'baz']; + var done = assert.async(); + var promises = []; + filterIds.forEach(function (filterId) { + var visibilityWasQueried = false; + var filter = new MockedFilter_1.MockedFilter(filterId, undefined, undefined, controller); + filter.isVisible = function (rowId) { + visibilityWasQueried = true; + return true; + }; + // Run + var promise = controller.attachFilter(filter) + .then(function () { + // Assert: Filter was queried for the visibility of result items + assert.ok(visibilityWasQueried, "Filter \"" + filterId + "\" was queried after attaching."); + }); + promises.push(promise); + // Assert: Filter correctly attached and retained. + assert.deepEqual(controller.getFilter(filterId), filter, "Controller knows \"" + filterId + "\" filter."); + }); + jQuery.when.apply(jQuery, promises).then(done); + }; + return ControllerTest; +}()); +exports.ControllerTest = ControllerTest; + +},{"../../../resources/ts/Filtered/Controller":1,"../../../resources/ts/Filtered/View/View":5,"../Util/MockedFilter":12}],8:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +/// <reference types="jquery" /> +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var ValueFilter_1 = require("../../../../resources/ts/Filtered/Filter/ValueFilter"); +var Controller_1 = require("../../../../resources/ts/Filtered/Controller"); +var QUnitTest_1 = require("../../Util/QUnitTest"); +var ValueFilterTest = /** @class */ (function (_super) { + __extends(ValueFilterTest, _super); + function ValueFilterTest() { + return _super !== null && _super.apply(this, arguments) || this; + } + // TODO: + // public isVisible( rowId: string ): boolean { + // public onFilterUpdated( eventObject: JQueryEventObject ) { + ValueFilterTest.prototype.runTests = function () { + QUnit.test('ValueFilter: Can construct', this.testCanConstruct); + QUnit.test('ValueFilter: Init', this.testInit); + QUnit.test('ValueFilter: Update on and/or switch.', this.testUseOr); + return true; + }; + ; + ValueFilterTest.prototype.testCanConstruct = function (assert) { + var controller = undefined; + var options = {}; + var f = new ValueFilter_1.ValueFilter('foo', $(), 'fooPR', controller, options); + assert.ok(f instanceof ValueFilter_1.ValueFilter, 'Can construct ValueFilter.'); + }; + ; + ValueFilterTest.prototype.testInit = function (assert) { + // Setup + var controller = new Controller_1.Controller($(), {}, {}); + var options = { + 'switches': [ + 'and or' + ], + 'values': [ + 'foo', + 'bar' + ], + 'collapsible': 'uncollapsed', + 'type': 'value', + 'label': 'FooLabel' + }; + var target = $('<div>'); + var f = new ValueFilter_1.ValueFilter('foo', target, 'fooPR', controller, options); + // Run + f.init(); + // Assert + assert.strictEqual(target.find('.filtered-filter-container').length, 1, 'Added container for collapsable content.'); + assert.strictEqual(target.find('.filtered-value-andor').length, 1, 'Added container for and/or switch.'); + var done = assert.async(); + setTimeout(function () { + // Assert: One input added per value + for (var _i = 0, _a = options.values; _i < _a.length; _i++) { + var value = _a[_i]; + assert.strictEqual(target.find("input[value=\"" + value + "\"]").length, 1, "Added option for value \"" + value + "\"."); + } + done(); + }, 100); + }; + ; + ValueFilterTest.prototype.testUseOr = function (assert) { + // Setup + var controller = new Controller_1.Controller($(), {}, {}); + controller.onFilterUpdated = function (filterId) { + // Assert + assert.ok(true, 'Filter updated.'); + var d = jQuery.Deferred(); + d.resolve(); + return d.promise(); + }; + var f = new ValueFilter_1.ValueFilter('foo', $(), 'fooPR', controller, {}); + assert.expect(1); + // Run + f.useOr(true); + }; + ; + return ValueFilterTest; +}(QUnitTest_1.QUnitTest)); +exports.ValueFilterTest = ValueFilterTest; + +},{"../../../../resources/ts/Filtered/Controller":1,"../../../../resources/ts/Filtered/Filter/ValueFilter":3,"../../Util/QUnitTest":13}],9:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +/// <reference types="jquery" /> +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var ViewTest_1 = require("./ViewTest"); +var MapView_1 = require("../../../../resources/ts/Filtered/View/MapView"); +var Controller_1 = require("../../../../resources/ts/Filtered/Controller"); +var MapViewTest = /** @class */ (function (_super) { + __extends(MapViewTest, _super); + function MapViewTest() { + return _super !== null && _super.apply(this, arguments) || this; + } + // TODO: + MapViewTest.prototype.getTestObject = function (id, target, c, options) { + if (id === void 0) { id = 'foo'; } + if (target === void 0) { target = undefined; } + if (c === void 0) { c = undefined; } + if (options === void 0) { options = {}; } + c = c || new Controller_1.Controller(undefined, {}, undefined); + return new MapView_1.MapView(id, target, c, options); + }; + ; + MapViewTest.prototype.runTests = function () { + _super.prototype.runTests.call(this); + return true; + }; + ; + return MapViewTest; +}(ViewTest_1.ViewTest)); +exports.MapViewTest = MapViewTest; + +},{"../../../../resources/ts/Filtered/Controller":1,"../../../../resources/ts/Filtered/View/MapView":4,"./ViewTest":10}],10:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +/// <reference types="jquery" /> +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var QUnitTest_1 = require("../../Util/QUnitTest"); +var View_1 = require("../../../../resources/ts/Filtered/View/View"); +var Controller_1 = require("../../../../resources/ts/Filtered/Controller"); +var ViewTest = /** @class */ (function (_super) { + __extends(ViewTest, _super); + function ViewTest() { + return _super !== null && _super.apply(this, arguments) || this; + } + // Coverage: + // [x] public constructor( id: string, target: JQuery, c: Controller, options: Options = {} ) + // [x] public init() + // [x] public getTargetElement(): JQuery + // [ ] public showRows( rowIds: string[] ) + // [ ] public hideRows( rowIds: string[] ) + // [x] public show() + // [x] public hide() + ViewTest.prototype.getTestObject = function (id, target, c, options) { + if (id === void 0) { id = 'foo'; } + if (target === void 0) { target = undefined; } + if (c === void 0) { c = undefined; } + if (options === void 0) { options = {}; } + c = c || new Controller_1.Controller(undefined, {}, undefined); + return new View_1.View(id, target, c, options); + }; + ; + ViewTest.prototype.runTests = function () { + var className = this.getTestObject().constructor['name']; + var that = this; + QUnit.test(className + ": Can construct, init and knows target element", function (assert) { that.testBasics(assert, that); }); + QUnit.test(className + ": Show and Hide", function (assert) { that.testShowAndHide(assert, that); }); + return true; + }; + ; + ViewTest.prototype.testBasics = function (assert, that) { + //Setup + var target = $('<div>'); + // Run + var v = that.getTestObject('foo', target); + var ret = v.init(); + if (ret !== undefined) { + var done_1 = assert.async(); + ret.then(function () { + assert.ok(v instanceof View_1.View, 'Can construct View. (P)'); + assert.strictEqual(v.getTargetElement(), target, 'View retains target element. (P)'); + done_1(); + }); + } + else { + // Assert + assert.ok(v instanceof View_1.View, 'Can construct View.'); + assert.strictEqual(v.getTargetElement(), target, 'View retains target element.'); + } + }; + ; + ViewTest.prototype.testShowAndHide = function (assert, that) { + // Setup + var target = $('<div>'); + target.show = function () { assert.ok(true, 'Target element shown.'); return target; }; + target.hide = function () { assert.ok(true, 'Target element hidden.'); return target; }; + var v = that.getTestObject('foo', target); + v.init(); + v.show(); + v.hide(); + assert.expect(2); + }; + ; + return ViewTest; +}(QUnitTest_1.QUnitTest)); +exports.ViewTest = ViewTest; + +},{"../../../../resources/ts/Filtered/Controller":1,"../../../../resources/ts/Filtered/View/View":5,"../../Util/QUnitTest":13}],11:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +/// <reference types="jquery" /> +exports.__esModule = true; +var ViewSelector_1 = require("../../../resources/ts/Filtered/ViewSelector"); +var Controller_1 = require("../../../resources/ts/Filtered/Controller"); +var ViewSelectorTest = /** @class */ (function () { + function ViewSelectorTest() { + } + ViewSelectorTest.prototype.runTests = function () { + QUnit.test('ViewSelector: Can construct', this.testCanConstruct); + QUnit.test('ViewSelector: Init for 1 view', this.testInitSingleView); + QUnit.test('ViewSelector: Init for 2 views', this.testInitMultipleViews); + QUnit.test('ViewSelector: Selecting views when clicked (3 views: foo, bar, baz)', this.testSelectViews); + return true; + }; + ViewSelectorTest.prototype.testCanConstruct = function (assert) { + var v = new ViewSelector_1.ViewSelector(undefined, [], undefined); + assert.ok(v instanceof ViewSelector_1.ViewSelector, 'Can construct ViewSelector.'); + }; + ViewSelectorTest.prototype.testInitSingleView = function (assert) { + // Setup + var callCount = 0; + var viewName = 'foo'; + var target = $('<div style="display:none">'); + target.append('<div class="' + viewName + '">'); + target.on = function () { + var args = []; + for (var _a = 0; _a < arguments.length; _a++) { + args[_a] = arguments[_a]; + } + callCount++; + return target; + }; + target.appendTo('body'); + var v = new ViewSelector_1.ViewSelector(target, [viewName], undefined); + // Run + v.init(); + // Assert + assert.strictEqual(callCount, 0, 'Registers no Click events.'); + assert.ok(target.is(':hidden'), 'Target element is NOT visible.'); + // Tear down + target.remove(); + }; + ViewSelectorTest.prototype.testInitMultipleViews = function (assert) { + // Setup + var target = $('<div style="display:none">'); + var viewSelectors = {}; + var viewIDs = ['foo', 'bar']; + for (var _a = 0, viewIDs_1 = viewIDs; _a < viewIDs_1.length; _a++) { + var id = viewIDs_1[_a]; + viewSelectors[id] = $('<div class="' + id + '">'); + target.append(viewSelectors[id]); + } + var eventRegistrationCount = 0; + target.origOn = target.on; + target.on = function () { + var args = []; + for (var _a = 0; _a < arguments.length; _a++) { + args[_a] = arguments[_a]; + } + eventRegistrationCount++; + return target.origOn.apply(target, args); + }; + target.appendTo('body'); + var v = new ViewSelector_1.ViewSelector(target, viewIDs, undefined); + // Run test: Initialize ViewSelector + v.init(); + // Assert + assert.strictEqual(eventRegistrationCount, viewIDs.length, "Registers " + viewIDs.length + " Click events."); + assert.ok(target.children().first().hasClass('selected'), 'First view selector is marked as selected.'); + assert.ok(target.is(':visible'), 'Target element is visible.'); + // Tear down + target.remove(); + }; + ViewSelectorTest.prototype.testSelectViews = function (assert) { + // Setup + var target = $('<div style="display:none">'); + var viewSelectors = {}; + var viewIDs = ['foo', 'bar', 'baz']; + for (var _i = 0, viewIDs_2 = viewIDs; _i < viewIDs_2.length; _i++) { + var id = viewIDs_2[_i]; + viewSelectors[id] = $('<div class="' + id + '">'); + target.append(viewSelectors[id]); + } + target.appendTo('body'); + var c = new Controller_1.Controller(undefined, undefined, undefined); + c.onViewSelected = function (viewID) { + // Assert that the ViewSelector called the Controller when clicked + assert.ok(true, "Controller was called to select view \"" + viewID + "\"."); + }; + var v = new ViewSelector_1.ViewSelector(target, viewIDs, c); + v.init(); + // Run test: Select view + assert.expect(6); + for (var id in viewSelectors) { + viewSelectors[id].click(); + // Assert: Only the clicked ViewController has class 'selected' + assert.ok(viewSelectors[id].hasClass('selected') && !viewSelectors[id].siblings().hasClass('selected'), "View selector \"" + id + "\" marked as selected, siblings NOT marked as selected."); + } + // Tear down + target.remove(); + }; + return ViewSelectorTest; +}()); +exports.ViewSelectorTest = ViewSelectorTest; + +},{"../../../resources/ts/Filtered/Controller":1,"../../../resources/ts/Filtered/ViewSelector":6}],12:[function(require,module,exports){ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var Filter_1 = require("../../../resources/ts/Filtered/Filter/Filter"); +var MockedFilter = /** @class */ (function (_super) { + __extends(MockedFilter, _super); + function MockedFilter() { + return _super !== null && _super.apply(this, arguments) || this; + } + return MockedFilter; +}(Filter_1.Filter)); +exports.MockedFilter = MockedFilter; + +},{"../../../resources/ts/Filtered/Filter/Filter":2}],13:[function(require,module,exports){ +"use strict"; +exports.__esModule = true; +var QUnitTest = /** @class */ (function () { + function QUnitTest() { + } + QUnitTest.prototype.runTests = function () { }; + ; + return QUnitTest; +}()); +exports.QUnitTest = QUnitTest; + +},{}],14:[function(require,module,exports){ +"use strict"; +exports.__esModule = true; +var QUnitTestHandler = /** @class */ (function () { + function QUnitTestHandler(moduleName, testclasses) { + this.isInitialised = false; + this.moduleName = moduleName; + this.testclasses = testclasses; + } + QUnitTestHandler.prototype.init = function () { + var _this = this; + if (this.isInitialised) { + return; + } + this.isInitialised = true; + QUnit.testDone(function (details) { + var message = "Pass: " + details.passed + " Fail: " + details.failed + " Total: " + details.total + " " + details.module + " - " + details.name + " (" + details.duration + "ms)"; + _this.reportResult(details.failed, message); + }); + QUnit.done(function (details) { + var message = "All tests finished. (" + details.runtime + "ms)\nPass: " + details.passed + " Fail: " + details.failed + " Total: " + details.total; + _this.reportResult(details.failed, message); + }); + }; + ; + QUnitTestHandler.prototype.reportResult = function (failed, message) { + if (failed === 0) { + console.log(message); + } + else { + console.error(message); + } + }; + QUnitTestHandler.prototype.runTests = function () { + this.init(); + QUnit.module(this.moduleName, QUnit.newMwEnvironment()); + this.testclasses.forEach(function (testclass) { + return new testclass().runTests(); + }); + }; + ; + return QUnitTestHandler; +}()); +exports.QUnitTestHandler = QUnitTestHandler; + +},{}],15:[function(require,module,exports){ +"use strict"; +/// <reference types="qunit" /> +exports.__esModule = true; +var ViewSelectorTest_1 = require("./Filtered/ViewSelectorTest"); +var ControllerTest_1 = require("./Filtered/ControllerTest"); +var ValueFilterTest_1 = require("./Filtered/Filter/ValueFilterTest"); +var QUnitTestHandler_1 = require("./Util/QUnitTestHandler"); +var ViewTest_1 = require("./Filtered/View/ViewTest"); +var MapViewTest_1 = require("./Filtered/View/MapViewTest"); +var testclasses = [ + ViewSelectorTest_1.ViewSelectorTest, + ControllerTest_1.ControllerTest, + ValueFilterTest_1.ValueFilterTest, + ViewTest_1.ViewTest, + MapViewTest_1.MapViewTest, +]; +var testhandler = new QUnitTestHandler_1.QUnitTestHandler('ext.srf.formats.filtered', testclasses); +testhandler.runTests(); + +},{"./Filtered/ControllerTest":7,"./Filtered/Filter/ValueFilterTest":8,"./Filtered/View/MapViewTest":9,"./Filtered/View/ViewTest":10,"./Filtered/ViewSelectorTest":11,"./Util/QUnitTestHandler":14}]},{},[15]); diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.gallery.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.gallery.test.js new file mode 100644 index 00000000..56db0d62 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.gallery.test.js @@ -0,0 +1,73 @@ +/** + * This file is part of the Semantic Result Formats QUnit Suite + * @see https://www.semantic-mediawiki.org/wiki/QUnit + * + * @section LICENSE + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + * @file + * + * @since 1.9 + * @ingroup SRF + * + * @licence GNU GPL v2+ + * @author mwjames + */ + +/** + * QUnit tests for the srf.formats.gallery class + * + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.formats.gallery', QUnit.newMwEnvironment() ); + + /** + * Test initialization and accessibility + * + * @since: 1.9 + */ + QUnit.test( 'init', 5, function ( assert ) { + var gallery = new srf.formats.gallery(); + + assert.ok( gallery instanceof Object, 'gallery instance was accessible' ); + assert.equal( $.type( gallery.redirect ), 'function', '.redirect() was accessible' ); + assert.equal( $.type( gallery.overlay ), 'function', '.overlay() was accessible' ); + assert.equal( $.type( gallery.slideshow ), 'function', '.slideshow() was accessible' ); + assert.equal( $.type( gallery.carousel ), 'function', '.carousel() was accessible' ); + + } ); + + /** + * Test overlay + * + * @since: 1.9 + */ + QUnit.test( 'overlay', 2, function ( assert ) { + + var context = $( '<div class="srf-overlay"</div>', '#qunit-fixture' ); + var gallery = new srf.formats.gallery(); + + var ns = 'File'; + + gallery.overlay( context, ns ); + assert.equal( $.type( gallery.defaults.path ), 'string', '.defaults.path was initialized and returned a string' ); + assert.equal( gallery.defaults.ns, ns, '.defaults.ns was initialized and returned the invoked string' ); + + } ); + + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.media.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.media.test.js new file mode 100644 index 00000000..55908382 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.media.test.js @@ -0,0 +1,131 @@ +/** + * This file is part of the Semantic Result Formats QUnit Suite + * @see https://www.semantic-mediawiki.org/wiki/QUnit + * + * @section LICENSE + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + * @file + * + * @since 1.9 + * @ingroup SRF + * + * @licence GNU GPL v2+ + * @author mwjames + */ + +/** + * QUnit tests for the srf.formats.media class + * + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.formats.media', QUnit.newMwEnvironment() ); + + var jsonString = '{\"data\":{\"File:Foo.mp3\":{\"mp3\":\"\\/mw\\/Foo.mp3\",\"subject\":\"File:Foo.mp3\"}},\"count\":5,\"mediaType\":\"audio\",\"mimeTypes\":\"ogg,mp3\",\"inspector\":true}'; + + /** + * Test initialization and accessibility + * + * @since: 1.9 + */ + QUnit.test( 'init', 8, function ( assert ) { + var media = new srf.formats.media(); + + assert.ok( media instanceof Object, 'srf.formats.media() instance was accessible' ); + assert.equal( $.type( media.defaults ), 'object', '.defaults was accessible' ); + assert.equal( $.type( media.parse ), 'function', '.parse() was accessible' ); + assert.equal( $.type( media.getId ), 'function', '.getId() was accessible' ); + assert.equal( $.type( media.getPlayerSize ), 'function', '.getPlayerSize() was accessible' ); + assert.equal( $.type( media.getData ), 'function', '.getData() was accessible' ); + assert.equal( $.type( media.getPlayerTemplate ), 'function', '.getPlayerTemplate() was accessible' ); + assert.equal( $.type( media.getInspector ), 'function', '.getInspector() was accessible' ); + + } ); + + /** + * Test template accessibility + * + * @since: 1.9 + */ + QUnit.test( 'template', 3, function ( assert ) { + + assert.equal( $.type( srf.template.jplayer.inspector ), 'function', '.jplayer.inspector() was accessible' ); + assert.equal( $.type( srf.template.jplayer.audio ), 'object', '.jplayer.audio returned an object' ); + assert.equal( $.type( srf.template.jplayer.video ), 'object', '.jplayer.video returned an object' ); + + } ); + + /** + * Test default settings + * + * @since: 1.9 + */ + QUnit.asyncTest( 'defaults', 2, function ( assert ) { + var media = new srf.formats.media(); + + $.get( media.defaults.posterImage ) + .done( function() { + QUnit.start(); + assert.ok( true, media.defaults.posterImage + ' verified' ); + } ) + .fail( function() { + // doesn't exists + QUnit.start(); + } ); + + $.get( media.defaults.jplayer.swfPath ) + .done( function() { + QUnit.start(); + assert.ok( true, media.defaults.jplayer.swfPath + ' verified' ); + } ) + .fail( function() { + // doesn't exists + QUnit.start(); + } ); + + } ); + + /** + * Test parse + * + * @since: 1.9 + */ + QUnit.test( 'parse', 1, function ( assert ) { + var media = new srf.formats.media(); + + assert.equal( $.type( media.parse( jsonString ) ), 'object', '.parse() returned an object' ); + + } ); + + /** + * Test getData + * + * @since: 1.9 + */ + QUnit.test( 'getData', 2, function ( assert ) { + var media = new srf.formats.media(); + var json = media.parse( jsonString ); + var result = media.getData( json.data, json.mediaType ); + + $.map( result, function ( data ) { + assert.equal( data.subject, 'File:Foo.mp3', 'subject returned "File:Foo.mp3"' ); + assert.equal( data.title, 'File:Foo.mp3', 'title returned "File:Foo.mp3"' ); + } ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.tagcloud.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.tagcloud.test.js new file mode 100644 index 00000000..11fddce8 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/formats/ext.srf.formats.tagcloud.test.js @@ -0,0 +1,178 @@ +/*! + * This file is part of the Semantic Result Formats QUnit Suite + * @see https://www.semantic-mediawiki.org/wiki/QUnit + * + * @section LICENSE + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * + * @since 1.9 + * @ingroup SRF + * + * @license GNU GPL v2+ + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.formats.tagcloud', QUnit.newMwEnvironment() ); + + var context = $( + '<div><div id="test" class="srf-container">' + + '<div id="test1" class="srf-tags"><ul>' + + '<li><a href="/test1">Test1</a></li>' + + '<li><a href="/test2">Test2</a></li>' + + '</ul></div></div></div>', '#qunit-fixture' ); + + /** + * Test initialization and accessibility + * + * @since: 1.9 + */ + QUnit.test( 'init', 4, function ( assert ) { + var tagcloud = new srf.formats.tagcloud(); + + assert.equal( $.type( tagcloud.defaults ), 'object', '.defaults was accessible' ); + assert.equal( $.type( tagcloud.sphere ), 'function', '.sphere() was accessible' ); + assert.equal( $.type( tagcloud.wordcloud ), 'function', '.wordcloud() was accessible' ); + assert.equal( $.type( tagcloud.load ), 'function', '.load() was accessible' ); + + } ); + + /** + * Test dependencies + * + * @since: 1.9 + */ + QUnit.test( 'dependencies', 4, function ( assert ) { + var util = new srf.util(); + + assert.equal( $.type( util.assert ), 'function', 'util.assert was accessible' ); + assert.equal( $.type( smw.async.load ), 'function', 'smw.async.load was accessible' ); + assert.equal( $.type( util.spinner.hide ), 'function', 'util.spinner.hide was accessible' ); + assert.equal( $.type( util.message.set ), 'function', 'util.message.set was accessible' ); + + } ); + + /** + * Test load + * + * @since: 1.9 + */ + QUnit.test( 'load', 4, function ( assert ) { + var tagcloud = new srf.formats.tagcloud(); + var result, + options; + + context.data( 'version', '0.4.1' ); + + options = { + context: context, + element: 'canvas', + module: 'ext.jquery.tagcanvas', + method: tagcloud.sphere + }; + + result = tagcloud.load( options ); + assert.ok( result, 'sphere was initialized' ); + + options = { + context: context, + element: 'svg', + module: 'ext.d3.wordcloud', + method: tagcloud.wordcloud + }; + + result = tagcloud.load( options ); + assert.ok( result, 'wordcloud was initialized' ); + + // Check for a non existing element + options = { + context: context, + element: 'lula', + module: '', + method: '' + }; + + result = tagcloud.load( options ); + assert.ok( result, 'non existing element' ); + + // Check invalid version + options = { + context: context, + element: 'lula', + module: '', + method: '' + }; + + tagcloud.version = '0.4.2'; + result = tagcloud.load( options ); + assert.equal( result, false, 'wrong version' ); + + } ); + + /** + * Test sphere/tagcanvas + * + * @since: 1.9 + */ + QUnit.asyncTest( 'sphere', 1, function ( assert ) { + var tagcloud = new srf.formats.tagcloud(); + + context.find( '.srf-container' ).data( { + 'width': 100, + 'height': 100, + 'font': 'sans' + } ); + + // Tagcanvas dies during testing for some reasons, + // QUnit returns with a time-out + mw.loader.using( 'ext.jquery.tagcanvas', function() { + QUnit.start(); + tagcloud.sphere( context ); + assert.ok( context.find( 'canvas' ), 'canvas element was found' ); + } ); + + // As of now mark this test as OK because of the above issue + assert.ok( true, 'Not really true but for now we pass' ); + } ); + + /** + * Test wordcloud + * + * @since: 1.9 + */ + QUnit.asyncTest( 'wordcloud', 2, function ( assert ) { + var tagcloud = new srf.formats.tagcloud(); + + context.find( '.srf-container' ).data( { + 'width': 100, + 'height': 100, + 'font': 'sans' + } ); + + mw.loader.using( 'ext.d3.wordcloud', function() { + QUnit.start(); + var result = tagcloud.wordcloud( context ); + assert.ok( result, 'function returned true' ); + assert.ok( context.find( 'svg' ), 'svg element was found' ); + } ); + + } ); + + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.eventcalendar.tests.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.eventcalendar.tests.js new file mode 100644 index 00000000..ea919647 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.eventcalendar.tests.js @@ -0,0 +1,137 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.widgets.eventcalendar', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + var context = $( '<div class="srf-eventcalendar"><div class="info"></div><div id="smw-test" class="container"></div></div>', '#qunit-fixture' ), + container = context.find( '.container' ); + + /** + * calendarpane widget testing + * + * @since 1.9 + */ + QUnit.test( 'calendarpane widget', 4, function ( assert ) { + var pane = context.find( '.info' ); + + // Set visibility + pane.calendarpane( { + 'show': true + } ); + + // Without fieldset + var test = pane.calendarpane( 'portlet', { + 'class' : 'test', + 'title' : 'Test', + 'fieldset': false + } ); + + var results = test.find( 'fieldset' ).length; + assert.ok( results === 0, pass + 'the test portlet was created without fieldset (false)' ); + + // With fieldset + var test = pane.calendarpane( 'portlet', { + 'class' : 'test', + 'title' : 'Test', + 'fieldset': true + } ); + + var results = test.find( 'fieldset' ).length; + assert.ok( results > 0, pass + 'the test portlet was created with a fieldset (true)' ); + + // Toggle + pane.calendarpane( 'toggle' ); + var result = pane.calendarpane( 'context' ).css( 'display' ); + assert.equal( result , 'none', pass + 'the pane toggle was successful (hide) ' ); + + pane.calendarpane( 'toggle' ); + var result = pane.calendarpane( 'context' ).css( 'display' ); + assert.equal( result, 'block', pass + 'the pane toggle was successful (show)' ); + + } ); + + /** + * calendarbutton widget testing + * + * @since 1.9 + */ + QUnit.test( 'calendarbutton widget', 1, function ( assert ) { + var button = context.find( '.info' ); + + button.calendarbutton( { + 'class': 'pane', + icon : 'ui-icon ui-icon-bookmark', + title: '', + theme: '' + } ) + .on( 'click', '.srf-calendarbutton-pane' , function( event ) { + assert.ok( true, pass + 'the click trigger was successful' ); + } ); + + button.find( '.srf-calendarbutton-pane' ).trigger( 'click' ); + + } ); + + /** + * calendarparameters widget testing + * + * @since 1.9 + */ + QUnit.test( 'calendarparameters widget - eventStart', 4, function ( assert ) { + var pane = context.find( '.info' ); + + // Set visibility + pane.calendarpane( { + 'show': true + } ); + + var param = pane.calendarpane( 'portlet', { + 'class' : 'parameters', + 'title' : 'Test', + 'fieldset': true + } ).find( 'fieldset' ).calendarparameters(); + + // Start parameter + param.calendarparameters( 'eventStart', { + type: 'earliest', + change: function( type ){ + assert.ok( true, pass + 'the change event (' + type + ') was triggered' ); + }, + reset: function(){ + assert.ok( true, pass + 'the reset event was triggered' ); + } + } ); + + var results = param.find( '.srf-calendarparameters-minmax' ).length; + assert.ok( results === 0, pass + 'the minmax portlet was created' ); + + // Trigger change earliest + param.find( '#min' ).trigger( 'change' ); + + // Change option + param.calendarparameters( + 'option', 'eventStart', { + 'type': 'latest' + } ); + + // Trigger change for latest + param.find( '#max' ).trigger( 'change' ); + + // Trigger click for reset + param.find( '.reset-link' ).trigger( 'click' ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.optionslist.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.optionslist.test.js new file mode 100644 index 00000000..ee575e7e --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.optionslist.test.js @@ -0,0 +1,154 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.widgets.optionslist', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + var list = [ { key: 0, label: 'foo' }, { key: 2, label: 'fooBar' }, { key: 11, label: 'bar' } ]; + var list2 = [ 'foo', 'bar', 'fooBar' ]; + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( 'instance', 1, function ( assert ) { + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + context.optionslist(); + var result = context.optionslist( 'checklist', { + show: true, + list: list, + 'class': 'test' + } ); + + assert.ok( result.length > 0 , pass + 'the srf.checklist widget returned an object with length > 0' ); + + } ); + + /** + * onClick testing + * + * @since 1.9 + */ + QUnit.test( 'checklist click event', 2, function ( assert ) { + var result ; + var context; + + context = $( '<div class="test"></div>', '#qunit-fixture' ); + + context.optionslist(); + result = context.optionslist( 'checklist', { + show: true, + list: list, + 'class': 'test', + click: function( event, ui ){ + assert.equal( ui.value, 11, pass + 'object key (11) was returned for id(#bar)' ); + } + } ); + + // Trigger click + result.find( '#bar' ).trigger( 'click' ); + + context = $( '<div class="test"></div>', '#qunit-fixture' ); + context.optionslist(); + result = context.optionslist( 'checklist', { + show: true, + list: list2, + 'class': 'test', + click: function( event, ui ){ + assert.equal( ui.value, 1, pass + 'array key (1) was returned for id(#bar)' ); + } + } ); + + // Trigger click + result.find( '#bar' ).trigger( 'click' ); + + } ); + + /** + * show/hide option + * + * @since 1.9 + */ + QUnit.test( 'checklist show/hide ', 3, function ( assert ) { + var result; + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + context.optionslist(); + result = context.optionslist( 'checklist', { + show: true, + list: list, + 'class': 'listTest' + } ); + assert.equal( result.css( 'display' ) , 'block', pass + 'option resulted in a visible list' ); + + context.optionslist(); + result = context.optionslist( 'checklist', { + list: list, + 'class': 'listTest' + } ); + assert.equal( result.css( 'display' ) , 'block', pass + 'option resulted in a visible list' ); + + context.optionslist(); + result = context.optionslist( 'checklist', { + show: false, + list: list, + 'class': 'listTest' + } ); + assert.equal( result.css( 'display' ) , 'none', pass + 'option resulted in a hidden list' ); + + } ); + + /** + * change event testing + * + * @since 1.9 + */ + QUnit.test( 'selectlist change event', 2, function ( assert ) { + var result ; + var context; + + context = $( '<div class="test"></div>', '#qunit-fixture' ); + + context.optionslist(); + result = context.optionslist( 'selectlist', { + show: true, + list: list, + 'class': 'test', + change: function( event, ui ){ + assert.equal( ui.value, 11, pass + 'value (11) was returned' ); + + + } + } ); + + // Trigger click + result.find( 'option[value="11"]' ).trigger( 'change' ); + + context.optionslist(); + result = context.optionslist( 'selectlist', { + show: true, + list: list2, + 'class': 'test2', + change: function( event, ui ){ + assert.equal( ui.value, 2, pass + 'value (2) was returned' ); + } + } ); + + // Trigger click + result.find( 'option[value=2]' ).trigger( 'change' ); + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.panel.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.panel.test.js new file mode 100644 index 00000000..838ba706 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.panel.test.js @@ -0,0 +1,57 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.widgets.panel', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( 'instance', 1, function ( assert ) { + var result; + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + result = context.panel( { + 'show': true + } ); + assert.ok( result.find( '.srf-panel') , pass + 'the srf.panel widget returned a DOM object' ); + + } ); + + /** + * Portlet testing + * + * @since 1.9 + */ + QUnit.test( 'add portlet', 1, function ( assert ) { + var result; + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + result = context.panel( { + 'show': true + } ); + + result = result.panel( 'portlet', { + 'class' : 'portlet', + 'title' : 'portlet', + 'fieldset': true + } ); + assert.ok( result.find( '.portlet > fieldset' ), pass + 'the srf.panel widget added a portlet' ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file diff --git a/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.parameters.test.js b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.parameters.test.js new file mode 100644 index 00000000..85f213e8 --- /dev/null +++ b/www/wiki/extensions/SemanticResultFormats/tests/qunit/widgets/ext.srf.widgets.parameters.test.js @@ -0,0 +1,69 @@ +/** + * QUnit tests + * + * @since 1.9 + * + * @file + * @ingroup SRF + * + * @licence GNU GPL v2 or later + * @author mwjames + */ +( function ( $, mw, srf ) { + 'use strict'; + + QUnit.module( 'ext.srf.widgets.parameters', QUnit.newMwEnvironment() ); + + var pass = 'Passes because '; + + /** + * Instance testing + * + * @since 1.9 + */ + QUnit.test( 'instance', 1, function ( assert ) { + var result; + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + result = context.parameters(); + + assert.ok( result.find( '.parameters') , pass + 'the srf.parameters widget returned a DOM object' ); + + } ); + + /** + * Limit parameter test + * + * @since 1.9 + */ + QUnit.test( 'limit parameter test', 3, function ( assert ) { + var result; + var context = $( '<div class="test"></div>', '#qunit-fixture' ); + + var parameters = context.parameters(); + parameters.parameters( 'limit', { + limit : 10, + count : 1, + max : 20, + step : 1, + change: function( event, ui ) { + assert.equal( ui.value, ( 3 - 1 ), pass + 'the limit parameter was changed to 2' ); + } + } ); + + assert.equal( parameters.find( '.value' ).text(), "10", pass + 'the limit parameter is 10' ); + + // Simulate slider value change + parameters.find( '.slider' ).slider( "value", 3 ); + + // Update limit display + parameters.parameters( + 'option', 'limit', { + 'limit': 3, + 'count': 3 + } ) ; + assert.equal( parameters.find( '.value' ).text(), "3", pass + 'the limit parameter is 3' ); + + } ); + +}( jQuery, mediaWiki, semanticFormats ) );
\ No newline at end of file |