Updates to 3rd party libraries

Add Dockerfile and specific docker-php.ini
This commit is contained in:
2018-08-28 21:27:13 -04:00
parent 9edd6c1c35
commit d52454d1bb
511 changed files with 45960 additions and 2739 deletions

View File

@ -0,0 +1,98 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods\Content;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Writer\Ods\Content;
use PHPUnit\Framework\TestCase;
class ContentTest extends TestCase
{
private $samplesPath = __DIR__ . '/../../../data/Writer/Ods';
/**
* @var string
*/
private $compatibilityMode;
protected function setUp()
{
parent::setUp();
$this->compatibilityMode = Functions::getCompatibilityMode();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
}
protected function tearDown()
{
parent::tearDown();
Functions::setCompatibilityMode($this->compatibilityMode);
}
public function testWriteEmptySpreadsheet()
{
$content = new Content(new Ods(new Spreadsheet()));
$xml = $content->write();
self::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->setCellValueExplicit(
'C2',
'=IF(A3, CONCATENATE(A1, " ", A2), CONCATENATE(A2, " ", A1))',
DataType::TYPE_FORMULA
); // Formula
$worksheet1->setCellValue('D2', Date::PHPToExcel(1488635026)); // Date
$worksheet1->getStyle('D2')
->getNumberFormat()
->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME);
// Styles
$worksheet1->getStyle('A1')->getFont()->setBold(true);
$worksheet1->getStyle('B1')->getFont()->setItalic(true);
$worksheet1->getStyle('C1')->getFont()->setName('Courier');
$worksheet1->getStyle('C1')->getFont()->setSize(14);
$worksheet1->getStyle('C1')->getFont()->setColor(new Color(Color::COLOR_BLUE));
$worksheet1->getStyle('C1')->getFill()->setFillType(Fill::FILL_SOLID);
$worksheet1->getStyle('C1')->getFill()->setStartColor(new Color(Color::COLOR_RED));
$worksheet1->getStyle('C1')->getFont()->setUnderline(Font::UNDERLINE_SINGLE);
$worksheet1->getStyle('C2')->getFont()->setUnderline(Font::UNDERLINE_DOUBLE);
$worksheet1->getStyle('D2')->getFont()->setUnderline(Font::UNDERLINE_NONE);
// Worksheet 2
$worksheet2 = $workbook->createSheet();
$worksheet2->setTitle('New Worksheet');
$worksheet2->setCellValue('A1', 2);
// Write
$content = new Content(new Ods($workbook));
$xml = $content->write();
self::assertXmlStringEqualsXmlFile($this->samplesPath . '/content-with-data.xml', $xml);
}
}

View File

@ -0,0 +1,143 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls\Workbook;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xls\Parser;
use PhpOffice\PhpSpreadsheet\Writer\Xls\Workbook;
use PHPUnit\Framework\TestCase;
class WorkbookTest extends TestCase
{
/**
* @var Workbook
*/
private $workbook;
protected function setUp()
{
$spreadsheet = new Spreadsheet();
$strTotal = 0;
$strUnique = 0;
$str_table = [];
$colors = [];
$parser = new Parser();
$this->workbook = new Workbook($spreadsheet, $strTotal, $strUnique, $str_table, $colors, $parser);
}
/**
* @dataProvider providerAddColor
*
* @param array $testColors
* @param array $expectedResult
*/
public function testAddColor(array $testColors, array $expectedResult)
{
$workbookReflection = new \ReflectionClass(Workbook::class);
$methodAddColor = $workbookReflection->getMethod('addColor');
$propertyPalette = $workbookReflection->getProperty('palette');
$methodAddColor->setAccessible(true);
$propertyPalette->setAccessible(true);
foreach ($testColors as $testColor) {
$methodAddColor->invoke($this->workbook, $testColor);
}
$palette = $propertyPalette->getValue($this->workbook);
self::assertEquals($expectedResult, $palette);
}
public function providerAddColor()
{
$this->setUp();
$workbookReflection = new \ReflectionClass(Workbook::class);
$propertyPalette = $workbookReflection->getProperty('palette');
$propertyPalette->setAccessible(true);
$palette = $propertyPalette->getValue($this->workbook);
$newColor1 = [0x00, 0x00, 0x01, 0x00];
$newColor2 = [0x00, 0x00, 0x02, 0x00];
$newColor3 = [0x00, 0x00, 0x03, 0x00];
// Add one new color
$paletteTestOne = $palette;
$paletteTestOne[8] = $newColor1;
// Add one new color + one existing color after index 8
$paletteTestTwo = $paletteTestOne;
// Add one new color + one existing color before index 9
$paletteTestThree = $paletteTestOne;
$paletteTestThree[9] = $palette[8];
// Add three new color
$paletteTestFour = $palette;
$paletteTestFour[8] = $newColor1;
$paletteTestFour[9] = $newColor2;
$paletteTestFour[10] = $newColor3;
// Add all existing color
$colorsAdd = array_map([$this, 'paletteToColor'], $palette);
$paletteTestFive = $palette;
// Add new color after all existing color
$colorsAddTwo = array_map([$this, 'paletteToColor'], $palette);
$colorsAddTwo[] = $this->paletteToColor($newColor1);
$paletteTestSix = $palette;
// Add one existing color
$paletteTestSeven = $palette;
// Add two existing color
$paletteTestHeight = $palette;
// Add last existing color and add one new color
$keyPalette = array_keys($palette);
$last = end($keyPalette);
$lastColor = $this->paletteToColor($palette[$last]);
$paletteTestNine = $palette;
return [
[[$this->paletteToColor($newColor1)], $paletteTestOne],
[[$this->paletteToColor($newColor1), $this->paletteToColor($palette[12])], $paletteTestTwo],
[[$this->paletteToColor($newColor1), $this->paletteToColor($palette[8])], $paletteTestThree],
[[$this->paletteToColor($newColor1), $this->paletteToColor($newColor2), $this->paletteToColor($newColor3)], $paletteTestFour],
[$colorsAdd, $paletteTestFive],
[$colorsAddTwo, $paletteTestSix],
[[$this->paletteToColor($palette[8])], $paletteTestSeven],
[[$this->paletteToColor($palette[25]), $this->paletteToColor($palette[10])], $paletteTestHeight],
[[$lastColor, $this->paletteToColor($newColor1)], $paletteTestNine],
];
}
/**
* Change palette color to rgb string.
*
* @param array $palette palette color
*
* @return string rgb string
*/
private function paletteToColor($palette)
{
return $this->right('00' . dechex((int) ($palette[0])), 2)
. $this->right('00' . dechex((int) ($palette[1])), 2)
. $this->right('00' . dechex((int) ($palette[2])), 2);
}
/**
* Return n right character in string.
*
* @param string $value text to get right character
* @param int $nbchar number of char at right of string
*
* @return string
*/
private function right($value, $nbchar)
{
return mb_substr($value, mb_strlen($value) - $nbchar, $nbchar);
}
}

View File

@ -0,0 +1,103 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;
use Exception;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase;
use ZipArchive;
class UnparsedDataTest extends TestCase
{
/**
* Test load and save Xlsx file with unparsed data (form elements, protected sheets, alternate contents, printer settings,..).
*/
public function testLoadSaveXlsxWithUnparsedData()
{
$sampleFilename = './data/Writer/XLSX/form_pass_print.xlsm';
$resultFilename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
Settings::setLibXmlLoaderOptions(null); // reset to default options
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$excel = $reader->load($sampleFilename);
$excel->getSheet(1)->setCellValue('B1', '222');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($excel);
$writer->save($resultFilename);
self::assertFileExists($resultFilename);
$resultZip = new ZipArchive();
$resultZip->open($resultFilename);
$resultContentTypesRaw = $resultZip->getFromName('[Content_Types].xml');
$resultControlPropRaw = $resultZip->getFromName('xl/ctrlProps/ctrlProp1.xml');
$resultDrawingRaw = $resultZip->getFromName('xl/drawings/drawing1.xml');
$resultVmlDrawingRaw = $resultZip->getFromName('xl/drawings/vmlDrawing1.vml');
$resultPrinterSettingsRaw = $resultZip->getFromName('xl/printerSettings/printerSettings1.bin');
$resultVbaProjectRaw = $resultZip->getFromName('xl/vbaProject.bin');
$resultWorkbookRaw = $resultZip->getFromName('xl/workbook.xml');
$resultSheet1RelsRaw = $resultZip->getFromName('xl/worksheets/_rels/sheet1.xml.rels');
$resultSheet1Raw = $resultZip->getFromName('xl/worksheets/sheet1.xml');
$resultSheet2Raw = $resultZip->getFromName('xl/worksheets/sheet2.xml');
if (false === $resultZip->close()) {
throw new Exception("Could not close zip file \"{$resultFilename}\".");
}
unlink($resultFilename);
// [Content_Types].xml
$this->assertTrue(strpos($resultContentTypesRaw, 'application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings') > 0, 'Content type for printerSettings not found!');
$this->assertTrue(strpos($resultContentTypesRaw, 'application/vnd.ms-office.vbaProject') > 0, 'Content type for VbaProject not found!');
$this->assertTrue(strpos($resultContentTypesRaw, 'application/vnd.ms-excel.controlproperties+xml') > 0, 'Content type for ctrlProp not found!');
// xl/ctrlProps/ctrlProp1.xml
$this->assertTrue(!empty($resultControlPropRaw), 'ctrlProp not found!');
// xl/drawings/drawing1.xml
$this->assertTrue(strpos($resultDrawingRaw, '<mc:AlternateContent') > 0, 'AlternateContent at drawing.xml not found!');
// xl/drawings/vmlDrawing1.vml
$this->assertTrue(!empty($resultVmlDrawingRaw), 'vmlDrawing not found!');
// xl/printerSettings/printerSettings1.bin
$this->assertTrue(!empty($resultPrinterSettingsRaw), 'printerSettings.bin not found!');
// xl/vbaProject.bin
$this->assertTrue(!empty($resultVbaProjectRaw), 'vbaProject.bin not found!');
// xl/workbook.xml
$xmlWorkbook = simplexml_load_string($resultWorkbookRaw, 'SimpleXMLElement', Settings::getLibXmlLoaderOptions());
if (!$xmlWorkbook->workbookProtection) {
$this->fail('workbook.xml/workbookProtection not found!');
} else {
$this->assertEquals($xmlWorkbook->workbookProtection['workbookPassword'], 'CBEB', 'workbook.xml/workbookProtection[workbookPassword] is wrong!');
$this->assertEquals($xmlWorkbook->workbookProtection['lockStructure'], 'true', 'workbook.xml/workbookProtection[lockStructure] is wrong!');
$this->assertEquals($xmlWorkbook->sheets->sheet[0]['state'], '', 'workbook.xml/sheets/sheet[0][state] is wrong!');
$this->assertEquals($xmlWorkbook->sheets->sheet[1]['state'], 'hidden', 'workbook.xml/sheets/sheet[1][state] is wrong!');
}
unset($xmlWorkbook);
// xl/worksheets/_rels/sheet1.xml.rels
$this->assertTrue(strpos($resultSheet1RelsRaw, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings') > 0, 'Sheet relation with printerSettings not found!');
$this->assertTrue(strpos($resultSheet1RelsRaw, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing') > 0, 'Sheet relation with vmlDrawing not found!');
$this->assertTrue(strpos($resultSheet1RelsRaw, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp') > 0, 'Sheet relation with ctrlProp not found!');
// xl/worksheets/sheet1.xml
$this->assertTrue(strpos($resultSheet1Raw, '<mc:AlternateContent') > 0, 'AlternateContent at sheet1.xml not found!');
$xmlWorksheet = simplexml_load_string($resultSheet1Raw, 'SimpleXMLElement', Settings::getLibXmlLoaderOptions());
$pageSetupAttributes = $xmlWorksheet->pageSetup->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$this->assertTrue(!empty($pageSetupAttributes['id']), 'sheet1.xml/pageSetup[r:id] not found!');
if (!$xmlWorksheet->sheetProtection) {
$this->fail('sheet1.xml/sheetProtection not found!');
} else {
$this->assertEquals($xmlWorksheet->sheetProtection['password'], 'CBEB', 'sheet1.xml/sheetProtection[password] is wrong!');
$this->assertEquals($xmlWorksheet->sheetProtection['sheet'], 'true', 'sheet1.xml/sheetProtection[sheet] is wrong!');
$this->assertEquals($xmlWorksheet->sheetProtection['objects'], 'true', 'sheet1.xml/sheetProtection[objects] is wrong!');
$this->assertEquals($xmlWorksheet->sheetProtection['scenarios'], 'true', 'sheet1.xml/sheetProtection[scenarios] is wrong!');
}
unset($xmlWorksheet);
// xl/worksheets/sheet2.xml
$this->assertTrue(!empty($resultSheet2Raw), 'sheet2.xml not found!');
}
}