Browse Source

Add test for accessibleFields option in associations.

Refs #6320
Mark Story 11 years ago
parent
commit
8b5ff2e111
1 changed files with 33 additions and 1 deletions
  1. 33 1
      tests/TestCase/ORM/MarshallerTest.php

+ 33 - 1
tests/TestCase/ORM/MarshallerTest.php

@@ -124,6 +124,7 @@ class MarshallerTest extends TestCase
 
         $this->articles = $articles;
         $this->comments = $comments;
+        $this->users = $users;
     }
 
     /**
@@ -135,7 +136,7 @@ class MarshallerTest extends TestCase
     {
         parent::tearDown();
         TableRegistry::clear();
-        unset($this->articles, $this->comments);
+        unset($this->articles, $this->comments, $this->users);
     }
 
     /**
@@ -307,6 +308,37 @@ class MarshallerTest extends TestCase
     }
 
     /**
+     * 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.
      *
      * @return void