[wip] add tests
This commit is contained in:
84
tests/Filter/GenericFilterTest.php
Normal file
84
tests/Filter/GenericFilterTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Filter;
|
||||
|
||||
use ExampleDocumentAccess;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TypeError;
|
||||
|
||||
/**
|
||||
* @covers \Filter\GenericFilter
|
||||
*/
|
||||
class GenericFilterTest extends TestCase
|
||||
{
|
||||
use ExampleDocumentAccess;
|
||||
|
||||
public function testAllowsWhenMatchBasenameOfFile(): void
|
||||
{
|
||||
$filter = new GenericFilter('example');
|
||||
$document = $this->exampleDocument();
|
||||
|
||||
self::assertTrue($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testAllowsWhenMatchesPathToFile(): void
|
||||
{
|
||||
$filter = new GenericFilter('resources');
|
||||
$document = $this->exampleDocument();
|
||||
|
||||
self::assertTrue($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testAllowsWhenMatchesAnyMetadataField(): void
|
||||
{
|
||||
$filter = new GenericFilter('John Snow');
|
||||
$document = $this->exampleDocumentWithMetadata([
|
||||
'title' => 'some title',
|
||||
'author' => 'John Snow',
|
||||
]);
|
||||
|
||||
self::assertTrue($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testDisallowsWhenNotMatchingBasenameOfFile(): void
|
||||
{
|
||||
$filter = new GenericFilter('not-an-example');
|
||||
$document = $this->exampleDocument();
|
||||
|
||||
self::assertFalse($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testDisallowsWhenNotMatchingPathToFile(): void
|
||||
{
|
||||
$filter = new GenericFilter('this-is-definitely-not-in-the-path' . md5(time()));
|
||||
$document = $this->exampleDocument();
|
||||
|
||||
self::assertFalse($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testDisallowsWhenNotMatchingAnyMetadataField(): void
|
||||
{
|
||||
$filter = new GenericFilter('peepee');
|
||||
$document = $this->exampleDocumentWithMetadata([
|
||||
'title' => 'some title',
|
||||
'author' => 'John Snow',
|
||||
]);
|
||||
|
||||
self::assertFalse($filter->allows($document));
|
||||
}
|
||||
|
||||
public function testStringRepresentation(): void
|
||||
{
|
||||
$filter = new GenericFilter('i-am-a-field');
|
||||
self::assertEquals(
|
||||
'[*] contains \'i-am-a-field\'',
|
||||
(string)$filter
|
||||
);
|
||||
}
|
||||
|
||||
public function testDoesNotAcceptNull(): void
|
||||
{
|
||||
$this->expectException(TypeError::class);
|
||||
new GenericFilter(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user