static function random_tag() { $tag = ORM::factory("tag"); $tag->name = test::lorem_ipsum(rand(2, 4)); // Reload so that ORM coerces all fields into strings. return $tag->save()->reload(); }
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 generate_album_cover_from_bad_photo_test() { $album = test::random_album(); $photo = test::random_photo($album); $album->reload(); // At this point, the photo is valid and has a valid resize and thumb. Make it garble. file_put_contents($photo->file_path(), test::lorem_ipsum(200)); // Regenerate album from garbled photo. $photo->thumb_dirty = 1; $photo->save(); $album->thumb_dirty = 1; try { graphics::generate($album); $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // Exception expected } // Check that the image got replaced with a missing image placeholder $this->assert_same(file_get_contents(MODPATH . "gallery/images/missing_photo.jpg"), file_get_contents($album->thumb_path())); // Check that the items table got updated with new metadata $this->assert_equal(array(200, 200), array($album->thumb_width, $album->thumb_height)); // Check that the images are marked as dirty $this->assert_equal(1, $album->thumb_dirty); }