commit
71a6f6a937
@ -118,8 +118,7 @@ class CellValueFormatter
|
|||||||
// inline strings are formatted this way:
|
// inline strings are formatted this way:
|
||||||
// <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
|
// <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
|
||||||
$tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
|
$tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
|
||||||
$escapedCellValue = trim($tNode->nodeValue);
|
$cellValue = $this->escaper->unescape($tNode->nodeValue);
|
||||||
$cellValue = $this->escaper->unescape($escapedCellValue);
|
|
||||||
return $cellValue;
|
return $cellValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,6 +384,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://github.com/box/spout/issues/195
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReaderShouldNotTrimCellValues()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_untrimmed_strings.csv');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['A'],
|
||||||
|
[' A '],
|
||||||
|
["\n\tA\n\t"],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param string|void $fieldDelimiter
|
* @param string|void $fieldDelimiter
|
||||||
|
@ -419,6 +419,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
$this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://github.com/box/spout/issues/195
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReaderShouldNotTrimCellValues()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_untrimmed_strings.ods');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['A'],
|
||||||
|
[' A '],
|
||||||
|
["\n\tA\n\t"],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @return array All the read rows the given file
|
* @return array All the read rows the given file
|
||||||
|
@ -123,4 +123,46 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedFormattedValue, $formattedValue);
|
$this->assertEquals($expectedFormattedValue, $formattedValue);
|
||||||
$this->assertEquals($expectedType, gettype($formattedValue));
|
$this->assertEquals($expectedType, gettype($formattedValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function dataProviderForTestFormatStringCellValue()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['A', 'A'],
|
||||||
|
[' A ', ' A '],
|
||||||
|
["\n\tA\n\t", "\n\tA\n\t"],
|
||||||
|
[' ', ' '],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProviderForTestFormatStringCellValue
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @param string $expectedFormattedValue
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFormatInlineStringCellValue($value, $expectedFormattedValue)
|
||||||
|
{
|
||||||
|
$nodeListMock = $this->getMockBuilder('DOMNodeList')->disableOriginalConstructor()->getMock();
|
||||||
|
$nodeListMock
|
||||||
|
->expects($this->atLeastOnce())
|
||||||
|
->method('item')
|
||||||
|
->with(0)
|
||||||
|
->will($this->returnValue((object)['nodeValue' => $value]));
|
||||||
|
|
||||||
|
$nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock();
|
||||||
|
$nodeMock
|
||||||
|
->expects($this->atLeastOnce())
|
||||||
|
->method('getElementsByTagName')
|
||||||
|
->with(CellValueFormatter::XML_NODE_INLINE_STRING_VALUE)
|
||||||
|
->will($this->returnValue($nodeListMock));
|
||||||
|
|
||||||
|
$formatter = new CellValueFormatter(null, null);
|
||||||
|
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatInlineStringCellValue', $nodeMock);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedFormattedValue, $formattedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,6 +461,24 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://github.com/box/spout/issues/195
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReaderShouldNotTrimCellValues()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('sheet_with_untrimmed_inline_strings.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['A'],
|
||||||
|
[' A '],
|
||||||
|
["\n\tA\n\t"],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @return array All the read rows the given file
|
* @return array All the read rows the given file
|
||||||
|
5
tests/resources/csv/sheet_with_untrimmed_strings.csv
Normal file
5
tests/resources/csv/sheet_with_untrimmed_strings.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
A
|
||||||
|
" A "
|
||||||
|
"
|
||||||
|
A
|
||||||
|
"
|
|
BIN
tests/resources/ods/sheet_with_untrimmed_strings.ods
Normal file
BIN
tests/resources/ods/sheet_with_untrimmed_strings.ods
Normal file
Binary file not shown.
BIN
tests/resources/xlsx/sheet_with_untrimmed_inline_strings.xlsx
Normal file
BIN
tests/resources/xlsx/sheet_with_untrimmed_inline_strings.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user