Fix #195
This commit is contained in:
1 parent
b69e28050b
commit
6f0f7c9690
8 files changed
+100
-2
No files matched your search
@@ -384,6 +384,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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|void $fieldDelimiter
|
||||
|
||||
@@ -419,6 +419,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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
|
||||
* @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($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_strings.xlsx');
|
||||
|
||||
$expectedRows = [
|
||||
['A'],
|
||||
[' A '],
|
||||
["\n\tA\n\t"],
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return array All the read rows the given file
|
||||
|
||||
Reference in new issue
Block a user