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