/**
  * The thumbnails should be created automatically when first requested
  *
  * This is kind of like the Apache 404 trick, except we're sending
  * all traffic to index.php, so it's handled there, instead of a 404
  */
 public function testAutogenerateThumbnailsByURL()
 {
     $temp = __DIR__ . "/temp.png";
     $zend_db = Database::getConnection();
     $result = $zend_db->query("select * from media where media_type='image' limit 1")->execute();
     if (count($result)) {
         $row = $result->current();
         $media = new Media($row);
         $image = new Image($media);
         $image->clearCache();
         $this->assertFalse(file_exists($image->getFullPathForSize($this->testSize)));
         $url = $image->getURL($this->testSize);
         $request = curl_init($image->getURL($this->testSize));
         curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($request, CURLOPT_BINARYTRANSFER, true);
         file_put_contents($temp, curl_exec($request));
         $this->assertTrue(file_exists($temp));
         $info = getimagesize($temp);
         $this->assertTrue($info[0] == $this->testSize || $info[1] == $this->testSize);
         #if (file_exists($temp)) { unlink($temp); }
     }
 }
 public function testGenerateAndClearThumbnail()
 {
     copy($this->origFile, $this->testFile);
     $media = new Media();
     $media->setFile($this->FILE);
     $image = new Image($media);
     ob_start();
     $image->output($this->testSize);
     ob_end_clean();
     $newFile = SITE_HOME . "/media/{$media->getDirectory()}/{$media->getInternalFilename()}";
     $thumbnail = SITE_HOME . "/media/{$media->getDirectory()}/{$this->testSize}/{$media->getInternalFilename()}";
     $this->assertTrue(file_exists($thumbnail));
     $info = getimagesize($thumbnail);
     $this->assertTrue($info[0] == $this->testSize || $info[1] == $this->testSize);
     $image->clearCache();
     $this->assertFalse(file_exists($thumbnail));
     if (file_exists($thumbnail)) {
         unlink($thumbnail);
     }
     if (file_exists($newFile)) {
         unlink($newFile);
     }
 }