From 8b5ff2e111788c8c87d0cf68b4ce1fd9a94028e3 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 14 Apr 2015 22:08:09 -0400 Subject: [PATCH] Add test for accessibleFields option in associations. Refs #6320 --- tests/TestCase/ORM/MarshallerTest.php | 34 ++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index 510f1d50b77..0ead42fb05b 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -124,6 +124,7 @@ public function setUp() $this->articles = $articles; $this->comments = $comments; + $this->users = $users; } /** @@ -135,7 +136,7 @@ public function tearDown() { parent::tearDown(); TableRegistry::clear(); - unset($this->articles, $this->comments); + unset($this->articles, $this->comments, $this->users); } /** @@ -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. *