Skip to content

Commit

Permalink
Add test for accessibleFields option in associations.
Browse files Browse the repository at this point in the history
Refs #6320
  • Loading branch information
markstory committed Apr 15, 2015
1 parent 0b2b2aa commit 8b5ff2e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -124,6 +124,7 @@ public function setUp()

$this->articles = $articles;
$this->comments = $comments;
$this->users = $users;
}

/**
Expand All @@ -135,7 +136,7 @@ public function tearDown()
{
parent::tearDown();
TableRegistry::clear();
unset($this->articles, $this->comments);
unset($this->articles, $this->comments, $this->users);
}

/**
Expand Down Expand Up @@ -306,6 +307,37 @@ public function testOneAccessibleFieldsOption()
$this->assertTrue($result->not_in_schema);
}

/**
* Test one() supports accessibleFields option for associations
*
* @return void
*/
public function testOneAccessibleFieldsOptionForAssociations()
{
$data = [
'title' => 'My title',
'body' => 'My content',
'user' => [
'id' => 1,
'username' => 'mark',
]
];
$this->articles->entityClass(__NAMESPACE__ . '\ProtectedArticle');
$this->users->entityClass(__NAMESPACE__ . '\ProtectedArticle');

$marshall = new Marshaller($this->articles);

$result = $marshall->one($data, [
'associated' => [
'Users' => ['accessibleFields' => ['id' => true]]
],
'accessibleFields' => ['body' => false, 'user' => true]
]);
$this->assertNull($result->body);
$this->assertNull($result->user->username);
$this->assertEquals(1, $result->user->id);
}

/**
* test one() with a wrapping model name.
*
Expand Down

0 comments on commit 8b5ff2e

Please sign in to comment.