diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-04-30 21:25:39 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-04-30 21:25:39 -0700 |
commit | d0b5d31cbca7b5ce521ee180b6ca31e301b63b4e (patch) | |
tree | b28610c70815d08a95e38a5534a858457ed69117 /modules/image/image.test | |
parent | 84c4f7622e8cd2c90374e3907069aa256114558f (diff) | |
download | brdo-d0b5d31cbca7b5ce521ee180b6ca31e301b63b4e.tar.gz brdo-d0b5d31cbca7b5ce521ee180b6ca31e301b63b4e.tar.bz2 |
Issue #751168 by elliotttf, caktux, andyceo, setvik, xjm, sun, tim.plunkett: Fixed Regression: Missing 'Default image' per field instance.
Diffstat (limited to 'modules/image/image.test')
-rw-r--r-- | modules/image/image.test | 232 |
1 files changed, 231 insertions, 1 deletions
diff --git a/modules/image/image.test b/modules/image/image.test index 6775085f4..be6882764 100644 --- a/modules/image/image.test +++ b/modules/image/image.test @@ -587,7 +587,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); @@ -1306,3 +1307,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) + ) + ); + } + +} |