735103c120
* Improve Coverage for ODS Reader Reader/ODS/Properties is now 100% covered. Reader/ODS is covered except for 1 statement. As the original author put it, "table-header-rows TODO: figure this out ... I'm not sure that PhpExcel has an API for this". I'm still thinking about it, but, so far, I agree with the author. There are minimal code changes. - Several places test !zip->open() to see whether the test failed. However, zip->open() returns true or a string, so the test never detects failure. Change to zip->open() !== true. No previous tests. - Suppress warning messages from simplexml_load_string (there had been no tests for invalid xml). - One document property was misnamed, and one non-existent property was tested for. I added a number of tests, creating an ODS directory, and moving OdsTest to that directory. * Scrutinizer Recommendation Unused variable in one test. * Update CHANGELOG Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
111 lines
2.8 KiB
PHP
111 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Ods;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @TODO The class doesn't read the bold/italic/underline properties (rich text)
|
|
*/
|
|
class OdsInfoTest extends TestCase
|
|
{
|
|
public function testReadFileProperties(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/data.ods';
|
|
|
|
// Load into this instance
|
|
$reader = new Ods();
|
|
|
|
// Test "listWorksheetNames" method
|
|
|
|
self::assertEquals([
|
|
'Sheet1',
|
|
'Second Sheet',
|
|
], $reader->listWorksheetNames($filename));
|
|
}
|
|
|
|
public function testNoMimeType(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/nomimetype.ods';
|
|
|
|
// Load into this instance
|
|
$reader = new Ods();
|
|
|
|
self::assertTrue($reader->canRead($filename));
|
|
}
|
|
|
|
public function testReadBadFileProperties(): void
|
|
{
|
|
$this->expectException(ReaderException::class);
|
|
|
|
// Load into this instance
|
|
$reader = new Ods();
|
|
|
|
// Test "listWorksheetNames" method
|
|
|
|
self::assertEquals([
|
|
'Sheet1',
|
|
'Second Sheet',
|
|
], $reader->listWorksheetNames(__FILE__));
|
|
}
|
|
|
|
public function testReadFileInfo(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/data.ods';
|
|
|
|
// Load into this instance
|
|
$reader = new Ods();
|
|
|
|
// Test "listWorksheetNames" method
|
|
|
|
$wsinfo = $reader->listWorkSheetInfo($filename);
|
|
self::assertEquals([
|
|
[
|
|
'worksheetName' => 'Sheet1',
|
|
'lastColumnLetter' => 'C',
|
|
'lastColumnIndex' => 2,
|
|
'totalRows' => 12,
|
|
'totalColumns' => 3,
|
|
],
|
|
[
|
|
'worksheetName' => 'Second Sheet',
|
|
'lastColumnLetter' => 'A',
|
|
'lastColumnIndex' => 0,
|
|
'totalRows' => 2,
|
|
'totalColumns' => 1,
|
|
],
|
|
], $wsinfo);
|
|
}
|
|
|
|
public function testReadBadFileInfo(): void
|
|
{
|
|
$this->expectException(ReaderException::class);
|
|
$filename = __FILE__;
|
|
|
|
// Load into this instance
|
|
$reader = new Ods();
|
|
|
|
// Test "listWorksheetNames" method
|
|
|
|
$wsinfo = $reader->listWorkSheetInfo($filename);
|
|
self::assertEquals([
|
|
[
|
|
'worksheetName' => 'Sheet1',
|
|
'lastColumnLetter' => 'C',
|
|
'lastColumnIndex' => 2,
|
|
'totalRows' => 11,
|
|
'totalColumns' => 3,
|
|
],
|
|
[
|
|
'worksheetName' => 'Second Sheet',
|
|
'lastColumnLetter' => 'A',
|
|
'lastColumnIndex' => 0,
|
|
'totalRows' => 2,
|
|
'totalColumns' => 1,
|
|
],
|
|
], $wsinfo);
|
|
}
|
|
}
|