-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
3 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
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,63 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Filters; | ||
|
||
use Cone\Root\Filters\Filter; | ||
use Cone\Root\Tests\TestCase; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
|
||
class FilterTest extends TestCase | ||
{ | ||
protected Filter $filter; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->filter = new class() extends Filter | ||
{ | ||
public function __construct() | ||
{ | ||
$this->setKey('foo'); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'Test Filter'; | ||
} | ||
|
||
public function apply(Request $request, Builder $query, mixed $value): Builder | ||
{ | ||
return $query; | ||
} | ||
}; | ||
} | ||
|
||
public function test_a_filter_has_keys(): void | ||
{ | ||
$this->assertSame('foo', $this->filter->getKey()); | ||
$this->assertSame('foo', $this->filter->getRequestKey()); | ||
} | ||
|
||
public function test_a_filter_has_name(): void | ||
{ | ||
$this->assertSame('Test Filter', $this->filter->getName()); | ||
} | ||
|
||
public function test_a_filter_resolves_value_from_request(): void | ||
{ | ||
$this->app['request']->merge(['foo' => 'value']); | ||
|
||
$this->assertSame( | ||
'value', $this->filter->getValue($this->app['request']) | ||
); | ||
} | ||
|
||
public function test_a_filter_can_be_active(): void | ||
{ | ||
$this->app['request']->merge(['foo' => 'value']); | ||
|
||
$this->assertTrue($this->filter->isActive($this->app['request'])); | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Cone\Root\Tests\Filters; | ||
|
||
use Cone\Root\Filters\Select; | ||
use Cone\Root\Tests\TestCase; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\Request; | ||
|
||
class SelectFilterTest extends TestCase | ||
{ | ||
protected Select $filter; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->filter = new class() extends Select | ||
{ | ||
public function __construct() | ||
{ | ||
$this->setKey('foo'); | ||
} | ||
|
||
public function apply(Request $request, Builder $query, mixed $value): Builder | ||
{ | ||
return $query; | ||
} | ||
|
||
public function options(Request $request): array | ||
{ | ||
return [ | ||
'test' => 'value', | ||
'foo' => 'bar', | ||
]; | ||
} | ||
}; | ||
} | ||
|
||
public function test_a_select_filter_has_options(): void | ||
{ | ||
$this->assertSame( | ||
['test' => 'value', 'foo' => 'bar'], | ||
$this->filter->options($this->app['request']) | ||
); | ||
} | ||
|
||
public function test_a_select_filter_can_have_multiple_values(): void | ||
{ | ||
$this->app['request']->merge(['foo' => 'value']); | ||
|
||
$this->assertFalse($this->filter->isMultiple()); | ||
$this->assertSame( | ||
'value', $this->filter->getValue($this->app['request']) | ||
); | ||
|
||
$this->filter->multiple(); | ||
|
||
$this->assertTrue($this->filter->isMultiple()); | ||
$this->assertSame( | ||
['value'], $this->filter->getValue($this->app['request']) | ||
); | ||
} | ||
} |