1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\IsOK; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataManager; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer; |
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\Schema; |
9
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAssociationType; |
10
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypePropertyType; |
11
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TComplexTypeType; |
12
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType; |
13
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityTypeType; |
14
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReturnTypeType; |
15
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionType; |
16
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType; |
17
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTextType; |
18
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edmx\Edmx; |
19
|
|
|
use Mockery as m; |
20
|
|
|
|
21
|
|
|
class MetadataManagerNavigationTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
public function testEntitysAndPropertiesAndNavigationPropertiesAndRoleDIRECTION() |
24
|
|
|
{ |
25
|
|
|
$msg = null; |
26
|
|
|
$metadataManager = new MetadataManager(); |
27
|
|
|
$result = null; |
28
|
|
|
|
29
|
|
|
list($CategoryType, $result) = $metadataManager->addEntityType("Category"); |
30
|
|
|
$this->assertNotFalse($CategoryType, "Etype is false not type " . $metadataManager->getLastError()); |
31
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, "CategoryID", "Int32", null, false, true, "Identity"); |
32
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, "CategoryName", "String"); |
33
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, "Description", "String"); |
34
|
|
|
$metadataManager->addPropertyToEntityType($CategoryType, "Picture", "Binary"); |
35
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
36
|
|
|
|
37
|
|
|
list($CustomerDemographicType, $result) = $metadataManager->addEntityType("CustomerDemographic"); |
38
|
|
|
$metadataManager->addPropertyToEntityType($CustomerDemographicType, "CustomerTypeID", "String", null, false, true); |
|
|
|
|
39
|
|
|
$metadataManager->addPropertyToEntityType($CustomerDemographicType, "CustomerDesc", "String"); |
|
|
|
|
40
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
41
|
|
|
|
42
|
|
|
list($CustomerType, $result) = $metadataManager->addEntityType("Customer"); |
43
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "CustomerID", "String", null, false, true); |
|
|
|
|
44
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "CompanyName", "String"); |
|
|
|
|
45
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "ContactName", "String"); |
|
|
|
|
46
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "ContactTitle", "String"); |
|
|
|
|
47
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "Address", "String"); |
|
|
|
|
48
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "City", "String"); |
|
|
|
|
49
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "Region", "String"); |
|
|
|
|
50
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "PostalCode", "String"); |
|
|
|
|
51
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "Country", "String"); |
|
|
|
|
52
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "Phone", "String"); |
|
|
|
|
53
|
|
|
$metadataManager->addPropertyToEntityType($CustomerType, "Fax", "String"); |
|
|
|
|
54
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
55
|
|
|
|
56
|
|
|
list($EmployeeType, $result) = $metadataManager->addEntityType("Employee"); |
57
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "EmployeeID", "Int32", null, false, true, "Identity"); |
|
|
|
|
58
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "LastName", "String"); |
|
|
|
|
59
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "FirstName", "String"); |
|
|
|
|
60
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Title", "String"); |
|
|
|
|
61
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "TitleOfCourtesy", "String"); |
|
|
|
|
62
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "BirthDate", "DateTime"); |
|
|
|
|
63
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "HireDate", "DateTime"); |
|
|
|
|
64
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Address", "String"); |
|
|
|
|
65
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "City", "String"); |
|
|
|
|
66
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Region", "String"); |
|
|
|
|
67
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "PostalCode", "String"); |
|
|
|
|
68
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Country", "String"); |
|
|
|
|
69
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "HomePhone", "String"); |
|
|
|
|
70
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Extension", "String"); |
|
|
|
|
71
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Photo", "Binary"); |
|
|
|
|
72
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "Notes", "String"); |
|
|
|
|
73
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "ReportsTo", "Int32"); |
|
|
|
|
74
|
|
|
$metadataManager->addPropertyToEntityType($EmployeeType, "PhotoPath", "String"); |
|
|
|
|
75
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
76
|
|
|
|
77
|
|
|
list($Order_DetailType, $result) = $metadataManager->addEntityType("Order_Detail"); |
78
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, "OrderID", "Int32", null, false, true); |
|
|
|
|
79
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, "ProductID", "Int32", null, false, true); |
|
|
|
|
80
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, "UnitPrice", "Decimal"); |
|
|
|
|
81
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, "Quantity", "Int16"); |
|
|
|
|
82
|
|
|
$metadataManager->addPropertyToEntityType($Order_DetailType, "Discount", "Single"); |
|
|
|
|
83
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
84
|
|
|
|
85
|
|
|
list($OrderType, $result) = $metadataManager->addEntityType("Order"); |
86
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "OrderID", "Int32", null, false, true, "Identity"); |
|
|
|
|
87
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "CustomerID", "String"); |
|
|
|
|
88
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "EmployeeID", "Int32"); |
|
|
|
|
89
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "OrderDate", "DateTime"); |
|
|
|
|
90
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "RequiredDate", "DateTime"); |
|
|
|
|
91
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShippedDate", "DateTime"); |
|
|
|
|
92
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipVia", "DateTime"); |
|
|
|
|
93
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "Freight", "Decimal"); |
|
|
|
|
94
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipName", "String"); |
|
|
|
|
95
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipAddress", "String"); |
|
|
|
|
96
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipCity", "String"); |
|
|
|
|
97
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipRegion", "String"); |
|
|
|
|
98
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipPostalCode", "String"); |
|
|
|
|
99
|
|
|
$metadataManager->addPropertyToEntityType($OrderType, "ShipCountry", "String"); |
|
|
|
|
100
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
101
|
|
|
|
102
|
|
|
list($ProductType, $result) = $metadataManager->addEntityType("Product"); |
103
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "ProductID", "Int32", null, false, true, "Identity"); |
|
|
|
|
104
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "ProductName", "String"); |
|
|
|
|
105
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "SupplierID", "Int32"); |
|
|
|
|
106
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "CategoryID", "Int32"); |
|
|
|
|
107
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "QuantityPerUnit", "String"); |
|
|
|
|
108
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "UnitPrice", "Decimal"); |
|
|
|
|
109
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "UnitsInStock", "Int16"); |
|
|
|
|
110
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "UnitsOnOrder", "Int16"); |
|
|
|
|
111
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "ReorderLevel", "Int16"); |
|
|
|
|
112
|
|
|
$metadataManager->addPropertyToEntityType($ProductType, "Discontinued", "Boolean"); |
|
|
|
|
113
|
|
|
$this->assertTrue($metadataManager->getEdmx()->isOK($msg), $msg); |
114
|
|
|
|
115
|
|
|
$expectedRelation = "Data.Category_Products_Product_Category"; |
116
|
|
|
list($principalNav, ) = $metadataManager->addNavigationPropertyToEntityType( |
117
|
|
|
$CategoryType, "*", "Products", $ProductType, "1", "Category", ["CategoryID"], ["CategoryID"] |
|
|
|
|
118
|
|
|
); |
119
|
|
|
$this->assertEquals($expectedRelation, $principalNav->getRelationship()); |
120
|
|
|
$metadataManager->addNavigationPropertyToEntityType( |
121
|
|
|
$Order_DetailType, "1", "Order", $ProductType, "*", "Order_Details", ["OrderID"], ["CategoryID"] |
|
|
|
|
122
|
|
|
); |
123
|
|
|
// <NavigationProperty Name="Order_Details" Relationship="NorthwindModel.FK_Order_Details_Products" ToRole="Order_Details" FromRole="Products"/> |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
$msg = null; |
127
|
|
|
$edmx = $metadataManager->getEdmx(); |
128
|
|
|
$this->assertTrue($edmx->isOK($msg), $msg); |
129
|
|
|
$this->assertNull($msg); |
130
|
|
|
|
131
|
|
|
$d = $metadataManager->getEdmxXML(); |
132
|
|
|
$CategoryEType = null; |
133
|
|
|
$dom = new \DOMDocument(); |
134
|
|
|
$dom->loadXML($d); |
135
|
|
|
foreach ($dom->getElementsByTagName("EntityType") as $eType) { |
136
|
|
|
foreach ($eType->attributes as $aType) { |
137
|
|
|
if ($aType->name == "Name" && $aType->value == "Category") { |
138
|
|
|
$CategoryEType = $eType; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
$this->assertNotNull($CategoryEType, "Count not find the category entity Type to get the navigation property"); |
143
|
|
|
$this->assertEquals("Products", $CategoryEType->getElementsByTagName("NavigationProperty")[0]->getAttribute("Name"), "the product relationship was not found"); |
144
|
|
|
$ProductRelationship = $CategoryEType->getElementsByTagName("NavigationProperty")[0]->getAttribute("Relationship"); |
145
|
|
|
$ProductToRole = $CategoryEType->getElementsByTagName("NavigationProperty")[0]->getAttribute("ToRole"); |
146
|
|
|
$ProductFromRole = $CategoryEType->getElementsByTagName("NavigationProperty")[0]->getAttribute("FromRole"); |
147
|
|
|
$associationType = null; |
148
|
|
|
foreach ($dom->getElementsByTagName("Association") as $eType) { |
149
|
|
|
foreach ($eType->attributes as $aType) { |
150
|
|
|
if ($aType->name == "Name" && 'Data.'.$aType->value == $ProductRelationship) { |
151
|
|
|
$associationType = $eType; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
$this->assertNotNull($associationType, "count not find a matching assocation for the category"); |
156
|
|
|
foreach ($associationType->getElementsByTagName("End") as $childNode) { |
157
|
|
|
if ($childNode->getAttribute("Role") == $ProductToRole) { |
158
|
|
|
$this->assertEquals("Data.Product", $childNode->getAttribute("Type")); |
159
|
|
|
$this->assertEquals("1", $childNode->getAttribute("Multiplicity")); |
160
|
|
|
} elseif ($childNode->getAttribute("Role") == $ProductFromRole) { |
161
|
|
|
$this->assertEquals("Data.Category", $childNode->getAttribute("Type")); |
162
|
|
|
$this->assertEquals("*", $childNode->getAttribute("Multiplicity")); |
163
|
|
|
} else { |
164
|
|
|
throw new \Exception("Some how we ended up with an end role that was not in the NavigationProperty"); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.