View source
<?php
class ImageFieldTestCase extends FileFieldTestCase {
function setUp() {
$modules = array_merge(func_get_args(), array(
'content',
'filefield',
'imagefield',
'token',
'views',
));
call_user_func_array('parent::setUp', $modules);
}
function createImageField($name, $type, $field_options = array(), $widget_options = array()) {
$display_options = array(
'label' => array(
'format' => 'above',
),
'teaser' => array(
'format' => 'image_plain',
'exclude' => 0,
),
'full' => array(
'format' => 'image_plain',
'exclude' => 0,
),
);
$field_options = array_merge(array(
'widget_type' => 'imagefield_widget',
'display_settings' => $display_options,
), $field_options);
$widget_options = array_merge(array(
'type' => 'imagefield_widget',
'file_extensions' => 'jpg jpeg png gif',
'custom_alt' => '1',
'custom_title' => '1',
'max_resolution' => '',
'min_resolution' => '',
), $widget_options);
return parent::createFileField($name, $type, $field_options, $widget_options);
}
}
class ImageFieldDisplayTestCase extends ImageFieldTestCase {
function getInfo() {
return array(
'name' => t('ImageField display tests'),
'description' => t('Test the display of image fields in nodes.'),
'group' => t('ImageField'),
);
}
function testNodeDisplay() {
$field_name = 'field_' . strtolower($this
->randomName());
$type = $this
->drupalCreateContentType();
$field = $this
->createImageField($field_name, $type->name, array(), array(
'custom_alt' => '1',
'custom_title' => '1',
));
$test_file = $this
->getTestFile('image');
$nid = $this
->uploadNodeFile($test_file, $field, $type->name);
$edit = array(
$field['field_name'] . '[0][data][alt]' => 'foo',
$field['field_name'] . '[0][data][title]' => 'bar',
);
$this
->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$node = node_load($nid, NULL, TRUE);
$node_file = $node->{$field['field_name']}[0];
$class = 'imagefield imagefield-' . $field['field_name'];
$default_output = theme('imagefield_image', $node_file, $node_file['data']['alt'], $node_file['data']['title'], array(
'class' => $class,
));
$this
->assertRaw($default_output, t('Image formatter displaying correctly on full node view.'));
}
function testDefaultImage() {
$field_name = 'field_' . strtolower($this
->randomName());
$type = $this
->drupalCreateContentType();
$type->url_name = str_replace('_', '-', $type->name);
$field = $this
->createImageField($field_name, $type->name);
$test_file = $this
->getTestFile('image');
$destination = file_directory_path();
$default_image = field_file_save_file($test_file->filepath, array(), $destination);
$widget_options = array(
'use_default_image' => '1',
'default_image' => $default_image,
);
$field = $this
->updateFileField($field_name, $type->name, array(), $widget_options);
$edit = array(
'title' => $this
->randomName(),
);
$this
->drupalPost('node/add/' . $type->url_name, $edit, t('Save'));
$class = 'imagefield imagefield-' . $field['field_name'];
$default_output = theme('imagefield_image', $default_image, NULL, NULL, array(
'class' => $class,
));
$this
->assertRaw($default_output, t('Default image displaying correctly on full node view.'));
}
}
class ImageFieldValidateTestCase extends FileFieldValidateTestCase {
function getInfo() {
return array(
'name' => t('ImageField validation tests'),
'description' => t('Tests validation functions such as miniumum and maximum resolution, plus running all normal FileField validation tests.'),
'group' => t('ImageField'),
);
}
function setUp() {
$modules = array_merge(func_get_args(), array(
'content',
'filefield',
'imagefield',
'token',
'views',
));
call_user_func_array(array(
$this,
'parent::setUp',
), $modules);
$widget_options = array(
'type' => 'imagefield_widget',
'module' => 'imagefield',
'custom_alt' => '1',
'custom_title' => '1',
'max_resolution' => '',
'min_resolution' => '',
);
$this->field = $this
->updateFileField($this->field['field_name'], $this->node_type->name, array(), $widget_options);
}
function testResolution() {
$type = $this->node_type;
$field = $this->field;
$test_file = $this
->getTestFile('image', 64027);
$test_image_info = image_get_info($test_file->filepath);
$width = $test_image_info['width'];
$height = $test_image_info['height'];
$widget_options = array(
'min_resolution' => $width + 1 . 'x1',
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw(t('The image is too small; the minimum dimensions are'), t('Image could not be saved when too small horizontally.'));
$widget_options = array(
'min_resolution' => '1x' . ($height + 1),
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw('The image is too small; the minimum dimensions are', t('Image could not be saved when too small vertically.'));
$widget_options = array(
'min_resolution' => '',
'max_resolution' => $width / 4 . 'x40000',
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$nid = $this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw('The image was resized to fit within the maximum allowed dimensions', t('Image resized when too large horizontally.'));
$node = node_load($nid, NULL, TRUE);
$node_file = $node->{$field['field_name']}[0];
$image_info = image_get_info($node_file['filepath']);
$this
->assertTrue($image_info['height'] == $height / 4 && $image_info['width'] == $width / 4, t('Resized image has proper dimensions.'));
$widget_options = array(
'max_resolution' => '40000x' . $height / 2,
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$nid = $this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw('The image was resized to fit within the maximum allowed dimensions', t('Image resized when too large vertically.'));
$node = node_load($nid, NULL, TRUE);
$node_file = $node->{$field['field_name']}[0];
$image_info = image_get_info($node_file['filepath']);
$this
->assertTrue($image_info['height'] == $height / 2 && $image_info['width'] == $width / 2, t('Resized image has proper dimensions.'));
$widget_options = array(
'min_resolution' => '360x240',
'max_resolution' => '360x240',
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$nid = $this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertNoRaw('The image was resized to fit within the maximum allowed dimensions', t('Image was not resized when uploaded with exact dimensions.'));
$node = node_load($nid, NULL, TRUE);
$node_file = $node->{$field['field_name']}[0];
$image_info = image_get_info($node_file['filepath']);
$this
->assertTrue($image_info['height'] == $height && $image_info['width'] == $width, t('Resized image has proper dimensions.'));
$widget_options = array(
'min_resolution' => '300x200',
'max_resolution' => '340x220',
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$nid = $this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw('The image was resized to fit within the maximum allowed dimensions', t('Image was resized when fitting between maximum and minimum dimensions.'));
$widget_options = array(
'min_resolution' => '220x360',
'max_resolution' => '240x360',
);
$this
->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
$nid = $this
->uploadNodeFile($test_file, $this->field, $type->name);
$this
->assertRaw('The image will not fit between the dimensions of', t('Image was not uploaded when not fitting between maximum and minimum dimensions.'));
}
function testFileMaxSize() {
return;
}
function testNodeMaxSize() {
return;
}
}