| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MwSql; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class MwSqlTest extends MaintenanceBaseTestCase { |
| 13 |
|
| 14 |
protected function getMaintenanceClass() { |
| 15 |
return MwSql::class; |
| 16 |
} |
| 17 |
|
| 18 |
public function testExecuteForSelectQueryProvidedViaQueryOption() { |
| 19 |
|
| 20 |
$this->getDb()->newInsertQueryBuilder() |
| 21 |
->insertInto( 'updatelog' ) |
| 22 |
->row( [ 'ul_key' => 'testing', 'ul_value' => 'testing-value-12345' ] ) |
| 23 |
->caller( __METHOD__ ) |
| 24 |
->execute(); |
| 25 |
|
| 26 |
$this->maintenance->setOption( 'json', 1 ); |
| 27 |
|
| 28 |
$this->maintenance->setOption( |
| 29 |
'query', |
| 30 |
$this->newSelectQueryBuilder() |
| 31 |
->field( 'ul_value' ) |
| 32 |
->from( 'updatelog' ) |
| 33 |
->where( [ 'ul_key' => 'testing' ] ) |
| 34 |
->caller( __METHOD__ ) |
| 35 |
->getSQL() |
| 36 |
); |
| 37 |
$this->maintenance->execute(); |
| 38 |
$this->assertArrayEquals( |
| 39 |
[ [ 'ul_value' => 'testing-value-12345' ] ], |
| 40 |
json_decode( $this->getActualOutputForAssertion(), true ), |
| 41 |
true, |
| 42 |
true, |
| 43 |
'JSON output was not as expected.' |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
public function testExecuteForSelectQueryProvidedViaSQLFile() { |
| 48 |
|
| 49 |
$this->getDb()->newInsertQueryBuilder() |
| 50 |
->insertInto( 'updatelog' ) |
| 51 |
->row( [ 'ul_key' => 'testing', 'ul_value' => 'testing-value-12345' ] ) |
| 52 |
->caller( __METHOD__ ) |
| 53 |
->execute(); |
| 54 |
|
| 55 |
$this->maintenance->setOption( 'json', 1 ); |
| 56 |
|
| 57 |
$file = $this->getNewTempFile(); |
| 58 |
file_put_contents( |
| 59 |
$file, |
| 60 |
$this->newSelectQueryBuilder() |
| 61 |
->field( 'ul_value' ) |
| 62 |
->from( 'updatelog' ) |
| 63 |
->where( [ 'ul_key' => 'testing' ] ) |
| 64 |
->caller( __METHOD__ ) |
| 65 |
->getSQL() |
| 66 |
); |
| 67 |
$this->maintenance->setArg( 0, $file ); |
| 68 |
$this->maintenance->execute(); |
| 69 |
$this->assertArrayEquals( |
| 70 |
[ [ 'ul_value' => 'testing-value-12345' ] ], |
| 71 |
json_decode( $this->getActualOutputForAssertion(), true ), |
| 72 |
true, |
| 73 |
true, |
| 74 |
'JSON output was not as expected.' |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
public function testExecuteForUnconfiguredReplicaDB() { |
| 79 |
$this->expectCallToFatalError(); |
| 80 |
$this->expectOutputRegex( '/No replica DB server.*abceftest/' ); |
| 81 |
|
| 82 |
$this->maintenance->setOption( |
| 83 |
'query', |
| 84 |
$this->newSelectQueryBuilder() |
| 85 |
->field( 'abcdef' ) |
| 86 |
->from( 'updatelog' ) |
| 87 |
->where( [ 'ul_key' => 'testing' ] ) |
| 88 |
->caller( __METHOD__ ) |
| 89 |
->getSQL() |
| 90 |
); |
| 91 |
$this->maintenance->setOption( 'replicadb', 'abceftest' ); |
| 92 |
$this->maintenance->execute(); |
| 93 |
} |
| 94 |
} |