From 7cc018f03ccf262ca761662feedcf110c13d87bc Mon Sep 17 00:00:00 2001 From: sizuhiko Date: Fri, 14 Aug 2015 12:08:38 +0900 Subject: [PATCH] add option accessibleFields to newEntities method for Mass Assignment --- src/Adaptor/CakeFabricateAdaptor.php | 10 ++++++++-- tests/TestCase/CakeFabricateTest.php | 2 +- tests/test_app/Model/Entity/Post.php | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Adaptor/CakeFabricateAdaptor.php b/src/Adaptor/CakeFabricateAdaptor.php index 28a81e5..0e6bf51 100644 --- a/src/Adaptor/CakeFabricateAdaptor.php +++ b/src/Adaptor/CakeFabricateAdaptor.php @@ -102,7 +102,10 @@ public function getModel($modelName) public function create($modelName, $attributes, $recordCount) { $table = TableRegistry::get($modelName); - $entities = $table->newEntities($attributes, ['validate' => $this->options[self::OPTION_VALIDATE], 'accessibleFields' => ['*' => true]]); + $entities = $table->newEntities($attributes, [ + 'validate' => $this->options[self::OPTION_VALIDATE], + 'accessibleFields' => ['*' => true] + ]); $table->connection()->transactional(function () use ($table, $entities) { foreach ($entities as $entity) { $ret = $table->save($entity, [ @@ -124,7 +127,10 @@ public function create($modelName, $attributes, $recordCount) public function build($modelName, $data) { $table = TableRegistry::get($modelName); - $entity = $table->newEntity($data, ['validate' => $this->options[self::OPTION_VALIDATE]]); + $entity = $table->newEntity($data, [ + 'validate' => $this->options[self::OPTION_VALIDATE], + 'accessibleFields' => ['*' => true] + ]); return $entity; } diff --git a/tests/TestCase/CakeFabricateTest.php b/tests/TestCase/CakeFabricateTest.php index 3c28a14..601cfeb 100644 --- a/tests/TestCase/CakeFabricateTest.php +++ b/tests/TestCase/CakeFabricateTest.php @@ -29,7 +29,7 @@ public function testAttributesFor() { return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"]; }); $this->assertCount(10, $results); - for ($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; $i++) { $this->assertEquals($i+1, $results[$i]['id']); $this->assertEquals($i+1, $results[$i]['author_id']); $this->assertEquals(50, strlen($results[$i]['title'])); diff --git a/tests/test_app/Model/Entity/Post.php b/tests/test_app/Model/Entity/Post.php index eadd5bc..90d823b 100644 --- a/tests/test_app/Model/Entity/Post.php +++ b/tests/test_app/Model/Entity/Post.php @@ -8,4 +8,11 @@ */ class Post extends Entity { + protected $_accessible = [ + 'title' => true, + 'body' => true, + 'published' => true, + 'created' => true, + 'updated' => true + ]; }