Browse Source

Merge pull request #8329 from ifunk/feature-assoc-classname

Add getter for protected $_className value for Association.
Mark Story 10 years ago
parent
commit
bca53dcabc
2 changed files with 42 additions and 0 deletions
  1. 10 0
      src/ORM/Association.php
  2. 32 0
      tests/TestCase/ORM/AssociationTest.php

+ 10 - 0
src/ORM/Association.php

@@ -261,6 +261,16 @@ abstract class Association
     }
 
     /**
+     * The class name of the target table object
+     *
+     * @return string
+     */
+    public function className()
+    {
+        return $this->_className;
+    }
+
+    /**
      * Sets the table instance for the source side of the association. If no arguments
      * are passed, the current configured table instance is returned
      *

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

@@ -109,6 +109,38 @@ class AssociationTest extends TestCase
     }
 
     /**
+     * Tests that className() returns the correct association className
+     *
+     * @return void
+     */
+    public function testClassName()
+    {
+        $this->assertEquals('\Cake\Test\TestCase\ORM\TestTable', $this->association->className());
+    }
+
+    /**
+     * Tests that className() returns the correct (unnormalized) className
+     *
+     * @return void
+     */
+    public function testClassNameUnnormalized()
+    {
+        $config = [
+            'className' => 'Test',
+        ];
+        $this->association = $this->getMock(
+            '\Cake\ORM\Association',
+            [
+                '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide',
+                'saveAssociated', 'eagerLoader', 'type'
+            ],
+            ['Foo', $config]
+        );
+
+        $this->assertEquals('Test', $this->association->className());
+    }
+
+    /**
      * Tests that cascadeCallbacks() returns the correct configured value
      *
      * @return void