summaryrefslogtreecommitdiff
path: root/modules/gallery/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r--modules/gallery/tests/Item_Model_Test.php117
-rw-r--r--modules/gallery/tests/Legal_File_Helper_Test.php18
2 files changed, 133 insertions, 2 deletions
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index 83c9f79d..b6849413 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -124,11 +124,124 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$this->assert_equal($fullsize_file, file_get_contents($photo->file_path()));
}
- public function item_rename_wont_accept_slash_test() {
- $item = test::random_photo();
+ public function photo_rename_wont_accept_slash_test() {
+ $item = test::random_photo_unsaved();
$item->name = "/no_slashes/allowed/";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_slashes", $errors["name"]);
+ }
+ // Should be corrected on save.
$item->save();
$this->assert_equal("no_slashes_allowed.jpg", $item->name);
+ // Should be corrected on update.
+ $item->name = "/no_slashes/allowed/";
+ $item->save();
+ $this->assert_equal("no_slashes_allowed.jpg", $item->name);
+ }
+
+ public function photo_rename_wont_accept_backslash_test() {
+ $item = test::random_photo_unsaved();
+ $item->name = "\\no_backslashes\\allowed\\";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_backslashes", $errors["name"]);
+ }
+ // Should be corrected on save.
+ $item->save();
+ $this->assert_equal("no_backslashes_allowed.jpg", $item->name);
+ // Should be corrected on update.
+ $item->name = "\\no_backslashes\\allowed\\";
+ $item->save();
+ $this->assert_equal("no_backslashes_allowed.jpg", $item->name);
+ }
+
+ public function photo_rename_wont_accept_trailing_period_test() {
+ $item = test::random_photo_unsaved();
+ $item->name = "no_trailing_period_allowed.";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_trailing_period", $errors["name"]);
+ }
+ // Should be corrected on save.
+ $item->save();
+ $this->assert_equal("no_trailing_period_allowed.jpg", $item->name);
+ // Should be corrected on update.
+ $item->name = "no_trailing_period_allowed.";
+ $item->save();
+ $this->assert_equal("no_trailing_period_allowed.jpg", $item->name);
+ }
+
+ public function album_rename_wont_accept_slash_test() {
+ $item = test::random_album_unsaved();
+ $item->name = "/no_album_slashes/allowed/";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_slashes", $errors["name"]);
+ }
+ // Should be corrected on save.
+ $item->save();
+ $this->assert_equal("no_album_slashes_allowed", $item->name);
+ // Should be corrected on update.
+ $item->name = "/no_album_slashes/allowed/";
+ $item->save();
+ $this->assert_equal("no_album_slashes_allowed", $item->name);
+ }
+
+ public function album_rename_wont_accept_backslash_test() {
+ $item = test::random_album_unsaved();
+ $item->name = "\\no_album_backslashes\\allowed\\";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_backslashes", $errors["name"]);
+ }
+ // Should be corrected on save.
+ $item->save();
+ $this->assert_equal("no_album_backslashes_allowed", $item->name);
+ // Should be corrected on update.
+ $item->name = "\\no_album_backslashes\\allowed\\";
+ $item->save();
+ $this->assert_equal("no_album_backslashes_allowed", $item->name);
+ }
+
+ public function album_rename_wont_accept_trailing_period_test() {
+ $item = test::random_album_unsaved();
+ $item->name = ".no_trailing_period.allowed.";
+ // Should fail on validate.
+ try {
+ $item->validate();
+ $this->assert_true(false, "Shouldn't get here");
+ } catch (ORM_Validation_Exception $e) {
+ $errors = $e->validation->errors();
+ $this->assert_same("no_trailing_period", $errors["name"]);
+ }
+ // Should be corrected on save.
+ $item->save();
+ $this->assert_equal(".no_trailing_period.allowed", $item->name);
+ // Should be corrected on update.
+ $item->name = ".no_trailing_period.allowed.";
+ $item->save();
+ $this->assert_equal(".no_trailing_period.allowed", $item->name);
}
public function move_album_test() {
diff --git a/modules/gallery/tests/Legal_File_Helper_Test.php b/modules/gallery/tests/Legal_File_Helper_Test.php
index 3f520131..aab41c41 100644
--- a/modules/gallery/tests/Legal_File_Helper_Test.php
+++ b/modules/gallery/tests/Legal_File_Helper_Test.php
@@ -194,4 +194,22 @@ class Legal_File_Helper_Test extends Gallery_Unit_Test_Case {
}
}
}
+
+ public function sanitize_dirname_with_no_rename_test() {
+ $this->assert_equal("foo", legal_file::sanitize_dirname("foo"));
+ $this->assert_equal("foo.bar", legal_file::sanitize_dirname("foo.bar"));
+ $this->assert_equal(".foo.bar...baz", legal_file::sanitize_dirname(".foo.bar...baz"));
+ $this->assert_equal("foo bar spaces", legal_file::sanitize_dirname("foo bar spaces"));
+ $this->assert_equal("j'écris@un#nom_bizarre(mais quand_même_ça_passe \$ÇÀ@€",
+ legal_file::sanitize_dirname("j'écris@un#nom_bizarre(mais quand_même_ça_passe \$ÇÀ@€"));
+ }
+
+ public function sanitize_filename_with_corrections_test() {
+ $this->assert_equal("foo_bar", legal_file::sanitize_dirname("/foo/bar/"));
+ $this->assert_equal("foo_bar", legal_file::sanitize_dirname("\\foo\\bar\\"));
+ $this->assert_equal(".foo..bar", legal_file::sanitize_dirname(".foo..bar."));
+ $this->assert_equal("foo_bar", legal_file::sanitize_dirname("_foo__bar_"));
+ $this->assert_equal("album", legal_file::sanitize_dirname("_"));
+ $this->assert_equal("album", legal_file::sanitize_dirname(null));
+ }
} \ No newline at end of file