Browse Source

Added tests for the bindingKey() method

Jose Lorenzo Rodriguez 10 years ago
parent
commit
94cf64e0cf
1 changed files with 47 additions and 0 deletions
  1. 47 0
      tests/TestCase/ORM/AssociationTest.php

+ 47 - 0
tests/TestCase/ORM/AssociationTest.php

@@ -121,6 +121,53 @@ class AssociationTest extends TestCase
     }
 
     /**
+     * Tests the bindingKey method as a setter/getter
+     *
+     * @return void
+     */
+    public function testBindingKey()
+    {
+        $this->association->bindingKey('foo_id');
+        $this->assertEquals('foo_id', $this->association->bindingKey());
+    }
+
+    /**
+     * Tests the bindingKey() method when called with its defaults
+     *
+     * @return void
+     */
+    public function testBindingKeyDefault()
+    {
+        $this->source->primaryKey(['id', 'site_id']);
+        $this->association
+            ->expects($this->once())
+            ->method('isOwningSide')
+            ->will($this->returnValue(true));
+        $result = $this->association->bindingKey();
+        $this->assertEquals(['id', 'site_id'], $result);
+    }
+
+    /**
+     * Tests the bindingKey() method when the association source is not the
+     * owning side
+     *
+     * @return void
+     */
+    public function testBindingDefaultNoOwningSide()
+    {
+        $target = new Table;
+        $target->primaryKey(['foo', 'site_id']);
+        $this->association->target($target);
+
+        $this->association
+            ->expects($this->once())
+            ->method('isOwningSide')
+            ->will($this->returnValue(false));
+        $result = $this->association->bindingKey();
+        $this->assertEquals(['foo', 'site_id'], $result);
+    }
+
+    /**
      * Tests that name() returns the correct configured value
      *
      * @return void