Skip to content

Commit

Permalink
Merge "tests: Migrate assertSelect() to SelectQueryBuilder"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed May 9, 2024
2 parents 6616d1b + 21856d3 commit 23282da
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 52 deletions.
Expand Up @@ -78,16 +78,14 @@ public function testOnLoadExtensionSchemaUpdates() {

$dbUpdater->runUpdates( $dbUpdater->getExtensionUpdates(), true );

$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
[
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( [
[ 10, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
// 20 is not in a Wikibase NS
[ 30, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
]
);
] );
$this->assertTrue(
$dbUpdater->updateRowExists( LoadExtensionSchemaUpdatesHookHandler::UPDATE_KEY_UNEXPECTED_UNCONNECTED_PAGE )
);
Expand Down
Expand Up @@ -172,12 +172,10 @@ public function testInsertPageProp(
}
$primer->setPageProps();

$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
$expectedPageProps
);
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( $expectedPageProps );
}

public function testInsertPageProp_continue(): void {
Expand All @@ -200,32 +198,28 @@ public function testInsertPageProp_continue(): void {
// first run
$primer->setMaxPageId( 2 );
$primer->setPageProps();
$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
[
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( [
[ 1, 'expectedUnconnectedPage', '', 0.0 ],
[ 2, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
[ 3, 'wikibase_item', '', 0.0 ],
// 4 not yet processed
]
);
] );

$primer->setMinPageId( 3 );
$primer->setMaxPageId( 4 );
$primer->setPageProps();
$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
[
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( [
[ 1, 'expectedUnconnectedPage', '', 0.0 ],
[ 2, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
[ 3, 'wikibase_item', '', 0.0 ],
[ 4, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
]
);
] );
}

/**
Expand Down
Expand Up @@ -81,12 +81,10 @@ public function testExecute(): void {
$this->maintenance->loadWithArgv( [] );
$this->maintenance->execute();

$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
$expected
);
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( $expected );
}

public function testExecute_paging(): void {
Expand All @@ -106,18 +104,16 @@ public function testExecute_paging(): void {

$this->maintenance->loadWithArgv( $argv );
$this->maintenance->execute();
$this->assertSelect(
'page_props',
[ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ],
IDatabase::ALL_ROWS,
[
$this->newSelectQueryBuilder()
->select( [ 'pp_page', 'pp_propname', 'pp_value', 'pp_sortkey' ] )
->from( 'page_props' )
->assertResultSet( [
[ 1, 'expectedUnconnectedPage', '', 0.0 ],
// 2 is excluded
[ 3, 'wikibase_item', '', 0.0 ],
[ 4, 'unexpectedUnconnectedPage', $namespaceString, $namespaceFloat ],
// 101 is excluded
]
);
] );
}

/**
Expand Down
Expand Up @@ -43,10 +43,22 @@ public function testCleanupEverything() {

$this->getCleaner()->cleanTermInLangIds( $this->db, $this->db, [ $termInLang1Id, $termInLang2Id ] );

$this->assertSelect( 'wbt_text', 'wbx_id', '*', [] );
$this->assertSelect( 'wbt_text_in_lang', 'wbxl_id', '*', [] );
$this->assertSelect( 'wbt_term_in_lang', 'wbtl_id', '*', [] );
$this->assertSelect( 'wbt_type', 'wby_name', '*', [ [ 'label' ] ] );
$this->newSelectQueryBuilder()
->select( 'wbx_id' )
->from( 'wbt_text' )
->assertEmptyResult();
$this->newSelectQueryBuilder()
->select( 'wbxl_id' )
->from( 'wbt_text_in_lang' )
->assertEmptyResult();
$this->newSelectQueryBuilder()
->select( 'wbtl_id' )
->from( 'wbt_term_in_lang' )
->assertEmptyResult();
$this->newSelectQueryBuilder()
->select( 'wby_name' )
->from( 'wbt_type' )
->assertFieldValue( 'label' );
}

public function testCleanupTermInLangButNoTextInLang() {
Expand Down Expand Up @@ -246,18 +258,15 @@ public function testT237984_sharedTextIdsAreNotDeleted() {
}

private function assertTableReturns( array $elements, string $table, string $field ) {
$this->assertSelect(
$table,
$field,
'*',
array_map(
$this->newSelectQueryBuilder()
->select( $field )
->from( $table )
->assertResultSet( array_map(
function( $element ) {
return [ $element ];
},
$elements
),
[ 'ORDER BY' => $field ]
);
) );
}

private function assertTextTableReturns( array $elements ) {
Expand Down

0 comments on commit 23282da

Please sign in to comment.