22
33namespace FQ \Tests \Query ;
44
5+ use FQ \Query \FilesQuery ;
56use FQ \Query \FilesQueryChild ;
67use FQ \Query \FilesQueryRequirements ;
78
@@ -42,16 +43,122 @@ public function testGetRootDirsEmpty() {
4243
4344 public function testQuery () {
4445 $ queryChild = $ this ->queryChild ();
46+ $ this ->assertNotNull ($ queryChild ->query ());
4547 $ this ->assertTrue (is_a ($ queryChild ->query (), 'FQ\Query\FilesQuery ' ));
4648 }
4749
4850 public function testFiles () {
4951 $ queryChild = $ this ->queryChild ();
50- $ this ->assertTrue (is_a ($ queryChild ->Files (), 'FQ\Files ' ));
52+ $ this ->assertNotNull ($ queryChild ->files ());
53+ $ this ->assertTrue (is_a ($ queryChild ->files (), 'FQ\Files ' ));
5154 }
5255
5356 public function testChildDir () {
5457 $ queryChild = $ this ->queryChild ();
58+ $ this ->assertNotNull ($ queryChild ->childDir ());
5559 $ this ->assertTrue (is_a ($ queryChild ->childDir (), 'FQ\Dirs\ChildDir ' ));
5660 }
61+
62+ public function testRelativePath () {
63+ $ queryChild = $ this ->queryChild ();
64+ $ this ->runQuery ();
65+ $ this ->assertEquals ('/child1/File2.php ' , $ queryChild ->relativePath ());
66+ }
67+ public function testRelativePathWithCustomExtension () {
68+ $ queryChild = $ this ->queryChild ();
69+ $ this ->runQuery ('File2.ext ' );
70+ $ this ->assertEquals ('/child1/File2.ext ' , $ queryChild ->relativePath ());
71+ }
72+ public function testRawAbsolutePath () {
73+ $ queryChild = $ this ->queryChild ();
74+ $ this ->runQuery ();
75+ $ this ->assertEquals (array (
76+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File2.php '
77+ ), $ queryChild ->rawAbsolutePaths ());
78+ }
79+ public function testBaseAbsolutePath () {
80+ $ queryChild = $ this ->queryChild ();
81+ $ this ->runQuery ();
82+ $ this ->assertEquals (array (
83+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php '
84+ ), $ queryChild ->rawBasePaths ());
85+ }
86+
87+ public function testGeneratePaths () {
88+ $ this ->setExpectedException ('\FQ\Exceptions\FileQueryException ' , 'Cannot generate paths because method (non-existing-dir-method) is not defined in FQ\Dirs\RootDir ' );
89+ $ this ->runQuery ();
90+ $ this ->callNonPublicMethod ('_generatePaths ' , array ('non-existing-dir-method ' ));
91+ }
92+
93+ public function testFilteredAbsolutePathsWithoutFilters () {
94+ $ this ->query ()->filters (array (), false );
95+ $ queryChild = $ this ->queryChild ();
96+ $ firstRootDir = $ this ->_newActualRootDir ();
97+ $ secondRootDir = $ this ->_newActualRootDirSecond ();
98+ $ queryChild ->setRootDirs (array ($ firstRootDir , $ secondRootDir ));
99+ $ this ->runQuery ();
100+ $ this ->assertEquals (array (
101+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File2.php ' ,
102+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File2.php '
103+ ), $ queryChild ->filteredAbsolutePaths ());
104+ }
105+ public function testFilteredAbsolutePathsWithOneNonExistingFile () {
106+ $ query = $ this ->query ();
107+ $ queryChild = $ this ->queryChild ();
108+ $ query ->filters (FilesQuery::FILTER_EXISTING );
109+ $ firstRootDir = $ this ->_newActualRootDir ();
110+ $ secondRootDir = $ this ->_newActualRootDirSecond ();
111+ $ thirdFictitiousDir = $ this ->_newFictitiousRootDir ();
112+ $ queryChild ->setRootDirs (array ($ firstRootDir , $ secondRootDir , $ thirdFictitiousDir ));
113+ $ this ->runQuery ('File1 ' );
114+ $ this ->assertEquals (array (
115+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php ' ,
116+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File1.php ' ,
117+ self ::ROOT_DIR_FICTITIOUS_ID => self ::ROOT_DIR_FICTITIOUS_ABSOLUTE_PATH . '/child1/File1.php '
118+ ), $ queryChild ->rawAbsolutePaths ());
119+ $ this ->assertEquals (array (
120+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php ' ,
121+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File1.php '
122+ ), $ queryChild ->filteredAbsolutePaths ());
123+ }
124+
125+ public function testFilteredBasePathsWithoutFilters () {
126+ $ this ->query ()->filters (array (), false );
127+ $ queryChild = $ this ->queryChild ();
128+ $ firstRootDir = $ this ->_newActualRootDir ();
129+ $ secondRootDir = $ this ->_newActualRootDirSecond ();
130+ $ queryChild ->setRootDirs (array ($ firstRootDir , $ secondRootDir ));
131+ $ this ->runQuery ();
132+ $ this ->assertEquals (array (
133+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php ' ,
134+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_BASE_PATH . '/child1/File2.php '
135+ ), $ queryChild ->filteredBasePaths ());
136+ }
137+ public function testFilteredBasePathsWithOneNonExistingFile () {
138+ $ query = $ this ->query ();
139+ $ queryChild = $ this ->queryChild ();
140+ $ query ->filters (FilesQuery::FILTER_EXISTING );
141+ $ firstRootDir = $ this ->_newActualRootDir ();
142+ $ secondRootDir = $ this ->_newActualRootDirSecond ();
143+ $ thirdFictitiousDir = $ this ->_newFictitiousRootDir ();
144+ $ queryChild ->setRootDirs (array ($ firstRootDir , $ secondRootDir , $ thirdFictitiousDir ));
145+ $ this ->runQuery ('File1 ' );
146+ $ this ->assertEquals (array (
147+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File1.php ' ,
148+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_BASE_PATH . '/child1/File1.php ' ,
149+ self ::ROOT_DIR_FICTITIOUS_ID => self ::ROOT_DIR_FICTITIOUS_BASE_PATH . '/child1/File1.php '
150+ ), $ queryChild ->rawBasePaths ());
151+ $ this ->assertEquals (array (
152+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File1.php ' ,
153+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_BASE_PATH . '/child1/File1.php '
154+ ), $ queryChild ->filteredBasePaths ());
155+ }
156+
157+ /*public function testResetAfterQuery() {
158+ $queryChild = $this->queryChild();
159+ $this->runQuery();
160+ $this->assertEquals(array(
161+ self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php'
162+ ), $queryChild->rawBasePaths());
163+ }*/
57164}
0 commit comments