File indexing completed on 2024-05-19 04:01:08

0001 <?php
0002 /*
0003     SPDX-FileCopyrightText: 2017-2023 Volker Krause <vkrause@kde.org>
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 require_once('../src/server/shared/datastore.php');
0008 
0009 // default database configuration for sqlite, can be overridden by localconfig.php
0010 $USERFEEDBACK_DB_DRIVER = 'sqlite';
0011 $USERFEEDBACK_DB_NAME =  ':memory:';
0012 
0013 class DatastoreTestHelper
0014 {
0015     public static function setup()
0016     {
0017         // database schema setup
0018         $db = new Datastore();
0019         $db->checkSchema();
0020 
0021         // add dummy test data (from previous use of DBUnit, might make sense to move this to the corresponding tests relying on this instead)
0022         $db->pdoHandle()->exec('INSERT INTO tbl_product (col_id, col_name) VALUES (2, "org.kde.UnitTest")');
0023 
0024         $db->pdoHandle()->exec('INSERT INTO tbl_schema (col_id, col_product_id, col_name, col_type) VALUES (31, 2, "entry1", "scalar")');
0025         $db->pdoHandle()->exec('INSERT INTO tbl_schema (col_id, col_product_id, col_name, col_type) VALUES (32, 2, "entry2", "list")');
0026 
0027         $db->pdoHandle()->exec('INSERT INTO tbl_schema_element (col_id, col_schema_id, col_name, col_type) VALUES (42, 31, "element11", "string")');
0028         $db->pdoHandle()->exec('INSERT INTO tbl_schema_element (col_id, col_schema_id, col_name, col_type) VALUES (43, 31, "element12", "bool")');
0029         $db->pdoHandle()->exec('INSERT INTO tbl_schema_element (col_id, col_schema_id, col_name, col_type) VALUES (44, 32, "element21", "int")');
0030         $db->pdoHandle()->exec('INSERT INTO tbl_schema_element (col_id, col_schema_id, col_name, col_type) VALUES (45, 32, "element22", "number")');
0031 
0032         $db->pdoHandle()->exec('INSERT INTO tbl_survey (col_id, col_uuid, col_product_id, col_name, col_url, col_active, col_target) VALUES (101, "{962bbd80-7120-4f18-a4c0-5800fa323868}", 2, "myActiveSurvey", "http://survey.example/active", 1, "usageTime.value >= 3600")');
0033         $db->pdoHandle()->exec('INSERT INTO tbl_survey (col_id, col_uuid, col_product_id, col_name, col_url, col_active, col_target) VALUES (102, "{bdfa82c5-238f-404b-a441-07ca3d3eff7f}", 2, "myInactiveSurvey", "http://survey.example/inactive", 0, "screen[0].dpi < 200")');
0034 
0035         $stmt =
0036         $db->pdoHandle()->exec("INSERT INTO tbl_aggregation (col_id, col_name, col_product_id, col_type, col_elements) VALUES (201, 'Category: entry1.elem11', 2, 'category', '[ { \"type\": \"value\", \"schemaEntry\": \"entry1\", \"schemaEntryElement\": \"element11\" } ]')");
0037         $db->pdoHandle()->exec("INSERT INTO tbl_aggregation (col_id, col_name, col_product_id, col_type, col_elements) VALUES (202, 'entry2 size distribution', 2, 'numeric', '[ { \"type\": \"size\", \"schemaEntry\": \"entry2\" } ]')");
0038 
0039         return $db;
0040     }
0041 }
0042 
0043 ?>