From 83164089aef20cc2cf4cdcf8b32dfc4ef1baa764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Wed, 24 Jan 2007 04:10:05 +0000 Subject: [PATCH] Disallowid of 0 in deleteMaintainersForVersion(). Add a unit test to ensure that deleteMaintainersForVersion() behaves properly. --- include/maintainer.php | 3 +++ unit_test/test_maintainer.php | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/maintainer.php b/include/maintainer.php index 4d70c63..ff978dd 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -178,6 +178,9 @@ class maintainer function deleteMaintainersForVersion($oVersion) { + if(!$oVersion->iVersionId) + return FALSE; + $hResult = query_parameters("DELETE from appMaintainers WHERE versionId='?'", $oVersion->iVersionId); } diff --git a/unit_test/test_maintainer.php b/unit_test/test_maintainer.php index 27e9c6d..2903eff 100644 --- a/unit_test/test_maintainer.php +++ b/unit_test/test_maintainer.php @@ -305,6 +305,38 @@ function test_superMaintainerOnAppSubmit() return true; } +/* deleteMaintainersForVersion() should fail if versionId = 0 + Otherwise it will delete all super maintainers */ +function test_maintainer_deleteMaintainersForVersion() +{ + test_start(__FUNCTION__); + + global $test_email, $test_password; + + $oUser = new user(); + $oUser->login($test_email, $test_password); + + $oMaintainer = new maintainer(); + $oMaintainer->iAppId = 655000; + $oMaintainer->iVersionId = 0; + $oMaintainer->iUserId = 655000; + $oMaintainer->sMaintainReason = "Silly reason"; + $oMaintainer->bSuperMaintainer = 1; + + $oMaintainer->create(); + + $oVersion = new version(); + $oVersion->iVersionId = 0; + + if(maintainer::deleteMaintainersForVersion($oVersion) !== FALSE) + { + echo "Got success, but this should fail.\n"; + return FALSE; + } + + return TRUE; +} + if(!test_maintainer_getMaintainerCountForUser()) echo "test_maintainer_getMaintainerCountForUser() failed!\n"; else @@ -327,4 +359,9 @@ if(!test_superMaintainerOnAppSubmit()) else echo "test_superMaintainerOnAppSubmit() passed\n"; +if(!test_maintainer_deleteMaintainersForVersion()) + echo "test_maintainer_deleteMaintainersForVersion() failed!\n"; +else + echo "test_maintainer_deleteMaintianersForVersion() passed\n"; + ?>