2017-11-03 11:23:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Opdavies\Tests\GmailFilterBuilder;
|
|
|
|
|
|
|
|
use Opdavies\GmailFilterBuilder\Filter;
|
|
|
|
|
|
|
|
class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Filter
|
|
|
|
*/
|
|
|
|
private $filter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->filter = new Filter();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::has()
|
|
|
|
*/
|
|
|
|
public function testHas()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['hasTheWord' => 'something'],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->has('something')->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::from()
|
|
|
|
*/
|
|
|
|
public function testFrom()
|
|
|
|
{
|
|
|
|
// Ensure that we can set one from address.
|
|
|
|
$this->assertEquals(
|
2017-11-03 23:22:13 +00:00
|
|
|
['from' => 'foo@example.com'],
|
|
|
|
$this->filter->from('foo@example.com')->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Ensure that we can set multiple from addresses.
|
|
|
|
$this->assertEquals(
|
2017-11-03 23:22:13 +00:00
|
|
|
['from' => 'foo@example.com,bar@example.com'],
|
|
|
|
$this->filter
|
|
|
|
->from('foo@example.com', 'bar@example.com')
|
|
|
|
->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::label()
|
|
|
|
*/
|
|
|
|
public function testLabel()
|
|
|
|
{
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
['label' => 'Foo'],
|
|
|
|
$this->filter->label('Foo')->getProperties()
|
|
|
|
);
|
2017-11-03 11:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::archive()
|
|
|
|
*/
|
|
|
|
public function testArchive()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldArchive' => 'true'],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->archive()->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::labelAndArchive()
|
|
|
|
*/
|
|
|
|
public function testLabelAndArchive()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldArchive' => 'true', 'label' => 'Foo'],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->labelAndArchive('Foo')->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::spam()
|
|
|
|
*/
|
|
|
|
public function testSpam()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'shouldSpam' => 'true',
|
|
|
|
'shouldNeverSpam' => 'false'
|
|
|
|
],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->spam()->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::neverSpam()
|
|
|
|
*/
|
|
|
|
public function testNeverSpam()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'shouldSpam' => 'false',
|
|
|
|
'shouldNeverSpam' => 'true'
|
|
|
|
],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->neverSpam()->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Filter::trash()
|
|
|
|
*/
|
|
|
|
public function testTrash()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldTrash' => 'true'],
|
2017-11-03 23:22:13 +00:00
|
|
|
$this->filter->trash()->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-03 23:45:54 +00:00
|
|
|
public function testMarkAsRead()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['markAsRead' => 'true'],
|
|
|
|
$this->filter->read()->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStar()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldStar' => 'true'],
|
|
|
|
$this->filter->star()->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForwardTo()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['forwardTo' => 'foo@example.com'],
|
|
|
|
$this->filter->forward('foo@example.com')->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMarkImportant()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldAlwaysMarkAsImportant' => 'true'],
|
|
|
|
$this->filter->important()->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMarkNotImportant()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['shouldNeverMarkAsImportant' => 'true'],
|
|
|
|
$this->filter->notImportant()->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
public function testCategorise()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
['smartLabelToApply' => 'Foo'],
|
|
|
|
$this->filter->categorise('Foo')->getProperties()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-03 23:22:13 +00:00
|
|
|
public function testMethodsCanBeChained()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'from' => 'foo@example.com,bar@example.com',
|
|
|
|
'hasTheWord' => 'Something',
|
|
|
|
'label' => 'Foo',
|
2017-11-03 23:45:54 +00:00
|
|
|
'markAsRead' => 'true',
|
2017-11-03 23:22:13 +00:00
|
|
|
'shouldArchive' => 'true',
|
|
|
|
'shouldNeverSpam' => 'true',
|
|
|
|
'shouldSpam' => 'false',
|
2017-11-03 23:45:54 +00:00
|
|
|
'shouldStar' => 'true',
|
2017-11-03 23:22:13 +00:00
|
|
|
],
|
|
|
|
$this->filter->from('foo@example.com ', 'bar@example.com')
|
|
|
|
->has('Something')
|
|
|
|
->labelAndArchive('Foo')
|
2017-11-03 23:45:54 +00:00
|
|
|
->read()
|
2017-11-03 23:22:13 +00:00
|
|
|
->neverSpam()
|
2017-11-03 23:45:54 +00:00
|
|
|
->star()
|
2017-11-03 23:22:13 +00:00
|
|
|
->getProperties()
|
2017-11-03 11:23:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|