You are here

function ImageAttachTestCase::testEditNodeAttaching in Image 6

Verify that on the form for existing 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 106

Class

ImageAttachTestCase
Test image functionality.

Code

function testEditNodeAttaching() {
  variable_set('image_attach_existing', TRUE);

  // Create an image.
  $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'],
  ));

  // Create a story, attaching the existing image node.
  $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'],
  ));

  //  file_put_contents('DEBUGstory.html', $this->drupalGetContent());

  /*
  // TODO: test images are attached properly whether existing or new files.
  $this->drupalGet('node/' . $story_node->nid);
  $this->assertPattern('@<img[^>]+?' . $image_node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the story node page.'));
  */

  // Check that with existing images disabled
  variable_set('image_attach_existing', FALSE);

  // Create an UNATTACHED image.
  $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'],
  ));

  // TODO: test that only attached nodes are presented in the field -- ie that
  // $free_image_node is not available as an option.
  // NO IDEA how to do this in simpletest.

  /*
  $this->drupalGet('node/' . $story_node->nid);
  $this->assertFalse($this->setField('iids[]', $free_image_node->title));
  */
}