diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2012-05-12 13:06:18 +0000 | 
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2012-05-12 13:06:18 +0000 | 
| commit | f5098f54b8279f468d94747b1156e15ea05d6d25 (patch) | |
| tree | 2ecfb6663887ffbc72de8f231864b6c78bd62640 /modules/gallery/tests | |
| parent | a13fd7f373f3718037a2ce90a3cb408f24856602 (diff) | |
| parent | d1390bd87db1a7e59bbd72f5991fbbc6374c98b4 (diff) | |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/gallery/tests')
| -rw-r--r-- | modules/gallery/tests/Item_Model_Test.php | 50 | ||||
| -rw-r--r-- | modules/gallery/tests/Legal_File_Helper_Test.php | 32 | 
2 files changed, 80 insertions, 2 deletions
| diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 205d0a08..6d40230f 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -333,7 +333,36 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {        $photo->mime_type = "video/x-flv";        $photo->save();      } catch (ORM_Validation_Exception $e) { -      $this->assert_same(array("type" => "read_only"), $e->validation->errors()); +      $this->assert_same( +        array("name" => "illegal_data_file_extension", "type" => "read_only"), +        $e->validation->errors()); +      return;  // pass +    } +    $this->assert_true(false, "Shouldn't get here"); +  } + +  public function photo_files_must_have_an_extension_test() { +    try { +      $photo = test::random_photo_unsaved(); +      $photo->mime_type = "image/jpeg"; +      $photo->name = "no_extension"; +      $photo->save(); +    } catch (ORM_Validation_Exception $e) { +      $this->assert_same(array("name" => "illegal_data_file_extension"), $e->validation->errors()); +      return;  // pass +    } +    $this->assert_true(false, "Shouldn't get here"); +  } + +  public function movie_files_must_have_an_extension_test() { +    try { +      $movie = test::random_photo_unsaved(); +      $movie->type = "movie"; +      $movie->mime_type = "video/x-flv"; +      $movie->name = "no_extension"; +      $movie->save(); +    } catch (ORM_Validation_Exception $e) { +      $this->assert_same(array("name" => "illegal_data_file_extension"), $e->validation->errors());        return;  // pass      }      $this->assert_true(false, "Shouldn't get here"); @@ -421,7 +450,8 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {        $photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php");        $photo->save();      } catch (ORM_Validation_Exception $e) { -      $this->assert_same(array("mime_type" => "invalid"), $e->validation->errors()); +      $this->assert_same(array("mime_type" => "invalid", "name" => "illegal_data_file_extension"), +                         $e->validation->errors());        return;  // pass      }      $this->assert_true(false, "Shouldn't get here"); @@ -473,4 +503,20 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {        $this->assert_true(false, "Shouldn't get here");      }    } + +  public function cant_rename_to_illegal_extension_test() { +    foreach (array("test.php.test", "test.php", "test.PHP", +                   "test.php5", "test.php4", "test.pl") as $name) { +      try { +        $photo = test::random_photo(item::root()); +        $photo->name = $name; +        $photo->save(); +      } catch (ORM_Validation_Exception $e) { +        $this->assert_equal(array("name" => "illegal_data_file_extension"), +                            $e->validation->errors()); +        continue; +      } +      $this->assert_true(false, "Shouldn't get here"); +    } +  }  } diff --git a/modules/gallery/tests/Legal_File_Helper_Test.php b/modules/gallery/tests/Legal_File_Helper_Test.php new file mode 100644 index 00000000..c101de10 --- /dev/null +++ b/modules/gallery/tests/Legal_File_Helper_Test.php @@ -0,0 +1,32 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2012 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class Legal_File_Helper_Test extends Gallery_Unit_Test_Case { +  public function change_extension_test() { +    $this->assert_equal("foo.jpg", legal_file::change_extension("foo.png", "jpg")); +  } + +  public function change_four_letter_extension_test() { +    $this->assert_equal("foo.flv", legal_file::change_extension("foo.mpeg", "flv")); +  } + +  public function change_extension_with_no_extension_test() { +    $this->assert_equal("foo.flv", legal_file::change_extension("foo", "flv")); +  } +}
\ No newline at end of file | 
