1+ <?php
2+
3+ namespace FQ \Tests \Query \Selection ;
4+
5+ use FQ \Query \Selection \DirSelection ;
6+ use FQ \Tests \Query \AbstractFilesQueryTests ;
7+
8+ class DirSelectionTest extends AbstractFilesQueryTests {
9+
10+ /**
11+ * @var DirSelection
12+ */
13+ protected $ _dirSelection ;
14+
15+ protected function setUp () {
16+ parent ::setUp ();
17+
18+ $ this ->_dirSelection = new DirSelection ();
19+ $ this ->nonPublicMethodObject ($ this ->dirSelection ());
20+ }
21+ protected function dirSelection () {
22+ return $ this ->_dirSelection ;
23+ }
24+
25+ public function testConstructor () {
26+ $ dirSelection = new DirSelection ();
27+ $ this ->assertNotNull ($ dirSelection );
28+ }
29+
30+ public function testReset () {
31+ $ selection = $ this ->dirSelection ();
32+ $ selection ->reset ();
33+
34+ $ this ->assertEquals (array (), $ selection ->getIncludedDirsById ());
35+ $ this ->assertEquals (array (), $ selection ->getIncludedDirsByDir ());
36+ $ this ->assertEquals (array (), $ selection ->getExcludedDirsById ());
37+ $ this ->assertEquals (array (), $ selection ->getExcludedDirsByDir ());
38+
39+ $ this ->assertFalse ($ selection ->hasIncludedDirsByDir ());
40+ $ this ->assertFalse ($ selection ->hasIncludedDirsById ());
41+ $ this ->assertFalse ($ selection ->hasIncludedDirs ());
42+ }
43+
44+ public function testIncludeDirById () {
45+ $ selection = $ this ->dirSelection ();
46+
47+ $ selection ->includeDirById ('dir1 ' );
48+ $ selection ->includeDirById ('dir2 ' );
49+
50+ $ this ->assertEquals (array ('dir1 ' , 'dir2 ' ), $ selection ->getIncludedDirsById ());
51+ $ this ->assertFalse ($ selection ->hasIncludedDirsByDir ());
52+ $ this ->assertTrue ($ selection ->hasIncludedDirsById ());
53+ $ this ->assertTrue ($ selection ->hasIncludedDirs ());
54+ }
55+
56+ public function testExcludeDirById () {
57+ $ selection = $ this ->dirSelection ();
58+
59+ $ selection ->excludeDirById ('dir1 ' );
60+ $ selection ->excludeDirById ('dir2 ' );
61+
62+ $ this ->assertEquals (array ('dir1 ' , 'dir2 ' ), $ selection ->getExcludedDirsById ());
63+ $ this ->assertFalse ($ selection ->hasExcludedDirsByDir ());
64+ $ this ->assertTrue ($ selection ->hasExcludedDirsById ());
65+ $ this ->assertTrue ($ selection ->hasExcludedDirs ());
66+ }
67+
68+ public function testIncludeDirByDir () {
69+ $ selection = $ this ->dirSelection ();
70+
71+ $ dir1 = $ this ->_newActualRootDir ();
72+ $ dir2 = $ this ->_newActualRootDirSecond ();
73+ $ selection ->includeDir ($ dir1 );
74+ $ selection ->includeDir ($ dir2 );
75+
76+ $ this ->assertEquals (array ($ dir1 , $ dir2 ), $ selection ->getIncludedDirsByDir ());
77+ $ this ->assertTrue ($ selection ->hasIncludedDirsByDir ());
78+ $ this ->assertFalse ($ selection ->hasIncludedDirsById ());
79+ $ this ->assertTrue ($ selection ->hasIncludedDirs ());
80+ }
81+
82+ public function testExcludeDirByDir () {
83+ $ selection = $ this ->dirSelection ();
84+ $ dir1 = $ this ->_newActualRootDir ();
85+ $ dir2 = $ this ->_newActualRootDirSecond ();
86+ $ selection ->excludeDir ($ dir1 );
87+ $ selection ->excludeDir ($ dir2 );
88+
89+ $ this ->assertEquals (array ($ dir1 , $ dir2 ), $ selection ->getExcludedDirsByDir ());
90+ $ this ->assertTrue ($ selection ->hasExcludedDirsByDir ());
91+ $ this ->assertFalse ($ selection ->hasExcludedDirsById ());
92+ $ this ->assertTrue ($ selection ->hasExcludedDirs ());
93+ }
94+
95+ public function testIncludeAndExcludeADirAtTheSameTime () {
96+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryException ' , 'Cannot exclude a dir when you \'ve already defined included directories ' );
97+ $ selection = $ this ->dirSelection ();
98+ $ dir1 = $ this ->_newActualRootDir ();
99+ $ dir2 = $ this ->_newActualRootDirSecond ();
100+ $ selection ->includeDir ($ dir1 );
101+ $ selection ->excludeDir ($ dir2 );
102+ }
103+ public function testExcludeAndIncludeADirAtTheSameTime () {
104+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryException ' , 'Cannot include a dir when you \'ve already defined excluded directories ' );
105+ $ selection = $ this ->dirSelection ();
106+ $ dir1 = $ this ->_newActualRootDir ();
107+ $ dir2 = $ this ->_newActualRootDirSecond ();
108+ $ selection ->excludeDir ($ dir1 );
109+ $ selection ->includeDir ($ dir2 );
110+ }
111+
112+ public function testValidateQuerySelectionWhenDirIsNotAvailable () {
113+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryException ' , 'Query selection validation failed because one ore more selection IDs (root1) could not be found in the available directories. Available directory ids are "root2" ' );
114+ $ selection = $ this ->dirSelection ();
115+ $ dir1 = $ this ->_newActualRootDir ();
116+ $ dir2 = $ this ->_newActualRootDirSecond ();
117+ $ selection ->includeDir ($ dir1 );
118+ $ selection ->validateQuerySelection (array ($ dir2 ));
119+ }
120+ public function testValidateQuerySelectionWithExcludingWhenDirIsNotAvailable () {
121+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryException ' , 'Query selection validation failed because one ore more selection IDs (root1) could not be found in the available directories. Available directory ids are "root2" ' );
122+ $ selection = $ this ->dirSelection ();
123+ $ dir1 = $ this ->_newActualRootDir ();
124+ $ dir2 = $ this ->_newActualRootDirSecond ();
125+ $ selection ->excludeDir ($ dir1 );
126+ $ selection ->validateQuerySelection (array ($ dir2 ));
127+ }
128+
129+ public function testGetSelectionWithoutSelection () {
130+ $ selection = $ this ->dirSelection ();
131+ $ dir1 = $ this ->_newActualRootDir ();
132+ $ dir2 = $ this ->_newActualRootDirSecond ();
133+ $ this ->assertEquals (array ($ dir1 , $ dir2 ), $ selection ->getSelection (array ($ dir1 , $ dir2 )));
134+ }
135+ public function testGetSelectionByInclusion () {
136+ $ selection = $ this ->dirSelection ();
137+ $ dir1 = $ this ->_newActualRootDir ();
138+ $ dir2 = $ this ->_newActualRootDirSecond ();
139+ $ selection ->includeDir ($ dir1 );
140+ $ this ->assertEquals (array ($ dir1 ), $ selection ->getSelection (array ($ dir1 , $ dir2 )));
141+ }
142+ public function testGetSelectionByExclusion () {
143+ $ selection = $ this ->dirSelection ();
144+ $ dir1 = $ this ->_newActualRootDir ();
145+ $ dir2 = $ this ->_newActualRootDirSecond ();
146+ $ selection ->excludeDir ($ dir1 );
147+ $ this ->assertEquals (array ($ dir2 ), $ selection ->getSelection (array ($ dir1 , $ dir2 )));
148+ }
149+ }
0 commit comments