diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-20 22:49:32 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-20 22:49:32 +0000 |
commit | 99c481897b8d1574bf984a1d5ea732fe63482fe0 (patch) | |
tree | 00bfc1fd883d234292292ff6cc788e5c9564fed9 /core/tests | |
parent | 05f26fa2d4d45d99082c81f03fa71922770d18dc (diff) |
Add "created" and "updated" timestamps to the items table.
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/Item_Model_Test.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/tests/Item_Model_Test.php b/core/tests/Item_Model_Test.php new file mode 100644 index 00000000..6024366b --- /dev/null +++ b/core/tests/Item_Model_Test.php @@ -0,0 +1,63 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Item_Model_Test extends Unit_Test_Case { + public function saving_sets_created_and_updated_dates_test() { + $item = ORM::factory("item"); + $item->name = rand(); + $item->save(); + $this->assert_true(!empty($item->created)); + $this->assert_true(!empty($item->updated)); + } + + public function updating_doesnt_change_created_date_test() { + $item = ORM::factory("item"); + $item->name = rand(); + $item->save(); + + // Force the creation date to something well known + $db = Database::instance(); + $db->query("UPDATE `items` SET `created` = 0 WHERE `id` = $item->id"); + $db->query("UPDATE `items` SET `updated` = 0 WHERE `id` = $item->id"); + $item->reload(); + $item->title = "foo"; // force a change + $item->save(); + + $this->assert_true(empty($item->created)); + $this->assert_true(!empty($item->updated)); + } + + public function updating_view_count_only_doesnt_change_updated_date_test() { + $item = ORM::factory("item"); + $item->name = rand(); + $item->save(); + $item->reload(); + $this->assert_same(0, $item->view_count); + + // Force the updated date to something well known + $db = Database::instance(); + $db->query("UPDATE `items` SET `updated` = 0 WHERE `id` = $item->id"); + $item->reload(); + $item->view_count++; + $item->save(); + + $this->assert_same(1, $item->view_count); + $this->assert_true(empty($item->updated)); + } +} |