@@ -151,20 +151,95 @@ public function testOneAssociationsMany() {
151
151
$ this ->assertEquals ($ data ['Users ' ], $ result ->Users );
152
152
}
153
153
154
+ /**
155
+ * Test one() with deeper associations.
156
+ *
157
+ * @return void
158
+ */
154
159
public function testOneDeepAssociations () {
155
- $ this ->markTestIncomplete ('not done ' );
160
+ $ data = [
161
+ 'comment ' => 'First post ' ,
162
+ 'user_id ' => 2 ,
163
+ 'Articles ' => [
164
+ 'title ' => 'Article title ' ,
165
+ 'body ' => 'Article body ' ,
166
+ 'Users ' => [
167
+ 'username ' => 'mark ' ,
168
+ 'password ' => 'secret '
169
+ ],
170
+ ]
171
+ ];
172
+ $ marshall = new Marshaller ($ this ->comments );
173
+ $ result = $ marshall ->one ($ data , ['Articles ' => ['Users ' ]]);
174
+
175
+ $ this ->assertEquals (
176
+ $ data ['Articles ' ]['title ' ],
177
+ $ result ->article ->title
178
+ );
179
+ $ this ->assertEquals (
180
+ $ data ['Articles ' ]['Users ' ]['username ' ],
181
+ $ result ->article ->user ->username
182
+ );
183
+ $ this ->assertNull ($ result ->article ->Users );
184
+ $ this ->assertNull ($ result ->Articles );
156
185
}
157
186
187
+ /**
188
+ * Test many() with a simple set of data.
189
+ *
190
+ * @return void
191
+ */
158
192
public function testManySimple () {
159
- $ this ->markTestIncomplete ('not done ' );
193
+ $ data = [
194
+ ['comment ' => 'First post ' , 'user_id ' => 2 ],
195
+ ['comment ' => 'Second post ' , 'user_id ' => 2 ],
196
+ ];
197
+ $ marshall = new Marshaller ($ this ->comments );
198
+ $ result = $ marshall ->many ($ data );
199
+
200
+ $ this ->assertCount (2 , $ result );
201
+ $ this ->assertInstanceOf ('Cake\ORM\Entity ' , $ result [0 ]);
202
+ $ this ->assertInstanceOf ('Cake\ORM\Entity ' , $ result [1 ]);
203
+ $ this ->assertEquals ($ data [0 ]['comment ' ], $ result [0 ]->comment );
204
+ $ this ->assertEquals ($ data [1 ]['comment ' ], $ result [1 ]->comment );
160
205
}
161
206
207
+ /**
208
+ * test many() with nested associations.
209
+ *
210
+ * @return void
211
+ */
162
212
public function testManyAssociations () {
163
- $ this ->markTestIncomplete ('not done ' );
164
- }
165
-
166
- public function testManyDeepAssociations () {
167
- $ this ->markTestIncomplete ('not done ' );
213
+ $ data = [
214
+ [
215
+ 'comment ' => 'First post ' ,
216
+ 'user_id ' => 2 ,
217
+ 'Users ' => [
218
+ 'username ' => 'mark ' ,
219
+ ],
220
+ ],
221
+ [
222
+ 'comment ' => 'Second post ' ,
223
+ 'user_id ' => 2 ,
224
+ 'Users ' => [
225
+ 'username ' => 'jose ' ,
226
+ ],
227
+ ],
228
+ ];
229
+ $ marshall = new Marshaller ($ this ->comments );
230
+ $ result = $ marshall ->many ($ data , ['Users ' ]);
231
+
232
+ $ this ->assertCount (2 , $ result );
233
+ $ this ->assertInstanceOf ('Cake\ORM\Entity ' , $ result [0 ]);
234
+ $ this ->assertInstanceOf ('Cake\ORM\Entity ' , $ result [1 ]);
235
+ $ this ->assertEquals (
236
+ $ data [0 ]['Users ' ]['username ' ],
237
+ $ result [0 ]->user ->username
238
+ );
239
+ $ this ->assertEquals (
240
+ $ data [1 ]['Users ' ]['username ' ],
241
+ $ result [1 ]->user ->username
242
+ );
168
243
}
169
244
170
245
}
0 commit comments