1
|
|
|
<?php |
2
|
|
|
namespace Tests\AppBundle\Sync\Entity\Filter; |
3
|
|
|
|
4
|
|
|
use AppBundle\Sync\Entity\File; |
5
|
|
|
use AppBundle\Sync\Entity\Filter\ExcludeShows; |
6
|
|
|
use org\bovigo\vfs\vfsStream; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Exclude Shows filter tests |
10
|
|
|
* |
11
|
|
|
* @author Sergey Sadovoi <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ExcludeShowsTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
public function testFilter() |
16
|
|
|
{ |
17
|
|
|
$files = ['TEST00113.mov', 'AAAA00113.mov']; |
18
|
|
|
$excludes = ['AAAA']; |
19
|
|
|
$tree = ['exclude.list' => json_encode($excludes)]; |
20
|
|
|
|
21
|
|
|
// Init virtual FS |
22
|
|
|
vfsStream::setup('root', null, $tree); |
23
|
|
|
|
24
|
|
|
$filter = new ExcludeShows(); |
25
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
26
|
|
|
|
27
|
|
|
foreach ($files as $fileName) { |
28
|
|
|
$file = new File(); |
29
|
|
|
$file->setUid($fileName); |
30
|
|
|
|
31
|
|
|
$valid = (array_search(substr($fileName, 0, 4), $excludes) === false); |
32
|
|
|
$this->assertEquals($valid, $filter->valid($file)); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
38
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::UNDEFINED_PATH |
39
|
|
|
*/ |
40
|
|
|
public function testUnsetPath() |
41
|
|
|
{ |
42
|
|
|
$filter = new ExcludeShows(); |
43
|
|
|
$filter->valid(new File()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
48
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::MISSING_FILE |
49
|
|
|
*/ |
50
|
|
|
public function testMissingFile() |
51
|
|
|
{ |
52
|
|
|
$filter = new ExcludeShows(); |
53
|
|
|
$filter->setPath('/missing/path'); |
54
|
|
|
|
55
|
|
|
$filter->valid(new File()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
60
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::INVALID_JSON |
61
|
|
|
*/ |
62
|
|
|
public function testInvalidContent() |
63
|
|
|
{ |
64
|
|
|
$tree = ['exclude.list' => 'bad data']; |
65
|
|
|
|
66
|
|
|
// Init virtual FS |
67
|
|
|
vfsStream::setup('root', null, $tree); |
68
|
|
|
|
69
|
|
|
$filter = new ExcludeShows(); |
70
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
71
|
|
|
|
72
|
|
|
$filter->valid(new File()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
77
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::NOT_ARRAY |
78
|
|
|
*/ |
79
|
|
|
public function testContentNotArray() |
80
|
|
|
{ |
81
|
|
|
$tree = ['exclude.list' => '"bad data"']; |
82
|
|
|
|
83
|
|
|
// Init virtual FS |
84
|
|
|
vfsStream::setup('root', null, $tree); |
85
|
|
|
|
86
|
|
|
$filter = new ExcludeShows(); |
87
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
88
|
|
|
|
89
|
|
|
$filter->valid(new File()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|