diff options
Diffstat (limited to 'modules/image/image.test')
-rw-r--r-- | modules/image/image.test | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/modules/image/image.test b/modules/image/image.test index 91091940d..1c8e1a5b0 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -47,48 +47,70 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { parent::setUp(); $this->style_name = 'style_foo'; - $this->scheme = 'public'; image_style_save(array('name' => $this->style_name)); - - // Create the directories for the styles. - $status = file_prepare_directory($d = file_directory_path() . '/styles/' . $this->style_name, 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. - $file = reset($this->drupalGetTestFiles('image')); - $this->image_info = image_get_info($file->uri); - $this->image_filepath = file_unmanaged_copy($file->uri, NULL, FILE_EXISTS_RENAME); - $this->assertNotIdentical(FALSE, $this->image_filepath, t('Created the without generated image file.')); } /** * Test image_style_path(). */ function testImageStylePath() { - $actual = image_style_path($this->style_name, $this->image_filepath); - $expected = $this->scheme . '://styles/' . $this->style_name . '/' . basename($this->image_filepath); - $this->assertEqual($actual, $expected, t('Got the path for a file.')); + $actual = image_style_path($this->style_name, 'public://foo/bar.gif'); + $expected = 'public://styles/' . $this->style_name . '/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'; + $this->assertEqual($actual, $expected, t('Got the path for a relative file path.')); + } + + /** + * Test image_style_url() with a file using the "public://" scheme. + */ + function testImageStyleUrlAndPathPublic() { + $this->_testImageStyleUrlAndPath('public'); + } + + /** + * Test image_style_url() with a file using the "private://" scheme. + */ + function testImageStyleUrlAndPathPrivate() { + $this->_testImageStyleUrlAndPath('private'); } /** * Test image_style_url(). */ - function testImageStyleUrl() { + function _testImageStyleUrlAndPath($scheme) { + // 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'); + file_prepare_directory($d = 'temporary://', FILE_CREATE_DIRECTORY); + + // Create the directories for the styles. + $status = file_prepare_directory($d = $scheme . '://styles/' . $this->style_name, 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. + $file = reset($this->drupalGetTestFiles('image')); + $image_info = image_get_info($file->uri); + $original_uri = file_unmanaged_copy($file->uri, $scheme . '://', FILE_EXISTS_RENAME); + $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_path = $this->scheme . '://styles/' . $this->style_name . '/' . basename($this->image_filepath); - $this->assertFalse(file_exists($generated_path), t('Generated file does not exist.')); - $expected_generate_url = url('image/generate/' . $this->style_name . '/' . $this->scheme . '/' . basename($this->image_filepath), array('absolute' => TRUE)); + $generated_uri = $scheme . '://styles/' . $this->style_name . '/' . 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, $this->image_filepath); + $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 . ':' . md5($this->image_filepath); + $lock_name = 'image_style_generate:' . $this->style_name . ':' . md5($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.')); @@ -97,21 +119,21 @@ class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { // Fetch the URL that generates the file. $this->drupalGet($expected_generate_url); - $this->assertTrue(file_exists($generated_path), t('Generated file was created.')); - $this->assertRaw(file_get_contents($generated_path), t('URL returns expected file.')); - $generated_image_info = image_get_info($generated_path); + $this->assertTrue(file_exists($generated_uri), t('Generated file was created.')); + $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_path); - $actual_generated_url = image_style_url($this->style_name, $this->image_filepath); + $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_path), t('URL returns expected file.')); - $this->assertEqual($this->drupalGetHeader('Content-Type'), $this->image_info['mime_type'], t('Expected Content-Type was reported.')); - $this->assertEqual($this->drupalGetHeader('Content-Length'), $this->image_info['file_size'], t('Expected Content-Length was reported.')); + $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.')); } } |