Add ability to get all conditions within a filter group

This commit is contained in:
Oliver Davies 2019-04-04 00:00:00 +01:00
parent a3c5f4541d
commit 09cf724f70
2 changed files with 34 additions and 0 deletions

View file

@ -39,4 +39,9 @@ class FilterGroup
{
return $this->filters;
}
public function getConditions(): Collection
{
return $this->filters->map->getConditions();
}
}

View file

@ -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()
{