2
// $Id: image_attach.test,v 1.1 2010/01/10 17:33:50 joachim Exp $
5
* Test image functionality.
7
class ImageAttachTestCase extends DrupalWebTestCase {
10
protected $user_no_attach;
11
protected $user_no_create;
15
'name' => t('Image attach functionality'),
16
'description' => t('Test Image attach module functionality.'),
17
'group' => t('Image'),
22
parent::setUp('image', 'node', 'image_attach');
24
// Enable attaching on story nodes
25
variable_set('image_attach_story', TRUE);
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',
34
$this->drupalLogin($this->user_admin);
37
$this->image = 'misc/druplicon.png';
41
* Verify that the module's settings appear in the correct places.
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.'));
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.'));
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.
56
function testAddNodeAttaching() {
59
'title' => $this->randomName(),
60
'body' => $this->randomName(),
61
'files[image]' => realpath($this->image),
63
$this->drupalPost('node/add/image', $edit, t('Save'));
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."));
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."));
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(
79
'create story content', 'edit any story content',
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."));
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."));
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',
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."));
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.
107
function testEditNodeAttaching() {
108
variable_set('image_attach_existing', TRUE);
112
'title' => $this->randomName(),
113
'body' => $this->randomName(),
114
'files[image]' => realpath($this->image),
116
$this->drupalPost('node/add/image', $edit, t('Save'));
117
$attached_image_node = node_load(array('title' => $edit['title']));
119
// Create a story, attaching the existing image node.
121
'title' => $this->randomName(),
122
'body' => $this->randomName(),
123
'iids[]' => array($attached_image_node->nid),
125
$this->drupalPost('node/add/story', $edit, t('Save'));
126
$story_node = node_load(array('title' => $edit['title']));
128
// file_put_contents('DEBUGstory.html', $this->drupalGetContent());
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.'));
135
// Check that with existing images disabled
136
variable_set('image_attach_existing', FALSE);
137
// Create an UNATTACHED image.
139
'title' => $this->randomName(),
140
'body' => $this->randomName(),
141
'files[image]' => realpath($this->image),
143
$this->drupalPost('node/add/image', $edit, t('Save'));
144
$free_image_node = node_load(array('title' => $edit['title']));
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.
150
$this->drupalGet('node/' . $story_node->nid);
151
$this->assertFalse($this->setField('iids[]', $free_image_node->title));