1*8fed17f3SAndreas Gohr<?php 2*8fed17f3SAndreas Gohr 3*8fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 4*8fed17f3SAndreas Gohr 5*8fed17f3SAndreas Gohr/** 6*8fed17f3SAndreas Gohr * @group plugin_struct 7*8fed17f3SAndreas Gohr * @group plugins 8*8fed17f3SAndreas Gohr */ 9*8fed17f3SAndreas Gohrclass helper_db_struct_test extends StructTest 10*8fed17f3SAndreas Gohr{ 11*8fed17f3SAndreas Gohr 12*8fed17f3SAndreas Gohr public function setUp(): void 13*8fed17f3SAndreas Gohr { 14*8fed17f3SAndreas Gohr parent::setUp(); 15*8fed17f3SAndreas Gohr 16*8fed17f3SAndreas Gohr $this->loadSchemaJSON('schema1'); 17*8fed17f3SAndreas Gohr $this->loadSchemaJSON('schema2'); 18*8fed17f3SAndreas Gohr } 19*8fed17f3SAndreas Gohr 20*8fed17f3SAndreas Gohr /** 21*8fed17f3SAndreas Gohr * @noinspection SqlDialectInspection 22*8fed17f3SAndreas Gohr * @noinspection SqlNoDataSourceInspection 23*8fed17f3SAndreas Gohr */ 24*8fed17f3SAndreas Gohr public function test_json() 25*8fed17f3SAndreas Gohr { 26*8fed17f3SAndreas Gohr /** @var \helper_plugin_struct_db $helper */ 27*8fed17f3SAndreas Gohr $helper = plugin_load('helper', 'struct_db'); 28*8fed17f3SAndreas Gohr $sqlite = $helper->getDB(); 29*8fed17f3SAndreas Gohr 30*8fed17f3SAndreas Gohr $res = $sqlite->query("SELECT STRUCT_JSON('foo', 'bar') "); 31*8fed17f3SAndreas Gohr $result = $sqlite->res2single($res); 32*8fed17f3SAndreas Gohr $sqlite->res_close($res); 33*8fed17f3SAndreas Gohr $expect = '["foo","bar"]'; 34*8fed17f3SAndreas Gohr $this->assertEquals($expect, $result); 35*8fed17f3SAndreas Gohr 36*8fed17f3SAndreas Gohr $res = $sqlite->query("SELECT STRUCT_JSON(id, tbl) AS col FROM schemas"); 37*8fed17f3SAndreas Gohr $result = $sqlite->res2arr($res); 38*8fed17f3SAndreas Gohr $sqlite->res_close($res); 39*8fed17f3SAndreas Gohr 40*8fed17f3SAndreas Gohr $expect = [ 41*8fed17f3SAndreas Gohr ['col' => '[1,"schema1"]'], 42*8fed17f3SAndreas Gohr ['col' => '[2,"schema2"]'], 43*8fed17f3SAndreas Gohr ]; 44*8fed17f3SAndreas Gohr $this->assertEquals($expect, $result); 45*8fed17f3SAndreas Gohr } 46*8fed17f3SAndreas Gohr 47*8fed17f3SAndreas Gohr} 48