Exemple #1
0
 /**
  * Tests that cached images are regenerated properly after a cached file is renamed with new arguments
  * ToDo: This doesn't seem like something that is worth testing - what is the point of this?
  */
 public function testRegenerateImagesWithRenaming()
 {
     $image = $this->objFromFixture('Image', 'imageWithoutTitle');
     $image_generated = $image->ScaleWidth(200);
     $p = $image_generated->getFullPath();
     $this->assertTrue(file_exists($p), 'Resized image exists after creation call');
     // Encoding of the arguments is duplicated from cacheFilename
     $oldArgumentString = Convert::base64url_encode(array(200));
     $newArgumentString = Convert::base64url_encode(array(300));
     $newPath = str_replace($oldArgumentString, $newArgumentString, $p);
     if (!file_exists(dirname($newPath))) {
         mkdir(dirname($newPath));
     }
     $newRelative = str_replace($oldArgumentString, $newArgumentString, $image_generated->getFileName());
     rename($p, $newPath);
     $this->assertFalse(file_exists($p), 'Resized image does not exist at old path after renaming');
     $this->assertTrue(file_exists($newPath), 'Resized image exists at new path after renaming');
     $this->assertEquals(1, $image->regenerateFormattedImages(), 'Cached images were regenerated in the right number');
     $image_generated_2 = new Image_Cached($newRelative);
     $this->assertEquals(300, $image_generated_2->getWidth(), 'Cached image was regenerated with correct width');
 }
 public function FileIcon()
 {
     if ($this->parent->hasDataObject) {
         $field = $this->parent->fileFieldName . "ID";
         $file = DataObject::get_by_id($this->parent->fileClassName, $this->item->{$field});
     } else {
         $file = $this->item;
     }
     if ($file && $file->ID) {
         if ($file instanceof Image) {
             $img = $file;
         } else {
             $ext = $file->Extension;
             $imgExts = array('jpg', 'jpeg', 'gif');
             if (in_array($ext, $imgExts)) {
                 $img = new Image_Cached($file->Filename);
                 $img->ID = $file->ID;
                 //image resize functions require an id
             }
         }
         return isset($img) ? $img->CroppedImage(50, 50)->URL : $file->Icon();
     } else {
         return "{$this->item->{$field}}";
     }
 }
 public function testRegenerateImagesWithRenaming()
 {
     $image = $this->objFromFixture('Image', 'imageWithMetacharacters');
     $image_generated = $image->SetWidth(200);
     $p = $image_generated->getFullPath();
     $this->assertTrue(file_exists($p), 'Resized image exists after creation call');
     // Encoding of the arguments is duplicated from cacheFilename
     $oldArgumentString = base64_encode(json_encode(array(200)));
     $newArgumentString = base64_encode(json_encode(array(300)));
     $newPath = str_replace($oldArgumentString, $newArgumentString, $p);
     $newRelative = str_replace($oldArgumentString, $newArgumentString, $image_generated->getFileName());
     rename($p, $newPath);
     $this->assertFalse(file_exists($p), 'Resized image does not exist after movement call under old name');
     $this->assertTrue(file_exists($newPath), 'Resized image exists after movement call under new name');
     $this->assertEquals(1, $image->regenerateFormattedImages(), 'Cached images were regenerated in the right number');
     $image_generated_2 = new Image_Cached($newRelative);
     $this->assertEquals(300, $image_generated_2->getWidth(), 'Cached image was regenerated with correct width');
 }