Gergő Tisza has uploaded a new change for review.
https://gerrit.wikimedia.org/r/176511
Change subject: Add tests for verifyAttributionMetadata()
......................................................................
Add tests for verifyAttributionMetadata()
Change-Id: I331e8b87842c71c255db71155d36a6121d487567
---
M tests/phpunit/DataCollectorTest.php
1 file changed, 82 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommonsMetadata
refs/changes/11/176511/1
diff --git a/tests/phpunit/DataCollectorTest.php
b/tests/phpunit/DataCollectorTest.php
index 0cfae2e..37dffd5 100644
--- a/tests/phpunit/DataCollectorTest.php
+++ b/tests/phpunit/DataCollectorTest.php
@@ -185,6 +185,88 @@
$this->assertMetadataValue( 'AuthorCount', 2, $templateData );
}
+ /*-------------------- verifyAttributionMetadata tests -------------*/
+
+ public function testVerifyAttributionMetadata() {
+ $this->templateParser->expects( $this->once() )->method(
'parsePage' )
+ ->will( $this->returnValue( array(
+ TemplateParser::INFORMATION_FIELDS_KEY =>
array( array(
+ 'ImageDescription' => 'blah',
+ 'Artist' => 'blah blah',
+ 'Credit' => 'blah blah blah',
+ ) ),
+ TemplateParser::LICENSES_KEY => array( array(
'LicenseShortName' => 'quux' ) ),
+ ) ) );
+ $this->licenseParser->expects( $this->any() )->method(
'parseLicenseString' )
+ ->will( $this->returnValue( null ) );
+
+ $problems = $this->dataCollector->verifyAttributionMetadata( ''
);
+ $this->assertEmpty( $problems );
+ }
+
+ public function testVerifyAttributionMetadataWithAttribution() {
+ $this->templateParser->expects( $this->once() )->method(
'parsePage' )
+ ->will( $this->returnValue( array(
+ TemplateParser::INFORMATION_FIELDS_KEY =>
array( array(
+ 'ImageDescription' => 'blah',
+ 'Attribution' => 'blah blah',
+ ) ),
+ TemplateParser::LICENSES_KEY => array( array(
'LicenseShortName' => 'quux' ) ),
+ ) ) );
+ $this->licenseParser->expects( $this->any() )->method(
'parseLicenseString' )
+ ->will( $this->returnValue( null ) );
+
+ $problems = $this->dataCollector->verifyAttributionMetadata( ''
);
+ $this->assertEmpty( $problems );
+ }
+
+ public function testVerifyWithEmptyMetadata() {
+ $this->templateParser->expects( $this->once() )->method(
'parsePage' )
+ ->will( $this->returnValue( array(
+ TemplateParser::COORDINATES_KEY => array(),
+ TemplateParser::INFORMATION_FIELDS_KEY =>
array(),
+ TemplateParser::LICENSES_KEY => array(),
+ TemplateParser::DELETION_KEY => array(),
+ ) ) );
+ $this->licenseParser->expects( $this->any() )->method(
'parseLicenseString' )
+ ->will( $this->returnValue( null ) );
+
+ $problems = $this->dataCollector->verifyAttributionMetadata( ''
);
+
+ $this->assertContains( 'no-license', $problems );
+ $this->assertContains( 'no-description', $problems );
+ $this->assertContains( 'no-author', $problems );
+ $this->assertContains( 'no-source', $problems );
+ }
+
+ public function testVerifyWithNoMetadata() {
+ $this->templateParser->expects( $this->once() )->method(
'parsePage' )
+ ->will( $this->returnValue( array() ) );
+ $this->licenseParser->expects( $this->any() )->method(
'parseLicenseString' )
+ ->will( $this->returnValue( null ) );
+
+ $problems = $this->dataCollector->verifyAttributionMetadata( ''
);
+
+ $this->assertContains( 'no-license', $problems );
+ $this->assertContains( 'no-description', $problems );
+ $this->assertContains( 'no-author', $problems );
+ $this->assertContains( 'no-source', $problems );
+ }
+
+ public function testVerifyWithMissingMetadata() {
+ $this->templateParser->expects( $this->once() )->method(
'parsePage' )
+ ->will( $this->returnValue( null ) );
+ $this->licenseParser->expects( $this->any() )->method(
'parseLicenseString' )
+ ->will( $this->returnValue( null ) );
+
+ $problems = $this->dataCollector->verifyAttributionMetadata( ''
);
+
+ $this->assertContains( 'no-license', $problems );
+ $this->assertContains( 'no-description', $problems );
+ $this->assertContains( 'no-author', $problems );
+ $this->assertContains( 'no-source', $problems );
+ }
+
/*------------------------------- Helpers --------------------------*/
protected function assertMetadataValue( $field, $expected, $metadata,
$message = '' ) {
--
To view, visit https://gerrit.wikimedia.org/r/176511
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I331e8b87842c71c255db71155d36a6121d487567
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommonsMetadata
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits