diff options
Diffstat (limited to 'modules/image/image.test')
-rw-r--r-- | modules/image/image.test | 268 |
1 files changed, 265 insertions, 3 deletions
diff --git a/modules/image/image.test b/modules/image/image.test index ff5083a3d..e4b6d373a 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -105,7 +105,7 @@ class ImageFieldTestCase extends DrupalWebTestCase { /** * Tests the functions for generating paths and URLs for image styles. */ -class ImageStylesPathAndUrlUnitTest extends DrupalWebTestCase { +class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase { protected $style_name; protected $image_info; protected $image_filepath; @@ -370,6 +370,21 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase { } /** + * Test creating an image style with a numeric name and ensuring it can be + * applied to an image. + */ + function testNumericStyleName() { + $style_name = rand(); + $edit = array( + 'name' => $style_name, + ); + $this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style')); + $this->assertRaw(t('Style %name was created.', array('%name' => $style_name)), t('Image style successfully created.')); + $options = image_style_options(); + $this->assertTrue(array_key_exists($style_name, $options), t('Array key %key exists.', array('%key' => $style_name))); + } + + /** * General test to add a style, add/remove/edit effects to it, then delete it. */ function testStyle() { @@ -602,7 +617,8 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase { // Create an image field that uses the new style. $field_name = strtolower($this->randomName(10)); - $instance = $this->createImageField($field_name, 'article'); + $this->createImageField($field_name, 'article'); + $instance = field_info_instance('node', $field_name, 'article'); $instance['display']['default']['type'] = 'image'; $instance['display']['default']['settings']['image_style'] = $style_name; field_update_instance($instance); @@ -823,6 +839,23 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase { } /** + * Test passing attributes into the image field formatters. + */ + function testImageFieldFormatterAttributes() { + $image = theme('image_formatter', array( + 'item' => array( + 'uri' => 'http://example.com/example.png', + 'attributes' => array( + 'data-image-field-formatter' => 'testFound', + ), + 'alt' => t('Image field formatter attribute test.'), + 'title' => t('Image field formatter'), + ), + )); + $this->assertTrue(stripos($image, 'testFound') > 0, t('Image field formatters can have attributes.')); + } + + /** * Test use of a default image with an image field. */ function testImageFieldDefaultImage() { @@ -949,7 +982,7 @@ class ImageFieldValidateTestCase extends ImageFieldTestCase { /** * Tests that images have correct dimensions when styled. */ -class ImageDimensionsUnitTest extends DrupalWebTestCase { +class ImageDimensionsTestCase extends DrupalWebTestCase { public static function getInfo() { return array( @@ -1304,3 +1337,232 @@ class ImageDimensionsScaleTestCase extends DrupalUnitTestCase { } } } + +/** + * Tests default image settings. + */ +class ImageFieldDefaultImagesTestCase extends ImageFieldTestCase { + + public static function getInfo() { + return array( + 'name' => 'Image field default images tests', + 'description' => 'Tests setting up default images both to the field and field instance.', + 'group' => 'Image', + ); + } + + function setUp() { + parent::setUp(array('field_ui')); + } + + /** + * Tests CRUD for fields and fields instances with default images. + */ + function testDefaultImages() { + // Create files to use as the default images. + $files = $this->drupalGetTestFiles('image'); + $default_images = array(); + foreach (array('field', 'instance', 'instance2', 'field_new', 'instance_new') as $image_target) { + $file = array_pop($files); + $file = file_save($file); + $default_images[$image_target] = $file; + } + + // Create an image field and add an instance to the article content type. + $field_name = strtolower($this->randomName()); + $field_settings = array( + 'default_image' => $default_images['field']->fid, + ); + $instance_settings = array( + 'default_image' => $default_images['instance']->fid, + ); + $widget_settings = array( + 'preview_image_style' => 'medium', + ); + $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings); + $field = field_info_field($field_name); + $instance = field_info_instance('node', $field_name, 'article'); + + // Add another instance with another default image to the page content type. + $instance2 = array_merge($instance, array( + 'bundle' => 'page', + 'settings' => array( + 'default_image' => $default_images['instance2']->fid, + ), + )); + field_create_instance($instance2); + $instance2 = field_info_instance('node', $field_name, 'page'); + + + // Confirm the defaults are present on the article field admin form. + $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); + $this->assertFieldByXpath( + '//input[@name="field[settings][default_image][fid]"]', + $default_images['field']->fid, + format_string( + 'Article image field default equals expected file ID of @fid.', + array('@fid' => $default_images['field']->fid) + ) + ); + $this->assertFieldByXpath( + '//input[@name="instance[settings][default_image][fid]"]', + $default_images['instance']->fid, + format_string( + 'Article image field instance default equals expected file ID of @fid.', + array('@fid' => $default_images['instance']->fid) + ) + ); + + // Confirm the defaults are present on the page field admin form. + $this->drupalGet("admin/structure/types/manage/page/fields/$field_name"); + $this->assertFieldByXpath( + '//input[@name="field[settings][default_image][fid]"]', + $default_images['field']->fid, + format_string( + 'Page image field default equals expected file ID of @fid.', + array('@fid' => $default_images['field']->fid) + ) + ); + $this->assertFieldByXpath( + '//input[@name="instance[settings][default_image][fid]"]', + $default_images['instance2']->fid, + format_string( + 'Page image field instance default equals expected file ID of @fid.', + array('@fid' => $default_images['instance2']->fid) + ) + ); + + // Confirm that the image default is shown for a new article node. + $article = $this->drupalCreateNode(array('type' => 'article')); + $article_built = node_view($article); + $this->assertEqual( + $article_built[$field_name]['#items'][0]['fid'], + $default_images['instance']->fid, + format_string( + 'A new article node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance']->fid) + ) + ); + + // Confirm that the image default is shown for a new page node. + $page = $this->drupalCreateNode(array('type' => 'page')); + $page_built = node_view($page); + $this->assertEqual( + $page_built[$field_name]['#items'][0]['fid'], + $default_images['instance2']->fid, + format_string( + 'A new page node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance2']->fid) + ) + ); + + // Upload a new default for the field. + $field['settings']['default_image'] = $default_images['field_new']->fid; + field_update_field($field); + + // Confirm that the new field default is used on the article admin form. + $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); + $this->assertFieldByXpath( + '//input[@name="field[settings][default_image][fid]"]', + $default_images['field_new']->fid, + format_string( + 'Updated image field default equals expected file ID of @fid.', + array('@fid' => $default_images['field_new']->fid) + ) + ); + + // Reload the nodes and confirm the field instance defaults are used. + $article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE)); + $page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE)); + $this->assertEqual( + $article_built[$field_name]['#items'][0]['fid'], + $default_images['instance']->fid, + format_string( + 'An existing article node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance']->fid) + ) + ); + $this->assertEqual( + $page_built[$field_name]['#items'][0]['fid'], + $default_images['instance2']->fid, + format_string( + 'An existing page node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance2']->fid) + ) + ); + + // Upload a new default for the article's field instance. + $instance['settings']['default_image'] = $default_images['instance_new']->fid; + field_update_instance($instance); + + // Confirm the new field instance default is used on the article field + // admin form. + $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); + $this->assertFieldByXpath( + '//input[@name="instance[settings][default_image][fid]"]', + $default_images['instance_new']->fid, + format_string( + 'Updated article image field instance default equals expected file ID of @fid.', + array('@fid' => $default_images['instance_new']->fid) + ) + ); + + // Reload the nodes. + $article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE)); + $page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE)); + + // Confirm the article uses the new default. + $this->assertEqual( + $article_built[$field_name]['#items'][0]['fid'], + $default_images['instance_new']->fid, + format_string( + 'An existing article node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance_new']->fid) + ) + ); + // Confirm the page remains unchanged. + $this->assertEqual( + $page_built[$field_name]['#items'][0]['fid'], + $default_images['instance2']->fid, + format_string( + 'An existing page node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance2']->fid) + ) + ); + + // Remove the instance default from articles. + $instance['settings']['default_image'] = NULL; + field_update_instance($instance); + + // Confirm the article field instance default has been removed. + $this->drupalGet("admin/structure/types/manage/article/fields/$field_name"); + $this->assertFieldByXpath( + '//input[@name="instance[settings][default_image][fid]"]', + '', + 'Updated article image field instance default has been successfully removed.' + ); + + // Reload the nodes. + $article_built = node_view($article = node_load($article->nid, NULL, $reset = TRUE)); + $page_built = node_view($page = node_load($page->nid, NULL, $reset = TRUE)); + // Confirm the article uses the new field (not instance) default. + $this->assertEqual( + $article_built[$field_name]['#items'][0]['fid'], + $default_images['field_new']->fid, + format_string( + 'An existing article node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['field_new']->fid) + ) + ); + // Confirm the page remains unchanged. + $this->assertEqual( + $page_built[$field_name]['#items'][0]['fid'], + $default_images['instance2']->fid, + format_string( + 'An existing page node without an image has the expected default image file ID of @fid.', + array('@fid' => $default_images['instance2']->fid) + ) + ); + } + +} |