summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2010-06-30 22:37:49 (GMT)
committerAngie Byron2010-06-30 22:37:49 (GMT)
commit0ed7c5051f468cf1537df8c9328873047b80ce21 (patch)
tree587f13d8555ba37bdee89ce09c6850ef0549b6fb
parent9085e3ab226115cfcf65aec5ea05a33b15f549ff (diff)
#841242 by justinrandell, Stevel: Fixed HEAD BROKEN: some file/image tests are failing.
-rw-r--r--modules/file/tests/file.test4
-rw-r--r--modules/image/image.test46
-rw-r--r--modules/simpletest/tests/file.test11
3 files changed, 38 insertions, 23 deletions
diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test
index 562db0a..b228cb3 100644
--- a/modules/file/tests/file.test
+++ b/modules/file/tests/file.test
@@ -491,8 +491,8 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name);
- // Get the test file (a GIF image).
$test_file = $this->getTestFile('image');
+ list(, $test_file_extension) = explode('.', $test_file->filename);
// Disable extension checking.
$this->updateFileField($field_name, $type_name, array('file_extensions' => ''));
@@ -513,7 +513,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase {
$this->assertRaw($error_message, t('Node save failed when file uploaded with the wrong extension.'));
// Enable extension checking for text and image files.
- $this->updateFileField($field_name, $type_name, array('file_extensions' => 'txt gif'));
+ $this->updateFileField($field_name, $type_name, array('file_extensions' => "txt $test_file_extension"));
// Check that the file can be uploaded with extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
diff --git a/modules/image/image.test b/modules/image/image.test
index e03b5d8..9f0604d 100644
--- a/modules/image/image.test
+++ b/modules/image/image.test
@@ -167,7 +167,7 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
// Create the directories for the styles.
$d = $scheme . '://styles/' . $this->style_name;
$status = file_prepare_directory($d, FILE_CREATE_DIRECTORY);
- $this->assertNotIdentical(FALSE, $status, t('Created the directory for the generated images for the test style.' ));
+ $this->assertNotIdentical(FALSE, $status, t('Created the directory for the generated images for the test style.'));
// Create a working copy of the file.
$files = $this->drupalGetTestFiles('image');
@@ -212,8 +212,8 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase {
$this->drupalGet($expected_generated_url);
$this->assertEqual($actual_generated_url, $expected_generated_url, t('Got the download URL for an existing file.'));
$this->assertRaw(file_get_contents($generated_uri), t('URL returns expected file.'));
- $this->assertEqual($this->drupalGetHeader('Content-Type'), $image_info['mime_type'], t('Expected Content-Type was reported.'));
- $this->assertEqual($this->drupalGetHeader('Content-Length'), $image_info['file_size'], t('Expected Content-Length was reported.'));
+ $this->assertEqual($this->drupalGetHeader('Content-Type'), $generated_image_info['mime_type'], t('Expected Content-Type was reported.'));
+ $this->assertEqual($this->drupalGetHeader('Content-Length'), $generated_image_info['file_size'], t('Expected Content-Length was reported.'));
}
}
@@ -692,10 +692,12 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
* Tests for image field settings.
*/
function testImageFieldSettings() {
+ $test_image = current($this->drupalGetTestFiles('image'));
+ list(, $test_image_extension) = explode('.', $test_image->filename);
$field_name = strtolower($this->randomName());
$instance_settings = array(
'alt_field' => 1,
- 'file_extensions' => 'gif jpg jpeg',
+ 'file_extensions' => $test_image_extension,
'max_filesize' => '50 KB',
'max_resolution' => '100x100',
'min_resolution' => '10x10',
@@ -709,12 +711,11 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$this->drupalGet('node/add/article');
$this->assertText(t('Files must be less than 50 KB.'), t('Image widget max file size is displayed on article form.'));
- $this->assertText(t('Allowed file types: gif jpg jpeg.'), t('Image widget allowed file types displayed on article form.'));
+ $this->assertText(t('Allowed file types: ' . $test_image_extension . '.'), t('Image widget allowed file types displayed on article form.'));
$this->assertText(t('Images must be between 10x10 and 100x100 pixels.'), t('Image widget allowed resolution displayed on article form.'));
// We have to create the article first and then edit it because the alt
// and title fields do not display until the image has been attached.
- $test_image = current($this->drupalGetTestFiles('image'));
$nid = $this->uploadNodeImage($test_image, $field_name, 'article');
$this->drupalGet('node/' . $nid . '/edit');
$this->assertFieldByName($field_name . '[' . LANGUAGE_NONE . '][0][alt]', '', t('Alt field displayed on article form.'));
@@ -817,20 +818,33 @@ class ImageFieldValidateTestCase extends ImageFieldTestCase {
*/
function testResolution() {
$field_name = strtolower($this->randomName());
+ $min_resolution = 50;
+ $max_resolution = 100;
$instance_settings = array(
- 'max_resolution' => '100x100',
- 'min_resolution' => '50x50',
+ 'max_resolution' => $max_resolution . 'x' . $max_resolution,
+ 'min_resolution' => $min_resolution . 'x' . $min_resolution,
);
$this->createImageField($field_name, 'article', array(), $instance_settings);
- // Use image-test.png which has a resolution of 40x20.
- $test_image = current($this->drupalGetTestFiles('image', 48006));
- $nid = $this->uploadNodeImage($test_image, $field_name, 'article');
- $this->assertText(t('The specified file image-test.png could not be uploaded. The image is too small; the minimum dimensions are 50x50 pixels.'), t('Node save failed when minimum image resolution was not met.'));
-
- // Use image-1.png which has a resolution of 360x240.
- $test_image = current($this->drupalGetTestFiles('image', 64027));
- $nid = $this->uploadNodeImage($test_image, $field_name, 'article');
+ // We want a test image that is too small, and a test image that is too
+ // big, so cycle through test image files until we have what we need.
+ $image_that_is_too_big = FALSE;
+ $image_that_is_too_small = FALSE;
+ foreach ($this->drupalGetTestFiles('image') as $image) {
+ $info = image_get_info($image->uri);
+ if ($info['width'] > $max_resolution) {
+ $image_that_is_too_big = $image;
+ }
+ if ($info['width'] < $min_resolution) {
+ $image_that_is_too_small = $image;
+ }
+ if ($image_that_is_too_small && $image_that_is_too_big) {
+ break;
+ }
+ }
+ $nid = $this->uploadNodeImage($image_that_is_too_small, $field_name, 'article');
+ $this->assertText(t('The specified file ' . $image_that_is_too_small->filename . ' could not be uploaded. The image is too small; the minimum dimensions are 50x50 pixels.'), t('Node save failed when minimum image resolution was not met.'));
+ $nid = $this->uploadNodeImage($image_that_is_too_big, $field_name, 'article');
$this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'), t('Image exceeding max resolution was properly resized.'));
}
}
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index fe0ebc4..428b5a8 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -563,6 +563,7 @@ class FileSaveUploadTest extends FileHookTestCase {
$this->drupalLogin($account);
$this->image = current($this->drupalGetTestFiles('image'));
+ list(, $this->image_extension) = explode('.', $this->image->filename);
$this->assertTrue(is_file($this->image->uri), t("The image file we're going to upload exists."));
$this->phpfile = current($this->drupalGetTestFiles('php'));
@@ -665,8 +666,8 @@ class FileSaveUploadTest extends FileHookTestCase {
// Reset the hook counters.
file_test_reset();
- $extensions = 'foo gif';
- // Now tell file_save_upload() to allow ".gif".
+ $extensions = 'foo ' . $this->image_extension;
+ // Now tell file_save_upload() to allow the extension of our test image.
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->uri),
@@ -747,12 +748,12 @@ class FileSaveUploadTest extends FileHookTestCase {
function testHandleFileMunge() {
// Ensure insecure uploads are disabled for this test.
variable_set('allow_insecure_uploads', 0);
- $this->image = file_move($this->image, $this->image->uri . '.foo.gif');
+ $this->image = file_move($this->image, $this->image->uri . '.foo.' . $this->image_extension);
// Reset the hook counters to get rid of the 'move' we just called.
file_test_reset();
- $extensions = 'gif';
+ $extensions = $this->image_extension;
$edit = array(
'files[file_test_upload]' => drupal_realpath($this->image->uri),
'extensions' => $extensions,
@@ -760,7 +761,7 @@ class FileSaveUploadTest extends FileHookTestCase {
$munged_filename = $this->image->filename;
$munged_filename = substr($munged_filename, 0, strrpos($munged_filename, '.'));
- $munged_filename .= '_.gif';
+ $munged_filename .= '_.' . $this->image_extension;
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));