XMLSchemaTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection;
  11. class XMLSchemaTest extends \PHPUnit_Framework_TestCase
  12. {
  13. static public function dataValidateSchemaFiles()
  14. {
  15. $schemaFiles = array();
  16. $di = new \DirectoryIterator(__DIR__."/Fixtures/config/xml");
  17. foreach ($di as $element) {
  18. if ($element->isFile() && strpos($element->getFilename(), ".xml") !== false) {
  19. $schemaFiles[] = array($element->getPathname());
  20. }
  21. }
  22. return $schemaFiles;
  23. }
  24. /**
  25. * @dataProvider dataValidateSchemaFiles
  26. * @param string $file
  27. */
  28. public function testValidateSchema($file)
  29. {
  30. $found = false;
  31. $dom = new \DOMDocument('1.0', 'UTF-8');
  32. $dom->load($file);
  33. $dbalElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config");
  34. if ($dbalElements->length) {
  35. $dbalDom = new \DOMDocument('1.0', 'UTF-8');
  36. $dbalNode = $dbalDom->importNode($dbalElements->item(0));
  37. $dbalDom->appendChild($dbalNode);
  38. $ret = $dbalDom->schemaValidate(__DIR__."/../../Resources/config/schema/doctrine-1.0.xsd");
  39. $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
  40. $found = true;
  41. }
  42. $ormElements = $dom->getElementsByTagNameNS("http://symfony.com/schema/dic/doctrine", "config");
  43. if ($ormElements->length) {
  44. $ormDom = new \DOMDocument('1.0', 'UTF-8');
  45. $ormNode = $ormDom->importNode($ormElements->item(0));
  46. $ormDom->appendChild($ormNode);
  47. $ret = $ormDom->schemaValidate(__DIR__."/../../Resources/config/schema/doctrine-1.0.xsd");
  48. $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
  49. $found = true;
  50. }
  51. $this->assertTrue($found, "Neither <doctrine:orm> nor <doctrine:dbal> elements found in given XML. Are namespaces configured correctly?");
  52. }
  53. }