jenkins-bot has submitted this change and it was merged.

Change subject: Follow up tests for SpecialEntityUsage
......................................................................


Follow up tests for SpecialEntityUsage

See Ib23a348 and I44647d

Change-Id: I5c4f9d4d559d71e0b51d48ce321e481ae0f05471
---
M client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
1 file changed, 108 insertions(+), 5 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php 
b/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
index e3daa05..df6093e 100644
--- a/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
+++ b/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
@@ -6,7 +6,9 @@
 use RequestContext;
 use SpecialPageFactory;
 use SpecialPageTestBase;
+use Title;
 use Wikibase\Client\Specials\SpecialEntityUsage;
+use WikiPage;
 
 /**
  * @covers Wikibase\Client\Specials\SpecialEntityUsage
@@ -27,10 +29,18 @@
                                'value' => 11,
                                'namespace' => 0,
                                'title' => 'Tehran',
-                               'aspects' => 'S|O|L.fa',
+                               'aspects' => 'O|L.fa',
                                'eu_page_id' => 11,
                                'eu_entity_id' => 'Q3',
                        ],
+                       (object)[
+                               'value' => 22,
+                               'namespace' => 0,
+                               'title' => 'Athena',
+                               'aspects' => 'S',
+                               'eu_page_id' => 22,
+                               'eu_entity_id' => 'Q3',
+                       ]
                ];
 
                return new FakeResultWrapper( $rows );
@@ -53,18 +63,25 @@
 
        public function testExecuteWithValidParam() {
                list( $result, ) = $this->executeSpecialPage( 'Q3' );
-               $aspects = [
-                       wfMessage( 'wikibase-pageinfo-entity-usage-S' 
)->parse(),
+               $aspectsTehran = [
                        wfMessage( 'wikibase-pageinfo-entity-usage-O' 
)->parse(),
                        wfMessage( 'wikibase-pageinfo-entity-usage-L', 'fa' 
)->parse(),
                ];
-               $aspectList = 
RequestContext::getMain()->getLanguage()->commaList( $aspects );
+               $aspectsAthena = [
+                       wfMessage( 'wikibase-pageinfo-entity-usage-S' 
)->parse(),
+               ];
+
+               $lang = RequestContext::getMain()->getLanguage();
+               $aspectListTehran = $lang->commaList( $aspectsTehran );
+               $aspectListAthena = $lang->commaList( $aspectsAthena );
 
                $this->assertContains( 'Tehran', $result );
+               $this->assertContains( 'Athena', $result );
                $this->assertNotContains( '<p class="error"', $result );
                $expected = SpecialPageFactory::getLocalNameFor( 'EntityUsage', 
'Q3' );
                $this->assertContains( $expected, $result );
-               $this->assertContains( $aspectList, $result );
+               $this->assertContains( ': ' . $aspectListTehran . '</li>', 
$result );
+               $this->assertContains( ': ' . $aspectListAthena . '</li>', 
$result );
        }
 
        public function testExecuteWithInvalidParam() {
@@ -77,4 +94,90 @@
                );
        }
 
+       public function testReallyDoQuery() {
+               if ( wfGetDB( DB_REPLICA )->getType() === 'mysql' &&
+                       $this->usesTemporaryTables()
+               ) {
+                       $this->markTestSkipped( 'MySQL does not allow 
self-joins on temporary tables' );
+               }
+               $this->addReallyDoQueryData();
+
+               $special = new SpecialEntityUsage();
+               $special->prepareParams( 'Q3' );
+               $res = $special->reallyDoQuery( 50 );
+               $values = [];
+
+               foreach ( $res as $row ) {
+                       $values[] = [
+                               $row->value,
+                               $row->namespace,
+                               $row->title,
+                               $row->aspects,
+                               $row->eu_page_id
+                       ];
+               }
+
+               $expected = [
+                       [ '22', '0', 'Berlin', 'L.de', '22' ],
+                       [ '11', '0', 'Vienna', 'O|S', '11' ],
+               ];
+
+               $this->assertSame( $expected, $values );
+       }
+
+       private function addReallyDoQueryData() {
+               $db = wfGetDB( DB_MASTER );
+               $dump = [
+                       'page' => [
+                               [
+                                       'page_title' => 'Vienna',
+                                       'page_namespace' => 0,
+                                       'page_id' => 11,
+                               ],
+                               [
+                                       'page_title' => 'Berlin',
+                                       'page_namespace' => 0,
+                                       'page_id' => 22,
+                               ],
+                       ],
+                       'wbc_entity_usage' => [
+                               [
+                                       'eu_page_id' => 11,
+                                       'eu_entity_id' => 'Q3',
+                                       'eu_aspect' => 'S'
+                               ],
+                               [
+                                       'eu_page_id' => 11,
+                                       'eu_entity_id' => 'Q3',
+                                       'eu_aspect' => 'O'
+                               ],
+                               [
+                                       'eu_page_id' => 11,
+                                       'eu_entity_id' => 'Q4',
+                                       'eu_aspect' => 'L.en'
+                               ],
+                               [
+                                       'eu_page_id' => 22,
+                                       'eu_entity_id' => 'Q3',
+                                       'eu_aspect' => 'L.de'
+                               ],
+                       ],
+               ];
+
+               foreach ( $dump as $table => $rows ) {
+                       // Clean everything
+                       $db->delete( $table, '*' );
+
+                       foreach ( $rows as $row ) {
+                               if ( $table === 'page' ) {
+                                       $title = Title::newFromText( 
$row['page_title'], $row['page_namespace'] );
+                                       $page = WikiPage::factory( $title );
+                                       $page->insertOn( $db, $row['page_id'] );
+                               } else {
+                                       $db->insert( $table, $row );
+                               }
+                       }
+               }
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/315623
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5c4f9d4d559d71e0b51d48ce321e481ae0f05471
Gerrit-PatchSet: 16
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to