Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/173056
Change subject: Update label lookup tests, to check for exceptions and add
@group tags
......................................................................
Update label lookup tests, to check for exceptions and add @group tags
also use a mock LanguageFallbackChain to avoid side effects
from global state, caching, etc.
Change-Id: Icac13ff614935ca7161beb86476905ca0cdb5734
---
M lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
M lib/tests/phpunit/store/LanguageLabelLookupTest.php
2 files changed, 69 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/56/173056/1
diff --git a/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
b/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
index 470ffd4..b321fde 100644
--- a/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
+++ b/lib/tests/phpunit/store/LanguageFallbackLabelLookupTest.php
@@ -8,28 +8,65 @@
use Wikibase\Lib\Store\EntityTermLookup;
use Wikibase\Lib\Store\LanguageFallbackLabelLookup;
+/**
+ * @group Wikibase
+ * @group WikibaseLib
+ * @group WikibaseStore
+ */
class LanguageFallbackLabelLookupTest extends \MediaWikiTestCase {
public function testGetLabel() {
- $languageFallbackChainFactory = new
LanguageFallbackChainFactory();
- $fallbackChain =
$languageFallbackChainFactory->newFromLanguage( Language::factory( 'zh' ) );
+ $termLookup = $this->getTermLookup();
+ $fallbackChain = $this->getLanguageFallbackChain( 'zh' );
- $termLookup = new EntityTermLookup( $this->getTermIndex() );
$labelLookup = new LanguageFallbackLabelLookup( $termLookup,
$fallbackChain );
$label = $labelLookup->getLabel( new ItemId( 'Q118' ) );
- $this->assertEquals( '测试', $label );
+ $this->assertEquals( 'fallbackLabel', $label );
+ }
+
+ public function testGetLabel_entityNotFound() {
+ $termLookup = $this->getTermLookup();
+ $fallbackChain = $this->getLanguageFallbackChain( 'zh' );
+
+ $labelLookup = new LanguageFallbackLabelLookup( $termLookup,
$fallbackChain );
+
+ $this->setExpectedException(
'Wikibase\Lib\Store\StorageException' );
+ $labelLookup->getLabel( new ItemId( 'Q120' ) );
}
public function testGetLabel_notFound() {
- $languageFallbackChainFactory = new
LanguageFallbackChainFactory();
- $fallbackChain =
$languageFallbackChainFactory->newFromLanguage( Language::factory( 'zh' ) );
+ $termLookup = $this->getTermLookup();
+ $fallbackChain = $this->getLanguageFallbackChain( 'ar' );
- $termLookup = new EntityTermLookup( $this->getTermIndex() );
$labelLookup = new LanguageFallbackLabelLookup( $termLookup,
$fallbackChain );
$this->setExpectedException( 'OutOfBoundsException' );
- $label = $labelLookup->getLabel( new ItemId( 'Q120' ) );
+ $labelLookup->getLabel( new ItemId( 'Q116' ) );
+ }
+
+ private function getLanguageFallbackChain( $languageCode ) {
+ $languageFallbackChain = $this->getMockBuilder(
'Wikibase\LanguageFallbackChain' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $languageFallbackChain->expects( $this->any() )
+ ->method( 'extractPreferredValue' )
+ ->will( $this->returnCallback( function( array
$fallbackData ) use ( $languageCode ) {
+ if ( $languageCode === 'zh' &&
array_key_exists( 'zh-cn', $fallbackData ) ) {
+ return array( 'value' =>
'fallbackLabel' );
+ } else {
+ return null;
+ }
+ } ) );
+
+ return $languageFallbackChain;
+ }
+
+ private function getTermLookup() {
+ $entityLookup = new MockRepository();
+
+ return new EntityTermLookup( $this->getTermIndex(),
$entityLookup );
}
private function getTermIndex() {
diff --git a/lib/tests/phpunit/store/LanguageLabelLookupTest.php
b/lib/tests/phpunit/store/LanguageLabelLookupTest.php
index 27aeefa..c27b8d0 100644
--- a/lib/tests/phpunit/store/LanguageLabelLookupTest.php
+++ b/lib/tests/phpunit/store/LanguageLabelLookupTest.php
@@ -6,10 +6,15 @@
use Wikibase\Lib\Store\EntityTermLookup;
use Wikibase\Lib\Store\LanguageLabelLookup;
+/**
+ * @group Wikibase
+ * @group WikibaseLib
+ * @group WikibaseStore
+ */
class LanguageLabelLookupTest extends \MediaWikiTestCase {
public function testGetLabel() {
- $termLookup = new EntityTermLookup( $this->getTermIndex() );
+ $termLookup = $this->getTermLookup();
$labelLookup = new LanguageLabelLookup( $termLookup, 'en' );
$label = $labelLookup->getLabel( new ItemId( 'Q116' ) );
@@ -17,12 +22,27 @@
$this->assertEquals( 'New York City', $label );
}
- public function testGetLabel_notFound() {
- $termLookup = new EntityTermLookup( $this->getTermIndex() );
+ public function testGetLabel_entityNotFound() {
+ $termLookup = $this->getTermLookup();
$labelLookup = new LanguageLabelLookup( $termLookup, 'en' );
+ $this->setExpectedException(
'Wikibase\Lib\Store\StorageException' );
+ $labelLookup->getLabel( new ItemId( 'Q120' ) );
+ }
+
+ public function testGetLabel_notFound() {
+ $termLookup = $this->getTermLookup();
+ $labelLookup = new LanguageLabelLookup( $termLookup, 'fa' );
+
$this->setExpectedException( 'OutOfBoundsException' );
- $label = $labelLookup->getLabel( new ItemId( 'Q120' ) );
+
+ $labelLookup->getLabel( new ItemId( 'Q116' ) );
+ }
+
+ private function getTermLookup() {
+ $entityLookup = new MockRepository();
+
+ return new EntityTermLookup( $this->getTermIndex(),
$entityLookup );
}
private function getTermIndex() {
--
To view, visit https://gerrit.wikimedia.org/r/173056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icac13ff614935ca7161beb86476905ca0cdb5734
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits