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
|
|
|
|