From a6207a55b6fdcb50008efdc59d5aa5bc76ee892b Mon Sep 17 00:00:00 2001 From: mwjames Date: Sat, 27 Jul 2019 23:25:12 +0900 Subject: [PATCH] Extend unit tests (bibtex, vcard) --- .../BibTex/BibTexFileExportPrinterTest.php | 52 ++++++++++++++++++- .../Unit/vCard/vCardFileExportPrinterTest.php | 48 +++++++++++++++-- 2 files changed, 95 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php b/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php index 3148ba7d3..68aab69ba 100644 --- a/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php +++ b/tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php @@ -40,10 +40,11 @@ public function testCanConstruct() { /** * @dataProvider filenameProvider */ - public function testGetFileName( $filename, $expected ) { + public function testGetFileName( $filename, $searchlabel, $expected ) { $parameters = [ - 'filename' => $filename + 'filename' => $filename, + 'searchlabel' => $searchlabel ]; $instance = new BibTexFileExportPrinter( @@ -70,22 +71,69 @@ public function testGetMimeType() { ); } + 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 BibTexFileExportPrinter( + 'bibtex' + ); + + $this->assertEquals( + 'foo_link', + $instance->getResult( $this->queryResult, [], SMW_OUTPUT_HTML ) + ); + } + 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' + ]; } } diff --git a/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php b/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php index 7451271f8..f094268f6 100644 --- a/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php +++ b/tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php @@ -40,10 +40,11 @@ public function testCanConstruct() { /** * @dataProvider filenameProvider */ - public function testGetFileName( $filename, $expected ) { + public function testGetFileName( $filename, $searchlabel, $expected ) { $parameters = [ - 'filename' => $filename + 'filename' => $filename, + 'searchlabel' => $searchlabel ]; $instance = new vCardFileExportPrinter( @@ -70,22 +71,63 @@ public function testGetMimeType() { ); } + 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[ '', - 'vCard.vcf' + 'foo bar', + 'foo_bar.vcf' ]; yield[ 'foo', + '', 'foo.vcf' ]; yield[ 'foo.vcf', + '', 'foo.vcf' ]; + + yield[ + 'foo bar.vcf', + '', + 'foo_bar.vcf' + ]; } }