gmail-filter-builder/tests/Unit/BuilderTest.php

45 lines
1.5 KiB
PHP
Raw Normal View History

2017-11-04 00:32:39 +00:00
<?php
use Opdavies\GmailFilterBuilder\Builder;
use Opdavies\GmailFilterBuilder\Filter;
2017-11-28 07:09:17 +00:00
use PHPUnit\Framework\TestCase;
2017-11-04 00:32:39 +00:00
2017-11-28 07:09:17 +00:00
class BuilderTest extends TestCase
2017-11-04 00:32:39 +00:00
{
public function testBuild()
{
2017-12-30 10:28:19 +00:00
$filterA = (new Filter())
->from(['foo@example.com', 'test@example.com'])
2017-12-30 10:28:19 +00:00
->label('Some label')
->archive();
2017-11-04 00:32:39 +00:00
2017-12-30 10:28:19 +00:00
$filterB = (new Filter())
->has('from:bar@example.com')
->star()
->important();
2017-11-04 00:32:39 +00:00
$builder = new Builder([
$filterA->getProperties(),
$filterB->getProperties(),
]);
2017-12-30 10:28:19 +00:00
$result = $builder->build();
$expected = "<?xml version='1.0' encoding='UTF-8'?>";
$expected .= "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
$expected .= '<entry>';
$expected .= "<apps:property name='from' value='foo@example.com|test@example.com'/>";
$expected .= "<apps:property name='label' value='Some label'/>";
$expected .= "<apps:property name='shouldArchive' value='true'/>";
$expected .= '</entry>';
$expected .= '<entry>';
$expected .= "<apps:property name='hasTheWord' value='from:bar@example.com'/>";
$expected .= "<apps:property name='shouldStar' value='true'/>";
$expected .= "<apps:property name='shouldAlwaysMarkAsImportant' value='true'/>";
$expected .= '</entry>';
$expected .= '</feed>';
$this->assertEquals($expected, $result);
2017-11-04 00:32:39 +00:00
}
}