PhpSpreadsheet/tests/PhpSpreadsheetTests/Reader/CsvTest.php
Gabriel Caruso aed27a0bed Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase (#271)
Use the `PHPUnit\Framework\TestCase` notation instead of `PHPUnit_Framework_TestCase` while extending our TestCases. This will help us migrate to PHPUnit 6, that [no longer support snake case class names](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-6.0.md#changed-1).
2017-11-09 00:48:01 +09:00

45 lines
1.6 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader;
use PhpOffice\PhpSpreadsheet\Reader\Csv as ReaderCsv;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv as WriterCsv;
use PHPUnit\Framework\TestCase;
class CsvTest extends TestCase
{
public function testEnclosure()
{
$value = '<img alt="" src="http://example.com/image.jpg" />';
$filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet');
// Write temp file with value
$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()->getCell('A1')->setValue($value);
$writer = new WriterCsv($spreadsheet);
$writer->save($filename);
// Read written file
$reader = new ReaderCsv();
$reloadedSpreadsheet = $reader->load($filename);
$actual = $reloadedSpreadsheet->getActiveSheet()->getCell('A1')->getCalculatedValue();
self::assertSame($value, $actual, 'should be able to write and read strings with multiples quotes');
}
public function testDelimiterDetection()
{
$reader = new ReaderCsv();
self::assertNull($reader->getDelimiter());
$filename = __DIR__ . '/../../data/Reader/CSV/semicolon_separated.csv';
$spreadsheet = $reader->load($filename);
self::assertSame(';', $reader->getDelimiter(), 'should be able to infer the delimiter');
$actual = $spreadsheet->getActiveSheet()->getCell('C2')->getValue();
self::assertSame('25,5', $actual, 'should be able to retrieve values with commas');
}
}