Ods reader: tests for repeated spaces and rich text

This commit is contained in:
Paolo Agostinetto 2017-02-18 20:49:48 +01:00
parent e46c298fe1
commit 1dba2d1766
2 changed files with 56 additions and 40 deletions

View File

@ -23,34 +23,48 @@ class OdsTest extends \PHPUnit_Framework_TestCase
/** /**
* @var \PhpOffice\PhpSpreadsheet\Spreadsheet * @var \PhpOffice\PhpSpreadsheet\Spreadsheet
*/ */
public $spreadsheet; public $spreadsheetOOCalcTest;
/**
* @var \PhpOffice\PhpSpreadsheet\Spreadsheet
*/
public $spreadsheetData;
/** /**
* @return \PhpOffice\PhpSpreadsheet\Spreadsheet * @return \PhpOffice\PhpSpreadsheet\Spreadsheet
*/ */
protected function loadOOCalcTest(){ protected function loadOOCalcTestFile(){
if(!$this->spreadsheet){ if(!$this->spreadsheetOOCalcTest){
$filename = __DIR__ . '/../../../samples/templates/OOCalcTest.ods'; $filename = __DIR__ . '/../../../samples/templates/OOCalcTest.ods';
// Create new Spreadsheet
$this->spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// Load into this instance // Load into this instance
$reader = new Ods(); $reader = new Ods();
$this->spreadsheet = $reader->loadIntoExisting($filename, $this->spreadsheet); $this->spreadsheetOOCalcTest = $reader->loadIntoExisting($filename, new \PhpOffice\PhpSpreadsheet\Spreadsheet());
} }
return $this->spreadsheet; return $this->spreadsheetOOCalcTest;
} }
public function testLoadWorksheets() /**
{ * @return \PhpOffice\PhpSpreadsheet\Spreadsheet
*/
protected function loadDataFile(){
if(!$this->spreadsheetData){
$filename = __DIR__ . '/../../data/Reader/Ods/data.ods'; $filename = __DIR__ . '/../../data/Reader/Ods/data.ods';
// Load into this instance // Load into this instance
$reader = new Ods(); $reader = new Ods();
$spreadsheet = $reader->loadIntoExisting($filename, new \PhpOffice\PhpSpreadsheet\Spreadsheet()); $this->spreadsheetData = $reader->loadIntoExisting($filename, new \PhpOffice\PhpSpreadsheet\Spreadsheet());
}
return $this->spreadsheetData;
}
public function testLoadWorksheets()
{
$spreadsheet = $this->loadDataFile();
$this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); $this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet);
@ -65,9 +79,7 @@ class OdsTest extends \PHPUnit_Framework_TestCase
public function testReadValueAndComments(){ public function testReadValueAndComments(){
$spreadsheet = $this->loadOOCalcTest(); $spreadsheet = $this->loadOOCalcTestFile();
$this->assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet);
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
@ -115,14 +127,8 @@ class OdsTest extends \PHPUnit_Framework_TestCase
* Percentage, Currency * Percentage, Currency
*/ */
$filename = __DIR__ . '/../../data/Reader/Ods/data.ods'; $spreadsheet = $this->loadDataFile();
// Create new Spreadsheet
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// Load into this instance
$reader = new Ods();
$spreadsheet = $reader->loadIntoExisting($filename, $spreadsheet);
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
$this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A1")->getDataType()); // Percentage (10%) $this->assertEquals(DataType::TYPE_NUMERIC, $firstSheet->getCell("A1")->getDataType()); // Percentage (10%)
@ -140,7 +146,7 @@ class OdsTest extends \PHPUnit_Framework_TestCase
public function testReadColors() public function testReadColors()
{ {
$spreadsheet = $this->loadOOCalcTest(); $spreadsheet = $this->loadOOCalcTestFile();
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
// Background color // Background color
@ -152,6 +158,30 @@ class OdsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("FF000000", $style->getFill()->getEndColor()->getARGB()); $this->assertEquals("FF000000", $style->getFill()->getEndColor()->getARGB());
} }
public function testReadRichText(){
$spreadsheet = $this->loadOOCalcTestFile();
$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 testReadCellsWithRepeatedSpaces(){
$spreadsheet = $this->loadDataFile();
$firstSheet = $spreadsheet->getSheet(0);
$this->assertEquals("This has 4 spaces before and 2 after ", $firstSheet->getCell("A8")->getValue());
$this->assertEquals("This only one after ", $firstSheet->getCell("A9")->getValue());
$this->assertEquals("Test with DIFFERENT styles and multiple spaces: ", $firstSheet->getCell("A10")->getValue());
$this->assertEquals("test with new \nLines", $firstSheet->getCell("A11")->getValue());
}
/* /*
* Below some test for features not implemented yet * Below some test for features not implemented yet
*/ */
@ -160,7 +190,7 @@ class OdsTest extends \PHPUnit_Framework_TestCase
{ {
$this->markTestSkipped("Features not implemented yet"); $this->markTestSkipped("Features not implemented yet");
$spreadsheet = $this->loadOOCalcTest(); $spreadsheet = $this->loadOOCalcTestFile();
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
// Font styles // Font styles
@ -178,25 +208,11 @@ class OdsTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($style->getFont()->getItalic()); $this->assertTrue($style->getFont()->getItalic());
} }
public function testReadRichTExt(){
$this->markTestSkipped("Features not implemented yet");
$spreadsheet = $this->loadOOCalcTest();
$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(){ public function testReadHyperlinks(){
$this->markTestSkipped("Features not implemented fully"); $this->markTestSkipped("Features not implemented fully");
$spreadsheet = $this->loadOOCalcTest(); $spreadsheet = $this->loadOOCalcTestFile();
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
$hyperlink = $firstSheet->getCell("A29"); $hyperlink = $firstSheet->getCell("A29");

Binary file not shown.