88use Baril \Sqlout \Tests \Models \Comment ;
99use Baril \Sqlout \Tests \Models \Post ;
1010use Illuminate \Database \Eloquent \Relations \Relation ;
11+ use Laravel \Scout \Builder as ScoutBuilder ;
1112use Wamania \Snowball \StemmerFactory ;
1213
1314class SearchTest extends TestCase
@@ -50,6 +51,19 @@ public function test_simple_search()
5051 $ this ->assertEquals ($ post ->id , $ results ->first ()->id );
5152 }
5253
54+ public function test_paginated_search ()
55+ {
56+ Post::all ()->each (function ($ post ) {
57+ $ post ->title = 'gloubiboulga ' ;
58+ $ post ->save ();
59+ });
60+
61+ $ search = Post::search ('gloubiboulga ' )->paginate (2 );
62+ $ this ->assertEquals (2 , $ search ->count ());
63+ $ this ->assertEquals (5 , $ search ->total ());
64+ $ this ->assertEquals (3 , $ search ->lastPage ());
65+ }
66+
5367 public function test_search_by_model ()
5468 {
5569 $ post = Post::first ();
@@ -91,7 +105,7 @@ public function test_restricted_search()
91105 $ this ->assertEquals ($ posts [2 ]->id , $ results [0 ]->id );
92106 }
93107
94- public function test_forwarded_scope ()
108+ public function test_where_and_forwarded_scope ()
95109 {
96110 Comment::query ()->update (['text ' => 'schtroumpf ' ]);
97111 Comment::all ()->searchable ();
@@ -101,6 +115,10 @@ public function test_forwarded_scope()
101115
102116 $ this ->assertEquals (5 , Comment::search ('schtroumpf ' )->count ());
103117
118+ $ results = Comment::search ('schtroumpf ' )->where ('author ' , 'gargamel ' )->get ();
119+ $ this ->assertCount (1 , $ results );
120+ $ this ->assertEquals ($ comment ->id , $ results [0 ]->id );
121+
104122 $ results = Comment::search ('schtroumpf ' )->author ('gargamel ' )->get ();
105123 $ this ->assertCount (1 , $ results );
106124 $ this ->assertEquals ($ comment ->id , $ results [0 ]->id );
@@ -112,6 +130,12 @@ public function test_forwarded_scope()
112130 $ this ->assertEquals ($ comment ->id , $ results [0 ]->id );
113131 }
114132
133+ public function test_macro_has_priority_over_scope ()
134+ {
135+ ScoutBuilder::macro ('author ' , function () { return 'gargamel ' ; });
136+ $ this ->assertEquals ('gargamel ' , Comment::search ('schtroumpf ' )->author ());
137+ }
138+
115139 public function test_ordering ()
116140 {
117141 $ posts = Post::all ();
@@ -144,6 +168,18 @@ public function test_search_modes()
144168 $ log = DB ::getQueryLog ();
145169 $ query = end ($ log )['query ' ];
146170 $ this ->assertStringContainsString (Builder::NATURAL_LANGUAGE , $ query );
171+
172+ app ('config ' )->set ('scout.sqlout.default_mode ' , Builder::NATURAL_LANGUAGE );
173+
174+ Post::search ('kiki ' )->inBooleanMode ()->get ();
175+ $ log = DB ::getQueryLog ();
176+ $ query = end ($ log )['query ' ];
177+ $ this ->assertStringContainsString (Builder::BOOLEAN , $ query );
178+
179+ Post::search ('kiki ' )->withQueryExpansion ()->get ();
180+ $ log = DB ::getQueryLog ();
181+ $ query = end ($ log )['query ' ];
182+ $ this ->assertStringContainsString (Builder::QUERY_EXPANSION , $ query );
147183 }
148184
149185 public function test_filters ()
@@ -227,6 +263,7 @@ public function test_soft_delete()
227263 Post::first ()->delete ();
228264 $ this ->assertEquals (4 , Post::search ('bitch ' )->count ());
229265 $ this ->assertEquals (5 , Post::search ('bitch ' )->withTrashed ()->count ());
266+ $ this ->assertEquals (1 , Post::search ('bitch ' )->onlyTrashed ()->count ());
230267 }
231268
232269 public function test_morph_map ()
0 commit comments