Passed
Push — master ( d88efc...653645 )
by
unknown
12:43 queued 21s
created

ConditionalIconSetTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 51
c 1
b 0
f 0
dl 0
loc 75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testIconSet() 0 73 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
6
7
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\IconSetValues;
8
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
9
10
class ConditionalIconSetTest extends AbstractFunctional
11
{
12
    public function testIconSet(): void
13
    {
14
        $filename = 'tests/data/Reader/XLSX/conditionalFormattingIconSet.xlsx';
15
        $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
16
        $spreadsheet = $reader->load($filename);
17
        $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
18
        $spreadsheet->disconnectWorksheets();
19
        $worksheet = $reloadedSpreadsheet->getActiveSheet();
20
21
        $columnIndex = 'A';
22
        foreach (IconSetValues::cases() as $iconSetValue) {
23
            // styles
24
            $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11");
25
            self::assertCount(1, $styles);
26
27
            // icon set
28
            $iconSet = $styles[0]->getIconSet();
29
            self::assertNotNull($iconSet);
30
            self::assertSame($iconSetValue, $iconSet->getIconSetType() ?? IconSetValues::ThreeTrafficLights1);
31
32
            ++$columnIndex;
33
        }
34
35
        // icon set attributes
36
        $columnIndex = 'A';
37
        foreach (
38
            [
39
                ['reverse' => false, 'showValue' => false],
40
                ['reverse' => true, 'showValue' => false],
41
                ['reverse' => false, 'showValue' => true],
42
            ] as $expected
43
        ) {
44
            $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11");
45
            $iconSet = $styles[0]->getIconSet();
46
            self::assertNotNull($iconSet);
47
            self::assertSame($expected['reverse'], $iconSet->getReverse() ?? false);
48
            self::assertSame($expected['showValue'], $iconSet->getShowValue() ?? true);
49
            self::assertFalse($iconSet->getCustom() ?? false);
50
51
            ++$columnIndex;
52
        }
53
54
        // cfvos
55
        $columnIndex = 'A';
56
        foreach (
57
            [
58
                [['percent', '0', true], ['percent', '33', false], ['percent', '67', true]],
59
                [['percent', '0', true], ['num', '3', false], ['num', '7', true]],
60
                [['percent', '0', true], ['formula', '10/3', false], ['formula', '10/2', true]],
61
                [['percent', '0', true], ['percentile', '33', false], ['percentile', '67', true]],
62
            ] as $expected
63
        ) {
64
            $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11");
65
            $iconSet = $styles[0]->getIconSet();
66
            self::assertNotNull($iconSet);
67
            $cfvos = $iconSet->getCfvos();
68
            self::assertCount(count($expected), $cfvos);
69
            foreach ($expected as $i => [$type, $value, $gte]) {
70
                $cfvo = $cfvos[$i];
71
                self::assertSame($type, $cfvo->getType());
72
                self::assertSame($value, $cfvo->getValue());
73
                self::assertSame($gte, $cfvo->getGreaterThanOrEqual() ?? true);
74
                self::assertNull($cfvo->getCellFormula());
75
            }
76
77
            ++$columnIndex;
78
        }
79
80
        // unsupported icon sets
81
        for ($columnIndex = 'R'; $columnIndex <= 'U'; ++$columnIndex) {
82
            $styles = $worksheet->getConditionalStyles("{$columnIndex}2:{$columnIndex}11");
83
            $iconSet = $styles[0]->getIconSet();
84
            self::assertNull($iconSet);
85
        }
86
    }
87
}
88