18fed17f3SAndreas Gohr<?php 28fed17f3SAndreas Gohr 38fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 48fed17f3SAndreas Gohr 58fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta\Search; 68fed17f3SAndreas Gohr 78fed17f3SAndreas Gohr/** 88fed17f3SAndreas Gohr * Tests for the building of SQL-Queries for the struct plugin 98fed17f3SAndreas Gohr * 108fed17f3SAndreas Gohr * @group plugin_struct 118fed17f3SAndreas Gohr * @group plugins 128fed17f3SAndreas Gohr * 138fed17f3SAndreas Gohr */ 148fed17f3SAndreas Gohrclass AccessTableDataSQLTest extends StructTest 158fed17f3SAndreas Gohr{ 168fed17f3SAndreas Gohr 178fed17f3SAndreas Gohr /** 188fed17f3SAndreas Gohr * @return array 198fed17f3SAndreas Gohr * @see schemaDataSQL_struct_test::test_buildGetDataSQL 208fed17f3SAndreas Gohr * @noinspection SqlDialectInspection 218fed17f3SAndreas Gohr * @noinspection SqlNoDataSourceInspection 228fed17f3SAndreas Gohr */ 238fed17f3SAndreas Gohr public static function buildGetDataSQL_testdata() 248fed17f3SAndreas Gohr { 258fed17f3SAndreas Gohr $schemadata = new mock\AccessTableDataNoDB('testtable', 'pagename', 27); 268fed17f3SAndreas Gohr 278fed17f3SAndreas Gohr /** @noinspection SqlResolve */ 288fed17f3SAndreas Gohr return [ 298fed17f3SAndreas Gohr [ 308fed17f3SAndreas Gohr [ 318fed17f3SAndreas Gohr 'obj' => $schemadata, 328fed17f3SAndreas Gohr 'singles' => ['dokuwiki\\plugin\\struct\\types\\Text', 'dokuwiki\\plugin\\struct\\types\\Text'], 338fed17f3SAndreas Gohr 'multis' => [], 348fed17f3SAndreas Gohr ], 358fed17f3SAndreas Gohr "SELECT DATA.pid AS PID, 368fed17f3SAndreas Gohr DATA.col1 AS out1, 378fed17f3SAndreas Gohr DATA.col2 AS out2 388fed17f3SAndreas Gohr FROM data_testtable AS DATA 398fed17f3SAndreas Gohr WHERE (DATA.pid = ? 408fed17f3SAndreas Gohr AND DATA.rev = ?) 418fed17f3SAndreas Gohr GROUP BY DATA.pid,out1,out2", 428fed17f3SAndreas Gohr ['pagename', 27], 438fed17f3SAndreas Gohr 'no multis, with ts', 448fed17f3SAndreas Gohr ], 458fed17f3SAndreas Gohr [ 468fed17f3SAndreas Gohr [ 478fed17f3SAndreas Gohr 'obj' => $schemadata, 488fed17f3SAndreas Gohr 'singles' => ['dokuwiki\\plugin\\struct\\types\\Text', 'dokuwiki\\plugin\\struct\\types\\Text'], 498fed17f3SAndreas Gohr 'multis' => ['dokuwiki\\plugin\\struct\\types\\Text'], 508fed17f3SAndreas Gohr ], 518fed17f3SAndreas Gohr "SELECT DATA.pid AS PID, 528fed17f3SAndreas Gohr DATA.col1 AS out1, 538fed17f3SAndreas Gohr DATA.col2 AS out2, 54*acc82d60SAndreas Gohr GROUP_CONCAT_DISTINCT(M3.value,'" . Search::CONCAT_SEPARATOR . "') AS out3 558fed17f3SAndreas Gohr FROM data_testtable AS DATA 568fed17f3SAndreas Gohr LEFT OUTER JOIN multi_testtable AS M3 578fed17f3SAndreas Gohr ON DATA.pid = M3.pid 588fed17f3SAndreas Gohr AND DATA.rev = M3.rev 598fed17f3SAndreas Gohr AND M3.colref = 3 608fed17f3SAndreas Gohr WHERE (DATA.pid = ? 618fed17f3SAndreas Gohr AND DATA.rev = ?) 628fed17f3SAndreas Gohr GROUP BY DATA.pid,out1,out2", 638fed17f3SAndreas Gohr ['pagename', 27,], 648fed17f3SAndreas Gohr 'one multi, with ts', 658fed17f3SAndreas Gohr ], 668fed17f3SAndreas Gohr [ 678fed17f3SAndreas Gohr [ 688fed17f3SAndreas Gohr 'obj' => $schemadata, 698fed17f3SAndreas Gohr 'singles' => [], 708fed17f3SAndreas Gohr 'multis' => ['dokuwiki\\plugin\\struct\\types\\Text', 'dokuwiki\\plugin\\struct\\types\\Text'] 718fed17f3SAndreas Gohr ], 728fed17f3SAndreas Gohr "SELECT DATA.pid AS PID, 73*acc82d60SAndreas Gohr GROUP_CONCAT_DISTINCT(M1.value,'" . Search::CONCAT_SEPARATOR . "') AS out1, 74*acc82d60SAndreas Gohr GROUP_CONCAT_DISTINCT(M2.value,'" . Search::CONCAT_SEPARATOR . "') AS out2 758fed17f3SAndreas Gohr FROM data_testtable AS DATA 768fed17f3SAndreas Gohr LEFT OUTER JOIN multi_testtable AS M2 778fed17f3SAndreas Gohr ON DATA.pid = M2.pid 788fed17f3SAndreas Gohr AND DATA.rev = M2.rev 798fed17f3SAndreas Gohr AND M2.colref = 2 808fed17f3SAndreas Gohr LEFT OUTER JOIN multi_testtable AS M1 818fed17f3SAndreas Gohr ON DATA.pid = M1.pid 828fed17f3SAndreas Gohr AND DATA.rev = M1.rev 838fed17f3SAndreas Gohr AND M1.colref = 1 848fed17f3SAndreas Gohr WHERE (DATA.pid = ? 858fed17f3SAndreas Gohr AND DATA.rev = ?) 868fed17f3SAndreas Gohr GROUP BY DATA.pid", 878fed17f3SAndreas Gohr ['pagename', 27,], 888fed17f3SAndreas Gohr "only two multis" 898fed17f3SAndreas Gohr ] 908fed17f3SAndreas Gohr ]; 918fed17f3SAndreas Gohr } 928fed17f3SAndreas Gohr 938fed17f3SAndreas Gohr /** 948fed17f3SAndreas Gohr * @dataProvider buildGetDataSQL_testdata 958fed17f3SAndreas Gohr * 968fed17f3SAndreas Gohr * @covers \dokuwiki\plugin\struct\meta\SchemaData::buildGetDataSQL 978fed17f3SAndreas Gohr * 988fed17f3SAndreas Gohr * @param $testvals 998fed17f3SAndreas Gohr * @param string $expected_sql 1008fed17f3SAndreas Gohr * @param array $expected_opt 1018fed17f3SAndreas Gohr * @param string $msg 1028fed17f3SAndreas Gohr */ 1038fed17f3SAndreas Gohr public function test_buildGetDataSQL($testvals, $expected_sql, $expected_opt, $msg) 1048fed17f3SAndreas Gohr { 1058fed17f3SAndreas Gohr /** @var mock\AccessTableDataNoDB $obj */ 1068fed17f3SAndreas Gohr $obj = $testvals['obj']; 1078fed17f3SAndreas Gohr $obj->setColumns($testvals['singles'], $testvals['multis']); 1088fed17f3SAndreas Gohr 1098fed17f3SAndreas Gohr list($actual_sql, $actual_opt) = $obj->buildGetDataSQL(); 1108fed17f3SAndreas Gohr 1118fed17f3SAndreas Gohr $this->assertSame($this->cleanWS($expected_sql), $this->cleanWS($actual_sql), $msg); 1128fed17f3SAndreas Gohr $this->assertEquals($expected_opt, $actual_opt, $msg); 1138fed17f3SAndreas Gohr } 1148fed17f3SAndreas Gohr 1158fed17f3SAndreas Gohr} 116