18fed17f3SAndreas Gohr<?php 28fed17f3SAndreas Gohr 38fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 48fed17f3SAndreas Gohr 58fed17f3SAndreas Gohruse dokuwiki\plugin\struct\meta; 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 SearchTest extends StructTest 158fed17f3SAndreas Gohr{ 168fed17f3SAndreas Gohr 178fed17f3SAndreas Gohr public function setUp(): void 188fed17f3SAndreas Gohr { 198fed17f3SAndreas Gohr parent::setUp(); 208fed17f3SAndreas Gohr 218fed17f3SAndreas Gohr $this->loadSchemaJSON('schema1'); 228fed17f3SAndreas Gohr $this->loadSchemaJSON('schema2'); 238fed17f3SAndreas Gohr $_SERVER['REMOTE_USER'] = 'testuser'; 248fed17f3SAndreas Gohr 258fed17f3SAndreas Gohr $as = mock\Assignments::getInstance(); 268fed17f3SAndreas Gohr $page = 'page01'; 278fed17f3SAndreas Gohr $as->assignPageSchema($page, 'schema1'); 288fed17f3SAndreas Gohr $as->assignPageSchema($page, 'schema2'); 298fed17f3SAndreas Gohr saveWikiText($page, "===== TestTitle =====\nabc", "Summary"); 308fed17f3SAndreas Gohr p_get_metadata($page); 318fed17f3SAndreas Gohr $now = time(); 328fed17f3SAndreas Gohr $this->saveData( 338fed17f3SAndreas Gohr $page, 348fed17f3SAndreas Gohr 'schema1', 358fed17f3SAndreas Gohr [ 368fed17f3SAndreas Gohr 'first' => 'first data', 378fed17f3SAndreas Gohr 'second' => ['second data', 'more data', 'even more'], 388fed17f3SAndreas Gohr 'third' => 'third data', 398fed17f3SAndreas Gohr 'fourth' => 'fourth data' 408fed17f3SAndreas Gohr ], 418fed17f3SAndreas Gohr $now 428fed17f3SAndreas Gohr ); 438fed17f3SAndreas Gohr $this->saveData( 448fed17f3SAndreas Gohr $page, 458fed17f3SAndreas Gohr 'schema2', 468fed17f3SAndreas Gohr [ 478fed17f3SAndreas Gohr 'afirst' => 'first data', 488fed17f3SAndreas Gohr 'asecond' => ['second data', 'more data', 'even more'], 498fed17f3SAndreas Gohr 'athird' => 'third data', 508fed17f3SAndreas Gohr 'afourth' => 'fourth data' 518fed17f3SAndreas Gohr ], 528fed17f3SAndreas Gohr $now 538fed17f3SAndreas Gohr ); 548fed17f3SAndreas Gohr 558fed17f3SAndreas Gohr $as->assignPageSchema('test:document', 'schema1'); 568fed17f3SAndreas Gohr $as->assignPageSchema('test:document', 'schema2'); 578fed17f3SAndreas Gohr $this->saveData( 588fed17f3SAndreas Gohr 'test:document', 598fed17f3SAndreas Gohr 'schema1', 608fed17f3SAndreas Gohr [ 618fed17f3SAndreas Gohr 'first' => 'document first data', 628fed17f3SAndreas Gohr 'second' => ['second', 'more'], 638fed17f3SAndreas Gohr 'third' => '', 648fed17f3SAndreas Gohr 'fourth' => 'fourth data' 658fed17f3SAndreas Gohr ], 668fed17f3SAndreas Gohr $now 678fed17f3SAndreas Gohr ); 688fed17f3SAndreas Gohr $this->saveData( 698fed17f3SAndreas Gohr 'test:document', 708fed17f3SAndreas Gohr 'schema2', 718fed17f3SAndreas Gohr [ 728fed17f3SAndreas Gohr 'afirst' => 'first data', 738fed17f3SAndreas Gohr 'asecond' => ['second data', 'more data', 'even more'], 748fed17f3SAndreas Gohr 'athird' => 'third data', 758fed17f3SAndreas Gohr 'afourth' => 'fourth data' 768fed17f3SAndreas Gohr ], 778fed17f3SAndreas Gohr $now 788fed17f3SAndreas Gohr ); 798fed17f3SAndreas Gohr 808fed17f3SAndreas Gohr for ($i = 10; $i <= 20; $i++) { 818fed17f3SAndreas Gohr $this->saveData( 828fed17f3SAndreas Gohr "page$i", 838fed17f3SAndreas Gohr 'schema2', 848fed17f3SAndreas Gohr [ 858fed17f3SAndreas Gohr 'afirst' => "page$i first data", 868fed17f3SAndreas Gohr 'asecond' => ["page$i second data"], 878fed17f3SAndreas Gohr 'athird' => "page$i third data", 888fed17f3SAndreas Gohr 'afourth' => "page$i fourth data" 898fed17f3SAndreas Gohr ], 908fed17f3SAndreas Gohr $now 918fed17f3SAndreas Gohr ); 928fed17f3SAndreas Gohr $as->assignPageSchema("page$i", 'schema2'); 938fed17f3SAndreas Gohr } 948fed17f3SAndreas Gohr } 958fed17f3SAndreas Gohr 968fed17f3SAndreas Gohr public function test_simple() 978fed17f3SAndreas Gohr { 988fed17f3SAndreas Gohr $search = new mock\Search(); 998fed17f3SAndreas Gohr 1008fed17f3SAndreas Gohr $search->addSchema('schema1'); 1018fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 1028fed17f3SAndreas Gohr $search->addColumn('first'); 1038fed17f3SAndreas Gohr $search->addColumn('second'); 1048fed17f3SAndreas Gohr 1058fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 1068fed17f3SAndreas Gohr $result = $search->execute(); 1078fed17f3SAndreas Gohr 1088fed17f3SAndreas Gohr $this->assertCount(2, $result, 'result rows'); 1098fed17f3SAndreas Gohr $this->assertCount(3, $result[0], 'result columns'); 1108fed17f3SAndreas Gohr $this->assertEquals('page01', $result[0][0]->getValue()); 1118fed17f3SAndreas Gohr $this->assertEquals('first data', $result[0][1]->getValue()); 1128fed17f3SAndreas Gohr $this->assertEquals(['second data', 'more data', 'even more'], $result[0][2]->getValue()); 1138fed17f3SAndreas Gohr } 1148fed17f3SAndreas Gohr 1158fed17f3SAndreas Gohr public function test_simple_title() 1168fed17f3SAndreas Gohr { 1178fed17f3SAndreas Gohr $search = new mock\Search(); 1188fed17f3SAndreas Gohr 1198fed17f3SAndreas Gohr $search->addSchema('schema1'); 1208fed17f3SAndreas Gohr $search->addColumn('%title%'); 1218fed17f3SAndreas Gohr $search->addColumn('first'); 1228fed17f3SAndreas Gohr $search->addColumn('second'); 1238fed17f3SAndreas Gohr 1248fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 1258fed17f3SAndreas Gohr $result = $search->execute(); 1268fed17f3SAndreas Gohr 1278fed17f3SAndreas Gohr $this->assertCount(2, $result, 'result rows'); 1288fed17f3SAndreas Gohr $this->assertCount(3, $result[0], 'result columns'); 1298fed17f3SAndreas Gohr $this->assertEquals('["page01","TestTitle"]', $result[0][0]->getValue()); 1308fed17f3SAndreas Gohr $this->assertEquals('first data', $result[0][1]->getValue()); 1318fed17f3SAndreas Gohr $this->assertEquals(['second data', 'more data', 'even more'], $result[0][2]->getValue()); 1328fed17f3SAndreas Gohr } 1338fed17f3SAndreas Gohr 1348fed17f3SAndreas Gohr public function test_search_published() 1358fed17f3SAndreas Gohr { 1368fed17f3SAndreas Gohr $search = new mock\Search(); 1378fed17f3SAndreas Gohr $search->isNotPublisher(); 1388fed17f3SAndreas Gohr 1398fed17f3SAndreas Gohr $search->addSchema('schema1'); 1408fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 1418fed17f3SAndreas Gohr $search->addColumn('first'); 1428fed17f3SAndreas Gohr $search->addColumn('second'); 1438fed17f3SAndreas Gohr 1448fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 1458fed17f3SAndreas Gohr $result = $search->execute(); 1468fed17f3SAndreas Gohr 1478fed17f3SAndreas Gohr $this->assertCount(0, $result, 'result rows'); 1488fed17f3SAndreas Gohr } 1498fed17f3SAndreas Gohr 1508fed17f3SAndreas Gohr public function test_search_lasteditor() 1518fed17f3SAndreas Gohr { 1528fed17f3SAndreas Gohr $search = new mock\Search(); 1538fed17f3SAndreas Gohr 1548fed17f3SAndreas Gohr $search->addSchema('schema1'); 1558fed17f3SAndreas Gohr $search->addColumn('%title%'); 1568fed17f3SAndreas Gohr $search->addColumn('%lasteditor%'); 1578fed17f3SAndreas Gohr $search->addColumn('first'); 1588fed17f3SAndreas Gohr $search->addColumn('second'); 1598fed17f3SAndreas Gohr 1608fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 1618fed17f3SAndreas Gohr $result = $search->execute(); 1628fed17f3SAndreas Gohr 1638fed17f3SAndreas Gohr $this->assertCount(2, $result, 'result rows'); 1648fed17f3SAndreas Gohr $this->assertCount(4, $result[0], 'result columns'); 1658fed17f3SAndreas Gohr $this->assertEquals('testuser', $result[0][1]->getValue()); 1668fed17f3SAndreas Gohr $this->assertEquals(['second data', 'more data', 'even more'], $result[0][3]->getValue()); 1678fed17f3SAndreas Gohr } 1688fed17f3SAndreas Gohr 1698fed17f3SAndreas Gohr 1708fed17f3SAndreas Gohr /** 1718fed17f3SAndreas Gohr * @group slow 1728fed17f3SAndreas Gohr */ 1738fed17f3SAndreas Gohr public function test_search_lastupdate() 1748fed17f3SAndreas Gohr { 1758fed17f3SAndreas Gohr sleep(1); 1768fed17f3SAndreas Gohr saveWikiText('page01', "===== TestTitle =====\nabcd", "Summary"); 1778fed17f3SAndreas Gohr p_get_metadata('page01'); 1788fed17f3SAndreas Gohr 1798fed17f3SAndreas Gohr $search = new mock\Search(); 1808fed17f3SAndreas Gohr 1818fed17f3SAndreas Gohr $search->addSchema('schema1'); 1828fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 1838fed17f3SAndreas Gohr $search->addColumn('%lastupdate%'); 1848fed17f3SAndreas Gohr $search->addColumn('first'); 1858fed17f3SAndreas Gohr $search->addColumn('second'); 1868fed17f3SAndreas Gohr 1878fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 1888fed17f3SAndreas Gohr $result = $search->execute(); 1898fed17f3SAndreas Gohr 1908fed17f3SAndreas Gohr $expected_time = dformat(filemtime(wikiFN('page01')), '%Y-%m-%d %H:%M:%S'); 1918fed17f3SAndreas Gohr 1928fed17f3SAndreas Gohr $this->assertCount(2, $result, 'result rows'); 1938fed17f3SAndreas Gohr $this->assertCount(4, $result[0], 'result columns'); 194*850ad33eSAndreas Gohr $this->assertEquals($expected_time, $result[0][1]->getValue(), "Is your date.timezone set up in php.ini?"); 1958fed17f3SAndreas Gohr $this->assertEquals(['second data', 'more data', 'even more'], $result[0][3]->getValue()); 1968fed17f3SAndreas Gohr } 1978fed17f3SAndreas Gohr 1988fed17f3SAndreas Gohr /** 1998fed17f3SAndreas Gohr * @group slow 2008fed17f3SAndreas Gohr */ 2018fed17f3SAndreas Gohr public function test_search_lastsummary() 2028fed17f3SAndreas Gohr { 2038fed17f3SAndreas Gohr sleep(1); 2048fed17f3SAndreas Gohr $summary = 'Summary'; 2058fed17f3SAndreas Gohr saveWikiText('page01', "===== TestTitle =====\nabcd", $summary); 2068fed17f3SAndreas Gohr p_get_metadata('page01'); 2078fed17f3SAndreas Gohr 2088fed17f3SAndreas Gohr $search = new mock\Search(); 2098fed17f3SAndreas Gohr 2108fed17f3SAndreas Gohr $search->addSchema('schema1'); 2118fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 2128fed17f3SAndreas Gohr $search->addColumn('%lastsummary%'); 2138fed17f3SAndreas Gohr $search->addColumn('first'); 2148fed17f3SAndreas Gohr $search->addColumn('second'); 2158fed17f3SAndreas Gohr 2168fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 2178fed17f3SAndreas Gohr $result = $search->execute(); 2188fed17f3SAndreas Gohr 2198fed17f3SAndreas Gohr $this->assertCount(2, $result, 'result rows'); 2208fed17f3SAndreas Gohr $this->assertCount(4, $result[0], 'result columns'); 2218fed17f3SAndreas Gohr $this->assertEquals($summary, $result[0][1]->getValue()); 2228fed17f3SAndreas Gohr $this->assertEquals(array('second data', 'more data', 'even more'), $result[0][3]->getValue()); 2238fed17f3SAndreas Gohr } 2248fed17f3SAndreas Gohr 2258fed17f3SAndreas Gohr public function test_search() 2268fed17f3SAndreas Gohr { 2278fed17f3SAndreas Gohr $search = new mock\Search(); 2288fed17f3SAndreas Gohr 2298fed17f3SAndreas Gohr $search->addSchema('schema1'); 2308fed17f3SAndreas Gohr $search->addSchema('schema2', 'foo'); 2318fed17f3SAndreas Gohr $this->assertCount(2, $search->schemas); 2328fed17f3SAndreas Gohr 2338fed17f3SAndreas Gohr $search->addColumn('first'); 2348fed17f3SAndreas Gohr $this->assertEquals('schema1', $search->columns[0]->getTable()); 2358fed17f3SAndreas Gohr $this->assertEquals(1, $search->columns[0]->getColref()); 2368fed17f3SAndreas Gohr 2378fed17f3SAndreas Gohr $search->addColumn('afirst'); 2388fed17f3SAndreas Gohr $this->assertEquals('schema2', $search->columns[1]->getTable()); 2398fed17f3SAndreas Gohr $this->assertEquals(1, $search->columns[1]->getColref()); 2408fed17f3SAndreas Gohr 2418fed17f3SAndreas Gohr $search->addColumn('schema1.third'); 2428fed17f3SAndreas Gohr $this->assertEquals('schema1', $search->columns[2]->getTable()); 2438fed17f3SAndreas Gohr $this->assertEquals(3, $search->columns[2]->getColref()); 2448fed17f3SAndreas Gohr 2458fed17f3SAndreas Gohr $search->addColumn('foo.athird'); 2468fed17f3SAndreas Gohr $this->assertEquals('schema2', $search->columns[3]->getTable()); 2478fed17f3SAndreas Gohr $this->assertEquals(3, $search->columns[3]->getColref()); 2488fed17f3SAndreas Gohr 2498fed17f3SAndreas Gohr $search->addColumn('asecond'); 2508fed17f3SAndreas Gohr $this->assertEquals('schema2', $search->columns[4]->getTable()); 2518fed17f3SAndreas Gohr $this->assertEquals(2, $search->columns[4]->getColref()); 2528fed17f3SAndreas Gohr 2538fed17f3SAndreas Gohr $search->addColumn('doesntexist'); 2548fed17f3SAndreas Gohr $this->assertEquals(5, count($search->columns)); 2558fed17f3SAndreas Gohr 2568fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 2578fed17f3SAndreas Gohr $this->assertEquals('schema1', $search->columns[5]->getTable()); 2588fed17f3SAndreas Gohr $exception = false; 2598fed17f3SAndreas Gohr try { 2608fed17f3SAndreas Gohr $search->columns[5]->getColref(); 2618fed17f3SAndreas Gohr } catch (meta\StructException $e) { 2628fed17f3SAndreas Gohr $exception = true; 2638fed17f3SAndreas Gohr } 2648fed17f3SAndreas Gohr $this->assertTrue($exception, "Struct exception expected for accesing colref of PageColumn"); 2658fed17f3SAndreas Gohr 2668fed17f3SAndreas Gohr $search->addSort('first', false); 2678fed17f3SAndreas Gohr $this->assertCount(1, $search->sortby); 2688fed17f3SAndreas Gohr 2698fed17f3SAndreas Gohr $search->addFilter('%pageid%', '%ag%', '~', 'AND'); 2708fed17f3SAndreas Gohr $search->addFilter('second', '%sec%', '~', 'AND'); 2718fed17f3SAndreas Gohr $search->addFilter('first', '%rst%', '~', 'AND'); 2728fed17f3SAndreas Gohr 2738fed17f3SAndreas Gohr $result = $search->execute(); 2748fed17f3SAndreas Gohr $count = $search->getCount(); 2758fed17f3SAndreas Gohr 2768fed17f3SAndreas Gohr $this->assertEquals(1, $count, 'result count'); 2778fed17f3SAndreas Gohr $this->assertCount(1, $result, 'result rows'); 2788fed17f3SAndreas Gohr $this->assertCount(6, $result[0], 'result columns'); 2798fed17f3SAndreas Gohr 2808fed17f3SAndreas Gohr // sort by multi-column 2818fed17f3SAndreas Gohr $search->addSort('second'); 2828fed17f3SAndreas Gohr $this->assertCount(2, $search->sortby); 2838fed17f3SAndreas Gohr $result = $search->execute(); 2848fed17f3SAndreas Gohr $count = $search->getCount(); 2858fed17f3SAndreas Gohr $this->assertEquals(1, $count, 'result count'); 2868fed17f3SAndreas Gohr $this->assertCount(1, $result, 'result rows'); 2878fed17f3SAndreas Gohr $this->assertCount(6, $result[0], 'result columns'); 2888fed17f3SAndreas Gohr 2898fed17f3SAndreas Gohr /* 2908fed17f3SAndreas Gohr {#debugging 2918fed17f3SAndreas Gohr list($sql, $opts) = $search->getSQL(); 2928fed17f3SAndreas Gohr print "\n"; 2938fed17f3SAndreas Gohr print_r($sql); 2948fed17f3SAndreas Gohr print "\n"; 2958fed17f3SAndreas Gohr print_r($opts); 2968fed17f3SAndreas Gohr print "\n"; 2978fed17f3SAndreas Gohr #print_r($result); 2988fed17f3SAndreas Gohr } 2998fed17f3SAndreas Gohr */ 3008fed17f3SAndreas Gohr } 3018fed17f3SAndreas Gohr 3028fed17f3SAndreas Gohr public function test_ranges() 3038fed17f3SAndreas Gohr { 3048fed17f3SAndreas Gohr $search = new mock\Search(); 3058fed17f3SAndreas Gohr $search->addSchema('schema2'); 3068fed17f3SAndreas Gohr 3078fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 3088fed17f3SAndreas Gohr $search->addColumn('afirst'); 3098fed17f3SAndreas Gohr $search->addColumn('asecond'); 3108fed17f3SAndreas Gohr 3118fed17f3SAndreas Gohr $search->addFilter('%pageid%', '%ag%', '~', 'AND'); 3128fed17f3SAndreas Gohr 3138fed17f3SAndreas Gohr $search->addSort('%pageid%', false); 3148fed17f3SAndreas Gohr 3158fed17f3SAndreas Gohr /** @var meta\Value[][] $result */ 3168fed17f3SAndreas Gohr $result = $search->execute(); 3178fed17f3SAndreas Gohr $count = $search->getCount(); 3188fed17f3SAndreas Gohr 3198fed17f3SAndreas Gohr // check result dimensions 3208fed17f3SAndreas Gohr $this->assertEquals(12, $count, 'result count'); 3218fed17f3SAndreas Gohr $this->assertCount(12, $result, 'result rows'); 3228fed17f3SAndreas Gohr $this->assertCount(3, $result[0], 'result columns'); 3238fed17f3SAndreas Gohr 3248fed17f3SAndreas Gohr // check sorting 3258fed17f3SAndreas Gohr $this->assertEquals('page20', $result[0][0]->getValue()); 3268fed17f3SAndreas Gohr $this->assertEquals('page19', $result[1][0]->getValue()); 3278fed17f3SAndreas Gohr $this->assertEquals('page18', $result[2][0]->getValue()); 3288fed17f3SAndreas Gohr 3298fed17f3SAndreas Gohr // now add limit 3308fed17f3SAndreas Gohr $search->setLimit(5); 3318fed17f3SAndreas Gohr $result = $search->execute(); 3328fed17f3SAndreas Gohr $count = $search->getCount(); 3338fed17f3SAndreas Gohr 3348fed17f3SAndreas Gohr // check result dimensions 3358fed17f3SAndreas Gohr $this->assertEquals(12, $count, 'result count'); // full result set 3368fed17f3SAndreas Gohr $this->assertCount(5, $result, 'result rows'); // wanted result set 3378fed17f3SAndreas Gohr 3388fed17f3SAndreas Gohr // check the values 3398fed17f3SAndreas Gohr $this->assertEquals('page20', $result[0][0]->getValue()); 3408fed17f3SAndreas Gohr $this->assertEquals('page16', $result[4][0]->getValue()); 3418fed17f3SAndreas Gohr 3428fed17f3SAndreas Gohr // now add offset 3438fed17f3SAndreas Gohr $search->setOffset(5); 3448fed17f3SAndreas Gohr $result = $search->execute(); 3458fed17f3SAndreas Gohr $count = $search->getCount(); 3468fed17f3SAndreas Gohr 3478fed17f3SAndreas Gohr // check result dimensions 3488fed17f3SAndreas Gohr $this->assertEquals(12, $count, 'result count'); // full result set 3498fed17f3SAndreas Gohr $this->assertCount(5, $result, 'result rows'); // wanted result set 3508fed17f3SAndreas Gohr 3518fed17f3SAndreas Gohr // check the values 3528fed17f3SAndreas Gohr $this->assertEquals('page15', $result[0][0]->getValue()); 3538fed17f3SAndreas Gohr $this->assertEquals('page11', $result[4][0]->getValue()); 3548fed17f3SAndreas Gohr } 3558fed17f3SAndreas Gohr 3568fed17f3SAndreas Gohr public static function addFilter_testdata() 3578fed17f3SAndreas Gohr { 3588fed17f3SAndreas Gohr return [ 3598fed17f3SAndreas Gohr ['%pageid%', 'val', '<>', 'OR', [['%pageid%', 'val', '!=', 'OR']], false, 'replace <> comp'], 3608fed17f3SAndreas Gohr ['%pageid%', 'val', '*~', 'OR', [['%pageid%', '%val%', 'LIKE', 'OR']], false, 'replace *~ comp'], 3618fed17f3SAndreas Gohr ['%pageid%', 'val*', '~', 'OR', [['%pageid%', 'val%', 'LIKE', 'OR']], false, 'replace * in value'], 3628fed17f3SAndreas Gohr ['%pageid%', 'val.*', '=*', 'OR', [['%pageid%', 'val.*', 'REGEXP', 'OR']], false, 'replace * in value'], 3638fed17f3SAndreas Gohr ['nonexisting', 'val', '~', 'OR', [], false, 'ignore missing columns'], 3648fed17f3SAndreas Gohr ['%pageid%', 'val', '?', 'OR', [], '\dokuwiki\plugin\struct\meta\StructException', 'wrong comperator'], 3658fed17f3SAndreas Gohr ['%pageid%', 'val', '=', 'NOT', [], '\dokuwiki\plugin\struct\meta\StructException', 'wrong type'] 3668fed17f3SAndreas Gohr ]; 3678fed17f3SAndreas Gohr } 3688fed17f3SAndreas Gohr 3698fed17f3SAndreas Gohr /** 3708fed17f3SAndreas Gohr * @dataProvider addFilter_testdata 3718fed17f3SAndreas Gohr * 3728fed17f3SAndreas Gohr */ 3738fed17f3SAndreas Gohr public function test_addFilter($colname, $value, $comp, $type, $expected_filter, $expectException, $msg) 3748fed17f3SAndreas Gohr { 3758fed17f3SAndreas Gohr $search = new mock\Search(); 3768fed17f3SAndreas Gohr $search->addSchema('schema2'); 3778fed17f3SAndreas Gohr $search->addColumn('%pageid%'); 3788fed17f3SAndreas Gohr if ($expectException !== false) $this->setExpectedException($expectException); 3798fed17f3SAndreas Gohr 3808fed17f3SAndreas Gohr $search->addFilter($colname, $value, $comp, $type); 3818fed17f3SAndreas Gohr 3828fed17f3SAndreas Gohr if (count($expected_filter) === 0) { 3838fed17f3SAndreas Gohr $this->assertCount(0, $search->filter, $msg); 3848fed17f3SAndreas Gohr return; 3858fed17f3SAndreas Gohr } 3868fed17f3SAndreas Gohr $this->assertEquals($expected_filter[0][0], $search->filter[0][0]->getLabel(), $msg); 3878fed17f3SAndreas Gohr $this->assertEquals($expected_filter[0][1], $search->filter[0][1], $msg); 3888fed17f3SAndreas Gohr $this->assertEquals($expected_filter[0][2], $search->filter[0][2], $msg); 3898fed17f3SAndreas Gohr $this->assertEquals($expected_filter[0][3], $search->filter[0][3], $msg); 3908fed17f3SAndreas Gohr } 3918fed17f3SAndreas Gohr 3928fed17f3SAndreas Gohr public function test_wildcard() 3938fed17f3SAndreas Gohr { 3948fed17f3SAndreas Gohr $search = new mock\Search(); 3958fed17f3SAndreas Gohr $search->addSchema('schema2', 'alias'); 3968fed17f3SAndreas Gohr $search->addColumn('*'); 3978fed17f3SAndreas Gohr $this->assertCount(4, $search->getColumns()); 3988fed17f3SAndreas Gohr 3998fed17f3SAndreas Gohr $search = new mock\Search(); 4008fed17f3SAndreas Gohr $search->addSchema('schema2', 'alias'); 4018fed17f3SAndreas Gohr $search->addColumn('schema2.*'); 4028fed17f3SAndreas Gohr $this->assertCount(4, $search->getColumns()); 4038fed17f3SAndreas Gohr 4048fed17f3SAndreas Gohr $search = new mock\Search(); 4058fed17f3SAndreas Gohr $search->addSchema('schema2', 'alias'); 4068fed17f3SAndreas Gohr $search->addColumn('alias.*'); 4078fed17f3SAndreas Gohr $this->assertCount(4, $search->getColumns()); 4088fed17f3SAndreas Gohr 4098fed17f3SAndreas Gohr $search = new mock\Search(); 4108fed17f3SAndreas Gohr $search->addSchema('schema2', 'alias'); 4118fed17f3SAndreas Gohr $search->addColumn('nope.*'); 4128fed17f3SAndreas Gohr $this->assertCount(0, $search->getColumns()); 4138fed17f3SAndreas Gohr } 4148fed17f3SAndreas Gohr 4158fed17f3SAndreas Gohr public function test_filterValueList() 4168fed17f3SAndreas Gohr { 4178fed17f3SAndreas Gohr $search = new mock\Search(); 4188fed17f3SAndreas Gohr 4198fed17f3SAndreas Gohr //simple - single quote 4208fed17f3SAndreas Gohr $this->assertEquals(array('test'), 4218fed17f3SAndreas Gohr $this->callInaccessibleMethod($search, 'parseFilterValueList', array('("test")'))); 4228fed17f3SAndreas Gohr 4238fed17f3SAndreas Gohr //simple - double quote 4248fed17f3SAndreas Gohr $this->assertEquals(array('test'), 4258fed17f3SAndreas Gohr $this->callInaccessibleMethod($search, 'parseFilterValueList', array("('test')"))); 4268fed17f3SAndreas Gohr 4278fed17f3SAndreas Gohr //many elements 4288fed17f3SAndreas Gohr $this->assertEquals(array('test', 'test2', '18'), 4298fed17f3SAndreas Gohr $this->callInaccessibleMethod($search, 'parseFilterValueList', array('("test", \'test2\', 18)'))); 4308fed17f3SAndreas Gohr 4318fed17f3SAndreas Gohr $str = <<<'EOD' 4328fed17f3SAndreas Gohr("t\"est", 't\'est2', 18) 4338fed17f3SAndreas GohrEOD; 4348fed17f3SAndreas Gohr //escape sequences 4358fed17f3SAndreas Gohr $this->assertEquals(array('t"est', "t'est2", '18'), 4368fed17f3SAndreas Gohr $this->callInaccessibleMethod($search, 'parseFilterValueList', array($str))); 4378fed17f3SAndreas Gohr 4388fed17f3SAndreas Gohr //numbers 4398fed17f3SAndreas Gohr $this->assertEquals(array('18.7', '10e5', '-100'), 4408fed17f3SAndreas Gohr $this->callInaccessibleMethod($search, 'parseFilterValueList', array('(18.7, 10e5, -100)'))); 4418fed17f3SAndreas Gohr 4428fed17f3SAndreas Gohr } 4438fed17f3SAndreas Gohr} 444