function ImageImportTest::testImport in Image 7
Same name and namespace in other branches
- 6 contrib/image_import/tests/image_import.test \ImageImportTest::testImport()
File
- contrib/
image_import/ tests/ image_import.test, line 25
Class
Code
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.
}