@@ -73,4 +73,109 @@ public function testInheritGeolocation()
73
73
$ this ->string ($ location3 ->fields ['longitude ' ])->isEqualTo ('2.1734 ' );
74
74
$ this ->string ($ location3 ->fields ['altitude ' ])->isEqualTo ('39 ' );
75
75
}
76
+
77
+ public function testImportExternal ()
78
+ {
79
+ $ locations_id = \Dropdown::importExternal ('Location ' , 'testImportExternal_1 ' , getItemByTypeName ('Entity ' , '_test_root_entity ' , true ));
80
+ $ this ->integer ((int ) $ locations_id )->isGreaterThan (0 );
81
+ // Verify that the location was created
82
+ $ location = new \Location ();
83
+ $ location ->getFromDB ($ locations_id );
84
+ $ this ->string ($ location ->fields ['name ' ])->isEqualTo ('testImportExternal_1 ' );
85
+
86
+ // Try importing a location as a child of the location we just created
87
+ $ locations_id_2 = \Dropdown::importExternal ('Location ' , 'testImportExternal_2 ' , getItemByTypeName ('Entity ' , '_test_root_entity ' , true ), [
88
+ 'locations_id ' => $ locations_id
89
+ ]);
90
+ $ this ->integer ((int ) $ locations_id_2 )->isGreaterThan (0 );
91
+ // Verify that the location was created
92
+ $ location = new \Location ();
93
+ $ location ->getFromDB ($ locations_id_2 );
94
+ $ this ->string ($ location ->fields ['name ' ])->isEqualTo ('testImportExternal_2 ' );
95
+ // Verify that the location is a child of the location we just created
96
+ $ this ->integer ($ location ->fields ['locations_id ' ])->isEqualTo ($ locations_id );
97
+ }
98
+
99
+ public function testFindIDByName ()
100
+ {
101
+ $ entities_id = getItemByTypeName ('Entity ' , '_test_root_entity ' , true );
102
+
103
+ // Create a location
104
+ $ location = new \Location ();
105
+ $ location_id = $ location ->add ([
106
+ 'name ' => 'testFindIDByName_1 ' ,
107
+ 'entities_id ' => $ entities_id ,
108
+ ]);
109
+ $ this ->integer ((int ) $ location_id )->isGreaterThan (0 );
110
+
111
+ // Find the location by name
112
+ $ params = [
113
+ 'name ' => 'testFindIDByName_1 ' ,
114
+ 'entities_id ' => $ entities_id ,
115
+ ];
116
+ $ found_location_id = $ location ->findID ($ params );
117
+ $ this ->integer ((int ) $ found_location_id )->isEqualTo ($ location_id );
118
+
119
+ // Add child location
120
+ $ location_id_2 = $ location ->add ([
121
+ 'locations_id ' => $ location_id ,
122
+ 'name ' => 'testFindIDByName_2 ' ,
123
+ 'entities_id ' => $ entities_id ,
124
+ ]);
125
+ $ this ->integer ((int ) $ location_id_2 )->isGreaterThan (0 );
126
+
127
+ // Find the location by name (and locations_id)
128
+ $ params = [
129
+ 'name ' => 'testFindIDByName_2 ' ,
130
+ 'locations_id ' => $ location_id ,
131
+ 'entities_id ' => $ entities_id ,
132
+ ];
133
+ $ found_location_id = $ location ->findID ($ params );
134
+ $ this ->integer ((int ) $ found_location_id )->isEqualTo ($ location_id_2 );
135
+
136
+ // Verify finding ID with just name won't work for child location
137
+ $ params = [
138
+ 'name ' => 'testFindIDByName_2 ' ,
139
+ 'entities_id ' => $ entities_id ,
140
+ ];
141
+ $ found_location_id = $ location ->findID ($ params );
142
+ $ this ->integer ((int ) $ found_location_id )->isEqualTo (-1 );
143
+ }
144
+
145
+ public function testFindIDByCompleteName ()
146
+ {
147
+ $ entities_id = getItemByTypeName ('Entity ' , '_test_root_entity ' , true );
148
+
149
+ // Create a location
150
+ $ location = new \Location ();
151
+ $ location_id = $ location ->add ([
152
+ 'name ' => 'testFindIDByCompleteName_1 ' ,
153
+ 'entities_id ' => $ entities_id ,
154
+ ]);
155
+ $ this ->integer ((int ) $ location_id )->isGreaterThan (0 );
156
+
157
+ // Find the location by completename
158
+ $ params = [
159
+ 'completename ' => 'testFindIDByCompleteName_1 ' ,
160
+ 'entities_id ' => $ entities_id ,
161
+ ];
162
+ $ found_location_id = $ location ->findID ($ params );
163
+ $ this ->integer ((int ) $ found_location_id )->isEqualTo ($ location_id );
164
+
165
+ // Create a child location
166
+ $ location_id_2 = $ location ->add ([
167
+ 'locations_id ' => $ location_id ,
168
+ 'name ' => 'testFindIDByCompleteName_2 ' ,
169
+ 'entities_id ' => $ entities_id ,
170
+ ]);
171
+ $ this ->integer ((int ) $ location_id_2 )->isGreaterThan (0 );
172
+
173
+ // Find the location by completename
174
+ $ params = [
175
+ 'completename ' => 'testFindIDByCompleteName_1 > testFindIDByCompleteName_2 ' ,
176
+ 'entities_id ' => $ entities_id ,
177
+ ];
178
+ $ found_location_id = $ location ->findID ($ params );
179
+ $ this ->integer ((int ) $ found_location_id )->isEqualTo ($ location_id_2 );
180
+ }
76
181
}
0 commit comments