aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit
diff options
context:
space:
mode:
authorAmir Sarabadani <ladsgroup@gmail.com>2023-08-28 10:52:19 +0200
committerAmir Sarabadani <ladsgroup@gmail.com>2023-09-06 12:30:38 +0200
commit049b34b41ce07e12bb5da574cbfefdbb26e6a2ed (patch)
tree3c7b164461eaf24ed1c524dffbb7aa7bc60188ad /tests/phpunit
parent53858466f1128a9195bd2b3599c2b4a994652105 (diff)
downloadmediawikicore-049b34b41ce07e12bb5da574cbfefdbb26e6a2ed.tar.gz
mediawikicore-049b34b41ce07e12bb5da574cbfefdbb26e6a2ed.zip
Introduce RevisionSelectQueryBuilder
Deprecating RevisionStore::getQueryInfo() and cleaning up a lot of code Also removing a brittle test that wasn't really testing anything. Bug: T344971 Change-Id: Ifd690dc8f030f86e3567a717eaeb830cb6dc703b
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/includes/import/ImportExportTest.php20
-rw-r--r--tests/phpunit/includes/import/ImportTest.php24
-rw-r--r--tests/phpunit/includes/page/PageArchiveTest.php12
-rw-r--r--tests/phpunit/includes/page/UndeletePageTest.php13
-rw-r--r--tests/phpunit/integration/includes/revisionlist/RevisionListTest.php63
5 files changed, 26 insertions, 106 deletions
diff --git a/tests/phpunit/includes/import/ImportExportTest.php b/tests/phpunit/includes/import/ImportExportTest.php
index 7c264716c566..31b6a07868b8 100644
--- a/tests/phpunit/includes/import/ImportExportTest.php
+++ b/tests/phpunit/includes/import/ImportExportTest.php
@@ -3,6 +3,7 @@
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Tests\Maintenance\DumpAsserter;
use MediaWiki\Title\Title;
+use Wikimedia\Rdbms\SelectQueryBuilder;
/**
* Import/export round trip test.
@@ -122,19 +123,12 @@ class ImportExportTest extends MediaWikiLangTestCase {
*/
private function getRevisions( Title $title ) {
$store = $this->getServiceContainer()->getRevisionStore();
- $qi = $store->getQueryInfo();
-
- $conds = [ 'rev_page' => $title->getArticleID() ];
- $opt = [ 'ORDER BY' => 'rev_id ASC' ];
-
- $rows = $this->db->select(
- $qi['tables'],
- $qi['fields'],
- $conds,
- __METHOD__,
- $opt,
- $qi['joins']
- );
+ $queryBuilder = $store->newSelectQueryBuilder( $this->db )
+ ->joinComment()
+ ->where( [ 'rev_page' => $title->getArticleID() ] )
+ ->orderBy( 'rev_id', SelectQueryBuilder::SORT_ASC );
+
+ $rows = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
$status = $store->newRevisionsFromBatch( $rows );
return $status->getValue();
diff --git a/tests/phpunit/includes/import/ImportTest.php b/tests/phpunit/includes/import/ImportTest.php
index 562ee04a6001..8841e44ff581 100644
--- a/tests/phpunit/includes/import/ImportTest.php
+++ b/tests/phpunit/includes/import/ImportTest.php
@@ -285,30 +285,18 @@ EOF
$importer->doImport();
$db = wfGetDB( DB_PRIMARY );
- $revQuery = $services->getRevisionStore()->getQueryInfo();
-
- $row = $db->selectRow(
- $revQuery['tables'],
- $revQuery['fields'],
- [ 'rev_timestamp' => $db->timestamp( "201601010{$n}0000" ) ],
- __METHOD__,
- [],
- $revQuery['joins']
- );
+ $row = $services->getRevisionStore()->newSelectQueryBuilder( $db )
+ ->where( [ 'rev_timestamp' => $db->timestamp( "201601010{$n}0000" ) ] )
+ ->caller( __METHOD__ )->fetchRow();
$this->assertSame(
$assign && $create ? 'UserDoesNotExist' : 'Xxx>UserDoesNotExist',
$row->rev_user_text
);
$this->assertSame( $assign && $create ? $hookId : 0, (int)$row->rev_user );
- $row = $db->selectRow(
- $revQuery['tables'],
- $revQuery['fields'],
- [ 'rev_timestamp' => $db->timestamp( "201601010{$n}0001" ) ],
- __METHOD__,
- [],
- $revQuery['joins']
- );
+ $row = $services->getRevisionStore()->newSelectQueryBuilder( $db )
+ ->where( [ 'rev_timestamp' => $db->timestamp( "201601010{$n}0001" ) ] )
+ ->caller( __METHOD__ )->fetchRow();
$this->assertSame( ( $assign ? '' : 'Xxx>' ) . $user->getName(), $row->rev_user_text );
$this->assertSame( $assign ? $user->getId() : 0, (int)$row->rev_user );
}
diff --git a/tests/phpunit/includes/page/PageArchiveTest.php b/tests/phpunit/includes/page/PageArchiveTest.php
index 768fe34f80ed..d785edd7d53c 100644
--- a/tests/phpunit/includes/page/PageArchiveTest.php
+++ b/tests/phpunit/includes/page/PageArchiveTest.php
@@ -145,15 +145,9 @@ class PageArchiveTest extends MediaWikiIntegrationTestCase {
$archive->undeleteAsUser( [], $this->getTestSysop()->getUser() );
// Should be back in revision
- $revQuery = $revisionStore->getQueryInfo();
- $row = $dbr->selectRow(
- $revQuery['tables'],
- $revQuery['fields'],
- [ 'rev_id' => $this->ipRev->getId() ],
- __METHOD__,
- [],
- $revQuery['joins']
- );
+ $row = $revisionStore->newSelectQueryBuilder( $dbr )
+ ->where( [ 'rev_id' => $this->ipRev->getId() ] )
+ ->caller( __METHOD__ )->fetchRow();
$this->assertNotFalse( $row, 'row exists in revision table' );
$this->assertEquals( $this->ipEditor, $row->rev_user_text );
diff --git a/tests/phpunit/includes/page/UndeletePageTest.php b/tests/phpunit/includes/page/UndeletePageTest.php
index bec657e2093f..0aa1c81d7a3b 100644
--- a/tests/phpunit/includes/page/UndeletePageTest.php
+++ b/tests/phpunit/includes/page/UndeletePageTest.php
@@ -124,17 +124,12 @@ class UndeletePageTest extends MediaWikiIntegrationTestCase {
$status = $undeletePage->setUndeleteAssociatedTalk( true )->undeleteUnsafe( '' );
$this->assertEquals( 2, $status->value[UndeletePage::REVISIONS_RESTORED] );
- $revQuery = $revisionStore->getQueryInfo();
// check subject page and talk page are both back in the revision table
foreach ( [ 0, 1 ] as $key ) {
- $row = $dbr->selectRow(
- $revQuery['tables'],
- $revQuery['fields'],
- [ 'rev_id' => $this->pages[$key]['revId'] ],
- __METHOD__,
- [],
- $revQuery['joins']
- );
+ $row = $revisionStore->newSelectQueryBuilder( $dbr )
+ ->where( [ 'rev_id' => $this->pages[$key]['revId'] ] )
+ ->caller( __METHOD__ )->fetchRow();
+
$this->assertNotFalse( $row, 'row exists in revision table' );
$this->assertEquals( $this->ipEditor, $row->rev_user_text );
diff --git a/tests/phpunit/integration/includes/revisionlist/RevisionListTest.php b/tests/phpunit/integration/includes/revisionlist/RevisionListTest.php
index 1bb02658d004..39de1ef09fbe 100644
--- a/tests/phpunit/integration/includes/revisionlist/RevisionListTest.php
+++ b/tests/phpunit/integration/includes/revisionlist/RevisionListTest.php
@@ -2,8 +2,6 @@
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
-use Wikimedia\Rdbms\FakeResultWrapper;
-use Wikimedia\Rdbms\IDatabase;
/**
* @covers RevisionList
@@ -37,66 +35,17 @@ class RevisionListTest extends MediaWikiIntegrationTestCase {
);
}
- /**
- * @dataProvider provideTestDoQuery
- */
- public function testDoQuery( $filterIds ) {
- $context = new RequestContext();
-
- $page = new PageIdentityValue( 123, NS_MAIN, __METHOD__, PageIdentity::LOCAL );
- $revisionList = new RevisionList( $context, $page );
-
- $conds = [ 'rev_page' => 123 ];
- if ( $filterIds !== false ) {
- $revisionList->filterByIds( $filterIds );
- $conds['rev_id'] = $filterIds;
- }
-
- $revQuery = $this->getServiceContainer()
- ->getRevisionStore()
- ->getQueryInfo( [ 'page', 'user' ] );
-
- $db = $this->createMock( IDatabase::class );
- $db->expects( $this->once() )
- ->method( 'select' )
- ->with(
- $revQuery['tables'],
- $revQuery['fields'],
- $conds,
- 'RevisionList::doQuery',
- [ 'ORDER BY' => 'rev_id DESC' ],
- $revQuery['joins']
- )
- ->willReturn(
- new FakeResultWrapper( [] )
- );
-
- $revisionList->doQuery( $db );
- }
-
- public static function provideTestDoQuery() {
- return [
- 'no filter' => [ false ],
- 'with filter' => [ [ 1, 2, 91 ] ],
- ];
- }
-
public function testNewItem() {
// Need a row that is valid for RevisionFactory::newRevisionFromRow
$wikiPage = $this->getExistingTestPage( __METHOD__ );
$currentRevId = $wikiPage->getRevisionRecord()->getId();
- $revQuery = $this->getServiceContainer()
- ->getRevisionStore()
- ->getQueryInfo( [ 'page', 'user' ] );
- $row = $this->db->selectRow(
- $revQuery['tables'],
- $revQuery['fields'],
- [ 'rev_id' => $currentRevId ],
- __METHOD__,
- [],
- $revQuery['joins']
- );
+ $queryBuilder = $this->getServiceContainer()->getRevisionStore()->newSelectQueryBuilder( $this->db )
+ ->joinComment()
+ ->joinPage()
+ ->joinUser()
+ ->where( [ 'rev_id' => $currentRevId ] );
+ $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
$context = new RequestContext();
$context->setUser( $this->getTestSysop()->getUser() );