Dominic.sauer has uploaded a new change for review.
https://gerrit.wikimedia.org/r/216674
Change subject: Fix tests and set new threshold
......................................................................
Fix tests and set new threshold
Conflicts:
includes/CrossCheck/Comparer/StringComparer.php
tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
tests/phpunit/Violations/CrossCheckViolationContextTest.php
Change-Id: I0463ab43320bf0b531c45b6a7dc2bef55803f612
---
M includes/CrossCheck/Comparer/StringComparer.php
M tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
A tests/phpunit/Violations/CrossCheckViolationContextTest.php
3 files changed, 436 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityExternalValidation
refs/changes/74/216674/1
diff --git a/includes/CrossCheck/Comparer/StringComparer.php
b/includes/CrossCheck/Comparer/StringComparer.php
index 0c84ab6..d20e625 100755
--- a/includes/CrossCheck/Comparer/StringComparer.php
+++ b/includes/CrossCheck/Comparer/StringComparer.php
@@ -17,7 +17,7 @@
/**
* Threshold for matching compliance in prefix/suffix similarity checks
*/
- const SIMILARITY_THRESHOLD = 0.8;
+ const SIMILARITY_THRESHOLD = 0.75;
/**
* Compares two strings with each other.
@@ -220,6 +220,4 @@
return $percentage;
}
-
-
-}
\ No newline at end of file
+}
diff --git a/tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
b/tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
index 0491277..b3db2f8 100755
--- a/tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
+++ b/tests/phpunit/CrossCheck/Comparer/StringComparerTest.php
@@ -112,6 +112,11 @@
'oobar',
CompareResult::STATUS_PARTIAL_MATCH
),
+ array(
+ 'New York City',
+ 'New York City, NY',
+ CompareResult::STATUS_PARTIAL_MATCH
+ ),
// levenshtein partial match
array(
'foobar',
@@ -131,6 +136,11 @@
array(
'Schlossstraße',
'Schloßstraße',
+ CompareResult::STATUS_PARTIAL_MATCH
+ ),
+ array(
+ 'Yoko Ono',
+ 'Yōko Ono',
CompareResult::STATUS_PARTIAL_MATCH
),
// mismatches
@@ -158,6 +168,11 @@
'Johanna von Österreich',
'Johanna',
CompareResult::STATUS_MISMATCH
+ ),
+ array(
+ 'New York',
+ 'New York, NY',
+ CompareResult::STATUS_MISMATCH
)
);
}
diff --git a/tests/phpunit/Violations/CrossCheckViolationContextTest.php
b/tests/phpunit/Violations/CrossCheckViolationContextTest.php
new file mode 100755
index 0000000..d9e0844
--- /dev/null
+++ b/tests/phpunit/Violations/CrossCheckViolationContextTest.php
@@ -0,0 +1,419 @@
+<?php
+
+namespace WikibaseQuality\ExternalValidation\Test\Violations\Result;
+
+use DataValues\StringValue;
+use Language;
+use DataValues\DataValue;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\ItemId;
+use WikibaseQuality\ExternalValidation\Violations\CrossCheckViolationContext;
+use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
+
+
+/**
+ * @covers
WikibaseQuality\ExternalValidation\Violations\CrossCheckViolationContext
+ *
+ * @group WikibaseQualityExternalValidation
+ *
+ * @author BP2014N1
+ * @license GNU GPL v2+
+ */
+class CrossCheckViolationContextTest extends \MediaWikiTestCase {
+
+ /**
+ * @var CrossCheckViolationContext
+ */
+ private $violationContext;
+
+ public function setUp() {
+ parent::setUp();
+
+ $dumpMetaInformation = array(
+ $this->getDumpMetaInformationMock( new ItemId( 'Q21' ) ),
+ $this->getDumpMetaInformationMock( new ItemId( 'Q42' ) ),
+ $this->getDumpMetaInformationMock( new ItemId( 'Q84' ) )
+ );
+
+ $this->violationContext = new CrossCheckViolationContext(
+ $this->getDataValueDeserializerMock(),
+ $this->getEntityIdFormatterMock(),
+ $this->getValueFormatterMock(),
+ $this->getDumpMetaInformationRepoMock( $dumpMetaInformation ),
+ new JsonFileEntityLookup( __DIR__ . '/testdata' )
+ );
+ }
+
+ public function tearDown() {
+ unset( $this->violationContext );
+
+ parent::tearDown();
+ }
+
+
+ public function testGetTypes() {
+ $actualResult = $this->violationContext->getTypes();
+ $expectedResult = array(
+ new ItemId( 'Q21' ),
+ new ItemId( 'Q42' ),
+ new ItemId( 'Q84' )
+ );
+
+ $this->assertArrayEquals( $expectedResult, $actualResult );
+ }
+
+
+ /**
+ * @dataProvider isContextForDataProvider
+ */
+ public function testIsContextFor( $expectedResult, $violation ) {
+ $actualResult = $this->violationContext->isContextFor( $violation );
+
+ $this->assertEquals( $expectedResult, $actualResult );
+ }
+
+ /**
+ * Test cases for testIsContextFor
+ * @return array
+ */
+ public function isContextForDataProvider() {
+ return array(
+ array(
+ true,
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqev|foobar' )
+ ),
+ array(
+ false,
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqc|foobar' )
+ ),
+ array(
+ false,
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'foobar' )
+ )
+ );
+ }
+
+
+ /**
+ * @dataProvider getIconClassDataProvider
+ */
+ public function testGetIconClass( $violation, $expectedException = null ) {
+ $this->setExpectedException( $expectedException );
+
+ $actualResult = $this->violationContext->getIconClass( $violation );
+
+ $this->assertTrue( is_string( $actualResult ) );
+ }
+
+ /**
+ * Test cases for getIconClassDataProvider
+ * @return array
+ */
+ public function getIconClassDataProvider() {
+ return array(
+ array(
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqev|foobar' )
+ ),
+ array(
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqc|foobar' ),
+ 'InvalidArgumentException'
+ )
+ );
+ }
+
+
+ /**
+ * @dataProvider formatAdditionalInformationDataProvider
+ */
+ public function testFormatAdditionalInformation( $expectedResult,
$violation, $expectedException = null ) {
+ $this->setExpectedException( $expectedException );
+
+ global $wgLang;
+ $wgLang = Language::factory( 'qqx' );
+ $actualResult = $this->violationContext->formatAdditionalInformation(
$violation );
+
+ $this->assertEquals( $expectedResult, $actualResult );
+ }
+
+ /**
+ * Test cases for testFormatAdditionalInformation
+ * @return array
+ */
+ public function formatAdditionalInformationDataProvider() {
+ return array(
+ array(
+ '<p><span
class="wbq-violations-additional-information-header">(wbqev-violation-header-external-source)</span><br
/>Q42</p><p><span
class="wbq-violations-additional-information-header">(wbqev-violation-header-external-values)</span><br
/>foo</p>',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'Q1$c0f25a6f-9e33-41c8-be34-c86a730ff30b',
+ 'wbqev|foobar',
+ 'Q42',
+ array(
+ 'dump_id' => 'foobar',
+ 'external_values' => array( 'foo' )
+ )
+ )
+ ),
+ array(
+ '<p><span
class="wbq-violations-additional-information-header">(wbqev-violation-header-external-source)</span><br
/>Q42</p><p><span
class="wbq-violations-additional-information-header">(wbqev-violation-header-external-values)</span><br
/>foo<br />bar</p>',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'Q1$c0f25a6f-9e33-41c8-be34-c86a730ff30b',
+ 'wbqev|foobar',
+ 'Q42',
+ array(
+ 'dump_id' => 'foobar',
+ 'external_values' => array( 'foo', 'bar' )
+ )
+ )
+ ),
+ array(
+ null,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'Q1$c0f25a6f-9e33-41c8-be34-c86a730ff30b',
+ 'wbqev|foobar',
+ 'Q42',
+ array()
+ )
+ ),
+ array(
+ null,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'Q1$c0f25a6f-9e33-41c8-be34-c86a730ff30b',
+ 'wbqc|foobar',
+ 'Q42',
+ array()
+ ),
+ 'InvalidArgumentException'
+ )
+ );
+ }
+
+
+ /**
+ * @dataProvider getShortMessageDataProvider
+ */
+ public function testGetShortMessage( $expectedResult, $violation,
$expectedException = null ) {
+ $this->setExpectedException( $expectedException );
+
+ global $wgLang;
+ $wgLang = Language::factory( 'qqx' );
+ $actualResult = $this->violationContext->getShortMessage( $violation );
+
+ $this->assertEquals( $expectedResult, $actualResult );
+ }
+
+ /**
+ * Test cases for testGetShortMessage
+ * @return array
+ */
+ public function getShortMessageDataProvider() {
+ return array(
+ array(
+ '(wbqev-violation-short-message: Q42)',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q42'
+ )
+ ),
+ array(
+ '(wbqev-violation-short-message: Q84)',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84'
+ )
+ ),
+ array(
+ null,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqc|foobar',
+ 'Q84'
+ ),
+ 'InvalidArgumentException'
+ )
+ );
+ }
+
+
+ /**
+ * @dataProvider getLongMessageDataProvider
+ */
+ public function testGetLongMessage( $expectedResult, $permissionStatus,
$violation, $expectedException = null ){
+ $this->setExpectedException( $expectedException );
+
+ global $wgLang;
+ $wgLang = Language::factory( 'qqx' );
+ $actualResult = $this->violationContext->getLongMessage( $violation,
$permissionStatus );
+
+ $this->assertEquals( $expectedResult, $actualResult );
+ }
+
+ /**
+ * Test cases for testGetLongMessage
+ * @return array
+ */
+ public function getLongMessageDataProvider() {
+ return array(
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-external-values: bar, 1)<br
/>(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbqev-violation-mark-as-exception)</a></div>',
+ true,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array( 'external_values' => array( 'foo' => 'bar' ) )
+ )
+ ),
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-external-values: foo, bar, 2)<br
/>(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbqev-violation-mark-as-exception)</a></div>',
+ true,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array( 'external_values' => array( 'foo', 'bar' ) )
+ )
+ ),
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbqev-violation-mark-as-exception)</a></div>',
+ true,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array()
+ )
+ ),
+ array(
+ null,
+ true,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqc|foobar',
+ 'Q84'
+ ),
+ 'InvalidArgumentException'
+ ),
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-solve-issue)<br />',
+ false,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array()
+ )
+ )
+ );
+ }
+
+
+ private function getDataValueDeserializerMock() {
+ $mock = $this->getMockBuilder( 'Deserializers\Deserializer' )
+ ->setMethods( array( 'deserialize' ) )
+ ->getMockForAbstractClass();
+ $mock->expects( $this->any() )
+ ->method( 'deserialize' )
+ ->willReturnCallback(
+ function( $value ) {
+ return new StringValue( $value );
+ }
+ );
+
+ return $mock;
+ }
+
+ private function getEntityIdFormatterMock() {
+ $mock = $this->getMockBuilder( 'Wikibase\Lib\EntityIdFormatter' )
+ ->setMethods( array( 'formatEntityId' ) )
+ ->getMockForAbstractClass();
+ $mock->expects( $this->any() )
+ ->method( 'formatEntityId' )
+ ->willReturnCallback(
+ function( EntityId $entityId ) {
+ return $entityId->getSerialization();
+ }
+ );
+
+ return $mock;
+ }
+
+ private function getValueFormatterMock() {
+ $mock = $this->getMockBuilder( 'ValueFormatters\ValueFormatter' )
+ ->setMethods( array( 'format' ) )
+ ->getMockForAbstractClass();
+ $mock->expects( $this->any() )
+ ->method( 'format' )
+ ->willReturnCallback(
+ function( DataValue $dataValue ) {
+ return $dataValue->getValue();
+ }
+ );
+
+ return $mock;
+ }
+
+ private function getDumpMetaInformationRepoMock( array
$dumpMetaInformation ) {
+ $mock = $this->getMockBuilder(
'WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformationRepo'
)
+ ->setMethods( array( 'getWithId', 'getAll' ) )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getAll' )
+ ->willReturn( $dumpMetaInformation );
+ $mock->expects( $this->any() )
+ ->method( 'getWithId' )
+ ->willReturn( $this->getDumpMetaInformationMock( new ItemId( 'Q42'
) ) );
+
+ return $mock;
+ }
+
+ private function getDumpMetaInformationMock( EntityId $sourceItemId ) {
+ $mock = $this->getMockBuilder(
'WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformation' )
+ ->setMethods( array( 'getSourceItemId' ) )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getSourceItemId' )
+ ->willReturn( $sourceItemId );
+
+ return $mock;
+ }
+
+ private function getViolationMock( $entityId = null, $claimGuid = null,
$constraintId = null, $constraintTypeEntityId = null, $additionalInformation =
null ) {
+ $mock = $this->getMockBuilder( 'WikibaseQuality\Violations\Violation' )
+ ->setMethods( array( 'getEntityId', 'getClaimGuid',
'getConstraintId', 'getConstraintTypeEntityId', 'getAdditionalInfo' ) )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getEntityId' )
+ ->willReturn( $entityId );
+ $mock->expects( $this->any() )
+ ->method( 'getClaimGuid' )
+ ->willReturn( $claimGuid );
+ $mock->expects( $this->any() )
+ ->method( 'getConstraintId' )
+ ->willReturn( $constraintId );
+ $mock->expects( $this->any() )
+ ->method( 'getConstraintTypeEntityId' )
+ ->willReturn( $constraintTypeEntityId );
+ $mock->expects( $this->any() )
+ ->method( 'getAdditionalInfo' )
+ ->willReturn( $additionalInformation );
+
+ return $mock;
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/216674
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0463ab43320bf0b531c45b6a7dc2bef55803f612
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation
Gerrit-Branch: v1
Gerrit-Owner: Dominic.sauer <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits