public function generate_album_cover_from_png_test() { $input_file = MODPATH . "gallery/tests/test.jpg"; $output_file = TMPPATH . test::random_name() . ".png"; gallery_graphics::resize($input_file, $output_file, null, null); $album = test::random_album(); $photo = test::random_photo_unsaved($album); $photo->set_data_file($output_file); $photo->name = "album_cover_from_png.png"; $photo->save(); $album->reload(); // Check that the image was correctly resized and converted to jpg $this->assert_equal(array(200, 150, "image/jpeg", "jpg"), photo::get_file_metadata($album->thumb_path())); // Check that the items table got updated $this->assert_equal(array(200, 150), array($album->thumb_width, $album->thumb_height)); // Check that the image is not marked dirty $this->assert_equal(0, $album->thumb_dirty); }
public function resize_bad_jpg_test() { // Input is a garbled jpg, output is jpg autofit to 300x300 $input_file = TMPPATH . test::random_name() . ".jpg"; $output_file = TMPPATH . test::random_name() . ".jpg"; $options = array("width" => 300, "height" => 300, "master" => Image::AUTO); file_put_contents($input_file, test::lorem_ipsum(200)); // Should get passed to Image library and throw an exception try { gallery_graphics::resize($input_file, $output_file, $options, null); $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // pass } }
public function item_rename_wont_accept_slash_test() { $item = test::random_photo(); try { $item->name = test::random_name() . "/"; $item->save(); } catch (ORM_Validation_Exception $e) { $this->assert_equal(array("name" => "no_slashes"), $e->validation->errors()); return; } $this->assert_true(false, "Shouldn't get here"); }
public function add_watermark_reject_illegal_file_with_legal_extension_test() { // Source is a php file, watermark path has extension jpg $name = test::random_name(); $source_path = MODPATH . "watermark/tests/Admin_Watermarks_Controller_Test.php"; $watermark_path = TMPPATH . "uploadfile-123-{$name}.jpg"; copy($source_path, $watermark_path); // Setup and run Admin_Watermarks_Controller::add $controller = new Admin_Watermarks_Controller(); $_POST["file"] = $watermark_path; $_POST["csrf"] = access::csrf_token(); ob_start(); $controller->add(); $results = ob_get_clean(); // Delete all files marked using system::delete_later (from gallery_event::gallery_shutdown) system::delete_marked_files(); // Add should *not* be successful, and watermark should be deleted $this->assert_equal("", $results); $this->assert_false(file_exists($watermark_path)); $this->assert_false(file_exists(VARPATH . "modules/watermark/{$name}.php")); $this->assert_false(file_exists(VARPATH . "modules/watermark/{$name}.jpg")); }
public function legal_extension_that_does_match_gets_used_test() { foreach (array("jpg", "JPG", "Jpg", "jpeg") as $extension) { $photo = test::random_photo_unsaved(item::root()); $photo->name = test::random_name() . ".{$extension}"; $photo->save(); // Should get renamed with the correct jpg extension of the data file. $this->assert_equal($extension, pathinfo($photo->name, PATHINFO_EXTENSION)); } }