forked from OpenMage/magento-lts
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic unitTest for xml validation (OpenMage#2304)
- Loading branch information
1 parent
1a21e8d
commit 3a1deaf
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace OpenMage\Tests\Unit\Base; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class XmlFileLoadingTest extends TestCase | ||
{ | ||
|
||
public function provideXmlFiles(): array | ||
{ | ||
$root = realpath(__DIR__ . '/../../../../') . '/'; | ||
|
||
$result = []; | ||
$result[] = [ | ||
$root . 'lib/Zend/Locale/Data/es_419.xml' | ||
]; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider provideXmlFiles | ||
* @param $filepath | ||
* @return void | ||
*/ | ||
public function testFileLoading($filepath): void | ||
{ | ||
//$simplexml = new \SimpleXMLElement(file_get_contents($filepath)); | ||
$simplexml = simplexml_load_file( | ||
$filepath, | ||
null, | ||
LIBXML_PEDANTIC //not needed by OpenMage, but good to test more strictly | ||
); | ||
$this->assertNotEmpty($simplexml->asXML()); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider provideXmlFiles | ||
* @param $filepath | ||
* @return void | ||
*/ | ||
public function testXmlReaderIsValid($filepath): void | ||
{ | ||
$xml = \XMLReader::open($filepath); | ||
$xml->setParserProperty(\XMLReader::VALIDATE, true); | ||
$this->assertTrue($xml->isValid()); | ||
} | ||
} |