Browse Source

Added test to prove that using translate behavior and union queries now works

Jose Lorenzo Rodriguez 11 years ago
parent
commit
0277c3fec5
1 changed files with 19 additions and 0 deletions
  1. 19 0
      tests/TestCase/Model/Behavior/TranslateBehaviorTest.php

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

@@ -794,4 +794,23 @@ class TranslateBehaviorTest extends TestCase {
 		$this->assertEquals('Un artículo', $article->translation('spa')->title);
 	}
 
+/**
+ * Tests that translation queries are added to union queries as well.
+ *
+ * @return void
+ */
+	public function testTranslationWithUnionQuery() {
+		$table = TableRegistry::get('Comments');
+		$table->addBehavior('Translate', ['fields' => ['comment']]);
+		$table->locale('spa');
+		$query = $table->find()->where(['Comments.id' => 6]);
+		$query2 = $table->find()->where(['Comments.id' => 5]);
+		$query->union($query2);
+		$results = $query->toArray();
+		$this->assertCount(2, $results);
+
+		$this->assertEquals('First Comment for Second Article', $results[0]->comment);
+		$this->assertEquals('Second Comment for Second Article', $results[1]->comment);
+	}
+
 }