1<?php 2 3namespace dokuwiki\plugin\struct\test; 4 5/** 6 * Testing aggregation filter 7 * 8 * @group plugin_struct 9 * @group plugins 10 */ 11class AggregationFilterTest extends StructTest 12{ 13 protected $items = [ 14 [['green', 'yellow'], 'car', 'audi', 'a80'], 15 [[], 'car', 'audi', 'a4'], 16 [['red', 'black'], 'car', 'bmw', 'i3'], 17 [['green', 'blue'], 'laptop', 'apple', 'pro 16'], 18 [['blue', 'gray'], 'car', 'bmw', 'mini'], 19 [['red', 'black'], 'car', 'bmw', 'z1'], 20 [['red', 'blue'], 'laptop', 'apple', 'air'], 21 [['black', 'red'], 'laptop', 'apple', 'm1'], 22 [[], 'laptop', 'dell', 'xps'], 23 [['black', 'green'], '', 'audi', 'quattro'], 24 [['blue', 'yellow'], '', 'dell', 'inspiron'], 25 [['gray', 'yellow'], 'laptop', 'dell', 'latitude'], 26 ]; 27 28 public function testGetAllColumnValues() 29 { 30 $result = $this->createAggregationResult($this->items); 31 $filter = new mock\AggregationFilter(); 32 $values = $filter->getAllColumnValues($result); 33 34 $this->assertCount(4, $values); 35 36 // we expect value => displayValue pairs, sorted by displayValue 37 $this->assertSame( 38 [ 39 'black' => 'black', 40 'blue' => 'blue', 41 'gray' => 'gray', 42 'green' => 'green', 43 'red' => 'red', 44 'yellow' => 'yellow' 45 ], 46 $this->trimKeys($values[0]['values']) 47 ); 48 49 $this->assertEquals( 50 'Label 1', 51 $values[0]['label'] 52 ); 53 54 $this->assertSame( 55 [ 56 'car' => 'car', 57 'laptop' => 'laptop' 58 ], 59 $this->trimKeys($values[1]['values']) 60 ); 61 62 $this->assertEquals( 63 'Label 2', 64 $values[1]['label'] 65 ); 66 } 67 68 /** 69 * Reverses key padding workaround in AggregationFilter::getAllColumnValues() 70 * 71 * @param array $values 72 * @return int[]|string[] 73 */ 74 protected function trimKeys($values) 75 { 76 return array_flip(array_map(static fn($val) => trim($val), array_flip($values))); 77 } 78} 79