php-tests in eigenes verzeichnis (machts einfacher aufm server)
authorlseed <mail@joachim-breitner.de>
Thu, 25 Jun 2009 16:59:18 +0000 (18:59 +0200)
committerlseed <mail@joachim-breitner.de>
Thu, 25 Jun 2009 16:59:18 +0000 (18:59 +0200)
web/php-tests/BuisnessLogicTest.php [new file with mode: 0644]
web/php-tests/DatabaseTest.php [new file with mode: 0644]
web/php-tests/all_tests.php [new file with mode: 0644]
web/php/tests/BuisnessLogicTest.php [deleted file]
web/php/tests/DatabaseTest.php [deleted file]
web/php/tests/all_tests.php [deleted file]

diff --git a/web/php-tests/BuisnessLogicTest.php b/web/php-tests/BuisnessLogicTest.php
new file mode 100644 (file)
index 0000000..3026876
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+       include("../php/User.php");
+       include("../php/Plant.php");
+       include("../php/Controller.php");
+       include("../php/Season.php");
+       include("../php/SeasonScore.php");
+
+       class TestOfBuisnessLogic extends UnitTestCase
+       {
+               private $m_Controller;
+               
+               function __construct() {
+               }
+               
+               function setUp() {
+                       $this->m_Controller = new Controller();
+                       $db = new DataBase();
+                       $db->Clear();
+                       $db->Close();
+               }
+               
+               function tearDown() {
+                       $db = new DataBase();
+                       $db->Clear();
+                       $db->Close();
+                       unset($_SESSION['user']);
+                       unset($_SESSION['pw']);
+               }
+               
+               function validateRPCResponseWithoutData($res, $func) {
+                       $this->assertTrue($res != null, "No Result given");
+                       $this->assertTrue($res->m_Command == "RPC-Response", "Wrong Commandtype");
+                       $this->assertTrue($res->m_CalledFunction == $func, "Wrong CalledFunction");
+               }
+               function validateRPCResponse($res, $func, $data) {
+                       $this->validateRPCResponseWithoutData($res, $func);
+                       $this->assertTrue($res->m_Data == $data, "'".$res->m_Data."' was unexpected, '".$data."' expected");
+               }
+               function testAuthentication() {
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
+                       $this->validateRPCResponse($res, "IsLoggedIn", "false");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
+                       $this->validateRPCResponse($res, "Register", "{ success: true, msg: 'Benutzer erstellt und erfolgreich angemeldet.' }");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
+                       $this->validateRPCResponse($res, "IsLoggedIn", "true");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Logout", "", "", "", "");
+                       $this->validateRPCResponse($res, "Logout", "true");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
+                       $this->validateRPCResponse($res, "IsLoggedIn", "false");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
+                       $this->validateRPCResponse($res, "Auth", "true");
+               }
+               
+               function testPlantCreation() {
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "", "");
+                       $this->validateRPCResponse($res, "CreatePlant", "{ success: false, msg: 'Sie sind nicht angemeldet' }");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "newplant", "");
+                       $this->validateRPCResponse($res, "CreatePlant", "{ success: true, msg: 'Es wurde eine neue Pflanze für sie angelegt.' }");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("GetPlantList", "", "", "", "");
+                       $this->validateRPCResponseWithoutData($res, "GetPlantList");
+                       $expectedEnd = "Name: 'newplant', Code: '' }] }";
+                       substr($res->m_Data, -count($expectedEnd), 0);
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("SavePlant", "test", "", "newplant", "a b c");
+                       $this->validateRPCResponse($res, "SavePlant", "{ success: true, msg: '' }");
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("GetPlantList", "", "", "", "");
+                       $this->validateRPCResponseWithoutData($res, "GetPlantList");
+                       $expectedEnd = "Name: 'newplant', Code: 'a b c' }] }";
+                       substr($res->m_Data, -count($expectedEnd), 0);
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("DeletePlant", "test", "", "newplant", "");
+                       $this->validateRPCResponse($res, "DeletePlant", "{ success: true, msg: '' }");
+               }
+               
+               function testValidation() {
+                       
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "newplant", "RULE a GROW BY 1");
+                       
+                       $GLOBALS['ValidatorFile'] = '../../cgi/validate';
+                       $res = $this->m_Controller->HandleRemoteProcedureCall("ValidatePlant", "test", "", "newplant", "");
+                       $this->validateRPCResponse($res, "ValidatePlant", "{\"valid\":true}");
+                       
+               }
+       }
+?>
diff --git a/web/php-tests/DatabaseTest.php b/web/php-tests/DatabaseTest.php
new file mode 100644 (file)
index 0000000..949648c
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+       include("../php/Database.php");
+
+       class TestOfDataBase extends UnitTestCase
+       {
+               private $m_Database;
+               
+               function __construct() {
+               }
+               
+               function setUp() {
+                       $this->m_Database = new DataBase();
+                       $this->m_Database->Clear();
+               }
+               
+               function tearDown() {
+                       $this->m_Database->Clear();
+                       $this->m_Database->Close();
+               }
+               
+               function testClear() {
+                       $username = "argletam";
+                       $this->m_Database->CreateUser($username, "42aa");
+                       $user = $this->m_Database->GetUser($username);
+                       $userid = $user->ID;
+                       
+                       $res = $this->m_Database->Clear();
+                       $this->assertTrue($res, "Clear failed");
+                       
+                       $user = $this->m_Database->GetUser($username);
+                       $this->assertTrue($user == null, "A User was found even though the database was cleared");
+                       
+                       $plants = $this->m_Database->GetPlantsForUser($userid);
+                       $this->assertTrue(count($user) == 0, "Even though the database was cleared we found plants for a user");
+               }
+               
+               function testUser() {
+                       $username = "testuser";
+                       
+                       $result = $this->m_Database->CreateUser($username, "test");
+                       $this->assertTrue($result);
+                       
+                       $user = $this->m_Database->GetUser($username);
+                       $this->assertTrue($user != null);
+                       
+                       $user = $this->m_Database->GetUser("a");
+                       $this->assertTrue($user == null);
+                       
+                       $user = $this->m_Database->GetUser(null);
+                       $this->assertTrue($user == null);
+               }
+               
+               function testPlant() {
+                       $username = "testuser";
+                       
+                       $result = $this->m_Database->CreateUser($username, "test");
+                       $user = $this->m_Database->GetUser($username);
+                       
+                       $data_name = "myplant";
+                       $data_code = "my fancy plant code!";
+                       
+                       $result = $this->m_Database->InsertNewPlant($user->ID, $data_name, $data_code);
+                       $this->assertTrue($result);
+                       
+                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
+                       $this->assertTrue($plant != null);
+                       $this->assertTrue($plant->UserID == $user->ID);
+                       $this->assertTrue($plant->Name == $data_name);
+                       $this->assertTrue($plant->Code == $data_code);
+                       
+                       $plants = $this->m_Database->GetPlantsForUser($user->ID);
+                       $this->assertTrue($plants != null);
+                       $this->assertTrue(count($plants) == 1);
+                       $this->assertTrue($plants[0]->ID == $plant->ID);
+                       
+                       $data_code = $plant->Code = "My New and improved Plantcode. Featuring: even fancier code!";
+                       $result = $this->m_Database->UpdatePlant($plant);
+                       $this->assertTrue($result);
+                       
+                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
+                       $this->assertTrue($plant != null);
+                       $this->assertTrue($plant->UserID == $user->ID);
+                       $this->assertTrue($plant->Name == $data_name);
+                       $this->assertTrue($plant->Code == $data_code);
+                       
+                       $result = $this->m_Database->DropPlant($plant);
+                       $this->assertTrue($result);
+                       
+                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
+                       $this->assertTrue($plant == null);
+               }
+               
+               function testNextSeed() {
+                       $username = "testuser";
+                       $data_name = "myplant";
+                       $data_code = "my fancy plant code!";
+                       
+                       $this->m_Database->CreateUser($username, "test");
+                       $user = $this->m_Database->GetUser($username);
+                       
+                       $this->m_Database->InsertNewPlant($user->ID, $data_name, $data_code);
+                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
+                       
+                       $result = $this->m_Database->SetUsersNextSeed($user->ID, $plant->ID);
+                       $this->assertTrue($result);
+                       
+                       $user = $this->m_Database->GetUserByID($user->ID);
+                       $this->assertTrue($user != null);
+                       $this->assertTrue($user->NextSeedID == $plant->ID);
+                       
+                       $plant = $this->m_Database->GetPlantByID($user->ID, $plant->ID);
+                       $this->assertTrue($plant != null);
+                       $this->assertTrue($plant->IsActive);
+               }
+               
+               function testSeason() {
+                       $username = "testuser";
+                       $data_name = "myplant";
+                       $data_code = "my fancy plant code!";
+                       
+                       $this->m_Database->CreateUser($username, "test");
+                       $user = $this->m_Database->GetUser($username);
+                       
+                       $this->m_Database->m_Connection->query("INSERT INTO season (IsRunning) VALUES (true)");
+                       $stmt = $this->m_Database->m_Connection->query("SELECT ID FROM season");
+                       $seasonid = $stmt->fetch_object()->ID;
+                       $this->assertTrue($seasonid != null);
+                       $stmt->close();
+                       
+                       $this->m_Database->m_Connection->query("INSERT INTO seasonscore (UserID, SeasonID, Score) VALUES (".$user->ID.", ".$seasonid.", 5)");
+                       $seasonscores = $this->m_Database->GetAllSeasonScores();
+                       $this->assertTrue($seasonscores != null);
+                       $this->assertTrue(count($seasonscores) == 1, "expected 1 got ".count($seasonscores));
+                       $this->assertTrue($seasonscores[0]->UserID == $user->ID);
+                       $this->assertTrue($seasonscores[0]->SeasonID == $seasonid);
+                       $this->assertTrue($seasonscores[0]->Season != null);
+                       $this->assertTrue($seasonscores[0]->Season->IsRunning);
+               }
+       }
+
+?>
diff --git a/web/php-tests/all_tests.php b/web/php-tests/all_tests.php
new file mode 100644 (file)
index 0000000..97fd736
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+       require_once('simpletest/unit_tester.php');
+       require_once('simpletest/reporter.php');
+
+       $test = &new GroupTest('All tests');
+       $test->addTestFile('DatabaseTest.php');
+       $test->addTestFile('BuisnessLogicTest.php');
+       $test->run(new HtmlReporter());
+
+?>
diff --git a/web/php/tests/BuisnessLogicTest.php b/web/php/tests/BuisnessLogicTest.php
deleted file mode 100644 (file)
index cdfddc6..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-       include("../User.php");
-       include("../Plant.php");
-       include("../Controller.php");
-       include("../Season.php");
-       include("../SeasonScore.php");
-
-       class TestOfBuisnessLogic extends UnitTestCase
-       {
-               private $m_Controller;
-               
-               function __construct() {
-               }
-               
-               function setUp() {
-                       $this->m_Controller = new Controller();
-                       $db = new DataBase();
-                       $db->Clear();
-                       $db->Close();
-               }
-               
-               function tearDown() {
-                       $db = new DataBase();
-                       $db->Clear();
-                       $db->Close();
-                       unset($_SESSION['user']);
-                       unset($_SESSION['pw']);
-               }
-               
-               function validateRPCResponseWithoutData($res, $func) {
-                       $this->assertTrue($res != null, "No Result given");
-                       $this->assertTrue($res->m_Command == "RPC-Response", "Wrong Commandtype");
-                       $this->assertTrue($res->m_CalledFunction == $func, "Wrong CalledFunction");
-               }
-               function validateRPCResponse($res, $func, $data) {
-                       $this->validateRPCResponseWithoutData($res, $func);
-                       $this->assertTrue($res->m_Data == $data, "'".$res->m_Data."' was unexpected, '".$data."' expected");
-               }
-               function testAuthentication() {
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
-                       $this->validateRPCResponse($res, "IsLoggedIn", "false");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
-                       $this->validateRPCResponse($res, "Register", "{ success: true, msg: 'Benutzer erstellt und erfolgreich angemeldet.' }");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
-                       $this->validateRPCResponse($res, "IsLoggedIn", "true");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Logout", "", "", "", "");
-                       $this->validateRPCResponse($res, "Logout", "true");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("IsLoggedIn", "", "", "", "");
-                       $this->validateRPCResponse($res, "IsLoggedIn", "false");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
-                       $this->validateRPCResponse($res, "Auth", "true");
-               }
-               
-               function testPlantCreation() {
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "", "");
-                       $this->validateRPCResponse($res, "CreatePlant", "{ success: false, msg: 'Sie sind nicht angemeldet' }");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "newplant", "");
-                       $this->validateRPCResponse($res, "CreatePlant", "{ success: true, msg: 'Es wurde eine neue Pflanze für sie angelegt.' }");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("GetPlantList", "", "", "", "");
-                       $this->validateRPCResponseWithoutData($res, "GetPlantList");
-                       $expectedEnd = "Name: 'newplant', Code: '' }] }";
-                       substr($res->m_Data, -count($expectedEnd), 0);
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("SavePlant", "test", "", "newplant", "a b c");
-                       $this->validateRPCResponse($res, "SavePlant", "{ success: true, msg: '' }");
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("GetPlantList", "", "", "", "");
-                       $this->validateRPCResponseWithoutData($res, "GetPlantList");
-                       $expectedEnd = "Name: 'newplant', Code: 'a b c' }] }";
-                       substr($res->m_Data, -count($expectedEnd), 0);
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("DeletePlant", "test", "", "newplant", "");
-                       $this->validateRPCResponse($res, "DeletePlant", "{ success: true, msg: '' }");
-               }
-               
-               function testValidation() {
-                       
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Register", "test", "test", "", "");
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("Auth", "test", "test", "", "");
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("CreatePlant", "", "", "newplant", "RULE a GROW BY 1");
-                       
-                       $GLOBALS['ValidatorFile'] = '../../cgi/validate';
-                       $res = $this->m_Controller->HandleRemoteProcedureCall("ValidatePlant", "test", "", "newplant", "");
-                       $this->validateRPCResponse($res, "ValidatePlant", "{\"valid\":true}");
-                       
-               }
-       }
-?>
diff --git a/web/php/tests/DatabaseTest.php b/web/php/tests/DatabaseTest.php
deleted file mode 100644 (file)
index 757b7d0..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-       include("../Database.php");
-
-       class TestOfDataBase extends UnitTestCase
-       {
-               private $m_Database;
-               
-               function __construct() {
-               }
-               
-               function setUp() {
-                       $this->m_Database = new DataBase();
-                       $this->m_Database->Clear();
-               }
-               
-               function tearDown() {
-                       $this->m_Database->Clear();
-                       $this->m_Database->Close();
-               }
-               
-               function testClear() {
-                       $username = "argletam";
-                       $this->m_Database->CreateUser($username, "42aa");
-                       $user = $this->m_Database->GetUser($username);
-                       $userid = $user->ID;
-                       
-                       $res = $this->m_Database->Clear();
-                       $this->assertTrue($res, "Clear failed");
-                       
-                       $user = $this->m_Database->GetUser($username);
-                       $this->assertTrue($user == null, "A User was found even though the database was cleared");
-                       
-                       $plants = $this->m_Database->GetPlantsForUser($userid);
-                       $this->assertTrue(count($user) == 0, "Even though the database was cleared we found plants for a user");
-               }
-               
-               function testUser() {
-                       $username = "testuser";
-                       
-                       $result = $this->m_Database->CreateUser($username, "test");
-                       $this->assertTrue($result);
-                       
-                       $user = $this->m_Database->GetUser($username);
-                       $this->assertTrue($user != null);
-                       
-                       $user = $this->m_Database->GetUser("a");
-                       $this->assertTrue($user == null);
-                       
-                       $user = $this->m_Database->GetUser(null);
-                       $this->assertTrue($user == null);
-               }
-               
-               function testPlant() {
-                       $username = "testuser";
-                       
-                       $result = $this->m_Database->CreateUser($username, "test");
-                       $user = $this->m_Database->GetUser($username);
-                       
-                       $data_name = "myplant";
-                       $data_code = "my fancy plant code!";
-                       
-                       $result = $this->m_Database->InsertNewPlant($user->ID, $data_name, $data_code);
-                       $this->assertTrue($result);
-                       
-                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
-                       $this->assertTrue($plant != null);
-                       $this->assertTrue($plant->UserID == $user->ID);
-                       $this->assertTrue($plant->Name == $data_name);
-                       $this->assertTrue($plant->Code == $data_code);
-                       
-                       $plants = $this->m_Database->GetPlantsForUser($user->ID);
-                       $this->assertTrue($plants != null);
-                       $this->assertTrue(count($plants) == 1);
-                       $this->assertTrue($plants[0]->ID == $plant->ID);
-                       
-                       $data_code = $plant->Code = "My New and improved Plantcode. Featuring: even fancier code!";
-                       $result = $this->m_Database->UpdatePlant($plant);
-                       $this->assertTrue($result);
-                       
-                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
-                       $this->assertTrue($plant != null);
-                       $this->assertTrue($plant->UserID == $user->ID);
-                       $this->assertTrue($plant->Name == $data_name);
-                       $this->assertTrue($plant->Code == $data_code);
-                       
-                       $result = $this->m_Database->DropPlant($plant);
-                       $this->assertTrue($result);
-                       
-                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
-                       $this->assertTrue($plant == null);
-               }
-               
-               function testNextSeed() {
-                       $username = "testuser";
-                       $data_name = "myplant";
-                       $data_code = "my fancy plant code!";
-                       
-                       $this->m_Database->CreateUser($username, "test");
-                       $user = $this->m_Database->GetUser($username);
-                       
-                       $this->m_Database->InsertNewPlant($user->ID, $data_name, $data_code);
-                       $plant = $this->m_Database->GetPlant($user->ID, $data_name);
-                       
-                       $result = $this->m_Database->SetUsersNextSeed($user->ID, $plant->ID);
-                       $this->assertTrue($result);
-                       
-                       $user = $this->m_Database->GetUserByID($user->ID);
-                       $this->assertTrue($user != null);
-                       $this->assertTrue($user->NextSeedID == $plant->ID);
-                       
-                       $plant = $this->m_Database->GetPlantByID($user->ID, $plant->ID);
-                       $this->assertTrue($plant != null);
-                       $this->assertTrue($plant->IsActive);
-               }
-               
-               function testSeason() {
-                       $username = "testuser";
-                       $data_name = "myplant";
-                       $data_code = "my fancy plant code!";
-                       
-                       $this->m_Database->CreateUser($username, "test");
-                       $user = $this->m_Database->GetUser($username);
-                       
-                       $this->m_Database->m_Connection->query("INSERT INTO season (IsRunning) VALUES (true)");
-                       $stmt = $this->m_Database->m_Connection->query("SELECT ID FROM season");
-                       $seasonid = $stmt->fetch_object()->ID;
-                       $this->assertTrue($seasonid != null);
-                       $stmt->close();
-                       
-                       $this->m_Database->m_Connection->query("INSERT INTO seasonscore (UserID, SeasonID, Score) VALUES (".$user->ID.", ".$seasonid.", 5)");
-                       $seasonscores = $this->m_Database->GetAllSeasonScores();
-                       $this->assertTrue($seasonscores != null);
-                       $this->assertTrue(count($seasonscores) == 1, "expected 1 got ".count($seasonscores));
-                       $this->assertTrue($seasonscores[0]->UserID == $user->ID);
-                       $this->assertTrue($seasonscores[0]->SeasonID == $seasonid);
-                       $this->assertTrue($seasonscores[0]->Season != null);
-                       $this->assertTrue($seasonscores[0]->Season->IsRunning);
-               }
-       }
-
-?>
diff --git a/web/php/tests/all_tests.php b/web/php/tests/all_tests.php
deleted file mode 100644 (file)
index 97fd736..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-       require_once('simpletest/unit_tester.php');
-       require_once('simpletest/reporter.php');
-
-       $test = &new GroupTest('All tests');
-       $test->addTestFile('DatabaseTest.php');
-       $test->addTestFile('BuisnessLogicTest.php');
-       $test->run(new HtmlReporter());
-
-?>