|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\Edmx; |
|
6
|
|
|
|
|
7
|
|
|
class EdmxTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testIsOKAtDefault() |
|
10
|
|
|
{ |
|
11
|
|
|
$msg = null; |
|
12
|
|
|
$edmx = new Edmx(); |
|
13
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testDefaultSerializeOk() |
|
17
|
|
|
{ |
|
18
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
19
|
|
|
$msg = null; |
|
20
|
|
|
$edmx = new Edmx(); |
|
21
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
|
22
|
|
|
$this->assertNull($msg); |
|
23
|
|
|
$ymlDir = dirname(__DIR__) . $ds . "src" . $ds . "MetadataV3" . $ds . "JMSmetadata"; |
|
24
|
|
|
$serializer = |
|
25
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
|
26
|
|
|
->addMetadataDir($ymlDir) |
|
27
|
|
|
->build(); |
|
28
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
|
29
|
|
|
$this->v3MetadataAgainstXSD($d); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function v3MetadataAgainstXSD($data) |
|
33
|
|
|
{ |
|
34
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
35
|
|
|
$xml = new \DOMDocument(); |
|
36
|
|
|
$xml->loadXML($data); |
|
37
|
|
|
$xml->schemaValidate(dirname(__DIR__) . $ds . "xsd" . $ds . "/Microsoft.Data.Entity.Design.Edmx_3.xsd"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testWithSingleEntitySerializeOk() |
|
41
|
|
|
{ |
|
42
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
43
|
|
|
$msg = null; |
|
44
|
|
|
$NewEntity = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType(); |
|
45
|
|
|
$NewEntity->setName("simpleEntityType"); |
|
46
|
|
|
$this->assertTrue($NewEntity->isOK($msg), $msg); |
|
47
|
|
|
$this->assertNull($msg); |
|
48
|
|
|
$edmx = new Edmx(); |
|
49
|
|
|
$edmx->getDataServices()[0]->addToEntityType($NewEntity); |
|
50
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
|
51
|
|
|
$this->assertNull($msg); |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$ymlDir = dirname(__DIR__) . $ds . "src" . $ds . "MetadataV3" . $ds . "JMSmetadata"; |
|
55
|
|
|
$serializer = |
|
56
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
|
57
|
|
|
->addMetadataDir($ymlDir) |
|
58
|
|
|
->build(); |
|
59
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
|
60
|
|
|
$this->v3MetadataAgainstXSD($d); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testWithSingleEntityWithPropertiesSerializeOk() |
|
64
|
|
|
{ |
|
65
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
66
|
|
|
$msg = null; |
|
67
|
|
|
$NewProperty = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType(); |
|
68
|
|
|
$this->assertTrue($NewProperty->isOK($msg), $msg); |
|
69
|
|
|
$this->assertNull($msg); |
|
70
|
|
|
|
|
71
|
|
|
$NewEntity = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType(); |
|
72
|
|
|
$NewEntity->setName("simpleEntityType"); |
|
73
|
|
|
$this->assertTrue($NewEntity->isOK($msg), $msg); |
|
74
|
|
|
$this->assertNull($msg); |
|
75
|
|
|
$edmx = new Edmx(); |
|
76
|
|
|
$edmx->getDataServices()[0]->addToEntityType($NewEntity); |
|
77
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
|
78
|
|
|
$this->assertNull($msg); |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
$ymlDir = dirname(__DIR__) . $ds . "src" . $ds . "MetadataV3" . $ds . "JMSmetadata"; |
|
82
|
|
|
$serializer = |
|
83
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
|
84
|
|
|
->addMetadataDir($ymlDir) |
|
85
|
|
|
->build(); |
|
86
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
|
87
|
|
|
$this->v3MetadataAgainstXSD($d); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|