Browse Source

Tests the use of `model` config option

Algirdas Gurevicius 11 years ago
parent
commit
2ce8d65228
1 changed files with 28 additions and 0 deletions
  1. 28 0
      tests/TestCase/Model/Behavior/TranslateBehaviorTest.php

+ 28 - 0
tests/TestCase/Model/Behavior/TranslateBehaviorTest.php

@@ -818,4 +818,32 @@ class TranslateBehaviorTest extends TestCase {
 		$this->assertEquals('Second Comment for Second Article', $results[1]->comment);
 	}
 
+/**
+* Tests the use of `model` config option.
+* 
+* @return void
+* 
+*/
+	public function testChangingModelFieldValue() {
+		$table = TableRegistry::get('Articles');
+
+		$table->hasMany('OtherComments', ['className' => 'Comments']);
+		$table->OtherComments->addBehavior('Translate', ['fields' => ['comment'], 'model' => 'Comments']);
+		
+		$items = $table->OtherComments->associations();
+		$association = $items->getByProperty('comment_translation');
+		$this->assertNotEmpty($association, 'Translation association not found');
+		
+		$found = false;
+		foreach ($association->conditions() as $key => $value) {
+			
+			if (strpos($key, 'comment_translation.model') !== false) {
+				$found = true;
+				$this->assertEquals('Comments', $value);
+				break;
+			}
+		}
+		
+		$this->assertTrue($found, '`model` field condition on a Translation association was not found');
+	}
 }