1 image.test | public ImageStyleFlushTest::testFlush() |
General test to flush a style.
File
- core/
modules/ image/ tests/ image.test, line 1836 - Tests for image.module.
Class
- ImageStyleFlushTest
- Tests flushing of image styles.
Code
public function testFlush() {
// Setup a style to be created and effects to add to it.
$style_name = strtolower($this->randomName(10));
$style_label = $this->randomName();
$style_path = 'admin/config/media/image-styles/configure/' . $style_name;
$effect_edits = array(
'image_resize' => array(
'data[width]' => 100,
'data[height]' => 101,
),
'image_scale' => array(
'data[width]' => 110,
'data[height]' => 111,
'data[upscale]' => 1,
),
);
// Add style form.
$edit = array(
'name' => $style_name,
'label' => $style_label,
);
$this->backdropPost('admin/config/media/image-styles/add', $edit, t('Save and add effects'));
// Add each sample effect to the style.
foreach ($effect_edits as $effect => $edit) {
// Add the effect.
$this->backdropPost($style_path, array('new' => $effect), t('Add'));
if (!empty($edit)) {
$this->backdropPost(NULL, $edit, t('Add effect'));
}
}
// Load the saved image style.
backdrop_static_reset('image_styles');
$style = image_style_load($style_name);
// Create an image for the 'public' wrapper.
$image_path = $this->createSampleImage($style, 'public');
// Expecting to find 2 images, one is the sample.png image shown in
// image style preview.
$this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Create an image for the 'private' wrapper.
$image_path = $this->createSampleImage($style, 'private');
$this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Remove the 'image_scale' effect and updates the style, which in turn
// forces an image style flush.
$effect = array_pop($style['effects']);
$this->backdropPost($style_path . '/effects/' . $effect['ieid'] . '/delete', array(), t('Delete'));
$this->assertResponse(200);
$this->backdropPost($style_path, array(), t('Update style'));
$this->assertResponse(200);
// Post flush, expected 1 image in the 'public' wrapper (sample.png).
$this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'public')));
// Post flush, expected no image in the 'private' wrapper.
$this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'private')));
}