You are here

image_import.test in Image 7

Same filename and directory in other branches
  1. 6 contrib/image_import/tests/image_import.test

File

contrib/image_import/tests/image_import.test
View source
<?php

class ImageImportTest extends DrupalTestCase {
  function get_info() {
    return array(
      'name' => t('Image Import tests'),
      'desc' => t('Test Image Import module functionality.'),
      'group' => 'Image',
    );
  }
  function setUp() {
    parent::setUp();

    // Set an image import patch.
    $image_import_path = file_directory_path() . '/' . $this
      ->randomName();
    file_check_directory($image_import_path, FILE_CREATE_DIRECTORY);
    $this
      ->drupalVariableSet('image_import_path', $image_import_path);

    // User to create image galleries.
    $this->web_user = $this
      ->drupalCreateUserRolePerm(array(
      'create images',
      'view original images',
      'edit own images',
      'edit any images',
      'administer image galleries',
      'import images',
    ));
    $this
      ->drupalGet('logout');
    $this
      ->drupalLoginUser($this->web_user);
  }
  function testImport() {

    // Get 10 random images from 'misc' directory.
    $images_count = 10;
    $images_misc = file_scan_directory('misc', '.png');
    shuffle($images_misc);
    $images = array_slice($images_misc, 0, $images_count);
    $image_prefix = $this
      ->randomName();
    $edit = array();
    $i = 1;
    foreach ($images as $image) {

      // Copy each image to import directory with random names.
      file_copy($image->filename, variable_get('image_import_path', '') . '/' . $image_prefix . $image->basename);
      $edit['import_file[' . $i . ']'] = $i;
      $edit['title[' . $i . ']'] = $image_prefix . $image->basename;
      $edit['body[' . $i . ']'] = $image_prefix . $image->basename;
      $i++;
    }
    $this
      ->drupalPost('admin/content/image_import', $edit, 'Import');
    $this
      ->assertWantedRaw('Successfully imported', 'Successfully imported. %s');

    // Check each image is a node now.
    foreach ($images as $image) {
      $node = node_load(array(
        'title' => $image_prefix . $image->basename,
      ));
      $this
        ->assertTrue($node, 'Image ' . $image_prefix . $image->basename . ' successfully imported. %s');
    }

    // @todo import into a gallery.
  }
  function tearDown() {
    @rmdir(variable_get('image_import_path', ''));
    parent::tearDown();
  }

}

Classes

Namesort descending Description
ImageImportTest