X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FStorage%2FMcrWriteBothRevisionStoreDbTest.php;h=10c20b9bc538ce9676449ae03166ebc94c64f34f;hp=c98414258ade5b0131f3de73a172eb1cc8adec8f;hb=9b009467f87e03efb70db885a13a0a2aa56356a9;hpb=4b5773a4de8156c026be2aab92e059793d612fdd diff --git a/tests/phpunit/includes/Storage/McrWriteBothRevisionStoreDbTest.php b/tests/phpunit/includes/Storage/McrWriteBothRevisionStoreDbTest.php index c98414258a..10c20b9bc5 100644 --- a/tests/phpunit/includes/Storage/McrWriteBothRevisionStoreDbTest.php +++ b/tests/phpunit/includes/Storage/McrWriteBothRevisionStoreDbTest.php @@ -2,6 +2,7 @@ namespace MediaWiki\Tests\Storage; use InvalidArgumentException; +use MediaWiki\MediaWikiServices; use MediaWiki\Storage\RevisionRecord; use MediaWiki\Storage\SlotRecord; use Revision; @@ -32,6 +33,7 @@ class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase { } protected function assertRevisionExistsInDatabase( RevisionRecord $rev ) { + // New schema is being written $this->assertSelect( 'slots', [ 'count(*)' ], @@ -46,6 +48,16 @@ class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase { [ [ '1' ] ] ); + // Legacy schema is still being written + $this->assertSelect( + [ 'revision', 'text' ], + [ 'count(*)' ], + [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ], + [ [ 1 ] ], + [], + [ 'text' => [ 'INNER JOIN', [ 'rev_text_id = old_id' ] ] ] + ); + parent::assertRevisionExistsInDatabase( $rev ); } @@ -62,113 +74,6 @@ class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase { } } - public function provideGetArchiveQueryInfo() { - yield [ - [ - 'tables' => [ 'archive' ], - 'fields' => array_merge( - $this->getDefaultArchiveFields(), - [ - 'ar_comment_text' => 'ar_comment', - 'ar_comment_data' => 'NULL', - 'ar_comment_cid' => 'NULL', - 'ar_user_text' => 'ar_user_text', - 'ar_user' => 'ar_user', - 'ar_actor' => 'NULL', - 'ar_content_format', - 'ar_content_model', - ] - ), - 'joins' => [], - ] - ]; - } - - public function provideGetQueryInfo() { - yield [ - [], - [ - 'tables' => [ 'revision' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - $this->getContentHandlerQueryFields() - ), - 'joins' => [], - ] - ]; - yield [ - [ 'page', 'user' ], - [ - 'tables' => [ 'revision', 'page', 'user' ], - 'fields' => array_merge( - $this->getDefaultQueryFields(), - $this->getCommentQueryFields(), - $this->getActorQueryFields(), - $this->getContentHandlerQueryFields(), - [ - 'page_namespace', - 'page_title', - 'page_id', - 'page_latest', - 'page_is_redirect', - 'page_len', - 'user_name', - ] - ), - 'joins' => [ - 'page' => [ 'INNER JOIN', [ 'page_id = rev_page' ] ], - 'user' => [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ], - ], - ] - ]; - } - - public function provideGetSlotsQueryInfo() { - $db = wfGetDB( DB_REPLICA ); - - yield [ - [], - [ - 'tables' => [ - 'slots' => 'revision', - ], - 'fields' => array_merge( - [ - 'slot_revision_id' => 'slots.rev_id', - 'slot_content_id' => 'NULL', - 'slot_origin' => 'slots.rev_id', - 'role_name' => $db->addQuotes( 'main' ), - ] - ), - 'joins' => [], - ] - ]; - yield [ - [ 'content' ], - [ - 'tables' => [ - 'slots' => 'revision', - ], - 'fields' => array_merge( - [ - 'slot_revision_id' => 'slots.rev_id', - 'slot_content_id' => 'NULL', - 'slot_origin' => 'slots.rev_id', - 'role_name' => $db->addQuotes( 'main' ), - 'content_size' => 'slots.rev_len', - 'content_sha1' => 'slots.rev_sha1', - 'content_address' => - 'CONCAT(' . $db->addQuotes( 'tt:' ) . ',slots.rev_text_id)', - 'model_name' => 'slots.rev_content_model', - ] - ), - 'joins' => [], - ] - ]; - } - public function provideInsertRevisionOn_failures() { foreach ( parent::provideInsertRevisionOn_failures() as $case ) { yield $case; @@ -213,4 +118,68 @@ class McrWriteBothRevisionStoreDbTest extends RevisionStoreDbTestBase { ]; } + /** + * @covers \MediaWiki\Storage\RevisionStore::newRevisionFromArchiveRow + * @covers \MediaWiki\Storage\RevisionStore::insertRevisionOn + */ + public function testInsertRevisionFromArchiveRow_unmigratedArchiveRow() { + // The main purpose of this test is to assert that after reading an archive + // row using the old schema it can be inserted into the revision table, + // and a slot row is created based on slot emulated from the old-style archive row, + // when none such slot row exists yet. + + $title = $this->getTestPage()->getTitle(); + + $this->db->insert( + 'text', + [ 'old_text' => 'Just a test', 'old_flags' => 'utf-8' ], + __METHOD__ + ); + + $textId = $this->db->insertId(); + + $row = (object)[ + 'ar_minor_edit' => '0', + 'ar_user' => '0', + 'ar_user_text' => '127.0.0.1', + 'ar_actor' => null, + 'ar_len' => '11', + 'ar_deleted' => '0', + 'ar_rev_id' => 112277, + 'ar_timestamp' => $this->db->timestamp( '20180101000000' ), + 'ar_sha1' => 'deadbeef', + 'ar_page_id' => $title->getArticleID(), + 'ar_comment_text' => 'just a test', + 'ar_comment_data' => null, + 'ar_comment_cid' => null, + 'ar_content_format' => null, + 'ar_content_model' => null, + 'ts_tags' => null, + 'ar_id' => 17, + 'ar_namespace' => $title->getNamespace(), + 'ar_title' => $title->getDBkey(), + 'ar_text_id' => $textId, + 'ar_parent_id' => 112211, + ]; + + $store = MediaWikiServices::getInstance()->getRevisionStore(); + $rev = $store->newRevisionFromArchiveRow( $row ); + + // re-insert archived revision + $return = $store->insertRevisionOn( $rev, $this->db ); + + // is the new revision correct? + $this->assertRevisionCompleteness( $return ); + $this->assertRevisionRecordsEqual( $rev, $return ); + + // can we load it from the store? + $loaded = $store->getRevisionById( $return->getId() ); + $this->assertNotNull( $loaded ); + $this->assertRevisionCompleteness( $loaded ); + $this->assertRevisionRecordsEqual( $return, $loaded ); + + // can we find it directly in the database? + $this->assertRevisionExistsInDatabase( $return ); + } + }