55use PhpPlatform \RESTFul \HTTPRequest ;
66use PhpPlatform \SearchQueryParser \FindParams ;
77use PhpPlatform \SearchQueryParser \Parser ;
8+ use PhpPlatform \Errors \Exceptions \Http \_4XX \BadRequest ;
89
910class TestParser extends \PHPUnit_Framework_TestCase{
1011
@@ -29,13 +30,13 @@ function testParse($request,$modelClassName, $excludeFromFullTextSearch, $expect
2930 $ this ->assertEquals ($ expectedFindParams ['pagination ' ], $ findParams ->pagination );
3031 $ this ->assertEquals ($ expectedFindParams ['where ' ], $ findParams ->where );
3132
32- }catch (\ Exception $ e ){
33- $ this ->assertEquals ($ expectedException , $ e ->getMessage ());
33+ }catch (BadRequest $ e ){
34+ $ this ->assertEquals ($ expectedException , $ e ->getBody ());
3435 }
3536 }
3637
3738 function parseDataProvider (){
38- return [
39+ $ cases = [
3940 "without any search params " =>[
4041 $ this ->getHttpRequestWithQueryParameters ([
4142
@@ -51,8 +52,141 @@ function parseDataProvider(){
5152 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
5253 null ,
5354 ['filters ' =>['name ' =>'myName ' ],'sort ' =>[],'pagination ' =>null ,'where ' =>null ]
55+ ],
56+ "with filters with invalid field " =>[
57+ $ this ->getHttpRequestWithQueryParameters ([
58+ 'f ' =>base64_encode (json_encode (['address ' =>'myAddress ' ]))
59+ ]),
60+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
61+ null ,
62+ [],
63+ ['f ' =>'invalid ' ]
64+ ],
65+ "with filters without base64 encoded " =>[
66+ $ this ->getHttpRequestWithQueryParameters ([
67+ 'f ' =>json_encode (['name ' =>'myName ' ])
68+ ]),
69+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
70+ null ,
71+ [],
72+ ['f ' =>'invalid ' ]
73+ ],
74+ "with filters with invalid filter value " =>[
75+ $ this ->getHttpRequestWithQueryParameters ([
76+ 'f ' =>base64_encode (json_encode (['name ' =>['and ' =>'myName ' ]]))
77+ ]),
78+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
79+ null ,
80+ [],
81+ ['f ' =>'invalid ' ]
82+ ],
83+ "with filters for non get fields " =>[
84+ $ this ->getHttpRequestWithQueryParameters ([
85+ 'f ' =>base64_encode (json_encode (['password ' =>'myName ' ]))
86+ ]),
87+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
88+ null ,
89+ [],
90+ ['f ' =>'invalid ' ]
91+ ],
92+ "with filters with other operators " =>[
93+ $ this ->getHttpRequestWithQueryParameters ([
94+ 'f ' =>base64_encode (json_encode (['name ' =>['LIKE ' =>'myName ' ]]))
95+ ]),
96+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
97+ null ,
98+ ['filters ' =>['name ' =>['LIKE ' =>'myName ' ]],'sort ' =>[],'pagination ' =>null ,'where ' =>null ]
99+ ],
100+ "with filters for child model " =>[
101+ $ this ->getHttpRequestWithQueryParameters ([
102+ 'f ' =>base64_encode (json_encode (['name ' =>['LIKE ' =>'myName ' ]]))
103+ ]),
104+ 'PhpPlatform\Tests\SearchQueryParser\Models\M2 ' ,
105+ null ,
106+ ['filters ' =>['name ' =>['LIKE ' =>'myName ' ]],'sort ' =>[],'pagination ' =>null ,'where ' =>null ]
107+ ],
108+ "with filters for reference and autoIncrement fields " =>[
109+ $ this ->getHttpRequestWithQueryParameters ([
110+ 'f ' =>base64_encode (json_encode (['id ' =>'1 ' ,'m1Id ' =>'2 ' ]))
111+ ]),
112+ 'PhpPlatform\Tests\SearchQueryParser\Models\M2 ' ,
113+ null ,
114+ ['filters ' =>['id ' =>'1 ' ,'m1Id ' =>'2 ' ],'sort ' =>[],'pagination ' =>null ,'where ' =>null ]
115+ ],
116+
117+ "with sort " =>[
118+ $ this ->getHttpRequestWithQueryParameters ([
119+ 's ' =>base64_encode (json_encode (['name ' =>'ASC ' ]))
120+ ]),
121+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
122+ null ,
123+ ['filters ' =>[],'sort ' =>['name ' =>'ASC ' ],'pagination ' =>null ,'where ' =>null ]
124+ ],
125+ "with sort with invalid field " =>[
126+ $ this ->getHttpRequestWithQueryParameters ([
127+ 's ' =>base64_encode (json_encode (['address ' =>'ASC ' ]))
128+ ]),
129+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
130+ null ,
131+ [],
132+ ['s ' =>'invalid ' ]
133+ ],
134+ "with sort without base64 encoded " =>[
135+ $ this ->getHttpRequestWithQueryParameters ([
136+ 's ' =>json_encode (['name ' =>'myName ' ])
137+ ]),
138+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
139+ null ,
140+ [],
141+ ['s ' =>'invalid ' ]
142+ ],
143+ "with sort with invalid sort value " =>[
144+ $ this ->getHttpRequestWithQueryParameters ([
145+ 's ' =>base64_encode (json_encode (['name ' =>['and ' =>'myName ' ]]))
146+ ]),
147+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
148+ null ,
149+ [],
150+ ['s ' =>'invalid ' ]
151+ ],
152+ "with sort with invalid sort option " =>[
153+ $ this ->getHttpRequestWithQueryParameters ([
154+ 's ' =>base64_encode (json_encode (['name ' =>'increasing ' ]))
155+ ]),
156+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
157+ null ,
158+ [],
159+ ['s ' =>'invalid ' ]
160+ ],
161+ "with sort for non-get fields " =>[
162+ $ this ->getHttpRequestWithQueryParameters ([
163+ 's ' =>base64_encode (json_encode (['password ' =>'ASC ' ]))
164+ ]),
165+ 'PhpPlatform\Tests\SearchQueryParser\Models\M1 ' ,
166+ null ,
167+ [],
168+ ['s ' =>'invalid ' ]
169+ ],
170+ "with sort for child model " =>[
171+ $ this ->getHttpRequestWithQueryParameters ([
172+ 's ' =>base64_encode (json_encode (['name ' =>'DESC ' ]))
173+ ]),
174+ 'PhpPlatform\Tests\SearchQueryParser\Models\M2 ' ,
175+ null ,
176+ ['filters ' =>[],'sort ' =>['name ' =>'DESC ' ],'pagination ' =>null ,'where ' =>null ]
177+ ],
178+ "with sort for reference and autoIncrement fields " =>[
179+ $ this ->getHttpRequestWithQueryParameters ([
180+ 's ' =>base64_encode (json_encode (['id ' =>'ASC ' ,'m1Id ' =>'DESC ' ]))
181+ ]),
182+ 'PhpPlatform\Tests\SearchQueryParser\Models\M2 ' ,
183+ null ,
184+ ['filters ' =>[],'sort ' =>['id ' =>'ASC ' ,'m1Id ' =>'DESC ' ],'pagination ' =>null ,'where ' =>null ]
54185 ]
186+
55187 ];
188+ //return [$cases['with filters with other operators']];
189+ return $ cases ;
56190 }
57191
58192 /**
0 commit comments