/**
  * 
  */
 public function generateImages($nb)
 {
     for ($i = 0; $i < $nb; $i++) {
         $data = array('original_filename' => mt_rand() . '.jpg', 'filename' => md5(microtime()) . '.jpg', 'is_published' => rand(0, 1), 'mime_type' => 'image/jpg');
         $image = new sfImagePoolImage();
         $image->fromArray($data);
         $image->save();
         unset($image, $data);
     }
 }
 /**
  * Take array of data for a single upload and create an image, assigning
  * content of $tags as tag (CSV string or single tag or array).
  * 
  * This common logic is abstracted out so it can easily be used by other plugins
  * that require image upload but need to handle the actual upload logic themselves.
  * 
  * @param array $upload
  * @param mixed $tags
  * @return sfImagePoolImage
  */
 public static function createImageFromUpload($upload, $tags = null)
 {
     // upload was ok, mime type ok and file isn't too big so let's move it into the image pool
     // location and then create a new object for it.
     $file = new sfValidatedFile($upload['name'], $upload['type'], $upload['tmp_name'], $upload['size'], sfImagePoolPluginConfiguration::getBaseDir());
     // this will generate the unique filename
     $new_filename = $file->save();
     $image_data = array('original_filename' => $file->getOriginalName(), 'filename' => $new_filename, 'mime_type' => $file->getType());
     $image = new sfImagePoolImage();
     $image->fromArray($image_data);
     // now set tags if they've been supplied
     if ($tags) {
         $image->addTag($tags);
     }
     $image->save();
     return $image;
 }
<?php

require_once realpath(dirname(__FILE__) . '/../../bootstrap/unit.php');
$t = new lime_test(7, new lime_output_color());
$adapter_options = sfConfig::get('app_sf_image_pool_cache');
// Test will fail if no config options
// Rackspace do not have testing credentials available for the API so this test requires Rackspace account details
if (isset($adapter_options['options']) && !empty($adapter_options['options'])) {
    // Create an image
    $image = new sfImagePoolImage();
    $image->original_filename = 'test.png';
    $image->filename = 'test.png';
    $image->mime_type = 'image/png';
    $image->save();
    $t->isa_ok($image, 'sfImagePoolImage', 'Image created');
    $thumbnail_options = array('width' => 300, 'height' => 300, 'scale' => false);
    // Create cache
    $cache = sfImagePoolCache::getInstance($image, $adapter_options, $thumbnail_options);
    $t->isa_ok($cache, 'sfImagePoolRackspaceCloudFilesCache', 'Cache class created');
    $container = $cache->getContainer();
    $t->is($container->name, $adapter_options['options']['container'], 'Container created or already exists');
    // copy test file in place
    copy($_test_dir . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'test.png', $cache->getDestination());
    $url = $cache->commit(false);
    $imageCrop = sfImagePoolCropTable::getInstance()->findCrop($image, $thumbnail_options['width'], $thumbnail_options['height'], !$thumbnail_options['scale'], $cache::CROP_IDENTIFIER);
    $t->isa_ok($imageCrop, 'sfImagePoolCrop', 'Crop created');
    $objectName = $cache->getCloudName();
    $object = $container->get_object($objectName);
    $t->isa_ok($object, 'CF_Object', 'Image created on Rackspace cloud');
    $image->delete();
    $image = sfImagePoolImageTable::getInstance()->findOneByFilename('test.png');