From 3c7b2e23da28e124f8d337ed7e330616592f3a0b Mon Sep 17 00:00:00 2001 From: Paolo Agostinetto Date: Sat, 18 Feb 2017 13:36:08 +0100 Subject: [PATCH] Added unit tests for Ods reader --- tests/PhpSpreadsheetTests/Reader/OdsTest.php | 189 +++++++++++++++++++ tests/data/Reader/Ods/numbers.ods | Bin 0 -> 9003 bytes 2 files changed, 189 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Reader/OdsTest.php create mode 100644 tests/data/Reader/Ods/numbers.ods diff --git a/tests/PhpSpreadsheetTests/Reader/OdsTest.php b/tests/PhpSpreadsheetTests/Reader/OdsTest.php new file mode 100644 index 00000000..b530acee --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/OdsTest.php @@ -0,0 +1,189 @@ +spreadsheet){ + $filename = __DIR__ . '/../../../samples/templates/OOCalcTest.ods'; + + // Create new Spreadsheet + $this->spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + + // Load into this instance + $reader = new Ods(); + $this->spreadsheet = $reader->loadIntoExisting($filename, $this->spreadsheet); + } + + return $this->spreadsheet; + } + + public function testReadValueAndComments(){ + + $spreadsheet = $this->load(); + + $this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); + + $firstSheet = $spreadsheet->getSheet(0); + + $this->assertEquals(29, $firstSheet->getHighestRow()); + $this->assertEquals('N', $firstSheet->getHighestColumn()); + + // Simple cell value + $this->assertEquals("Test String 1", $firstSheet->getCell("A1")->getValue()); + + // Merged cell + $this->assertEquals("BOX", $firstSheet->getCell("B18")->getValue()); + + // Comments/Annotations + $this->assertEquals( + "Test for a simple colour-formatted string", + $firstSheet->getComment("A1")->getText()->getPlainText() + ); + + // Data types + $this->assertEquals(DataType::TYPE_STRING, $firstSheet->getCell("A1")->getDataType()); + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("B1")->getDataType()); // Int + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("B6")->getDataType()); // Float + $this->assertEquals(1.23, $firstSheet->getCell("B6")->getValue()); + $this->assertEquals(0, $firstSheet->getCell("G10")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A10")->getDataType()); // Date + $this->assertEquals(22269.0, $firstSheet->getCell("A10")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A13")->getDataType()); // Time + $this->assertEquals(25569.0625, $firstSheet->getCell("A13")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A15")->getDataType()); // Date + Time + $this->assertEquals(22269.0625, $firstSheet->getCell("A15")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A11")->getDataType()); // Fraction + + $this->assertEquals(DataType::TYPE_BOOL, $firstSheet->getCell("D6")->getDataType()); + $this->assertTrue($firstSheet->getCell("D6")->getValue()); + + $this->assertEquals(DataType::TYPE_FORMULA, $firstSheet->getCell("C6")->getDataType()); // Formula + $this->assertEquals("=TRUE()", $firstSheet->getCell("C6")->getValue()); // Formula + + /* + * Percentage, Currency + */ + + $filename = __DIR__ . '/../../data/Reader/Ods/numbers.ods'; + + // Create new Spreadsheet + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + + // Load into this instance + $reader = new Ods(); + $spreadsheet = $reader->loadIntoExisting($filename, $spreadsheet); + $firstSheet = $spreadsheet->getActiveSheet(); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A1")->getDataType()); // Percentage (10%) + $this->assertEquals(0.1, $firstSheet->getCell("A1")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A2")->getDataType()); // Percentage (10.00%) + $this->assertEquals(0.1, $firstSheet->getCell("A2")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A4")->getDataType()); // Currency (€10.00) + $this->assertEquals(10, $firstSheet->getCell("A4")->getValue()); + + $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A5")->getDataType()); // Currency ($20) + $this->assertEquals(20, $firstSheet->getCell("A5")->getValue()); + } + + public function testReadColors() + { + $spreadsheet = $this->load(); + $firstSheet = $spreadsheet->getSheet(0); + + // Background color + + $style = $firstSheet->getCell("K3")->getStyle(); + + $this->assertEquals("none", $style->getFill()->getFillType()); + $this->assertEquals("FFFFFFFF", $style->getFill()->getStartColor()->getARGB()); + $this->assertEquals("FF000000", $style->getFill()->getEndColor()->getARGB()); + } + + /* + * Below some test for features not implemented yet + */ + + public function testReadBoldItalicUnderline() + { + $this->markTestSkipped("Features not implemented yet"); + + $spreadsheet = $this->load(); + $firstSheet = $spreadsheet->getSheet(0); + + // Font styles + + $style = $firstSheet->getCell("A1")->getStyle(); + $this->assertEquals("FF000000", $style->getFont()->getColor()->getARGB()); + $this->assertEquals(11, $style->getFont()->getSize()); + $this->assertEquals(Font::UNDERLINE_NONE, $style->getFont()->getUnderline()); + + $style = $firstSheet->getCell("E3")->getStyle(); + $this->assertEquals(Font::UNDERLINE_SINGLE, $style->getFont()->getUnderline()); + + $style = $firstSheet->getCell("E1")->getStyle(); + $this->assertTrue($style->getFont()->getBold()); + $this->assertTrue($style->getFont()->getItalic()); + } + + public function testReadRichTExt(){ + + $this->markTestSkipped("Features not implemented yet"); + + $spreadsheet = $this->load(); + $firstSheet = $spreadsheet->getSheet(0); + + $this->assertEquals( + "I don't know if OOCalc supports Rich Text in the same way as Excel, " . + "And this row should be autofit height with text wrap", + $firstSheet->getCell("A28")->getValue() + ); + } + + public function testReadHyperlinks(){ + + $this->markTestSkipped("Features not implemented fully"); + + $spreadsheet = $this->load(); + $firstSheet = $spreadsheet->getSheet(0); + + $hyperlink = $firstSheet->getCell("A29"); + + $this->assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType()); + $this->assertEquals("PHPExcel", $hyperlink->getValue()); + $this->assertEquals("http://www.phpexcel.net/", $hyperlink->getHyperlink()->getUrl()); + } +} diff --git a/tests/data/Reader/Ods/numbers.ods b/tests/data/Reader/Ods/numbers.ods new file mode 100644 index 0000000000000000000000000000000000000000..b386a340c8df3f66af4eec7858eb2e9d9f127eff GIT binary patch literal 9003 zcmdUVbzD^2yZ%ThC7~jMfI+u{bfppS}0mGy8qkTJPTbjc1Ld2rS$)00031P*Rf?_AqAlr3L^1_uJi9022cfAk@YT zsA*J}wz(7qMh&~VqmHZnf8mdfJ z#X|t#etU6;DXVW`q6N}4Fow`Te>ADhKzcrs;vXL);UL{z@>ocaPx|iI002AyAi&y^o8PkE@-t ztGk=0pPNshpQo$0m$#3%x2tcsXF#-HV6cC1SYTLen4d>zfOkkxa9pTwcvx6ScuZ7u zL|9BhOhj;eOn7{JTwp|USX^3kVn$3#W_((HLPl{)RB&2cSXx4KUV1`tW~#XJ6oH3yV`ns zdfR%(diuY1e;w-`o*M3L9qR8H``SG@+&en_b$D!YWMX!5^y~c8$mHbI==9R${L1X& z%Ixya^7P2k+|68U zR*L$9;>?bEgScB>Jr+)vms*KGKO@K{YbefwP2g0!Sz|3bd>Ylye+`^ccR8T#55?Jmje3VE1jY){~pSK3|*lw1=-{@FGg3 z%ZY896XFu-dN%R`%-W>voEKiGsGqbjp81&8wB5E6Ub#MAXOwbso(|hMcJfxHQ#C0_ znu`)^nXhVQ%o3VV-4$>c2@GU%g;XVy^UEAK*{E-Q0(M+q(O0j&LFtq?vxeO)9EfJ> zB1y78`p=HhGwEP%SfstKiPuz?2D`pT&<0EVDQ!w?GJLCYp4DbLb?khR&+rcQ(VVm6 z;$p0$7`?B0@YoEElq7jbp@@*(L==NzWo~GojD4n3#WY^Yv7R41nZYz$ibO}fqLdY? zd@DcIVTis5<ufPI+j9CHC)781GIpvMKuo>e zczvmroqu^2$FGh%lo#^E9!~i~+SxgayCwWBUOtP|Ep1#$8ncq>4)QIebwTuWB%1Wd zDu2T}VQ_tReyC?@#nzMD#8!}M={wxov~N3mt;~_f+aceK`gem&fqn-)ZfC-K%=~;N z$yc@w!@0&{U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