1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hautzi\SystemMailBundle\Tests\SystemMailer\XML; |
4
|
|
|
|
5
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\XML\XsdValidator; |
6
|
|
|
|
7
|
|
|
class XsdValidatorTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
protected $xsd = <<<EOL |
10
|
|
|
<?xml version="1.0"?> |
11
|
|
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |
12
|
|
|
targetNamespace="http://christoph-hautzinger.de/schema/system-mail-bundle" |
13
|
|
|
xmlns="http://christoph-hautzinger.de/schema/system-mail-bundle" |
14
|
|
|
elementFormDefault="qualified"> |
15
|
|
|
|
16
|
|
|
<xs:element name="email"> |
17
|
|
|
<xs:complexType> |
18
|
|
|
<xs:sequence> |
19
|
|
|
<xs:element name="to" type="xs:string"/> |
20
|
|
|
<xs:element name="from" type="xs:string"/> |
21
|
|
|
</xs:sequence> |
22
|
|
|
</xs:complexType> |
23
|
|
|
</xs:element> |
24
|
|
|
|
25
|
|
|
</xs:schema> |
26
|
|
|
EOL; |
27
|
|
|
|
28
|
|
|
protected $validXml = <<<EOL |
29
|
|
|
<?xml version="1.0"?> |
30
|
|
|
<email xmlns="http://christoph-hautzinger.de/schema/system-mail-bundle" |
31
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
32
|
|
|
xsi:schemaLocation="http://christoph-hautzinger.de/schema/system-mail-bundle http://christoph-hautzinger.de/schema/system-mail-bundle/email-1.0.xsd"> |
33
|
|
|
<to>hautzi</to> |
34
|
|
|
<from>not-hautzi</from> |
35
|
|
|
</email> |
36
|
|
|
EOL; |
37
|
|
|
|
38
|
|
|
protected $invalidXml = <<<EOL |
39
|
|
|
<?xml version="1.0"?> |
40
|
|
|
<email xmlns="http://christoph-hautzinger.de/schema/system-mail-bundle" |
41
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
42
|
|
|
xsi:schemaLocation="http://christoph-hautzinger.de/schema/system-mail-bundle http://christoph-hautzinger.de/schema/system-mail-bundle/email-1.0.xsd"> |
43
|
|
|
<message>hautzi</message> |
44
|
|
|
<from>not-hautzi</from> |
45
|
|
|
</email> |
46
|
|
|
EOL; |
47
|
|
|
|
48
|
|
|
protected $tmpXsdFile; |
49
|
|
|
|
50
|
|
|
protected function setUp() |
51
|
|
|
{ |
52
|
|
|
$this->tmpXsdFile = tempnam('/tmp', 'FOO'); |
53
|
|
|
file_put_contents($this->tmpXsdFile, $this->xsd); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function tearDown() |
57
|
|
|
{ |
58
|
|
|
unlink($this->tmpXsdFile); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testValidationSuccess() |
63
|
|
|
{ |
64
|
|
|
$xsd = new XsdValidator(); |
65
|
|
|
|
66
|
|
|
$this->assertTrue($xsd->validate($this->validXml, $this->tmpXsdFile)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @expectedException \Hautzi\SystemMailBundle\SystemMailer\XML\XsdValidationException |
71
|
|
|
*/ |
72
|
|
|
public function testValidationFailsThrowsException() |
73
|
|
|
{ |
74
|
|
|
$xsd = new XsdValidator(); |
75
|
|
|
|
76
|
|
|
$xsd->validate($this->invalidXml, $this->tmpXsdFile); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|