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 ]; 26 27 $configParser = new meta\ConfigParser($lines); 28 $actual_config = $configParser->getConfig(); 29 30 $expected_config = [ 31 'limit' => 0, 32 'dynfilters' => false, 33 'summarize' => false, 34 'rownumbers' => false, 35 'sepbyheaders' => false, 36 'headers' => 37 [ 38 0 => NULL, 39 1 => NULL, 40 ], 41 'widths' => 42 [], 43 'filter' => 44 [], 45 'schemas' => 46 [ 47 0 => 48 [ 49 0 => 'testtable', 50 1 => '', 51 ], 52 1 => 53 [ 54 0 => 'another', 55 1 => '', 56 ], 57 2 => 58 [ 59 0 => 'foo', 60 1 => 'bar', 61 ], 62 ], 63 'cols' => 64 [ 65 0 => '%pageid%', 66 1 => 'count', 67 ], 68 'sort' => 69 [ 70 [ 71 0 => 'count', 72 1 => false, 73 ], 74 [ 75 0 => '%pageid%', 76 1 => true, 77 ], 78 [ 79 0 => 'bam', 80 1 => false, 81 ] 82 ], 83 'csv' => true, 84 'target' => '', 85 'align' => ['right', 'left', 'center', null], 86 'nesting' => 0, 87 'index' => 0, 88 ]; 89 90 $this->assertEquals($expected_config, $actual_config); 91 } 92 93 public function test_width() 94 { 95 $lines = ['width: 5, 15px, 23.4em, meh, 10em']; 96 97 $configParser = new meta\ConfigParser($lines); 98 99 $config = $configParser->getConfig(); 100 101 $this->assertEquals( 102 ['5px', '15px', '23.4em', '', '10em'], 103 $config['widths'] 104 ); 105 } 106 107 /** 108 * @see test_splitLine 109 */ 110 public function provide_splitLine() 111 { 112 return [ 113 ['', ['', '']], 114 [' ', ['', '']], 115 ['foo', ['foo', '']], 116 ['foo:bar', ['foo', 'bar']], 117 ['foo: bar', ['foo', 'bar']], 118 ['fOO: bar', ['foo', 'bar']], 119 [' fOO: bar ', ['foo', 'bar']], 120 ]; 121 } 122 123 /** 124 * @dataProvider provide_splitLine 125 */ 126 public function test_splitLine($line, $expected) 127 { 128 $configParser = new meta\ConfigParser(array()); 129 $actual = $this->callInaccessibleMethod($configParser, 'splitLine', [$line]); 130 $this->assertEquals($expected, $actual); 131 } 132} 133