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