1*8fed17f3SAndreas Gohr<?php 2*8fed17f3SAndreas Gohr 3*8fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 4*8fed17f3SAndreas Gohr 5*8fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta\QueryBuilder; 6*8fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta\StructException; 7*8fed17f3SAndreas Gohr 8*8fed17f3SAndreas Gohr/** 9*8fed17f3SAndreas Gohr * @group plugin_struct 10*8fed17f3SAndreas Gohr * @group plugins 11*8fed17f3SAndreas Gohr */ 12*8fed17f3SAndreas Gohrclass QueryBuilderFromTest extends StructTest 13*8fed17f3SAndreas Gohr{ 14*8fed17f3SAndreas Gohr 15*8fed17f3SAndreas Gohr /** 16*8fed17f3SAndreas Gohr * @noinspection SqlDialectInspection 17*8fed17f3SAndreas Gohr * @noinspection SqlNoDataSourceInspection 18*8fed17f3SAndreas Gohr */ 19*8fed17f3SAndreas Gohr public function test_join() 20*8fed17f3SAndreas Gohr { 21*8fed17f3SAndreas Gohr $qb = new QueryBuilder(); 22*8fed17f3SAndreas Gohr 23*8fed17f3SAndreas Gohr $qb->addTable('first', 'T1'); 24*8fed17f3SAndreas Gohr $qb->addTable('second', 'T2'); 25*8fed17f3SAndreas Gohr $qb->addTable('third', 'T3'); 26*8fed17f3SAndreas Gohr 27*8fed17f3SAndreas Gohr $qb->addLeftJoin('T2', 'fourth', 'T4', 'T2.foo=T4.foo'); 28*8fed17f3SAndreas Gohr 29*8fed17f3SAndreas Gohr $expectedSQL = ' 30*8fed17f3SAndreas Gohr SELECT FROM first AS T1, second AS T2 LEFT OUTER JOIN fourth AS T4 31*8fed17f3SAndreas Gohr ON T2.foo = T4.foo, third AS T3 WHERE 32*8fed17f3SAndreas Gohr '; 33*8fed17f3SAndreas Gohr 34*8fed17f3SAndreas Gohr list($actual_sql, $actual_opts) = $qb->getSQL(); 35*8fed17f3SAndreas Gohr $this->assertEquals($this->cleanWS($expectedSQL), $this->cleanWS($actual_sql)); 36*8fed17f3SAndreas Gohr $this->assertEquals(array(), $actual_opts); 37*8fed17f3SAndreas Gohr } 38*8fed17f3SAndreas Gohr 39*8fed17f3SAndreas Gohr public function test_table_alias_exception() 40*8fed17f3SAndreas Gohr { 41*8fed17f3SAndreas Gohr $this->expectException(StructException::class); 42*8fed17f3SAndreas Gohr $qb = new QueryBuilder(); 43*8fed17f3SAndreas Gohr 44*8fed17f3SAndreas Gohr $qb->addTable('first', 'T1'); 45*8fed17f3SAndreas Gohr $qb->addTable('second', 'T1'); 46*8fed17f3SAndreas Gohr } 47*8fed17f3SAndreas Gohr 48*8fed17f3SAndreas Gohr public function test_leftjoin_missing_alias_exception() 49*8fed17f3SAndreas Gohr { 50*8fed17f3SAndreas Gohr $this->expectException(StructException::class); 51*8fed17f3SAndreas Gohr $qb = new QueryBuilder(); 52*8fed17f3SAndreas Gohr 53*8fed17f3SAndreas Gohr $qb->addTable('first', 'T1'); 54*8fed17f3SAndreas Gohr $qb->addLeftJoin('T2', 'third', 'T3', 'T2.bar = T3.bar'); 55*8fed17f3SAndreas Gohr } 56*8fed17f3SAndreas Gohr 57*8fed17f3SAndreas Gohr public function test_leftjoin_existing_alias_exception() 58*8fed17f3SAndreas Gohr { 59*8fed17f3SAndreas Gohr $this->expectException(StructException::class); 60*8fed17f3SAndreas Gohr $qb = new QueryBuilder(); 61*8fed17f3SAndreas Gohr 62*8fed17f3SAndreas Gohr $qb->addTable('first', 'T1'); 63*8fed17f3SAndreas Gohr $qb->addTable('second', 'T2'); 64*8fed17f3SAndreas Gohr $qb->addLeftJoin('T2', 'third', 'T1', 'T2.bar = T1.bar'); 65*8fed17f3SAndreas Gohr } 66*8fed17f3SAndreas Gohr} 67