xref: /plugin/struct/_test/HelperDBTest.php (revision 6a819106d9214b25a316f4707f497180f2b71449)
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        $res = $sqlite->query("SELECT STRUCT_JSON('foo', 'bar') ");
31        $result = $sqlite->res2single($res);
32        $sqlite->res_close($res);
33        $expect = '["foo","bar"]';
34        $this->assertEquals($expect, $result);
35
36        $res = $sqlite->query("SELECT STRUCT_JSON(id, tbl) AS col FROM schemas");
37        $result = $sqlite->res2arr($res);
38        $sqlite->res_close($res);
39
40        $expect = [
41            ['col' => '[1,"schema1"]'],
42            ['col' => '[2,"schema2"]'],
43        ];
44        $this->assertEquals($expect, $result);
45    }
46
47}
48