image_import.test in Image 7
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();
$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);
$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() {
$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) {
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');
foreach ($images as $image) {
$node = node_load(array(
'title' => $image_prefix . $image->basename,
));
$this
->assertTrue($node, 'Image ' . $image_prefix . $image->basename . ' successfully imported. %s');
}
}
function tearDown() {
@rmdir(variable_get('image_import_path', ''));
parent::tearDown();
}
}