You are here

function ImageTestCase::testImageCreateNodeFrom in Image 6

Same name and namespace in other branches
  1. 7 tests/image.test \ImageTestCase::testImageCreateNodeFrom()

Verify image_create_node_from() works like regular image node creation.

File

tests/image.test, line 309

Class

ImageTestCase
Test image functionality.

Code

function testImageCreateNodeFrom() {
  $edit = array(
    'title' => $this
      ->randomName(),
    'body' => $this
      ->randomName(),
    'files[image]' => realpath($this->image),
  );
  $this
    ->drupalPost('node/add/image', $edit, t('Save'));
  $this
    ->assertRaw(t('@type %title has been created.', array(
    '@type' => 'Image',
    '%title' => $edit['title'],
  )), t('Image created.'));
  $node_post = node_load(array(
    'title' => $edit['title'],
  ));
  $this
    ->assertTrue($node_post, t('Form created image node found in database.'));

  // Copy the image, since image_create_node_from() deletes the original image.
  file_copy($edit['files[image]'], file_directory_temp());
  $node_api = image_create_node_from(file_directory_temp() . '/' . basename($edit['files[image]']), $edit['title'], $edit['body']);
  $this
    ->assertTrue(is_object($node_api) && $node_api->nid, t('API created image node found in database.'));

  // Rebuild derivative images.
  $node_api = node_load($node_api->nid, NULL, TRUE);

  // Verify that both nodes are equal.
  $equality = $node_post->title == $node_api->title;
  $this
    ->assertTrue($equality, t('Image node titles are equal.'));
  $equality = $equality && strip_tags($node_post->body) == strip_tags($node_api->body);
  $this
    ->assertTrue($equality, t('Image node body texts are equal.'));
  $equality = $equality && filesize($node_post->images['_original']) == filesize($node_api->images['_original']);
  $this
    ->assertTrue($equality, t('Original images are equal.'));

  /*
  // These tests are temporarily commented out as they fail due to
  // image_create_node_from() not creative derivatives.
  // @see <http://drupal.org/node/670686> for details.
  $equality = $equality && (filesize($node_post->images['preview']) == filesize($node_api->images['preview']));
  $this->assertTrue($equality, t('Preview images are equal.'));
  $equality = $equality && (filesize($node_post->images['thumbnail']) == filesize($node_api->images['thumbnail']));
  $this->assertTrue($equality, t('Preview images are equal.'));
  */
}