Skip to content

Commit

Permalink
Extend unit tests (bibtex, vcard)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jul 27, 2019
1 parent 266c298 commit a6207a5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
52 changes: 50 additions & 2 deletions tests/phpunit/Unit/BibTex/BibTexFileExportPrinterTest.php
Expand Up @@ -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(
Expand All @@ -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'
];
}

}
48 changes: 45 additions & 3 deletions tests/phpunit/Unit/vCard/vCardFileExportPrinterTest.php
Expand Up @@ -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(
Expand All @@ -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'
];
}

}

0 comments on commit a6207a5

Please sign in to comment.