- protected function getDefaultQueryFields( $returnTextIdField = true ) {
- $fields = [
- 'rev_id',
- 'rev_page',
- 'rev_timestamp',
- 'rev_minor_edit',
- 'rev_deleted',
- 'rev_len',
- 'rev_parent_id',
- 'rev_sha1',
- ];
- if ( $returnTextIdField ) {
- $fields[] = 'rev_text_id';
- }
- return $fields;
- }
-
- protected function getCommentQueryFields() {
- return [
- 'rev_comment_text' => 'rev_comment',
- 'rev_comment_data' => 'NULL',
- 'rev_comment_cid' => 'NULL',
- ];
- }
-
- protected function getActorQueryFields() {
- return [
- 'rev_user' => 'rev_user',
- 'rev_user_text' => 'rev_user_text',
- 'rev_actor' => 'NULL',
- ];
- }
-
- protected function getContentHandlerQueryFields() {
- return [
- 'rev_content_format',
- 'rev_content_model',
- ];
- }
-
- abstract public function provideGetQueryInfo();
-
- /**
- * @dataProvider provideGetQueryInfo
- * @covers \MediaWiki\Storage\RevisionStore::getQueryInfo
- */
- public function testGetQueryInfo( $options, $expected ) {
- $store = MediaWikiServices::getInstance()->getRevisionStore();
-
- $queryInfo = $store->getQueryInfo( $options );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['tables'],
- $queryInfo['tables']
- );
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['fields'],
- $queryInfo['fields']
- );
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['joins'],
- $queryInfo['joins']
- );
- }
-
- protected function getDefaultArchiveFields( $returnTextFields = true ) {
- $fields = [
- 'ar_id',
- 'ar_page_id',
- 'ar_namespace',
- 'ar_title',
- 'ar_rev_id',
- 'ar_timestamp',
- 'ar_minor_edit',
- 'ar_deleted',
- 'ar_len',
- 'ar_parent_id',
- 'ar_sha1',
- ];
- if ( $returnTextFields ) {
- $fields[] = 'ar_text_id';
- }
- return $fields;
- }
-
- abstract public function provideGetArchiveQueryInfo();
-
- /**
- * @dataProvider provideGetArchiveQueryInfo
- * @covers \MediaWiki\Storage\RevisionStore::getArchiveQueryInfo
- */
- public function testGetArchiveQueryInfo( $expected ) {
- $store = MediaWikiServices::getInstance()->getRevisionStore();
-
- $archiveQueryInfo = $store->getArchiveQueryInfo();
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['tables'],
- $archiveQueryInfo['tables']
- );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['fields'],
- $archiveQueryInfo['fields']
- );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['joins'],
- $archiveQueryInfo['joins']
- );
- }
-
- abstract public function provideGetSlotsQueryInfo();
-
- /**
- * @dataProvider provideGetSlotsQueryInfo
- * @covers \MediaWiki\Storage\RevisionStore::getSlotsQueryInfo
- */
- public function testGetSlotsQueryInfo( $options, $expected ) {
- $store = MediaWikiServices::getInstance()->getRevisionStore();
-
- $archiveQueryInfo = $store->getSlotsQueryInfo( $options );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['tables'],
- $archiveQueryInfo['tables']
- );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['fields'],
- $archiveQueryInfo['fields']
- );
-
- $this->assertArrayEqualsIgnoringIntKeyOrder(
- $expected['joins'],
- $archiveQueryInfo['joins']
- );
- }
-
- /**
- * Assert that the two arrays passed are equal, ignoring the order of the values that integer
- * keys.
- *
- * Note: Failures of this assertion can be slightly confusing as the arrays are actually
- * split into a string key array and an int key array before assertions occur.
- *
- * @param array $expected
- * @param array $actual
- */
- private function assertArrayEqualsIgnoringIntKeyOrder( array $expected, array $actual ) {
- $this->objectAssociativeSort( $expected );
- $this->objectAssociativeSort( $actual );
-
- // Separate the int key values from the string key values so that assertion failures are
- // easier to understand.
- $expectedIntKeyValues = [];
- $actualIntKeyValues = [];
-
- // Remove all int keys and re add them at the end after sorting by value
- // This will result in all int keys being in the same order with same ints at the end of
- // the array
- foreach ( $expected as $key => $value ) {
- if ( is_int( $key ) ) {
- unset( $expected[$key] );
- $expectedIntKeyValues[] = $value;
- }
- }
- foreach ( $actual as $key => $value ) {
- if ( is_int( $key ) ) {
- unset( $actual[$key] );
- $actualIntKeyValues[] = $value;
- }
- }
-
- $this->assertArrayEquals( $expected, $actual, false, true );
- $this->assertArrayEquals( $expectedIntKeyValues, $actualIntKeyValues, false, true );
- }
-