From 562051099102ef442a13e59f0d6b490efa14238f Mon Sep 17 00:00:00 2001 From: Paolo Agostinetto Date: Sat, 4 Mar 2017 15:22:20 +0100 Subject: [PATCH] Writer\Ods\Content: basic unit tests --- .../Writer/Ods/ContentTest.php | 62 +++++++++++++++++++ tests/data/Writer/Ods/content-empty.xml | 20 ++++++ tests/data/Writer/Ods/content-with-data.xml | 60 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php create mode 100644 tests/data/Writer/Ods/content-empty.xml create mode 100644 tests/data/Writer/Ods/content-with-data.xml diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php new file mode 100644 index 00000000..70d920dc --- /dev/null +++ b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php @@ -0,0 +1,62 @@ +setParentWriter(new Ods(new Spreadsheet())); + + $xml = $content->write(); + + $this->assertXmlStringEqualsXmlFile($this->samplesPath . "/content-empty.xml", $xml); + } + + public function testWriteSpreadsheet() + { + $workbook = new Spreadsheet(); + + // Worksheet 1 + $worksheet1 = $workbook->getActiveSheet(); + $worksheet1->setCellValue('A1', 1); // Number + $worksheet1->setCellValue('B1', 12345.6789); // Number + $worksheet1->setCellValue('C1', "1"); // Number without cast + $worksheet1->setCellValueExplicit('D1', "01234", DataType::TYPE_STRING); // Number casted to string + $worksheet1->setCellValue('E1', "Lorem ipsum"); // String + + $worksheet1->setCellValue('A2', true); // Boolean + $worksheet1->setCellValue('B2', false); // Boolean + $worksheet1->setCellValue('C2', '=IF(A3, CONCATENATE(A1, " ", A2), CONCATENATE(A2, " ", A1))'); // Formula + + $worksheet1->setCellValue('D2', Date::PHPToExcel(1488635026)); // Date + $worksheet1->getStyle('D2') + ->getNumberFormat() + ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); + + // Worksheet 2 + $worksheet2 = $workbook->createSheet(); + $worksheet2->setTitle('New Worksheet'); + $worksheet2->setCellValue('A1', 2); + + // Write + $content = new Content(); + $content->setParentWriter(new Ods($workbook)); + + $xml = $content->write(); + + $this->assertXmlStringEqualsXmlFile($this->samplesPath . "/content-with-data.xml", $xml); + } +} diff --git a/tests/data/Writer/Ods/content-empty.xml b/tests/data/Writer/Ods/content-empty.xml new file mode 100644 index 00000000..67cc35f2 --- /dev/null +++ b/tests/data/Writer/Ods/content-empty.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/data/Writer/Ods/content-with-data.xml b/tests/data/Writer/Ods/content-with-data.xml new file mode 100644 index 00000000..42f87553 --- /dev/null +++ b/tests/data/Writer/Ods/content-with-data.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + 1 + + + 12345.6789 + + + 1 + + + 01234 + + + Lorem ipsum + + + + + + 1 + + + + + + 1 TRUE + + + 42798.572060185 + + + + + + + + + + + 2 + + + + + + + + \ No newline at end of file