image_example.test

  1. examples
    1. 7 image_example/image_example.test
    2. 8 image_example/image_example.test

Test case for testing the image example module.

This file contains the tests cases to check if the module is performing as expected.

Classes

NameDescription
ImageExampleTestCase@file Test case for testing the image example module.

File

image_example/image_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test case for testing the image example module.
  5. *
  6. * This file contains the tests cases to check if the module is performing as
  7. * expected.
  8. */
  9. class ImageExampleTestCase extends DrupalWebTestCase {
  10. protected $web_user;
  11. public static function getInfo() {
  12. return array(
  13. 'name' => 'Image example functionality',
  14. 'description' => 'Test functionality of the Image Example module.',
  15. 'group' => 'Examples',
  16. );
  17. }
  18. /**
  19. * Enable modules and create user with specific permissions.
  20. */
  21. function setUp() {
  22. parent::setUp('image_example');
  23. // Create user with permission to administer image styles.
  24. $this->web_user = $this->drupalCreateUser(array('administer image styles', 'administer blocks'));
  25. }
  26. /**
  27. * Test implementations of image API hooks.
  28. */
  29. function testImageExample() {
  30. // Login the admin user.
  31. $this->drupalLogin($this->web_user);
  32. // Verify that the default style added by
  33. // image_example_image_default_styles() is in the list of image styles.
  34. $image_styles = image_styles();
  35. $this->assertTrue(isset($image_styles['image_example_style']), t('The default style image_example_style is in the list of image styles.'));
  36. // Verify that the effect added to the default 'thumbnail' style by
  37. // image_example_image_styles_alter() is present.
  38. $this->assertTrue((isset($image_styles['thumbnail']['effects'][1]['name']) && $image_styles['thumbnail']['effects'][1]['name'] == 'image_example_colorize'), t('Effect added to the thumbnail style via hook_image_styles_alter() is present.'));
  39. // Create a new image style and add the effect provided by
  40. // image_example_effect_info().
  41. $new_style = array('name' => drupal_strtolower($this->randomName()));
  42. $new_style = image_style_save($new_style);
  43. $this->assertTrue(isset($new_style['isid']), t('Image style @style_name created.', array('@style_name' => $new_style['name'])));
  44. $edit = array(
  45. 'new' => 'image_example_colorize',
  46. );
  47. $this->drupalPost('admin/config/media/image-styles/edit/' . $new_style['name'], $edit, t('Add'));
  48. // Verify the 'color' field provided by image_example_colorize_form()
  49. // appears on the effect configuration page. And that we can fill it out.
  50. $this->assertField('data[color]', t('Color field provided by image_example_effect_colorize_form is present on effect configuration page.'));
  51. $edit = array(
  52. 'data[color]' => '#000000',
  53. );
  54. $this->drupalPost(NULL, $edit, t('Add effect'));
  55. $this->assertText(t('The image effect was successfully applied.'), t('Colorize effect added to @style_name.', array('@style_name' => $new_style['name'])));
  56. // Set the variable 'image_example_style_name' to the name of our new style
  57. // then rename the style and ensure the variable name is changed.
  58. // @todo Enable this block once http://drupal.org/node/713872 is fixed.
  59. if (defined('bug_713872_fixed')) {
  60. $style = image_style_load($new_style['name']);
  61. variable_set('image_example_style_name', $style['name']);
  62. $style['name'] = drupal_strtolower($this->randomName());
  63. $style = image_style_save($style);
  64. $variable = variable_get('image_example_style_name', '');
  65. $this->assertTrue(($variable == $style['name']), t('Variable image_example_style_name successfully updated when renaming image style.'));
  66. }
  67. }
  68. /**
  69. * Tests for image block provided by module.
  70. */
  71. function testImageExamplePage() {
  72. // Login the admin user.
  73. $this->drupalLogin($this->web_user);
  74. $this->drupalCreateNode(array('promote' => 1));
  75. // Upload an image to the image page.
  76. $images = $this->drupalGetTestFiles('image');
  77. $edit = array(
  78. 'files[image_example_image_fid]' => drupal_realpath($images[0]->uri),
  79. 'image_example_style_name' => 'image_example_style',
  80. );
  81. $this->drupalPost('image_example/styles', $edit, t('Save'));
  82. $this->assertText(t('The image @image_name was uploaded', array('@image_name' => $images[0]->filename)), t('Image uploaded to image block.'));
  83. // Verify the image is displayed.
  84. $this->drupalGet('image_example/styles');
  85. $fid = variable_get('image_example_image_fid', FALSE);
  86. $image = isset($fid) ? file_load($fid) : NULL;
  87. $this->assertRaw(file_uri_target($image->uri), t('Image is displayed'));
  88. }
  89. }
Login or register to post comments