Browse Source

Add tests for count with autoFields

Ladislav Gallay 11 years ago
parent
commit
b6cddfdda9
1 changed files with 27 additions and 0 deletions
  1. 27 0
      tests/TestCase/ORM/QueryTest.php

+ 27 - 0
tests/TestCase/ORM/QueryTest.php

@@ -2072,5 +2072,32 @@ class QueryTest extends TestCase {
 		$this->assertArrayHasKey('name', $result['author']);
 		$this->assertArrayHasKey('compute', $result);
 	}
+	
+/**
+ * Test count with autoFields
+ *
+ * @return void
+ */
+	public function testAutoFieldsCount() {
+		$table = TableRegistry::get('Articles');
+		$table->belongsTo('Authors');
+
+		$resultNormal = $table->find()
+			->select(['myField' => '(SELECT RAND())'])
+			->hydrate(false)
+			->contain('Authors')
+			->count();
+
+		$resultAutoFields = $table->find()
+			->select(['myField' => '(SELECT RAND())'])
+			->autoFields(true)
+			->hydrate(false)
+			->contain('Authors')
+			->count();
+
+		$this->assertNotNull($resultNormal);
+		$this->assertNotNull($resultAutoFields);
+		$this->assertEquals($resultNormal, $resultAutoFields);
+	}
 
 }