View source
<?php
class ImageAttachTestCase extends DrupalWebTestCase {
protected $user_admin;
protected $user_no_attach;
protected $user_no_create;
public static function getInfo() {
return array(
'name' => t('Image attach functionality'),
'description' => t('Test Image attach module functionality.'),
'group' => t('Image'),
);
}
function setUp() {
parent::setUp('image', 'node', 'image_attach');
variable_set('image_attach_story', TRUE);
$this->user_admin = $this
->drupalCreateUser(array(
'create images',
'view original images',
'edit own images',
'create story content',
'edit any story content',
'administer content types',
'attach images',
));
$this
->drupalLogin($this->user_admin);
$this->image = 'misc/druplicon.png';
}
function testSettings() {
$this
->drupalGet('admin/content/node-type/story');
$this
->assertText(t('Image Attach settings'), t('Image attach settings displayed on the story type settings page.'));
$this
->drupalGet('admin/content/node-type/image');
$this
->assertNoText(t('Image Attach settings'), t('Image attach settings are not available on the image type settings page.'));
}
function testAddNodeAttaching() {
$edit = array(
'title' => $this
->randomName(),
'body' => $this
->randomName(),
'files[image]' => realpath($this->image),
);
$this
->drupalPost('node/add/image', $edit, t('Save'));
variable_set('image_attach_existing', FALSE);
$this
->drupalGet('node/add/story');
$this
->assertNoFieldById('edit-iids', '', t("With 'Attached existing images' DISABLED, existing images selection box is NOT shown on a new node form."));
variable_set('image_attach_existing', TRUE);
$this
->drupalGet('node/add/story');
$this
->assertFieldById('edit-iids', '', t("With 'Attached existing images' enabled, existing images selection box is shown on a new node form."));
$this->user_no_create = $this
->drupalCreateUser(array(
'attach images',
'create story content',
'edit any story content',
));
$this
->drupalLogin($this->user_no_create);
variable_set('image_attach_existing', FALSE);
$this
->drupalGet('node/add/story');
$this
->assertNoText(t('Attached images'), t("With existing images DISABLED, a user without the 'create images' permission can NOT attach images at all."));
variable_set('image_attach_existing', TRUE);
$this
->drupalGet('node/add/story');
$this
->assertNoFieldById('edit-image', '', t("A user without the 'create images' permission can NOT upload a new image to attach."));
$this->user_no_attach = $this
->drupalCreateUser(array(
'create story content',
'edit any story content',
));
$this
->drupalLogin($this->user_no_attach);
$this
->drupalGet('node/add/story');
$this
->assertNoText(t('Attached images'), t("A user without the 'attach images' permission can NOT attach images at all."));
}
function testEditNodeAttaching() {
variable_set('image_attach_existing', TRUE);
$edit = array(
'title' => $this
->randomName(),
'body' => $this
->randomName(),
'files[image]' => realpath($this->image),
);
$this
->drupalPost('node/add/image', $edit, t('Save'));
$attached_image_node = node_load(array(
'title' => $edit['title'],
));
$edit = array(
'title' => $this
->randomName(),
'body' => $this
->randomName(),
'iids[]' => array(
$attached_image_node->nid,
),
);
$this
->drupalPost('node/add/story', $edit, t('Save'));
$story_node = node_load(array(
'title' => $edit['title'],
));
variable_set('image_attach_existing', FALSE);
$edit = array(
'title' => $this
->randomName(),
'body' => $this
->randomName(),
'files[image]' => realpath($this->image),
);
$this
->drupalPost('node/add/image', $edit, t('Save'));
$free_image_node = node_load(array(
'title' => $edit['title'],
));
}
}