Browse Source

Add tests for foreign key generation with dot separated table names.

Refs #6616
Mark Story 10 years ago
parent
commit
e820d973fc

+ 16 - 0
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -92,6 +92,22 @@ class BelongsToTest extends TestCase
     }
 
     /**
+     * Test that foreignKey generation ignores database names in target table.
+     *
+     * @return void
+     */
+    public function testForeignKey()
+    {
+        $this->company->table('schema.companies');
+        $this->client->table('schema.clients');
+        $assoc = new BelongsTo('Companies', [
+            'sourceTable' => $this->client,
+            'targetTable' => $this->company,
+        ]);
+        $this->assertEquals('company_id', $assoc->foreignKey());
+    }
+
+    /**
      * Tests that the association reports it can be joined
      *
      * @return void

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

@@ -84,6 +84,20 @@ class HasManyTest extends TestCase
     }
 
     /**
+     * Test that foreignKey generation ignores database names in target table.
+     *
+     * @return void
+     */
+    public function testForeignKey()
+    {
+        $this->author->table('schema.authors');
+        $assoc = new HasMany('Articles', [
+            'sourceTable' => $this->author
+        ]);
+        $this->assertEquals('author_id', $assoc->foreignKey());
+    }
+
+    /**
      * Tests that the association reports it can be joined
      *
      * @return void

+ 3 - 0
tests/TestCase/ORM/TableTest.php

@@ -136,6 +136,9 @@ class TableTest extends TestCase
 
         $table->table('other');
         $this->assertEquals('other', $table->table());
+
+        $table->table('database.other');
+        $this->assertEquals('database.other', $table->table());
     }
 
     /**