You are here

function ImageAttachTestCase::testAddNodeAttaching in Image 6

Verify that on the form for new nodes the image attach form component is presented in the correct way (or indeed not at all) for the various combinations of permissions.

File

contrib/image_attach/tests/image_attach.test, line 55

Class

ImageAttachTestCase
Test image functionality.

Code

function testAddNodeAttaching() {

  // Create an image.
  $edit = array(
    'title' => $this
      ->randomName(),
    'body' => $this
      ->randomName(),
    'files[image]' => realpath($this->image),
  );
  $this
    ->drupalPost('node/add/image', $edit, t('Save'));

  // Check existing image nodes either show or don't show as potential attachments,
  // depending on the setting.
  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."));

  // Check that a user who may attach images but not create them cannot see
  // the upload part of the form
  $this->user_no_create = $this
    ->drupalCreateUser(array(
    'attach images',
    'create story content',
    'edit any story content',
  ));
  $this
    ->drupalLogin($this->user_no_create);

  // ... with existing images disabled, no part of the form should be visible.
  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."));

  // ... with exiting images enabled, they still can't upload.
  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."));

  // Check that a user who may not attach images cannot see
  // any part of the form.
  $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."));
}