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