Exemplo n.º 1
0
 /**
  * Test that many() also receives a fieldList option
  *
  * @return void
  */
 public function testManyFieldList()
 {
     $data = [['comment' => 'First post', 'user_id' => 2, 'foo' => 'bar'], ['comment' => 'Second post', 'user_id' => 2, 'foo' => 'bar']];
     $marshall = new Marshaller($this->comments);
     $result = $marshall->many($data, ['fieldList' => ['comment', 'user_id']]);
     $this->assertCount(2, $result);
     unset($data[0]['foo'], $data[1]['foo']);
     $this->assertEquals($data[0], $result[0]->toArray());
     $this->assertEquals($data[1], $result[1]->toArray());
 }
Exemplo n.º 2
0
 /**
  * test many() with nested associations.
  *
  * @return void
  */
 public function testManyAssociations()
 {
     $data = [['comment' => 'First post', 'user_id' => 2, 'user' => ['username' => 'mark']], ['comment' => 'Second post', 'user_id' => 2, 'user' => ['username' => 'jose']]];
     $marshall = new Marshaller($this->comments);
     $result = $marshall->many($data, ['Users']);
     $this->assertCount(2, $result);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $result[0]);
     $this->assertInstanceOf('Cake\\ORM\\Entity', $result[1]);
     $this->assertEquals($data[0]['user']['username'], $result[0]->user->username);
     $this->assertEquals($data[1]['user']['username'], $result[1]->user->username);
 }