2015-04-29 21:23:14 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
2015-04-29 21:23:14 +00:00
|
|
|
|
2017-09-18 08:03:32 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
2017-09-20 05:20:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xml;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2018-01-14 07:59:34 +00:00
|
|
|
class XmlTest extends TestCase
|
2015-04-29 21:23:14 +00:00
|
|
|
{
|
2017-09-20 05:20:12 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerInvalidSimpleXML
|
|
|
|
*
|
|
|
|
* @param $filename
|
|
|
|
*/
|
|
|
|
public function testInvalidSimpleXML($filename)
|
|
|
|
{
|
2018-01-28 06:59:38 +00:00
|
|
|
$this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class);
|
|
|
|
|
2017-09-20 05:20:12 +00:00
|
|
|
$xmlReader = new Xml();
|
|
|
|
$xmlReader->trySimpleXMLLoadString($filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerInvalidSimpleXML()
|
|
|
|
{
|
|
|
|
$tests = [];
|
2018-01-14 07:59:34 +00:00
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/Xml/XEETestInvalidSimpleXML*.xml') as $file) {
|
2016-10-23 18:16:36 +00:00
|
|
|
$tests[basename($file)] = [realpath($file)];
|
2015-04-29 21:23:14 +00:00
|
|
|
}
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-04-29 21:23:14 +00:00
|
|
|
return $tests;
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
|
2017-09-18 08:03:32 +00:00
|
|
|
/**
|
|
|
|
* Check if it can read XML Hyperlink correctly.
|
|
|
|
*/
|
|
|
|
public function testReadHyperlinks()
|
|
|
|
{
|
2018-01-14 07:59:34 +00:00
|
|
|
$reader = new Xml();
|
|
|
|
$spreadsheet = $reader->load('../samples/templates/Excel2003XMLTest.xml');
|
2017-09-18 08:03:32 +00:00
|
|
|
$firstSheet = $spreadsheet->getSheet(0);
|
|
|
|
|
|
|
|
$hyperlink = $firstSheet->getCell('L1');
|
|
|
|
|
|
|
|
self::assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
|
|
|
|
self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
|
2018-10-23 11:26:25 +00:00
|
|
|
self::assertEquals('https://phpspreadsheet.readthedocs.io', $hyperlink->getHyperlink()->getUrl());
|
2017-09-18 08:03:32 +00:00
|
|
|
}
|
2018-01-14 07:59:34 +00:00
|
|
|
|
|
|
|
public function testReadWithoutStyle()
|
|
|
|
{
|
|
|
|
$reader = new Xml();
|
|
|
|
$spreadsheet = $reader->load(__DIR__ . '/../../data/Reader/Xml/WithoutStyle.xml');
|
|
|
|
self::assertSame('Test String 1', $spreadsheet->getActiveSheet()->getCell('A1')->getValue());
|
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
}
|