-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Filters; | ||
|
||
use Cone\Root\Filters\MediaSearch; | ||
use Cone\Root\Tests\TestCase; | ||
|
||
class MediaSearchTest extends TestCase | ||
{ | ||
public function test_a_media_search_has_searchable_attributes(): void | ||
{ | ||
$filter = new MediaSearch(['file_name', 'name']); | ||
|
||
$this->assertSame( | ||
['file_name' => null, 'name' => null], | ||
$filter->getSearchableAttributes() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Filters; | ||
|
||
use Cone\Root\Fields\BelongsToMany; | ||
use Cone\Root\Fields\Fields; | ||
use Cone\Root\Fields\Text; | ||
use Cone\Root\Filters\Search; | ||
use Cone\Root\Tests\TestCase; | ||
use Cone\Root\Tests\User; | ||
|
||
class SearchTest extends TestCase | ||
{ | ||
public function test_a_search_filter_modifies_query(): void | ||
{ | ||
$filter = new Search(new Fields([ | ||
new Text('Name'), | ||
new BelongsToMany('Teams'), | ||
])); | ||
|
||
$this->assertSame( | ||
'select * from "users" where "users"."deleted_at" is null', | ||
$filter->apply($this->app['request'], User::query(), null)->toRawSql() | ||
); | ||
|
||
$this->assertSame( | ||
'select * from "users" where ("users"."name" like \'%foo%\' or exists (select * from "teams" inner join "team_user" on "teams"."id" = "team_user"."team_id" where "users"."id" = "team_user"."user_id" and "teams"."id" like \'%foo%\')) and "users"."deleted_at" is null', | ||
$filter->apply($this->app['request'], User::query(), 'foo')->toRawSql() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Filters; | ||
|
||
use Cone\Root\Fields\Fields; | ||
use Cone\Root\Fields\MorphTo; | ||
use Cone\Root\Fields\Text; | ||
use Cone\Root\Filters\Sort; | ||
use Cone\Root\Tests\TestCase; | ||
use Cone\Root\Tests\User; | ||
|
||
class SortTest extends TestCase | ||
{ | ||
public function test_a_sort_filter_modifies_query(): void | ||
{ | ||
$filter = new Sort(new Fields([ | ||
Text::make('Name')->sortable(), | ||
MorphTo::make('Employer')->sortable(column: 'name'), | ||
])); | ||
|
||
$this->assertSame( | ||
'select * from "users" where "users"."deleted_at" is null', | ||
$filter->apply($this->app['request'], User::query(), ['by' => 'dummy'])->toRawSql() | ||
); | ||
|
||
$this->assertSame( | ||
'select * from "users" where "users"."deleted_at" is null order by "users"."name" desc', | ||
$filter->apply($this->app['request'], User::query(), ['by' => 'name'])->toRawSql() | ||
); | ||
|
||
$this->assertSame( | ||
'select * from "users" where "users"."deleted_at" is null order by (select "users"."name" from "users" where "users"."employer_id" = "users"."id" and "users"."deleted_at" is null) desc', | ||
$filter->apply($this->app['request'], User::query(), ['by' => 'employer'])->toRawSql() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters