Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/image/tests/src/Functional/ImageDimensionsTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
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\Tests\BrowserTestBase; | 7 use Drupal\Tests\BrowserTestBase; |
7 use Drupal\Tests\TestFileCreationTrait; | 8 use Drupal\Tests\TestFileCreationTrait; |
8 | 9 |
9 /** | 10 /** |
33 public function testImageDimensions() { | 34 public function testImageDimensions() { |
34 $image_factory = $this->container->get('image.factory'); | 35 $image_factory = $this->container->get('image.factory'); |
35 // Create a working copy of the file. | 36 // Create a working copy of the file. |
36 $files = $this->drupalGetTestFiles('image'); | 37 $files = $this->drupalGetTestFiles('image'); |
37 $file = reset($files); | 38 $file = reset($files); |
38 $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME); | 39 /** @var \Drupal\Core\File\FileSystemInterface $file_system */ |
40 $file_system = \Drupal::service('file_system'); | |
41 $original_uri = $file_system->copy($file->uri, 'public://', FileSystemInterface::EXISTS_RENAME); | |
39 | 42 |
40 // Create a style. | 43 // Create a style. |
41 /** @var $style \Drupal\image\ImageStyleInterface */ | 44 /** @var $style \Drupal\image\ImageStyleInterface */ |
42 $style = ImageStyle::create(['name' => 'test', 'label' => 'Test']); | 45 $style = ImageStyle::create(['name' => 'test', 'label' => 'Test']); |
43 $style->save(); | 46 $style->save(); |
44 $generated_uri = 'public://styles/test/public/' . \Drupal::service('file_system')->basename($original_uri); | 47 $generated_uri = 'public://styles/test/public/' . $file_system->basename($original_uri); |
45 $url = file_url_transform_relative($style->buildUrl($original_uri)); | 48 $url = file_url_transform_relative($style->buildUrl($original_uri)); |
46 | 49 |
47 $variables = [ | 50 $variables = [ |
48 '#theme' => 'image_style', | 51 '#theme' => 'image_style', |
49 '#style_name' => 'test', | 52 '#style_name' => 'test', |
255 '#uri' => $original_uri, | 258 '#uri' => $original_uri, |
256 '#width' => 40, | 259 '#width' => 40, |
257 '#height' => 20, | 260 '#height' => 20, |
258 ]; | 261 ]; |
259 // PNG original image. Should be resized to 100x100. | 262 // PNG original image. Should be resized to 100x100. |
260 $generated_uri = 'public://styles/test_uri/public/' . \Drupal::service('file_system')->basename($original_uri); | 263 $generated_uri = 'public://styles/test_uri/public/' . $file_system->basename($original_uri); |
261 $url = file_url_transform_relative($style->buildUrl($original_uri)); | 264 $url = file_url_transform_relative($style->buildUrl($original_uri)); |
262 $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="100" height="100" alt="" class="image-style-test-uri" />'); | 265 $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="100" height="100" alt="" class="image-style-test-uri" />'); |
263 $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.'); | 266 $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.'); |
264 $this->drupalGet($this->getAbsoluteUrl($url)); | 267 $this->drupalGet($this->getAbsoluteUrl($url)); |
265 $this->assertResponse(200, 'Image was generated at the URL.'); | 268 $this->assertResponse(200, 'Image was generated at the URL.'); |
267 $image_file = $image_factory->get($generated_uri); | 270 $image_file = $image_factory->get($generated_uri); |
268 $this->assertEqual($image_file->getWidth(), 100); | 271 $this->assertEqual($image_file->getWidth(), 100); |
269 $this->assertEqual($image_file->getHeight(), 100); | 272 $this->assertEqual($image_file->getHeight(), 100); |
270 // GIF original image. Should be resized to 50x50. | 273 // GIF original image. Should be resized to 50x50. |
271 $file = $files[1]; | 274 $file = $files[1]; |
272 $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME); | 275 $original_uri = $file_system->copy($file->uri, 'public://', FileSystemInterface::EXISTS_RENAME); |
273 $generated_uri = 'public://styles/test_uri/public/' . \Drupal::service('file_system')->basename($original_uri); | 276 $generated_uri = 'public://styles/test_uri/public/' . $file_system->basename($original_uri); |
274 $url = file_url_transform_relative($style->buildUrl($original_uri)); | 277 $url = file_url_transform_relative($style->buildUrl($original_uri)); |
275 $variables['#uri'] = $original_uri; | 278 $variables['#uri'] = $original_uri; |
276 $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="50" height="50" alt="" class="image-style-test-uri" />'); | 279 $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="50" height="50" alt="" class="image-style-test-uri" />'); |
277 $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.'); | 280 $this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.'); |
278 $this->drupalGet($this->getAbsoluteUrl($url)); | 281 $this->drupalGet($this->getAbsoluteUrl($url)); |