Inline strings can contain multiple value nodes

We were working under the assumption that XLSX's inline strings only had a single value node (`<t>`). This is incorrect.
To get the actual value of an inline string node, we need to concatenate the value of all its child nodes.
This commit is contained in:
Adrien Loison committed 2021-05-14 21:32:54 +02:00
1 parent 69eeeff478
commit 782be55524
5 files changed
+30 -7

No files matched your search

@@ -186,18 +186,22 @@ class CellValueFormatterTest extends TestCase
public function testFormatInlineStringCellValue($value, $expectedFormattedValue)
{
$nodeListMock = $this->createMock(\DOMNodeList::class);
$nodeListMock
->expects($this->atLeastOnce())
->method('count')
->willReturn(1);
$nodeListMock
->expects($this->atLeastOnce())
->method('item')
->with(0)
->will($this->returnValue((object) ['nodeValue' => $value]));
->willReturn((object) ['nodeValue' => $value]);
$nodeMock = $this->createMock(\DOMElement::class);
$nodeMock
->expects($this->atLeastOnce())
->method('getElementsByTagName')
->with(CellValueFormatter::XML_NODE_INLINE_STRING_VALUE)
->will($this->returnValue($nodeListMock));
->willReturn($nodeListMock);
$formatter = new CellValueFormatter(null, null, false, false, new Escaper\XLSX());
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatInlineStringCellValue', $nodeMock);
+13
View File
@@ -72,6 +72,19 @@ class ReaderTest extends TestCase
}
}
/**
* @return void
*/
public function testReadShouldSupportInlineStringsWithMultipleValueNodes()
{
$allRows = $this->getAllRowsForFile('sheet_with_multiple_value_nodes_in_inline_strings.xlsx');
$expectedRows = [
['VALUE 1 VALUE 2 VALUE 3 VALUE 4', 's1 - B1'],
];
$this->assertEquals($expectedRows, $allRows);
}
/**
* @return void
*/