1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\Schema;
6use dokuwiki\plugin\struct\meta\StructException;
7
8/**
9 * @group plugin_struct
10 * @group plugins
11 *
12 */
13class schema_struct_test extends StructTest
14{
15
16    /**
17     * Testdata for @return array
18     * @see schema_struct_test::test_cleanTableName
19     *
20     */
21    public static function cleanTableName_testdata()
22    {
23        return array(
24            array(
25                'abc',
26                'abc',
27            ),
28            array(
29                '123abc',
30                'abc',
31            ),
32            array(
33                'abc123',
34                'abc123',
35            ),
36            array(
37                '_a_b_c_',
38                'a_b_c_',
39            ),
40            array(
41                '-a-b-c-',
42                'abc',
43            ),
44            array(
45                '/a/b/c/',
46                'abc',
47            ),
48            array(
49                '\\a\\b\\c\\',
50                'abc',
51            )
52        );
53    }
54
55    /**
56     * @dataProvider cleanTableName_testdata
57     *
58     * @covers       \dokuwiki\plugin\struct\meta\Schema::cleanTableName
59     *
60     * @param string $input_name
61     * @param string $expected_cleaned_name
62     */
63    public function test_cleanTableName($input_name, $expected_cleaned_name)
64    {
65        $actual_cleaned_name = Schema::cleanTableName($input_name);
66        $this->assertSame($expected_cleaned_name, $actual_cleaned_name, $input_name);
67    }
68
69    public function test_deletefail()
70    {
71        $this->expectException(StructException::class);
72        $schema = new Schema('foo');
73        $schema->delete();
74    }
75
76    public function test_deleteok()
77    {
78        $this->loadSchemaJSON('schema1');
79
80        $schema = new Schema('schema1');
81        $this->assertEquals(1, $schema->getId());
82        $schema->delete();
83        $this->assertEquals(0, $schema->getId());
84
85        $schema = new Schema('schema1');
86        $this->assertEquals(0, $schema->getId());
87    }
88}
89