comparison core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\image\Functional; 3 namespace Drupal\Tests\image\Functional;
4 4
5 use Drupal\Core\File\FileSystemInterface;
5 use Drupal\image\Entity\ImageStyle; 6 use Drupal\image\Entity\ImageStyle;
6 use Drupal\language\Entity\ConfigurableLanguage; 7 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase; 8 use Drupal\Tests\BrowserTestBase;
8 use Drupal\Tests\TestFileCreationTrait; 9 use Drupal\Tests\TestFileCreationTrait;
9 10
132 // functions work for other than the default scheme. 133 // functions work for other than the default scheme.
133 $this->config('system.file')->set('default_scheme', 'temporary')->save(); 134 $this->config('system.file')->set('default_scheme', 'temporary')->save();
134 135
135 // Create the directories for the styles. 136 // Create the directories for the styles.
136 $directory = $scheme . '://styles/' . $this->style->id(); 137 $directory = $scheme . '://styles/' . $this->style->id();
137 $status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY); 138 $status = \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
138 $this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.'); 139 $this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
139 140
140 // Override the language to build the URL for the correct language. 141 // Override the language to build the URL for the correct language.
141 if ($langcode) { 142 if ($langcode) {
142 $language_manager = \Drupal::service('language_manager'); 143 $language_manager = \Drupal::service('language_manager');
145 } 146 }
146 147
147 // Create a working copy of the file. 148 // Create a working copy of the file.
148 $files = $this->drupalGetTestFiles('image'); 149 $files = $this->drupalGetTestFiles('image');
149 $file = array_shift($files); 150 $file = array_shift($files);
150 $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME); 151 /** @var \Drupal\Core\File\FileSystemInterface $file_system */
152 $file_system = \Drupal::service('file_system');
153 $original_uri = $file_system->copy($file->uri, $scheme . '://', FileSystemInterface::EXISTS_RENAME);
151 // Let the image_module_test module know about this file, so it can claim 154 // Let the image_module_test module know about this file, so it can claim
152 // ownership in hook_file_download(). 155 // ownership in hook_file_download().
153 \Drupal::state()->set('image.test_file_download', $original_uri); 156 \Drupal::state()->set('image.test_file_download', $original_uri);
154 $this->assertNotIdentical(FALSE, $original_uri, 'Created the generated image file.'); 157 $this->assertNotIdentical(FALSE, $original_uri, 'Created the generated image file.');
155 158
229 $this->assertResponse(403, 'Confirmed that access is denied for the private image style.'); 232 $this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
230 233
231 // Repeat this with a different file that we do not have access to and 234 // Repeat this with a different file that we do not have access to and
232 // make sure that access is denied. 235 // make sure that access is denied.
233 $file_noaccess = array_shift($files); 236 $file_noaccess = array_shift($files);
234 $original_uri_noaccess = file_unmanaged_copy($file_noaccess->uri, $scheme . '://', FILE_EXISTS_RENAME); 237 $original_uri_noaccess = $file_system->copy($file_noaccess->uri, $scheme . '://', FileSystemInterface::EXISTS_RENAME);
235 $generated_uri_noaccess = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . drupal_basename($original_uri_noaccess); 238 $generated_uri_noaccess = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . $file_system->basename($original_uri_noaccess);
236 $this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.'); 239 $this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.');
237 $generate_url_noaccess = $this->style->buildUrl($original_uri_noaccess); 240 $generate_url_noaccess = $this->style->buildUrl($original_uri_noaccess);
238 241
239 $this->drupalGet($generate_url_noaccess); 242 $this->drupalGet($generate_url_noaccess);
240 $this->assertResponse(403, 'Confirmed that access is denied for the private image style.'); 243 $this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
269 ->save(); 272 ->save();
270 273
271 // Create another working copy of the file. 274 // Create another working copy of the file.
272 $files = $this->drupalGetTestFiles('image'); 275 $files = $this->drupalGetTestFiles('image');
273 $file = array_shift($files); 276 $file = array_shift($files);
274 $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME); 277 $original_uri = $file_system->copy($file->uri, $scheme . '://', FileSystemInterface::EXISTS_RENAME);
275 // Let the image_module_test module know about this file, so it can claim 278 // Let the image_module_test module know about this file, so it can claim
276 // ownership in hook_file_download(). 279 // ownership in hook_file_download().
277 \Drupal::state()->set('image.test_file_download', $original_uri); 280 \Drupal::state()->set('image.test_file_download', $original_uri);
278 281
279 // Suppress the security token in the URL, then get the URL of a file that 282 // Suppress the security token in the URL, then get the URL of a file that