public function testSaveMainImage()
 {
     /** $model @var LocalEventImage[ ] */
     $model = new LocalEventImage();
     $model->setAttributes($this->getMockRecord('LocalEventMain'), false);
     $model->file = $this->getMockCuploadedImage('image/jpeg', 1);
     $model->cropFactor = array('width' => 1280, 'height' => 1024, 'cropWidth' => 800, 'cropHeight' => 800, 'x' => 0, 'y' => 0);
     $this->assertTrue($model->validate(), "record not validated");
     $this->assertTrue($model->save(), "record not saved");
     foreach ($model->imageSizes as $imageSize) {
         $this->assertFileExists($model->getImageURIPath($imageSize), $imageSize . " does not exist");
     }
 }
 public function saveImages($model, $instanceName)
 {
     $recordType = 'LocalEvent';
     $images = CUploadedFile::getInstancesByName($instanceName);
     if ($images) {
         foreach ($images as $num => $pic) {
             $img = new LocalEventImage();
             if ($instanceName == 'mainImage') {
                 $recordType = 'LocalEventMain';
                 $img->cropFactor = $this->mainImageCropFactor;
             }
             $img->file = $pic;
             $img->recordId = $model->id;
             $img->recordType = $recordType;
             if ($img->save() && $instanceName == 'mainImage') {
                 $model->mainImageID = $img->id;
                 $model->update(array('mainImageID'));
             }
         }
     }
 }