1 filter_image_dialog.test public FilterEditorImageDialogTestCase::testEditorImageStyleDimensions()

Check image dimension transform when using style.

File

core/modules/filter/tests/filter_image_dialog.test, line 70
Functional tests for the Filter module.

Class

FilterEditorImageDialogTestCase
Test for filter editor image dialog.

Code

public function testEditorImageStyleDimensions() {
  // Create dummy image file.
  file_unmanaged_copy('core/misc/feed.png', $this->public_files_directory . '/dummy.png');
  $image = entity_create('file', array());
  $image->uri = 'public://dummy.png';
  $image->filename = 'dummy.png';
  $image->type = 'image';
  $image->uid = $this->editorUser->uid;
  $image->status = 0;
  $image->save();

  // Create a node and get the nid for the calling path.
  $node = $this->backdropCreateNode();
  $calling_path = "node/{$node->nid}/edit";
  $link_token = filter_editor_dialog_token($this->format, 'image', $this->editorUser, $calling_path);
  $options = array(
    'query' => array(
      'token' => $link_token,
      'calling_path' => $calling_path,
    ),
  );
  $this->backdropGet('editor/dialog/image/' . $this->format->format, $options);

  // Insert path of the file created above.
  $path = base_path() . $this->public_files_directory . '/' . $image->filename;
  $file_path = base_path() . $this->public_files_directory;

  // Use "Medium" image style, simulate picking from library.
  $edit = array(
    'attributes[src]' => $path,
    'image_style' => 'medium',
  );
  $this->backdropPost(NULL, $edit, t('Insert'));
  $this->assertRaw('width:250|height:250|src:' . $file_path . '/styles/medium/public/dummy.png|fid:1', 'Image dimensions adapted, image style path in use.');

  // Also set width and height attribute, which should get ignored.
  $edit = array(
    'attributes[src]' => $path,
    'image_style' => 'medium',
    'attributes[width]' => 500,
    'attributes[height]' => 500,
  );
  $this->backdropPost(NULL, $edit, t('Insert'));
  $this->assertRaw('width:250|height:250|src:' . $file_path . '/styles/medium/public/dummy.png|fid:1', 'Image dimensions adapted, custom dimensions ignored, image style path in use.');

  // Set width and height for original image (no image style).
  $edit = array(
    'attributes[src]' => $path,
    'image_style' => '',
    'attributes[width]' => 500,
    'attributes[height]' => 500,
  );
  $this->backdropPost(NULL, $edit, t('Insert'));
  $this->assertRaw('width:500|height:500|src:' . $file_path . '/dummy.png|fid:1', 'Custom image dimensions set, image served from original path.');

  // Simulate upload - as far as AJAX upload can be simulated.
  $edit = array(
    'fid[fid]' => '1',
    'image_style' => 'large',
  );
  $this->backdropPost(NULL, $edit, t('Insert'));
  $this->assertRaw('width:600|height:600|src:' . $file_path . '/styles/large/public/dummy.png|fid:1', 'Image dimensions adapted, image style path in use.');

}