| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Installer; |
| 4 |
|
| 5 |
use MediaWiki\Installer\DatabaseUpdater; |
| 6 |
use MediaWikiIntegrationTestCase; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class DatabaseUpdaterTest extends MediaWikiIntegrationTestCase { |
| 13 |
|
| 14 |
public function testUpdateRowExists( $key, $expectedReturnValue ) { |
| 15 |
|
| 16 |
$this->getDb()->newInsertQueryBuilder() |
| 17 |
->insertInto( 'updatelog' ) |
| 18 |
->row( [ 'ul_key' => 'test', 'ul_value' => null ] ) |
| 19 |
->caller( __METHOD__ ) |
| 20 |
->execute(); |
| 21 |
|
| 22 |
$objectUnderTest = DatabaseUpdater::newForDB( |
| 23 |
$this->getServiceContainer()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY ) |
| 24 |
); |
| 25 |
$this->assertSame( $expectedReturnValue, $objectUnderTest->updateRowExists( $key ) ); |
| 26 |
} |
| 27 |
|
| 28 |
public static function provideUpdateRowExists() { |
| 29 |
return [ |
| 30 |
'Key is present in updatelog table' => [ 'test', true ], |
| 31 |
'Key is not present in updatelog table' => [ 'testing', false ], |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
public function testInsertUpdateRow( $key, $val ) { |
| 37 |
|
| 38 |
$objectUnderTest = DatabaseUpdater::newForDB( |
| 39 |
$this->getServiceContainer()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY ) |
| 40 |
); |
| 41 |
$objectUnderTest->insertUpdateRow( $key, $val ); |
| 42 |
|
| 43 |
$this->newSelectQueryBuilder() |
| 44 |
->select( [ 'ul_key', 'ul_value' ] ) |
| 45 |
->from( 'updatelog' ) |
| 46 |
->caller( __METHOD__ ) |
| 47 |
->assertRowValue( [ $key, $val ] ); |
| 48 |
} |
| 49 |
|
| 50 |
public static function provideInsertUpdateRow() { |
| 51 |
return [ |
| 52 |
'Value is not null' => [ 'test', 'test' ], |
| 53 |
'Value is null' => [ 'testing', null ], |
| 54 |
]; |
| 55 |
} |
| 56 |
} |