18
18
19
19
use Cake \Core \Configure ;
20
20
use Cake \Database \ConnectionManager ;
21
+ use Cake \Database \Expression \OrderByExpression ;
21
22
use Cake \Database \Expression \QueryExpression ;
22
23
use Cake \ORM \Table ;
23
24
use Cake \ORM \TableRegistry ;
@@ -2023,6 +2024,21 @@ public function testMagicFindFirstOr() {
2023
2024
$ this ->assertEquals ($ expected , $ result ->clause ('where ' ));
2024
2025
}
2025
2026
2027
+ /**
2028
+ * Test setting order by clauses on magic finders.
2029
+ *
2030
+ * @return void
2031
+ */
2032
+ public function testMagicFindFirstOrderBy () {
2033
+ $ table = TableRegistry::get ('Users ' );
2034
+
2035
+ $ result = $ table ->findByAuthorIdOrPublished (1 , 'Y ' , ['id ' => 'DESC ' ]);
2036
+ $ this ->assertInstanceOf ('Cake\ORM\Query ' , $ result );
2037
+ $ this ->assertEquals (1 , $ result ->clause ('limit ' ));
2038
+ $ expected = new OrderByExpression (['id ' => 'DESC ' ]);
2039
+ $ this ->assertEquals ($ expected , $ result ->clause ('order ' ));
2040
+ }
2041
+
2026
2042
2027
2043
/**
2028
2044
* Test magic findAllByXX method.
@@ -2034,7 +2050,7 @@ public function testMagicFindAll() {
2034
2050
2035
2051
$ result = $ table ->findAllByAuthorId (1 );
2036
2052
$ this ->assertInstanceOf ('Cake\ORM\Query ' , $ result );
2037
- $ this ->assertEquals ( null , $ result ->clause ('limit ' ));
2053
+ $ this ->assertNull ( $ result ->clause ('limit ' ));
2038
2054
$ expected = new QueryExpression (
2039
2055
['author_id ' => 1 ],
2040
2056
['author_id ' => 'integer ' ],
@@ -2053,7 +2069,7 @@ public function testMagicFindAllAnd() {
2053
2069
2054
2070
$ result = $ table ->findAllByAuthorIdAndPublished (1 , 'Y ' );
2055
2071
$ this ->assertInstanceOf ('Cake\ORM\Query ' , $ result );
2056
- $ this ->assertEquals ( null , $ result ->clause ('limit ' ));
2072
+ $ this ->assertNull ( $ result ->clause ('limit ' ));
2057
2073
$ expected = new QueryExpression (
2058
2074
['author_id ' => 1 , 'published ' => 'Y ' ]
2059
2075
);
@@ -2070,12 +2086,28 @@ public function testMagicFindAllOr() {
2070
2086
2071
2087
$ result = $ table ->findAllByAuthorIdOrPublished (1 , 'Y ' );
2072
2088
$ this ->assertInstanceOf ('Cake\ORM\Query ' , $ result );
2073
- $ this ->assertEquals ( null , $ result ->clause ('limit ' ));
2089
+ $ this ->assertNull ( $ result ->clause ('limit ' ));
2074
2090
$ expected = new QueryExpression ();
2075
2091
$ expected ->add (
2076
2092
['or ' => ['author_id ' => 1 , 'published ' => 'Y ' ]]
2077
2093
);
2078
2094
$ this ->assertEquals ($ expected , $ result ->clause ('where ' ));
2095
+ $ this ->assertNull ($ result ->clause ('order ' ));
2096
+ }
2097
+
2098
+ /**
2099
+ * Test setting order by clauses on magic finders.
2100
+ *
2101
+ * @return void
2102
+ */
2103
+ public function testMagicFindAllOrderBy () {
2104
+ $ table = TableRegistry::get ('Users ' );
2105
+
2106
+ $ result = $ table ->findAllByAuthorIdOrPublished (1 , 'Y ' , ['id ' => 'DESC ' ]);
2107
+ $ this ->assertInstanceOf ('Cake\ORM\Query ' , $ result );
2108
+ $ this ->assertNull ($ result ->clause ('limit ' ));
2109
+ $ expected = new OrderByExpression (['id ' => 'DESC ' ]);
2110
+ $ this ->assertEquals ($ expected , $ result ->clause ('order ' ));
2079
2111
}
2080
2112
2081
2113
}
0 commit comments