mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
Ensure that empty values do not add to or from conditions
This commit is contained in:
parent
634fc87897
commit
9f1d80f968
|
@ -48,9 +48,11 @@ class Filter
|
|||
*/
|
||||
public function from($values)
|
||||
{
|
||||
$this->properties['from'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
if (!empty($values)) {
|
||||
$this->properties['from'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -62,9 +64,11 @@ class Filter
|
|||
*/
|
||||
public function to($values)
|
||||
{
|
||||
$this->properties['to'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
if (!empty($values)) {
|
||||
$this->properties['to'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,18 @@ class FilterTest extends TestCase
|
|||
['from' => ['foo@example.com', 'bar@example.com']],
|
||||
$this->filter->from(['foo@example.com', 'bar@example.com'])->getProperties()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no 'from' key exists if no values were entered.
|
||||
*
|
||||
* @covers Filter::from()
|
||||
*/
|
||||
public function testNoFromPropertyExistsIfTheValueIsEmpty()
|
||||
{
|
||||
$this->assertArrayNotHasKey('from', $this->filter->from('')->getProperties());
|
||||
$this->assertArrayNotHasKey('from', $this->filter->from([])->getProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +88,15 @@ class FilterTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no 'to' key exists if values were entered.
|
||||
*/
|
||||
public function testNoToPropertyExistsIfTheValueIsEmpty()
|
||||
{
|
||||
$this->assertArrayNotHasKey('to', $this->filter->to('')->getProperties());
|
||||
$this->assertArrayNotHasKey('to', $this->filter->to([])->getProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::subject()
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue