Browse Source

Add regression test for #7163

Mark Story 10 years ago
parent
commit
9b0c1fc560
1 changed files with 22 additions and 0 deletions
  1. 22 0
      tests/TestCase/ORM/QueryRegressionTest.php

+ 22 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -1022,4 +1022,26 @@ class QueryRegressionTest extends TestCase
 
         $this->assertEquals([['name' => 'nate', 'tag' => 'tag1']], $results);
     }
+
+    /**
+     * Test expression based ordering with unions.
+     *
+     * @return void
+     */
+    public function testComplexOrderWithUnion()
+    {
+        $table = TableRegistry::get('Comments');
+        $query = $table->find();
+        $inner = $table->find()->where(['id >' => 3]);
+        $inner2 = $table->find()->where(['id <' => 3]);
+
+        $order = $query->func()->concat(['inside__comment' => 'literal', 'test']);
+
+        $query->select(['inside__comment' => 'Comments__comment'])
+            ->from(['inside' => $inner->unionAll($inner2)])
+            ->orderAsc($order);
+
+        $results = $query->toArray();
+        $this->assertCount(5, $results);
+    }
 }