MediaWiki  1.33.0
McrWriteBothRevisionStoreDbTest.php
Go to the documentation of this file.
1 <?php
3 
4 use InvalidArgumentException;
10 
22 
24 
25  protected function revisionToRow( Revision $rev, $options = [ 'page', 'user', 'comment' ] ) {
26  $row = parent::revisionToRow( $rev, $options );
27 
28  $row->rev_text_id = (string)$rev->getTextId();
29  $row->rev_content_format = (string)$rev->getContentFormat();
30  $row->rev_content_model = (string)$rev->getContentModel();
31 
32  return $row;
33  }
34 
36  // New schema is being written
37  $this->assertSelect(
38  'slots',
39  [ 'count(*)' ],
40  [ 'slot_revision_id' => $rev->getId() ],
41  [ [ '1' ] ]
42  );
43 
44  $this->assertSelect(
45  'content',
46  [ 'count(*)' ],
47  [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
48  [ [ '1' ] ]
49  );
50 
51  // Legacy schema is still being written
52  $this->assertSelect(
53  [ 'revision', 'text' ],
54  [ 'count(*)' ],
55  [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
56  [ [ 1 ] ],
57  [],
58  [ 'text' => [ 'JOIN', [ 'rev_text_id = old_id' ] ] ]
59  );
60 
61  parent::assertRevisionExistsInDatabase( $rev );
62  }
63 
68  protected function assertSameSlotContent( SlotRecord $a, SlotRecord $b ) {
69  parent::assertSameSlotContent( $a, $b );
70 
71  // Assert that the same content ID has been used
72  if ( $a->hasContentId() && $b->hasContentId() ) {
73  $this->assertSame( $a->getContentId(), $b->getContentId() );
74  }
75  }
76 
78  foreach ( parent::provideInsertRevisionOn_failures() as $case ) {
79  yield $case;
80  }
81 
82  yield 'slot that is not main slot' => [
83  [
84  'content' => [
85  'main' => new WikitextContent( 'Chicken' ),
86  'lalala' => new WikitextContent( 'Duck' ),
87  ],
88  'comment' => $this->getRandomCommentStoreComment(),
89  'timestamp' => '20171117010101',
90  'user' => true,
91  ],
92  new InvalidArgumentException( 'Only the main slot is supported' )
93  ];
94  }
95 
97  foreach ( parent::provideNewMutableRevisionFromArray() as $case ) {
98  yield $case;
99  }
100 
101  yield 'Basic array, with page & id' => [
102  [
103  'id' => 2,
104  'page' => 1,
105  'text_id' => 2,
106  'timestamp' => '20171017114835',
107  'user_text' => '111.0.1.2',
108  'user' => 0,
109  'minor_edit' => false,
110  'deleted' => 0,
111  'len' => 46,
112  'parent_id' => 1,
113  'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
114  'comment' => 'Goat Comment!',
115  'content_format' => 'text/x-wiki',
116  'content_model' => 'wikitext',
117  ]
118  ];
119  }
120 
126  // The main purpose of this test is to assert that after reading an archive
127  // row using the old schema it can be inserted into the revision table,
128  // and a slot row is created based on slot emulated from the old-style archive row,
129  // when none such slot row exists yet.
130 
131  $title = $this->getTestPage()->getTitle();
132 
133  $this->db->insert(
134  'text',
135  [ 'old_text' => 'Just a test', 'old_flags' => 'utf-8' ],
136  __METHOD__
137  );
138 
139  $textId = $this->db->insertId();
140 
141  $row = (object)[
142  'ar_minor_edit' => '0',
143  'ar_user' => '0',
144  'ar_user_text' => '127.0.0.1',
145  'ar_actor' => null,
146  'ar_len' => '11',
147  'ar_deleted' => '0',
148  'ar_rev_id' => 112277,
149  'ar_timestamp' => $this->db->timestamp( '20180101000000' ),
150  'ar_sha1' => 'deadbeef',
151  'ar_page_id' => $title->getArticleID(),
152  'ar_comment_text' => 'just a test',
153  'ar_comment_data' => null,
154  'ar_comment_cid' => null,
155  'ar_content_format' => null,
156  'ar_content_model' => null,
157  'ts_tags' => null,
158  'ar_id' => 17,
159  'ar_namespace' => $title->getNamespace(),
160  'ar_title' => $title->getDBkey(),
161  'ar_text_id' => $textId,
162  'ar_parent_id' => 112211,
163  ];
164 
165  $store = MediaWikiServices::getInstance()->getRevisionStore();
166  $rev = $store->newRevisionFromArchiveRow( $row );
167 
168  // re-insert archived revision
169  $return = $store->insertRevisionOn( $rev, $this->db );
170 
171  // is the new revision correct?
172  $this->assertRevisionCompleteness( $return );
173  $this->assertRevisionRecordsEqual( $rev, $return );
174 
175  // can we load it from the store?
176  $loaded = $store->getRevisionById( $return->getId() );
177  $this->assertNotNull( $loaded );
178  $this->assertRevisionCompleteness( $loaded );
179  $this->assertRevisionRecordsEqual( $return, $loaded );
180 
181  // can we find it directly in the database?
182  $this->assertRevisionExistsInDatabase( $return );
183  }
184 
185 }
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\provideNewMutableRevisionFromArray
provideNewMutableRevisionFromArray()
Definition: McrWriteBothRevisionStoreDbTest.php:96
Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:191
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Revision
Definition: Revision.php:40
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionCompleteness
assertRevisionCompleteness(RevisionRecord $r)
Definition: RevisionStoreDbTestBase.php:309
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest
Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
Definition: McrWriteBothRevisionStoreDbTest.php:21
Revision\SlotRecord\hasContentId
hasContentId()
Whether this slot has a content ID.
Definition: SlotRecord.php:469
MediaWiki\Tests\Revision\RevisionStoreDbTestBase
Database RevisionStore.
Definition: RevisionStoreDbTestBase.php:43
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\assertRevisionExistsInDatabase
assertRevisionExistsInDatabase(RevisionRecord $rev)
Definition: McrWriteBothRevisionStoreDbTest.php:35
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:2000
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:273
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:124
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\revisionToRow
revisionToRow(Revision $rev, $options=[ 'page', 'user', 'comment'])
Definition: McrWriteBothRevisionStoreDbTest.php:25
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getRandomCommentStoreComment
getRandomCommentStoreComment()
Definition: RevisionStoreDbTestBase.php:390
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\assertRevisionRecordsEqual
assertRevisionRecordsEqual(RevisionRecord $r1, RevisionRecord $r2)
Definition: RevisionStoreDbTestBase.php:257
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1985
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\provideInsertRevisionOn_failures
provideInsertRevisionOn_failures()
Definition: McrWriteBothRevisionStoreDbTest.php:77
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1769
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWiki\Tests\Revision\RevisionStoreDbTestBase\getTestPage
getTestPage()
Definition: RevisionStoreDbTestBase.php:109
MediaWiki\Tests\Revision\McrWriteBothSchemaOverride
trait McrWriteBothSchemaOverride
Trait providing schema overrides that allow tests to run against the intermediate MCR database schema...
Definition: McrWriteBothSchemaOverride.php:11
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Revision\SlotRecord\getContentId
getContentId()
Returns the ID of the content meta data row associated with the slot.
Definition: SlotRecord.php:513
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\assertSameSlotContent
assertSameSlotContent(SlotRecord $a, SlotRecord $b)
Definition: McrWriteBothRevisionStoreDbTest.php:68
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
MediaWiki\Tests\Revision\McrWriteBothRevisionStoreDbTest\testInsertRevisionFromArchiveRow_unmigratedArchiveRow
testInsertRevisionFromArchiveRow_unmigratedArchiveRow()
\MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow \MediaWiki\Revision\RevisionStore::inser...
Definition: McrWriteBothRevisionStoreDbTest.php:125