Ladsgroup has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315623

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, 87 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/23/315623/1

diff --git a/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php 
b/client/tests/phpunit/includes/Specials/SpecialEntityUsageTest.php
index e3daa05..322734e 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
@@ -21,19 +23,78 @@
  */
 class SpecialEntityUsageTest extends SpecialPageTestBase {
 
+
        public function reallyDoQueryMock() {
                $rows = [
                        (object)[
                                '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 );
+       }
+
+       public function addDBDataOnce() {
+               $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' => 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 );
+                               }
+                       }
+               }
        }
 
        /**
@@ -53,18 +114,28 @@
 
        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(),
+               ];
+               $aspectsAll = array_merge( $aspectsTehran, $aspectsAthena );
+
+               $lang = RequestContext::getMain()->getLanguage();
+               $aspectListTehran = $lang->commaList( $aspectsTehran );
+               $aspectListAthena = $lang->commaList( $aspectsAthena );
+               $aspectListAll = $lang->commaList( $aspectsAll );
 
                $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, $result );
+               $this->assertContains( $aspectListAthena, $result );
+               $this->assertNotContains( $aspectListAll, $result );
        }
 
        public function testExecuteWithInvalidParam() {
@@ -77,4 +148,15 @@
                );
        }
 
+       public function testReallyDoQuery() {
+               if ( wfGetDB( DB_SLAVE )->getType() === 'mysql' ) {
+                       $this->markTestSkipped( 'MySQL does not allow selfjoins 
on temporary tables' );
+               }
+
+               $special = new SpecialEntityUsage();
+               $special->prepareParams( 'Q3' );
+               $res = $special->reallyDoQuery( 50 );
+               var_dump( $res );
+               $this->assertTrue( false );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c4f9d4d559d71e0b51d48ce321e481ae0f05471
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>

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

Reply via email to