Skip to content

Commit ed8331f

Browse files
committed
Add additional tests for marshaller.
1 parent c32a1d1 commit ed8331f

File tree

1 file changed

+82
-7
lines changed

1 file changed

+82
-7
lines changed

Cake/Test/TestCase/ORM/MarshallerTest.php

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,95 @@ public function testOneAssociationsMany() {
151151
$this->assertEquals($data['Users'], $result->Users);
152152
}
153153

154+
/**
155+
* Test one() with deeper associations.
156+
*
157+
* @return void
158+
*/
154159
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);
156185
}
157186

187+
/**
188+
* Test many() with a simple set of data.
189+
*
190+
* @return void
191+
*/
158192
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);
160205
}
161206

207+
/**
208+
* test many() with nested associations.
209+
*
210+
* @return void
211+
*/
162212
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+
);
168243
}
169244

170245
}

0 commit comments

Comments
 (0)