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