Browse Source

Adding test that's currently failing

This needs to pass, and did pass before the new plugin / TR handling.
Patrick Conroy 11 years ago
parent
commit
66a3e8e994
1 changed files with 23 additions and 1 deletions
  1. 23 1
      tests/TestCase/ORM/Association/BelongsToTest.php

+ 23 - 1
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -36,7 +36,7 @@ class BelongsToTest extends TestCase
      *
      * @var array
      */
-    public $fixtures = ['core.articles', 'core.comments'];
+    public $fixtures = ['core.articles', 'core.comments', 'core.authors'];
 
     /**
      * Don't autoload fixtures as most tests uses mocks.
@@ -103,6 +103,28 @@ class BelongsToTest extends TestCase
     }
 
     /**
+     * Tests that the alias set on associations is actually on the Entity
+     *
+     * @return void
+     */
+    public function testCustomAlias()
+    {
+        $table = TableRegistry::get('Articles', [
+            'className' => 'TestPlugin.Articles'
+        ]);
+        $table->addAssociations([
+            'belongsTo' => [
+                'FooAuthors' => ['className' => 'TestPlugin.Authors', 'foreignKey' => 'author_id']
+            ]
+        ]);
+        $article = $table->find()->contain(['FooAuthors'])->first();
+
+        $this->assertTrue(isset($article->foo_author));
+        $this->assertEquals($article->foo_author->name, 'mariano');
+        $this->assertNull($article->Authors);
+    }
+
+    /**
      * Tests that the correct join and fields are attached to a query depending on
      * the association config
      *