imagecache_proportions.test in Imagecache Proportions 7
Tests for imagecache_proportions
File
imagecache_proportions.testView source
<?php
/**
* @file
* Tests for imagecache_proportions
*/
class ImagecacheProportionsTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Imagecache Proportions test proportions',
'description' => 'Test the processing of image style proportions',
'group' => 'Imagecache Proportions',
);
}
/**
* Tests if the image style is well calculated from image size.
*/
function testCalculateProportions() {
$cases = array();
$cases[] = array(
'width' => 100,
'height' => 100,
'looseness' => 0,
'style' => 'squared_preset',
);
$cases[] = array(
'width' => 200,
'height' => 100,
'looseness' => 0,
'style' => 'horizontal_preset',
);
$cases[] = array(
'width' => 100,
'height' => 200,
'looseness' => 0,
'style' => 'vertical_preset',
);
$cases[] = array(
'width' => 120,
'height' => 100,
'looseness' => 20,
'style' => 'squared_preset',
);
$cases[] = array(
'width' => 100,
'height' => 120,
'looseness' => 20,
'style' => 'squared_preset',
);
$cases[] = array(
'width' => 121,
'height' => 100,
'looseness' => 20,
'style' => 'horizontal_preset',
);
$cases[] = array(
'width' => 100,
'height' => 121,
'looseness' => 20,
'style' => 'vertical_preset',
);
foreach ($cases as $case) {
$style = imagecache_proportions_calculate_proportions($case['width'], $case['height'], $case['looseness']);
$this
->assertEqual($style, $case['style'], t('Styles Match'));
}
}
}
class ImagecacheProportionsDisplaytestCase extends ImageFieldTestCase {
function setUp() {
parent::setUp('imagecache_proportions');
}
public static function getInfo() {
return array(
'name' => 'Imagecache Proportions display test',
'description' => 'Test the display of imagecache proportions',
'group' => 'Imagecache Proportions',
);
}
/**
* Tests imagecache proportions formatters on node display.
*/
function testDisplayStyles() {
module_load_include('test', 'image');
$scheme = 'public';
$field_name = strtolower($this
->randomName());
$this
->createImageField($field_name, 'article', array(
'uri_scheme' => $scheme,
));
$image = current($this
->drupalGetTestFiles('image'));
$nid = $this
->uploadNodeImage($image, $field_name, 'article');
$node = node_load($nid, NULL, TRUE);
$image_uri = $node->{$field_name}[LANGUAGE_NONE][0]['uri'];
$image_info = array(
'path' => $image_uri,
'width' => 40,
'height' => 20,
);
$instance = field_info_instance('node', $field_name, 'article');
// Test link to image.
$instance['display']['default']['type'] = 'image';
$instance['display']['default']['settings']['image_link'] = 'file';
field_update_instance($instance);
$default_output = l(theme('image', $image_info), file_create_url($image_uri), array(
'html' => TRUE,
));
$this
->drupalGet('node/' . $nid);
$this
->assertRaw($default_output, t('Image linked to file formatter displaying correctly on full node view.'));
// Test link to node.
$instance['display']['default']['settings']['image_link'] = 'content';
field_update_instance($instance);
$default_output = l(theme('image', $image_info), 'node/' . $nid, array(
'html' => TRUE,
'attributes' => array(
'class' => 'active',
),
));
$this
->drupalGet('node/' . $nid);
$this
->assertRaw($default_output, t('Image linked to content formatter displaying correctly on full node view.'));
// Test link to none.
$instance['display']['default']['settings']['image_link'] = '';
field_update_instance($instance);
$default_output = theme('image', $image_info);
$this
->drupalGet('node/' . $nid);
$this
->assertRaw($default_output, t('Image style thumbnail formatter displaying correctly on full node view.'));
}
}
Classes
Name | Description |
---|---|
ImagecacheProportionsDisplaytestCase | |
ImagecacheProportionsTestCase | @file Tests for imagecache_proportions |