Completed
Push — master ( 763b20...735103 )
by Adrien
09:55
created

OdsInfoTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
c 1
b 0
f 0
dl 0
loc 97
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testReadFileProperties() 0 13 1
A testNoMimeType() 0 8 1
A testReadBadFileInfo() 0 27 1
A testReadFileInfo() 0 26 1
A testReadBadFileProperties() 0 13 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
6
use PhpOffice\PhpSpreadsheet\Reader\Ods;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @TODO The class doesn't read the bold/italic/underline properties (rich text)
11
 */
12
class OdsInfoTest extends TestCase
13
{
14
    public function testReadFileProperties(): void
15
    {
16
        $filename = 'tests/data/Reader/Ods/data.ods';
17
18
        // Load into this instance
19
        $reader = new Ods();
20
21
        // Test "listWorksheetNames" method
22
23
        self::assertEquals([
24
            'Sheet1',
25
            'Second Sheet',
26
        ], $reader->listWorksheetNames($filename));
27
    }
28
29
    public function testNoMimeType(): void
30
    {
31
        $filename = 'tests/data/Reader/Ods/nomimetype.ods';
32
33
        // Load into this instance
34
        $reader = new Ods();
35
36
        self::assertTrue($reader->canRead($filename));
37
    }
38
39
    public function testReadBadFileProperties(): void
40
    {
41
        $this->expectException(ReaderException::class);
42
43
        // Load into this instance
44
        $reader = new Ods();
45
46
        // Test "listWorksheetNames" method
47
48
        self::assertEquals([
49
            'Sheet1',
50
            'Second Sheet',
51
        ], $reader->listWorksheetNames(__FILE__));
52
    }
53
54
    public function testReadFileInfo(): void
55
    {
56
        $filename = 'tests/data/Reader/Ods/data.ods';
57
58
        // Load into this instance
59
        $reader = new Ods();
60
61
        // Test "listWorksheetNames" method
62
63
        $wsinfo = $reader->listWorkSheetInfo($filename);
64
        self::assertEquals([
65
            [
66
                'worksheetName' => 'Sheet1',
67
                'lastColumnLetter' => 'C',
68
                'lastColumnIndex' => 2,
69
                'totalRows' => 12,
70
                'totalColumns' => 3,
71
            ],
72
            [
73
                'worksheetName' => 'Second Sheet',
74
                'lastColumnLetter' => 'A',
75
                'lastColumnIndex' => 0,
76
                'totalRows' => 2,
77
                'totalColumns' => 1,
78
            ],
79
        ], $wsinfo);
80
    }
81
82
    public function testReadBadFileInfo(): void
83
    {
84
        $this->expectException(ReaderException::class);
85
        $filename = __FILE__;
86
87
        // Load into this instance
88
        $reader = new Ods();
89
90
        // Test "listWorksheetNames" method
91
92
        $wsinfo = $reader->listWorkSheetInfo($filename);
93
        self::assertEquals([
94
            [
95
                'worksheetName' => 'Sheet1',
96
                'lastColumnLetter' => 'C',
97
                'lastColumnIndex' => 2,
98
                'totalRows' => 11,
99
                'totalColumns' => 3,
100
            ],
101
            [
102
                'worksheetName' => 'Second Sheet',
103
                'lastColumnLetter' => 'A',
104
                'lastColumnIndex' => 0,
105
                'totalRows' => 2,
106
                'totalColumns' => 1,
107
            ],
108
        ], $wsinfo);
109
    }
110
}
111