1<?php 2 3namespace dokuwiki\plugin\struct\test; 4 5use dokuwiki\plugin\struct\meta; 6 7/** 8 * Tests for parsing the aggregation config for the struct plugin 9 * 10 * @group plugin_struct 11 * @group plugins 12 * 13 */ 14class ConfigParserTest extends StructTest 15{ 16 17 public function test_simple() 18 { 19 $lines = [ 20 "schema : testtable, another, foo bar", 21 "cols : %pageid%, count", 22 "sort : ^count", 23 "sort : %pageid%, ^bam", 24 "align : r,l,center,foo", 25 "class : foo, bar", 26 ]; 27 28 $configParser = new meta\ConfigParser($lines); 29 $actual_config = $configParser->getConfig(); 30 31 $expected_config = [ 32 'limit' => 0, 33 'dynfilters' => false, 34 'summarize' => false, 35 'rownumbers' => false, 36 'sepbyheaders' => false, 37 'headers' => 38 [ 39 0 => NULL, 40 1 => NULL, 41 ], 42 'widths' => 43 [], 44 'filter' => 45 [], 46 'schemas' => 47 [ 48 0 => 49 [ 50 0 => 'testtable', 51 1 => '', 52 ], 53 1 => 54 [ 55 0 => 'another', 56 1 => '', 57 ], 58 2 => 59 [ 60 0 => 'foo', 61 1 => 'bar', 62 ], 63 ], 64 'cols' => 65 [ 66 0 => '%pageid%', 67 1 => 'count', 68 ], 69 'sort' => 70 [ 71 [ 72 0 => 'count', 73 1 => false, 74 ], 75 [ 76 0 => '%pageid%', 77 1 => true, 78 ], 79 [ 80 0 => 'bam', 81 1 => false, 82 ] 83 ], 84 'csv' => true, 85 'target' => '', 86 'align' => ['right', 'left', 'center', null], 87 'nesting' => 0, 88 'index' => 0, 89 'classes' => ['struct-custom-foo', 'struct-custom-bar'], 90 ]; 91 92 $this->assertEquals($expected_config, $actual_config); 93 } 94 95 public function test_width() 96 { 97 $lines = ['width: 5, 15px, 23.4em, meh, 10em']; 98 99 $configParser = new meta\ConfigParser($lines); 100 101 $config = $configParser->getConfig(); 102 103 $this->assertEquals( 104 ['5px', '15px', '23.4em', '', '10em'], 105 $config['widths'] 106 ); 107 } 108 109 /** 110 * @see test_splitLine 111 */ 112 public function provide_splitLine() 113 { 114 return [ 115 ['', ['', '']], 116 [' ', ['', '']], 117 ['foo', ['foo', '']], 118 ['foo:bar', ['foo', 'bar']], 119 ['foo: bar', ['foo', 'bar']], 120 ['fOO: bar', ['foo', 'bar']], 121 [' fOO: bar ', ['foo', 'bar']], 122 ]; 123 } 124 125 /** 126 * @dataProvider provide_splitLine 127 */ 128 public function test_splitLine($line, $expected) 129 { 130 $configParser = new meta\ConfigParser(array()); 131 $actual = $this->callInaccessibleMethod($configParser, 'splitLine', [$line]); 132 $this->assertEquals($expected, $actual); 133 } 134} 135