mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-01-22 20:17:31 +00:00
Add ability to get all conditions within a filter group
This commit is contained in:
parent
a3c5f4541d
commit
09cf724f70
|
@ -39,4 +39,9 @@ class FilterGroup
|
|||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
public function getConditions(): Collection
|
||||
{
|
||||
return $this->filters->map->getConditions();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\Opdavies\GmailFilterBuilder;
|
|||
use Opdavies\GmailFilterBuilder\Model\Filter;
|
||||
use Opdavies\GmailFilterBuilder\Model\FilterGroup;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
class OtherwiseHasTest extends TestCase
|
||||
{
|
||||
|
@ -47,6 +48,34 @@ class OtherwiseHasTest extends TestCase
|
|||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function get_all_conditions_from_a_filter_group()
|
||||
{
|
||||
$filters = FilterGroup::if(
|
||||
Filter::create()
|
||||
->has('to:me@example.com subject:Foo')
|
||||
->read()
|
||||
)->otherwise(
|
||||
Filter::create()
|
||||
->has('to:me@example.com subject:Bar')
|
||||
->trash()
|
||||
)->otherwise(
|
||||
Filter::create()
|
||||
->has('to:me@example.com subject:Baz')
|
||||
->trash()
|
||||
);
|
||||
|
||||
$expected = [
|
||||
['to:me@example.com', 'subject:Foo'],
|
||||
['to:me@example.com', 'subject:Bar'],
|
||||
['to:me@example.com', 'subject:Baz'],
|
||||
];
|
||||
|
||||
$conditions = $filters->getConditions();
|
||||
$this->assertInstanceOf(Collection::class, $conditions);
|
||||
$this->assertSame($expected, $conditions->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function different_conditions_are_negated_in_subsequent_filters()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue