diff options
Diffstat (limited to 'modules/image/image.test')
-rw-r--r-- | modules/image/image.test | 60 |
1 files changed, 20 insertions, 40 deletions
diff --git a/modules/image/image.test b/modules/image/image.test index ec00a7209..3c0c9ca93 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -121,7 +121,7 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { } function setUp() { - parent::setUp(); + parent::setUp('image_module_test'); $this->style_name = 'style_foo'; image_style_save(array('name' => $this->style_name)); @@ -131,12 +131,13 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { * Test image_style_path(). */ function testImageStylePath() { - $actual = image_style_path($this->style_name, 'public://foo/bar.gif'); - $expected = 'public://styles/' . $this->style_name . '/foo/bar.gif'; + $scheme = 'public'; + $actual = image_style_path($this->style_name, "$scheme://foo/bar.gif"); + $expected = "$scheme://styles/" . $this->style_name . "/$scheme/foo/bar.gif"; $this->assertEqual($actual, $expected, t('Got the path for a file URI.')); $actual = image_style_path($this->style_name, 'foo/bar.gif'); - $expected = 'public://styles/' . $this->style_name . '/foo/bar.gif'; + $expected = "$scheme://styles/" . $this->style_name . "/$scheme/foo/bar.gif"; $this->assertEqual($actual, $expected, t('Got the path for a relative file path.')); } @@ -161,12 +162,10 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { // Make the default scheme neither "public" nor "private" to verify the // functions work for other than the default scheme. variable_set('file_default_scheme', 'temporary'); - $d = 'temporary://'; - file_prepare_directory($d, FILE_CREATE_DIRECTORY); // Create the directories for the styles. - $d = $scheme . '://styles/' . $this->style_name; - $status = file_prepare_directory($d, FILE_CREATE_DIRECTORY); + $directory = $scheme . '://styles/' . $this->style_name; + $status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY); $this->assertNotIdentical(FALSE, $status, t('Created the directory for the generated images for the test style.')); // Create a working copy of the file. @@ -174,46 +173,27 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { $file = reset($files); $image_info = image_get_info($file->uri); $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME); + // Let the image_module_test module know about this file, so it can claim + // ownership in hook_file_download(). + variable_set('image_module_test_file_download', $original_uri); $this->assertNotIdentical(FALSE, $original_uri, t('Created the generated image file.')); - // Get the URL of a file that has not been generated yet and try to access - // it before image_style_url has been called. - $generated_uri = $scheme . '://styles/' . $this->style_name . '/' . basename($original_uri); + // Get the URL of a file that has not been generated and try to create it. + $generated_uri = $scheme . '://styles/' . $this->style_name . '/' . $scheme . '/'. basename($original_uri); $this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.')); - $expected_generate_url = url('image/generate/' . $this->style_name . '/' . $scheme . '/' . basename($original_uri), array('absolute' => TRUE)); - $this->drupalGet($expected_generate_url); - $this->assertResponse(403, t('Access to generate URL was denied.')); - - // Check that a generate URL is returned. - $actual_generate_url = image_style_url($this->style_name, $original_uri); - $this->assertEqual($actual_generate_url, $expected_generate_url, t('Got the generate URL for a non-existent file.')); - - // Fetch the URL that generates the file while another process appears to - // be generating the same file (this is signaled using a lock). - $lock_name = 'image_style_generate:' . $this->style_name . ':' . drupal_hash_base64($original_uri); - $this->assertTrue(lock_acquire($lock_name), t('Lock was acquired.')); - $this->drupalGet($expected_generate_url); - $this->assertResponse(503, t('Service Unavailable response received.')); - $this->assertTrue($this->drupalGetHeader('Retry-After'), t('Retry-After header received.')); - lock_release($lock_name); + $generate_url = image_style_url($this->style_name, $original_uri); // Fetch the URL that generates the file. - $this->drupalGet($expected_generate_url); - $this->assertTrue(file_exists($generated_uri), t('Generated file was created.')); + $this->drupalGet($generate_url); + $this->assertResponse(200, t('Image was generated at the URL.')); + $this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.')); $this->assertRaw(file_get_contents($generated_uri), t('URL returns expected file.')); $generated_image_info = image_get_info($generated_uri); $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.')); - $this->assertTrue(lock_may_be_available($lock_name), t('Lock was released.')); - - // Check that the URL points directly to the generated file. - $expected_generated_url = file_create_url($generated_uri); - $actual_generated_url = image_style_url($this->style_name, $original_uri); - $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'), $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.')); + if ($scheme == 'private') { + $this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', t('Expected custom header has been added.')); + } } } @@ -684,7 +664,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { // Ensure the derrivative image is generated so we do not have to deal with // image style callback paths. $this->drupalGet(image_style_url('thumbnail', $image_uri)); - $image_info['path'] = image_style_url('thumbnail', $image_uri); + $image_info['path'] = image_style_path('thumbnail', $image_uri); $image_info['getsize'] = FALSE; $default_output = theme('image', $image_info); $this->drupalGet('node/' . $nid); |