~acquia/drupal/1.x-6.x

« back to all changes in this revision

Viewing changes to modules/acquia/image/contrib/image_attach/tests/image_attach.test

  • Committer: Peter Wolanin
  • Date: 2010-09-16 20:46:19 UTC
  • Revision ID: pwolanin@quita.local-20100916204619-3vmf2ohk25lu741e
   Acquia Drupal 1.2.28 (Drupal 6.19 core) has just been released and
   contains important security updates and bug fixes. We recommend that
   you update to the new version as soon as possible.
    1. Please reference the [1]Getting Started Guide for information about
       updating your site.
    2. Next, [2]download the new version.

   Acquia Drupal consists of Acquia's package of Drupal core with a
   curated set of contributed modules, plus the ability to connect to the
   Acquia Network. Acquia Drupal 1.2.28 (Drupal 6.19 core) includes the
   following updates: 
   ===================================================
     * Updated the Mollom module to [3]6.x-1.14. This includes a security
       fix for an information disclosure vulnerability described in
       [4]SA-CONTRIB-2010-091.
     * Updated the Acquia Network Connector to [5]6.x-1.10 which includes
       the ability to get a free 30 day trial of the Acquia Network from
       within the Drupal site.
     * Updated the Administration menu module to [6]6.x-1.6.
     * Updated the Image module to [7]6.x-1.0-beta6.
     * Updated the jQuery UI module to [8]6.x-1.4.
     * Updated the Printer, e-mail and PDF versions module to [9]6.x-1.12.
     * Updated the Webform module to [10]6.x-2.10.

References

   1. http://acquia.com/documentation/getting-started/introduction
   2. http://acquia.com/downloads
   3. http://drupal.org/node/912420
   4. http://drupal.org/node/912412
   5. http://drupal.org/node/913758
   6. http://drupal.org/node/901356
   7. http://drupal.org/node/893072
   8. http://drupal.org/node/906160
   9. http://drupal.org/node/889974
  10. http://drupal.org/node/883396

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: image_attach.test,v 1.1 2010/01/10 17:33:50 joachim Exp $
 
3
 
 
4
/**
 
5
 * Test image functionality.
 
6
 */
 
7
class ImageAttachTestCase extends DrupalWebTestCase {
 
8
 
 
9
  protected $user_admin;
 
10
  protected $user_no_attach;
 
11
  protected $user_no_create;
 
12
 
 
13
  function getInfo() {
 
14
    return array(
 
15
      'name' => t('Image attach functionality'),
 
16
      'description' => t('Test Image attach module functionality.'),
 
17
      'group' => t('Image'),
 
18
    );
 
19
  }
 
20
 
 
21
  function setUp() {
 
22
    parent::setUp('image', 'node', 'image_attach');
 
23
    
 
24
    // Enable attaching on story nodes
 
25
    variable_set('image_attach_story', TRUE);  
 
26
 
 
27
    // User to create nodes etc.
 
28
    $this->user_admin = $this->drupalCreateUser(array(
 
29
      'create images', 'view original images', 'edit own images',
 
30
      'create story content', 'edit any story content',
 
31
      'administer content types',
 
32
      'attach images',
 
33
    ));
 
34
    $this->drupalLogin($this->user_admin);
 
35
    
 
36
    // Uploadable image.
 
37
    $this->image = 'misc/druplicon.png';
 
38
  }
 
39
 
 
40
  /**
 
41
   * Verify that the module's settings appear in the correct places.
 
42
   */
 
43
  function testSettings() {
 
44
    $this->drupalGet('admin/content/node-type/story');
 
45
    $this->assertText(t('Image Attach settings'), t('Image attach settings displayed on the story type settings page.'));
 
46
    
 
47
    $this->drupalGet('admin/content/node-type/image');
 
48
    $this->assertNoText(t('Image Attach settings'), t('Image attach settings are not available on the image type settings page.'));
 
49
  }
 
50
  
 
51
  /**
 
52
   * Verify that on the form for new nodes the image attach form component is 
 
53
   * presented in the correct way (or indeed not at all) for the various 
 
54
   * combinations of permissions.
 
55
   */
 
56
  function testAddNodeAttaching() {
 
57
    // Create an image.
 
58
    $edit = array(
 
59
      'title' => $this->randomName(),
 
60
      'body' => $this->randomName(),
 
61
      'files[image]' => realpath($this->image),
 
62
    );
 
63
    $this->drupalPost('node/add/image', $edit, t('Save'));
 
64
 
 
65
    // Check existing image nodes either show or don't show as potential attachments,
 
66
    // depending on the setting.
 
67
    variable_set('image_attach_existing', FALSE);
 
68
    $this->drupalGet('node/add/story');
 
69
    $this->assertNoFieldById('edit-iids', '', t("With 'Attached existing images' DISABLED, existing images selection box is NOT shown on a new node form."));
 
70
    
 
71
    variable_set('image_attach_existing', TRUE);
 
72
    $this->drupalGet('node/add/story');
 
73
    $this->assertFieldById('edit-iids', '', t("With 'Attached existing images' enabled, existing images selection box is shown on a new node form."));
 
74
    
 
75
    // Check that a user who may attach images but not create them cannot see
 
76
    // the upload part of the form
 
77
    $this->user_no_create = $this->drupalCreateUser(array(
 
78
      'attach images',
 
79
      'create story content', 'edit any story content',
 
80
    ));
 
81
    $this->drupalLogin($this->user_no_create);
 
82
    // ... with existing images disabled, no part of the form should be visible.
 
83
    variable_set('image_attach_existing', FALSE);
 
84
    $this->drupalGet('node/add/story');
 
85
    $this->assertNoText(t('Attached images'), t("With existing images DISABLED, a user without the 'create images' permission can NOT attach images at all."));
 
86
    
 
87
    // ... with exiting images enabled, they still can't upload.
 
88
    variable_set('image_attach_existing', TRUE);
 
89
    $this->drupalGet('node/add/story');
 
90
    $this->assertNoFieldById('edit-image', '', t("A user without the 'create images' permission can NOT upload a new image to attach."));
 
91
   
 
92
    // Check that a user who may not attach images cannot see
 
93
    // any part of the form.
 
94
    $this->user_no_attach = $this->drupalCreateUser(array(
 
95
      'create story content', 'edit any story content',
 
96
    ));
 
97
    $this->drupalLogin($this->user_no_attach);
 
98
    $this->drupalGet('node/add/story');
 
99
    $this->assertNoText(t('Attached images'), t("A user without the 'attach images' permission can NOT attach images at all."));
 
100
  }
 
101
  
 
102
  /**
 
103
   * Verify that on the form for existing nodes the image attach form component is 
 
104
   * presented in the correct way (or indeed not at all) for the various 
 
105
   * combinations of permissions.
 
106
   */
 
107
  function testEditNodeAttaching() {
 
108
    variable_set('image_attach_existing', TRUE);
 
109
    
 
110
    // Create an image.
 
111
    $edit = array(
 
112
      'title' => $this->randomName(),
 
113
      'body' => $this->randomName(),
 
114
      'files[image]' => realpath($this->image),
 
115
    );    
 
116
    $this->drupalPost('node/add/image', $edit, t('Save'));
 
117
    $attached_image_node = node_load(array('title' => $edit['title']));
 
118
    
 
119
    // Create a story, attaching the existing image node.
 
120
    $edit = array(
 
121
      'title' => $this->randomName(),
 
122
      'body' => $this->randomName(),
 
123
      'iids[]' => array($attached_image_node->nid),
 
124
    );
 
125
    $this->drupalPost('node/add/story', $edit, t('Save'));
 
126
    $story_node = node_load(array('title' => $edit['title']));
 
127
 
 
128
    //  file_put_contents('DEBUGstory.html', $this->drupalGetContent());
 
129
    /*
 
130
    // TODO: test images are attached properly whether existing or new files.
 
131
    $this->drupalGet('node/' . $story_node->nid);
 
132
    $this->assertPattern('@<img[^>]+?' . $image_node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the story node page.'));
 
133
    */
 
134
    
 
135
    // Check that with existing images disabled 
 
136
    variable_set('image_attach_existing', FALSE);
 
137
    // Create an UNATTACHED image.
 
138
    $edit = array(
 
139
      'title' => $this->randomName(),
 
140
      'body' => $this->randomName(),
 
141
      'files[image]' => realpath($this->image),
 
142
    );    
 
143
    $this->drupalPost('node/add/image', $edit, t('Save'));
 
144
    $free_image_node = node_load(array('title' => $edit['title']));
 
145
    
 
146
    // TODO: test that only attached nodes are presented in the field -- ie that
 
147
    // $free_image_node is not available as an option.
 
148
    // NO IDEA how to do this in simpletest.
 
149
    /*
 
150
    $this->drupalGet('node/' . $story_node->nid);
 
151
    $this->assertFalse($this->setField('iids[]', $free_image_node->title));
 
152
    */
 
153
  }
 
154
}