File: utilstest.php

package info (click to toggle)
kuserfeedback 1.3.0-9
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,496 kB
  • sloc: cpp: 13,251; php: 2,192; xml: 224; yacc: 90; lex: 82; sh: 17; makefile: 8
file content (81 lines) | stat: -rw-r--r-- 2,461 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
    SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: MIT
*/

require_once('../src/server/shared/utils.php');

class UtilsTest extends PHPUnit\Framework\TestCase
{
    public static function isValidIdentifier_data()
    {
        return [
            'empty' => [ '', false ],
            'number' => [ 42, false ],
            'numstring' => [ '42', false ],
            'leading number' => [ '1foo', false ],
            'alpha only' => [ 'foo', true ],
            'leading space' => [ ' foo', false ],
            'middle space' => [ 'f o o', false ],
            'trailing space' => [ 'foo ', false ],
            'valid' => [ 'foo42', true ],
            'leading underscore' => [ '_foo', true ],
            'underscore' => [ 'f_o_o', true ],
            'dots and dashes' => [ 'org.kde.unit-test', true ],
            'control' => [ "fo\no", false ]
        ];
    }

    /** @dataProvider isValidIdentifier_data */
    public function testIsValidIdentifier($str, $result)
    {
        $this->assertEquals($result, Utils::isValidIdentifier($str));
    }

    public static function normalize_data()
    {
        return [
            'empty' => [ '', '' ],
            'normal' => [ 'foo', 'foo' ],
            'dot' => [ 'org.kde.foo', 'org_kde_foo' ]
        ];
    }

    /** @dataProvider normalize_data */
    public function testNormalize($input, $output)
    {
        $this->assertEquals($output, Utils::normalizeString($input));
    }

    public static function primaryKeyColumn_data()
    {
        return [
            'sqlite' => [ 'sqlite', 'id', 'id INTEGER PRIMARY KEY AUTOINCREMENT' ],
            'pgsql' => [ 'pgsql', 'id', 'id SERIAL PRIMARY KEY' ],
            'mysql' => [ 'mysql', 'id', 'id INTEGER PRIMARY KEY AUTO_INCREMENT' ]
        ];
    }

    /** @dataProvider primaryKeyColumn_data */
    public function primaryKeyColumn($driver, $name, $output)
    {
        $this->assertEquals($output, Utils::primaryKeyColumnDeclaration($driver, $name));
    }

    public static function sqlStringType_data()
    {
        return [
            'sqlite' => [ 'sqlite', 'VARCHAR' ],
            'mysql' => [ 'mysql', 'VARCHAR(255)' ],
            'pgsql' => [ 'pgsql', 'VARCHAR' ],
        ];
    }

    /** @dataProvider sqlStringType_data */
    public function testSqlStringType($driver, $output)
    {
        $this->assertEquals($output, Utils::sqlStringType($driver));
    }
}