OdsInfoTest.php 2.8 KB

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