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