X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseTest.php;h=7933f19f4946d608bb957d48e71e6d4acd3b651d;hb=2b2f9e229d2772d680393c1e7d7e4a41dae5b114;hp=70b6c3603249d17a131c992acfced10d29c5e8fb;hpb=a8a5f03b3b6653136c4dc5925d6bb2b806010725;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php index 70b6c36032..7933f19f49 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseTest.php @@ -94,6 +94,52 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { ); } + public function provideTableNamesWithIndexClauseOrJOIN() { + return [ + 'one-element array' => [ + [ 'table' ], [], 'table ' + ], + 'comma join' => [ + [ 'table1', 'table2' ], [], 'table1,table2 ' + ], + 'real join' => [ + [ 'table1', 'table2' ], + [ 'table2' => [ 'LEFT JOIN', 't1_id = t2_id' ] ], + 'table1 LEFT JOIN table2 ON ((t1_id = t2_id))' + ], + 'real join with multiple conditionals' => [ + [ 'table1', 'table2' ], + [ 'table2' => [ 'LEFT JOIN', [ 't1_id = t2_id', 't2_x = \'X\'' ] ] ], + 'table1 LEFT JOIN table2 ON ((t1_id = t2_id) AND (t2_x = \'X\'))' + ], + 'join with parenthesized group' => [ + [ 'table1', 'n' => [ 'table2', 'table3' ] ], + [ + 'table3' => [ 'JOIN', 't2_id = t3_id' ], + 'n' => [ 'LEFT JOIN', 't1_id = t2_id' ], + ], + 'table1 LEFT JOIN (table2 JOIN table3 ON ((t2_id = t3_id))) ON ((t1_id = t2_id))' + ], + 'join with degenerate parenthesized group' => [ + [ 'table1', 'n' => [ 't2' => 'table2' ] ], + [ + 'n' => [ 'LEFT JOIN', 't1_id = t2_id' ], + ], + 'table1 LEFT JOIN table2 t2 ON ((t1_id = t2_id))' + ], + ]; + } + + /** + * @dataProvider provideTableNamesWithIndexClauseOrJOIN + * @covers Wikimedia\Rdbms\Database::tableNamesWithIndexClauseOrJOIN + */ + public function testTableNamesWithIndexClauseOrJOIN( $tables, $join_conds, $expect ) { + $clause = TestingAccessWrapper::newFromObject( $this->db ) + ->tableNamesWithIndexClauseOrJOIN( $tables, [], [], $join_conds ); + $this->assertSame( $expect, $clause ); + } + /** * @covers Wikimedia\Rdbms\Database::onTransactionIdle * @covers Wikimedia\Rdbms\Database::runOnTransactionIdleCallbacks