Browse Source

Merge pull request #16797 from cakephp/issue-16778

Add test for propertyName and validation
Mark Story 3 years ago
parent
commit
bae80000d2
1 changed files with 21 additions and 0 deletions
  1. 21 0
      tests/TestCase/ORM/Association/HasManyTest.php

+ 21 - 0
tests/TestCase/ORM/Association/HasManyTest.php

@@ -616,6 +616,27 @@ class HasManyTest extends TestCase
     }
 
     /**
+     * Tests propertyName is used during marshalling and validation
+     */
+    public function testPropertyOptionMarshalAndValidation(): void
+    {
+        $authors = $this->getTableLocator()->get('Authors');
+        $authors->hasMany('Articles', [
+            'propertyName' => 'blogs',
+        ]);
+        $authors->getValidator()
+            ->requirePresence('blogs', true, 'blogs must be set');
+
+        $data = [
+            'name' => 'corey',
+        ];
+        $author = $authors->newEntity($data);
+        $this->assertEmpty($author->blogs, 'No blogs set');
+        $this->assertTrue($author->hasErrors(), 'Should have validation errors');
+        $this->assertArrayHasKey('blogs', $author->getErrors());
+    }
+
+    /**
      * Test that plugin names are omitted from property()
      */
     public function testPropertyNoPlugin(): void