XsdTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Data\Test\Unit\Argument;
  7. class XsdTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * Path to xsd schema file for validating argument types
  11. * @var string
  12. */
  13. protected $_typesXsdSchema;
  14. /**
  15. * @var \Magento\Framework\TestFramework\Unit\Utility\XsdValidator
  16. */
  17. protected $_xsdValidator;
  18. protected function setUp()
  19. {
  20. if (!function_exists('libxml_set_external_entity_loader')) {
  21. $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
  22. }
  23. $this->_typesXsdSchema = __DIR__ . "/_files/types_schema.xsd";
  24. $this->_xsdValidator = new \Magento\Framework\TestFramework\Unit\Utility\XsdValidator();
  25. }
  26. /**
  27. * @param string $xmlString
  28. * @param array $expectedError
  29. * @dataProvider schemaCorrectlyIdentifiesInvalidTypesXmlDataProvider
  30. */
  31. public function testSchemaCorrectlyIdentifiesInvalidTypesXml($xmlString, $expectedError)
  32. {
  33. $actualError = $this->_xsdValidator->validate($this->_typesXsdSchema, $xmlString);
  34. $this->assertEquals($expectedError, $actualError);
  35. }
  36. /**
  37. * Data provider with invalid type declaration
  38. *
  39. * @return array
  40. */
  41. public function schemaCorrectlyIdentifiesInvalidTypesXmlDataProvider()
  42. {
  43. return include __DIR__ . '/_files/typesInvalidArray.php';
  44. }
  45. public function testSchemaCorrectlyIdentifiesValidXml()
  46. {
  47. $xmlString = file_get_contents(__DIR__ . '/_files/types_valid.xml');
  48. $actualResult = $this->_xsdValidator->validate($this->_typesXsdSchema, $xmlString);
  49. $this->assertEmpty($actualResult, join("\n", $actualResult));
  50. }
  51. }