diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-09-07 19:52:47 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-09-07 20:07:37 -0700 |
commit | 2f666f4c527a89df235c7fdaab4b5483c5dd2595 (patch) | |
tree | 01d5a293c0296cfdab24a4409ea23ae9f3a98f1d | |
parent | d6ca88166291a5084a5e22f8b305dd497c3cc799 (diff) |
Add item::validate_url_safe() with a test.
-rw-r--r-- | modules/gallery/helpers/item.php | 7 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 16 |
2 files changed, 23 insertions, 0 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index bf948731..7ce6519e 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -90,6 +90,13 @@ class item_Core { } } + static function validate_url_safe($input) { + if (preg_match("/[^A-Za-z0-9-_]/", $input->value)) { + $input->add_error("not_url_safe", 1); + } + Kohana::log("alert",print_r($input,1)); + } + static function validate_no_name_conflict($input) { $itemid = Input::instance()->post("item"); if (is_array($itemid)) { diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 3f80733f..87859565 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -38,6 +38,16 @@ class Item_Helper_Test extends Unit_Test_Case { ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); } + public function validate_url_safe_test() { + $input = new MockInput(); + $input->value = "Ab_cd-ef-d9"; + item::validate_url_safe($input); + $this->assert_true(!isset($input->not_url_safe)); + + $input->value = "ab&cd"; + item::validate_url_safe($input); + $this->assert_equal(1, $input->not_url_safe); + } private static function _create_random_item($album) { // Set all required fields (values are irrelevant) @@ -47,3 +57,9 @@ class Item_Helper_Test extends Unit_Test_Case { return $item->add_to_parent($album); } } + +class MockInput { + function add_error($error, $value) { + $this->$error = $value; + } +}
\ No newline at end of file |