Same conditions are kept within a filter group

This commit is contained in:
Oliver Davies 2019-04-01 23:26:00 +01:00
parent 1578cc81a3
commit f700382355
2 changed files with 26 additions and 3 deletions

View file

@ -30,8 +30,13 @@ class FilterGroup
return $this;
}
public function toArray(): array
/**
* Get all filters within this filter group.
*
* @return Collection
*/
public function all(): Collection
{
return $this->filters->toArray();
return $this->filters;
}
}

View file

@ -26,6 +26,24 @@ class OtherwiseTest extends TestCase
->trash()
);
$this->assertCount(3, $filters->toArray());
$this->assertCount(3, $filters->all());
}
/** @test */
public function same_conditions_are_kept_between_filters()
{
$filters = FilterGroup::if(
Filter::create()
->has('to:me@example.com subject:Foo')
->read()
)->otherwise(
Filter::create()
->has('to:me@example.com subject:Bar')
->trash()
);
$filters->all()->each(function (Filter $filter) {
$this->assertTrue($filter->getConditions()->contains('to:me@example.com'));
});
}
}