@@ -142,14 +142,21 @@ public function testImageAltTitleFields() {
142142 * Test archive upload.
143143 */
144144 public function testArchiveUpload () {
145+ $ file_storage = \Drupal::service ('entity.manager ' )->getStorage ('file ' );
145146 // Create files for the archive.
146147 file_unmanaged_save_data ($ this ->randomString (), 'temporary://test_text.txt ' );
147148 file_unmanaged_save_data ($ this ->randomString (), 'temporary://test_png.png ' );
148149 file_unmanaged_save_data ($ this ->randomString (), 'temporary://test_jpg.jpg ' );
149150
151+ $ text_file_path = file_directory_temp () . '/test_text.txt ' ;
152+ $ png_file_path = file_directory_temp () . '/test_png.png ' ;
153+ $ jpg_file_path = file_directory_temp () . '/test_jpg.jpg ' ;
154+
150155 $ archive_path = file_directory_temp () . '/archive.tar.gz ' ;
151156 $ archiver = new Tar ($ archive_path );
152- $ archiver ->add ('test_text.txt test_png.png test_jpg.jpg ' );
157+ $ archiver ->add ($ text_file_path );
158+ $ archiver ->add ($ png_file_path );
159+ $ archiver ->add ($ jpg_file_path );
153160
154161 $ edit = [
155162 'files[upload] ' => $ archive_path ,
@@ -161,23 +168,27 @@ public function testArchiveUpload() {
161168
162169 $ this ->assertText ('Extracted archive.tar.gz and added 1 new files. ' );
163170
164- // File that match the pattern can be found in the database.
165- $ this ->assertEqual ('test_jpg.jpg ' , $ this ->getFileByFilename ('test_jpg.jpg ' )->getFilename ());
171+ // Files that match the pattern can be found in the database.
172+ $ this ->assertTrue ($ file = !empty ($ file_storage ->loadByProperties (['filename ' => 'test_jpg.jpg ' ])));
173+ // Files that match the pattern should be permanent.
174+ $ this ->assertTrue ($ file ? $ this ->getFileByFilename ('test_jpg.jpg ' )->isPermanent () : FALSE );
166175 // Files that don't match the pattern are not in the database.
167- $ this ->assertFalse ($ this -> getFileByFilename ( ' test_png.png ' ));
168- $ this ->assertFalse ($ this -> getFileByFilename ( ' test_text.txt ' ));
176+ $ this ->assertFalse (! empty ( $ file_storage -> loadByProperties ([ ' filename ' => ' test_png.png ']) ));
177+ $ this ->assertFalse (! empty ( $ file_storage -> loadByProperties ([ ' filename ' => ' test_text.txt ']) ));
169178 // Archive is removed since we checked the remove_archive checkbox.
170- $ this ->assertFalse ($ this -> getFileByFilename ( ' archive.tar.gz ' ));
179+ $ this ->assertFalse (! empty ( $ file_storage -> loadByProperties ([ ' filename ' => ' archive.tar.gz ']) ));
171180
172181 $ all_files = file_scan_directory ('public:// ' , '/.*/ ' );
173182 // Only files that match the pattern are in the public directory.
174- $ this ->assertTrue (array_key_exists ('public://archive.tar/test_jpg.jpg ' , $ all_files ));
175- $ this ->assertFalse (array_key_exists ('public://archive.tar/test_png.png ' , $ all_files ));
176- $ this ->assertFalse (array_key_exists ('public://archive.tar/test_text.txt ' , $ all_files ));
183+ $ this ->assertTrue (array_key_exists ('public://archive.tar/ ' . $ jpg_file_path , $ all_files ));
184+ $ this ->assertFalse (array_key_exists ('public://archive.tar/ ' . $ png_file_path , $ all_files ));
185+ $ this ->assertFalse (array_key_exists ('public://archive.tar/ ' . $ text_file_path , $ all_files ));
177186 $ this ->assertFalse (array_key_exists ('public://archive.tar.gz ' , $ all_files ));
178187
179- $ archive_uri = file_unmanaged_save_data (NULL , 'temporary://archive2.tar.gz ' );
180- $ archive_path = file_directory_temp () . '/ ' . file_uri_target ($ archive_uri );
188+ $ archive_path = file_directory_temp () . '/archive2.tar.gz ' ;
189+ $ archiver = new Tar ($ archive_path );
190+ $ archiver ->add ($ text_file_path );
191+
181192 $ edit = [
182193 'files[upload] ' => $ archive_path ,
183194 'remove_archive ' => FALSE ,
@@ -186,7 +197,9 @@ public function testArchiveUpload() {
186197 $ this ->drupalPostForm (NULL , $ edit , t ('Submit ' ));
187198
188199 // Archive is in the database since value for remove_checkbox is FALSE.
189- $ this ->assertEqual ('archive2.tar.gz ' , $ this ->getFileByFilename ('archive2.tar.gz ' )->getFilename ());
200+ $ this ->assertTrue ($ file = !empty ($ file_storage ->loadByProperties (['filename ' => 'archive2.tar.gz ' ])));
201+ // Check if the archive is set to permanent.
202+ $ this ->assertTrue ($ file ? $ this ->getFileByFilename ('archive2.tar.gz ' )->isPermanent () : FALSE );
190203
191204 $ all_files = file_scan_directory ('public:// ' , '/.*/ ' );
192205 $ this ->assertTrue (array_key_exists ('public://archive2.tar.gz ' , $ all_files ));
0 commit comments