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
|
|
|
$msg = null; |
19
|
|
|
$edmx = new Edmx(); |
20
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
21
|
|
|
$this->assertNull($msg); |
22
|
|
|
$ymlDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . "MetadataV3" . DIRECTORY_SEPARATOR . "JMSmetadata"; |
23
|
|
|
$serializer = |
24
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
25
|
|
|
->addMetadataDir($ymlDir) |
26
|
|
|
->build(); |
27
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
28
|
|
|
$this->V3MetadataAgainstXSD($d); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function V3MetadataAgainstXSD($data) |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
$xml = new \DOMDocument(); |
35
|
|
|
$xml->loadXML($data); |
36
|
|
|
$xml->schemaValidate(dirname(__DIR__) . DIRECTORY_SEPARATOR . "xsd" . DIRECTORY_SEPARATOR . "/Microsoft.Data.Entity.Design.Edmx_3.xsd"); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testWithSingleEntitySerializeOk() |
40
|
|
|
{ |
41
|
|
|
$msg = null; |
42
|
|
|
$NewEntity = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType(); |
43
|
|
|
$NewEntity->setName("simpleEntityType"); |
44
|
|
|
$this->assertTrue($NewEntity->isOK($msg), $msg); |
45
|
|
|
$this->assertNull($msg); |
46
|
|
|
$edmx = new Edmx(); |
47
|
|
|
$edmx->getDataServices()[0]->addToEntityType($NewEntity); |
48
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
49
|
|
|
$this->assertNull($msg); |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
$ymlDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . "MetadataV3" . DIRECTORY_SEPARATOR . "JMSmetadata"; |
53
|
|
|
$serializer = |
54
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
55
|
|
|
->addMetadataDir($ymlDir) |
56
|
|
|
->build(); |
57
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
58
|
|
|
$this->V3MetadataAgainstXSD($d); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testWithSingleEntityWithPropertiesSerializeOk() |
62
|
|
|
{ |
63
|
|
|
$msg = null; |
64
|
|
|
$NewProperty = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType(); |
65
|
|
|
$this->assertTrue($NewProperty->isOK($msg), $msg); |
66
|
|
|
$this->assertNull($msg); |
67
|
|
|
|
68
|
|
|
$NewEntity = new \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType(); |
69
|
|
|
$NewEntity->setName("simpleEntityType"); |
70
|
|
|
$this->assertTrue($NewEntity->isOK($msg), $msg); |
71
|
|
|
$this->assertNull($msg); |
72
|
|
|
$edmx = new Edmx(); |
73
|
|
|
$edmx->getDataServices()[0]->addToEntityType($NewEntity); |
74
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
75
|
|
|
$this->assertNull($msg); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$ymlDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . "MetadataV3" . DIRECTORY_SEPARATOR . "JMSmetadata"; |
79
|
|
|
$serializer = |
80
|
|
|
\JMS\Serializer\SerializerBuilder::create() |
81
|
|
|
->addMetadataDir($ymlDir) |
82
|
|
|
->build(); |
83
|
|
|
$d = $serializer->serialize($edmx, "xml"); |
84
|
|
|
$this->V3MetadataAgainstXSD($d); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|