Passed
Push — develop ( 7a4cbd...edb68c )
by Adrien
34:56
created

testPreserveWorkbookViewAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 52
rs 9.0472
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Functional;
4
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
7
class WorkbookViewAttributesTest extends AbstractFunctional
8
{
9
    public function providerFormats()
10
    {
11
        return [
12
            ['Xlsx'],
13
        ];
14
    }
15
16
    /**
17
     * Test that workbook bookview attributes such as 'showSheetTabs',
18
     * (the attribute controlling worksheet tabs visibility,)
19
     * are preserved when xlsx documents are read and written.
20
     *
21
     * @see https://github.com/PHPOffice/PhpSpreadsheet/issues/523
22
     *
23
     * @dataProvider providerFormats
24
     *
25
     * @param string $format
26
     */
27
    public function testPreserveWorkbookViewAttributes($format)
28
    {
29
        // Create a dummy workbook with two worksheets
30
        $workbook = new Spreadsheet();
31
        $worksheet1 = $workbook->getActiveSheet();
32
        $worksheet1->setTitle('Tweedledee');
33
        $worksheet1->setCellValue('A1', 1);
34
        $worksheet2 = $workbook->createSheet();
35
        $worksheet2->setTitle('Tweeldedum');
36
        $worksheet2->setCellValue('A1', 2);
37
38
        // Check that the bookview attributes return default values
39
        $this->assertTrue($workbook->getShowHorizontalScroll());
40
        $this->assertTrue($workbook->getShowVerticalScroll());
41
        $this->assertTrue($workbook->getShowSheetTabs());
42
        $this->assertTrue($workbook->getAutoFilterDateGrouping());
43
        $this->assertFalse($workbook->getMinimized());
44
        $this->assertSame(0, $workbook->getFirstSheetIndex());
45
        $this->assertSame(600, $workbook->getTabRatio());
46
        $this->assertSame(Spreadsheet::VISIBILITY_VISIBLE, $workbook->getVisibility());
47
48
        // Set the bookview attributes to non-default values
49
        $workbook->setShowHorizontalScroll(false);
50
        $workbook->setShowVerticalScroll(false);
51
        $workbook->setShowSheetTabs(false);
52
        $workbook->setAutoFilterDateGrouping(false);
53
        $workbook->setMinimized(true);
54
        $workbook->setFirstSheetIndex(1);
55
        $workbook->setTabRatio(700);
56
        $workbook->setVisibility(Spreadsheet::VISIBILITY_HIDDEN);
57
58
        // Check that bookview attributes were set properly
59
        $this->assertFalse($workbook->getShowHorizontalScroll());
60
        $this->assertFalse($workbook->getShowVerticalScroll());
61
        $this->assertFalse($workbook->getShowSheetTabs());
62
        $this->assertFalse($workbook->getAutoFilterDateGrouping());
63
        $this->assertTrue($workbook->getMinimized());
64
        $this->assertSame(1, $workbook->getFirstSheetIndex());
65
        $this->assertSame(700, $workbook->getTabRatio());
66
        $this->assertSame(Spreadsheet::VISIBILITY_HIDDEN, $workbook->getVisibility());
67
68
        $workbook2 = $this->writeAndReload($workbook, $format);
69
70
        // Check that the read spreadsheet has the right bookview attributes
71
        $this->assertFalse($workbook2->getShowHorizontalScroll());
72
        $this->assertFalse($workbook2->getShowVerticalScroll());
73
        $this->assertFalse($workbook2->getShowSheetTabs());
74
        $this->assertFalse($workbook2->getAutoFilterDateGrouping());
75
        $this->assertTrue($workbook2->getMinimized());
76
        $this->assertSame(1, $workbook2->getFirstSheetIndex());
77
        $this->assertSame(700, $workbook2->getTabRatio());
78
        $this->assertSame(Spreadsheet::VISIBILITY_HIDDEN, $workbook2->getVisibility());
79
    }
80
}
81