Author: commana Date: Tue Oct 26 16:27:57 2010 New Revision: 5716 Log: Included all eStudy2Go database tests to AllDBTests Added: trunk/unit-tests/database/EstudyZendPDOAdapter.php Modified: trunk/eStudy2Go/application/models/User.php trunk/eStudy2Go/tests/models/AllModelDbTests.php trunk/eStudy2Go/tests/models/BannedUserTest.php trunk/eStudy2Go/tests/models/CoursesTest.php trunk/eStudy2Go/tests/models/EventsTest.php trunk/eStudy2Go/tests/models/MessagingInboxTest.php trunk/eStudy2Go/tests/models/MessagingOutboxTest.php trunk/eStudy2Go/tests/models/MyLinksTest.php trunk/eStudy2Go/tests/models/NewsIndicatorTest.php trunk/eStudy2Go/tests/models/UserTest.php trunk/unit-tests/AllDBTests.php Modified: trunk/eStudy2Go/application/models/User.php ============================================================================== --- trunk/eStudy2Go/application/models/User.php (original) +++ trunk/eStudy2Go/application/models/User.php Tue Oct 26 16:27:57 2010 @@ -2,7 +2,7 @@ /*--------------------------------------------------------------------------+ This file is part of eStudy2Go. -- Beschreibung: +- Beschreibung: - Version: 2008-12-08 - Autor(en): Paul-Christian Volkmer <pau...@mn...> @@ -29,9 +29,13 @@ /** Model_Table_User */ protected $_table; + public function __construct(Zend_Db_Adapter_Abstract $db) { + Zend_Db_Table_Abstract::setDefaultAdapter($db); + } + /** * Tabellen-Objekt - * + * * @return Model_User_Table */ public function getTable() { @@ -67,7 +71,7 @@ /** * UserID per Login - * + * * @return User */ public function fetchUserID( $login ) { Modified: trunk/eStudy2Go/tests/models/AllModelDbTests.php ============================================================================== --- trunk/eStudy2Go/tests/models/AllModelDbTests.php (original) +++ trunk/eStudy2Go/tests/models/AllModelDbTests.php Tue Oct 26 16:27:57 2010 @@ -1,7 +1,4 @@ <?php -require_once __DIR__ . '/../../../unit-tests/registerphar.inc.php'; - -require_once 'PHPUnit/Framework.php'; require_once 'UserTest.php'; require_once 'CoursesTest.php'; @@ -11,10 +8,11 @@ require_once 'MessagingOutboxTest.php'; require_once 'MyLinksTest.php'; -class AllModelDbTests { - public static function suite() { +class Estudy2Go_AllModelDbTests { + + public static function suite() { $suite = new PHPUnit_Framework_TestSuite("eStudy2Go: All Model-Tests"); - + $suite->addTestSuite("UserTest"); $suite->addTestSuite("CoursesTest"); $suite->addTestSuite("BannedUserTest"); @@ -24,5 +22,5 @@ $suite->addTestSuite("MyLinksTest"); return $suite; - } + } } Modified: trunk/eStudy2Go/tests/models/BannedUserTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/BannedUserTest.php (original) +++ trunk/eStudy2Go/tests/models/BannedUserTest.php Tue Oct 26 16:27:57 2010 @@ -1,73 +1,51 @@ <?php -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -require_once dirname(__FILE__) . '/../../application/models/BannedUser.php'; +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); +require_once APPLICATION_PATH . '/models/BannedUser.php'; -class BannedUserTest extends Zend_Test_PHPUnit_DatabaseTestCase { +class BannedUserTest extends AbstractEStudyDatabaseTest { - private $connectionMock; private $model; + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "common/mkf/estudy.sql"); + } + protected function setUp() { - $this->model = new Model_BannedUser( $this->db() ); - $this->cleanUpDb(); parent::setUp(); + $this->model = new Model_BannedUser($this->db()); } - - protected function tearDown() { - $this->cleanUpDb(); - parent::tearDown(); + + protected function getDataSet() { + return $this->createXMLDataSet(__DIR__ . '/dbFiles/bannedusersSeed.xml'); } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE bannedusers;"); + + protected function db() { + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - - protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/bannedusersSeed.xml'); - } - - protected function db() { - return $this->getConnection()->getConnection(); - } - + public function testShouldReturnBannedUser() { $expected = array( - "ID" => 1, - "userID" => 2, - "bannedBy" => 1, - "reason" => "Testreason", - "time" => 1240039097, - "expire" => 0 - ); - $actual = $this->model->userBanInformation(2)->toArray(); - + "ID" => 1, + "userID" => 2, + "bannedBy" => 1, + "reason" => "Testreason", + "time" => 1240039097, + "expire" => 0 + ); + $actual = $this->model->userBanInformation(2)->toArray(); + $this->assertEquals($expected, $actual); } - + public function testShouldReturnNull() { - $actual = $this->model->userBanInformation(1); - + $actual = $this->model->userBanInformation(1); + $this->assertNull($actual); } } Modified: trunk/eStudy2Go/tests/models/CoursesTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/CoursesTest.php (original) +++ trunk/eStudy2Go/tests/models/CoursesTest.php Tue Oct 26 16:27:57 2010 @@ -1,111 +1,85 @@ <?php -require_once 'phar://Zend.phar/Zend/Date.php'; -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Session/Namespace.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +require_once 'Zend/Date.php'; +require_once 'Zend/Session/Namespace.php'; -require_once dirname(__FILE__) . '/../../application/models/Courses.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); - +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; + require_once APPLICATION_PATH . "/libs/EstudySession.php"; +require_once APPLICATION_PATH . '/models/Courses.php'; class EstudySessionMock extends EstudySession { + public function __construct() { // Initialize session $_SESSION['Test'] = 'Test'; } } -class CoursesTest extends Zend_Test_PHPUnit_DatabaseTestCase { - private $connectionMock; +class CoursesTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "courses/courses.sql"); + } + protected function setUp() { + parent::setUp(); $this->model = new Model_Courses($this->db(), new EstudySessionMock()); - $this->cleanUpDb(); - parent::setUp(); } - - protected function tearDown() { - $this->cleanUpDb(); - parent::tearDown(); + + protected function getDataSet() { + return $this->createXMLDataSet(__DIR__ . '/dbFiles/coursesSeed.xml'); } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE courses;"); + + protected function db() { + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - - protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/coursesSeed.xml'); - } - - protected function db() { - return $this->getConnection()->getConnection(); - } - + public function testShouldReturnFirstCourse() { - $expected = array( "ID" => 1, "Name" => "Testkurs1"); - $actual = $this->model->fetchCourse(1); - + $expected = array("ID" => 1, "Name" => "Testkurs1"); + $actual = $this->model->fetchCourse(1); + $this->assertEquals($expected, $actual); } - + public function testShouldReturnFirstECom() { - $expected = array( "ID" => 2, "Name" => "Testkurs2"); - $actual = $this->model->fetchECom(2); - + $expected = array("ID" => 2, "Name" => "Testkurs2"); + $actual = $this->model->fetchECom(2); + $this->assertEquals($expected, $actual); } - + public function testShouldNotReturnEComAsCourse() { - $actual = $this->model->fetchCourse(2); - + $actual = $this->model->fetchCourse(2); + $this->assertFalse($actual); } - + public function testShouldNotReturnCourseAsECom() { - $actual = $this->model->fetchECom(1); - + $actual = $this->model->fetchECom(1); + $this->assertFalse($actual); } - + public function testShouldReturnAllCourses() { - $expected = array( - array("ID" => 3, "Name" => "Testkurs3"), - array("ID" => 4, "Name" => "Testkurs4"), - ); - - $actual = $this->model->fetchOpenCourses(0); - + $expected = array(array("ID" => 3, "Name" => "Testkurs3"), array("ID" => 4, "Name" => "Testkurs4")); + + $actual = $this->model->fetchOpenCourses(0); + $this->assertEquals($expected, $actual); } - + public function testShouldReturnAllEComs() { - $expected = array( - array("ID" => 5, "Name" => "Testkurs5"), - array("ID" => 6, "Name" => "Testkurs6"), - ); - - $actual = $this->model->fetchOpenEComs(0); - + $expected = array(array("ID" => 5, "Name" => "Testkurs5"), array("ID" => 6, "Name" => "Testkurs6")); + + $actual = $this->model->fetchOpenEComs(0); + $this->assertEquals($expected, $actual); } } Modified: trunk/eStudy2Go/tests/models/EventsTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/EventsTest.php (original) +++ trunk/eStudy2Go/tests/models/EventsTest.php Tue Oct 26 16:27:57 2010 @@ -1,111 +1,91 @@ <?php -require_once 'phar://Zend.phar/Zend/Date.php'; -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +require_once 'Zend/Date.php'; -require_once dirname(__FILE__) . '/../../application/models/Events.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -class EventsTest extends Zend_Test_PHPUnit_DatabaseTestCase { +require_once APPLICATION_PATH . '/models/Events.php'; - private $connectionMock; +class EventsTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "calendar/calendar.sql"); + $this->loadSchema(PATH_TO_ROOT . "courses/courses.sql"); + $this->loadSchema(PATH_TO_ROOT . "teams/teams.sql"); + } + protected function setUp() { - $this->model = new Model_Events(1, $this->db()); - $this->cleanUpDb(); parent::setUp(); + $this->model = new Model_Events(1, $this->db()); } - - protected function tearDown() { - $this->cleanUpDb(); - parent::tearDown(); + + protected function getDataSet() { + return $this->createXMLDataSet(__DIR__ . '/dbFiles/eventsSeed.xml'); } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE calendar;"); - $this->getConnection()->getConnection()->query("TRUNCATE TABLE calendar_courses;"); + + protected function db() { + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - - protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/eventsSeed.xml'); - } - - protected function db() { - return $this->getConnection()->getConnection(); - } - + protected function insertEventFromToday() { $this->db()->query("INSERT INTO calendar VALUES('100',NOW(),NOW(),'Test100','Testtext100',1,0,0,0);"); $this->db()->query("INSERT INTO calendar_user VALUES(1,100);"); } - + public function testShouldReturnAllEventsOfFirstUser() { $expected = array( - array( - "eventid" => 1, - "eventtime" => "2111-11-11 11:11:00", - "endtime" => "2111-11-11 11:12:00", - "eventsubject" => "Test1", - "eventtext" => "Testtext1", - "eventactive" => 1, - "wholetime" => 0, - "facultative" => 0, - "recurringid" => 0 - ), - array( - "eventid" => 2, - "eventtime" => "2111-11-11 11:11:00", - "endtime" => "2111-11-11 11:12:00", - "eventsubject" => "Test2", - "eventtext" => "Testtext2", - "eventactive" => 1, - "wholetime" => 0, - "facultative" => 0, - "recurringid" => 0 - ) - ); - $actual = $this->model->fetchEvents(Model_Events::ALL); - + array( + "eventid" => 1, + "eventtime" => "2111-11-11 11:11:00", + "endtime" => "2111-11-11 11:12:00", + "eventsubject" => "Test1", + "eventtext" => "Testtext1", + "eventactive" => 1, + "wholetime" => 0, + "facultative" => 0, + "recurringid" => 0 + ), + array( + "eventid" => 2, + "eventtime" => "2111-11-11 11:11:00", + "endtime" => "2111-11-11 11:12:00", + "eventsubject" => "Test2", + "eventtext" => "Testtext2", + "eventactive" => 1, + "wholetime" => 0, + "facultative" => 0, + "recurringid" => 0 + ) + ); + $actual = $this->model->fetchEvents(Model_Events::ALL); + $this->assertEquals($expected, $actual); } - + public function testShouldReturnTodaysEventOfFirstUser() { $this->insertEventFromToday(); $date = new Zend_Date(); - + $expected = array( - array( - "eventid" => 100, - "eventtime" => $date->get("Y-MM-dd HH:mm:ss"), - "endtime" => $date->get("Y-MM-dd HH:mm:ss"), - "eventsubject" => "Test100", - "eventtext" => "Testtext100", - "eventactive" => 1, - "wholetime" => 0, - "facultative" => 0, - "recurringid" => 0 - ) - ); - $actual = $this->model->fetchEvents(Model_Events::TODAY); - + array( + "eventid" => 100, + "eventtime" => $date->get("Y-MM-dd HH:mm:ss"), + "endtime" => $date->get("Y-MM-dd HH:mm:ss"), + "eventsubject" => "Test100", + "eventtext" => "Testtext100", + "eventactive" => 1, + "wholetime" => 0, + "facultative" => 0, + "recurringid" => 0 + ) + ); + $actual = $this->model->fetchEvents(Model_Events::TODAY); + $this->assertEquals($expected, $actual); } } Modified: trunk/eStudy2Go/tests/models/MessagingInboxTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/MessagingInboxTest.php (original) +++ trunk/eStudy2Go/tests/models/MessagingInboxTest.php Tue Oct 26 16:27:57 2010 @@ -1,138 +1,117 @@ <?php -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -require_once dirname(__FILE__) . '/../../application/models/MessagingInbox.php'; +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); +require_once APPLICATION_PATH . '/models/MessagingInbox.php'; -class MessagingInboxTest extends Zend_Test_PHPUnit_DatabaseTestCase { - - private $connectionMock; +class MessagingInboxTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "messaging/messaging.sql"); + } + protected function setUp() { - $this->model = new Model_MessagingInbox( $this->db() ); - $this->cleanUpDb(); parent::setUp(); + $this->model = new Model_MessagingInbox($this->db()); } - - protected function tearDown() { - parent::tearDown(); + + protected function getDataSet() { + return $this->createXMLDataSet(__DIR__ . '/dbFiles/messagingInboxSeed.xml'); } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE messaging_inbox;"); + + protected function db() { + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - - protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/messagingInboxSeed.xml'); - } - - protected function db() { - return $this->getConnection()->getConnection(); - } - + public function testShouldNotReturnAnyMessages() { $expected = array(); $actual = $this->model->unreadMessages(10); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } - + public function testShouldReturnReadMessagesFromUser() { $expected = array( - array( - "ID" => 2, - "userID" => 9, - "authorID" => 1, - "subject" => "Subject2", - "message" => "Message2", - "date" => 1252577917, - "isRead" => 1, - "isArchived" => 0 - ), - array( - "ID" => 3, - "userID" => 9, - "authorID" => 2, - "subject" => "Subject3", - "message" => "Message3", - "date" => 1252577917, - "isRead" => 1, - "isArchived" => 0 - ) - ); - $actual = $this->model->readMessages(9); - - $this->assertEquals($expected,$actual); - } - - public function testShouldReturnSelectedMessage() { - $expected = array( - "ID" => 1, - "userID" => 10, + array( + "ID" => 2, + "userID" => 9, "authorID" => 1, - "subject" => "Subject1", - "message" => "Message1", + "subject" => "Subject2", + "message" => "Message2", "date" => 1252577917, "isRead" => 1, "isArchived" => 0 - ); + ), + array( + "ID" => 3, + "userID" => 9, + "authorID" => 2, + "subject" => "Subject3", + "message" => "Message3", + "date" => 1252577917, + "isRead" => 1, + "isArchived" => 0 + ) + ); + $actual = $this->model->readMessages(9); + + $this->assertEquals($expected, $actual); + } + + public function testShouldReturnSelectedMessage() { + $expected = array( + "ID" => 1, + "userID" => 10, + "authorID" => 1, + "subject" => "Subject1", + "message" => "Message1", + "date" => 1252577917, + "isRead" => 1, + "isArchived" => 0 + ); $actual = $this->model->message(1)->toArray(); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } - + public function testShouldNotReturnDeletedMessage() { $this->model->deleteMessage(4); $actual = $this->model->message(4); - + $this->assertNull($actual); } - + public function testShouldNotReturnReadMessage() { $this->model->markAsRead(5); - + $expected = array(); - + $actual = $this->model->unreadMessages(3); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } - + public function testShouldReturnArchivedMessage() { $this->model->markAsArchived(1); - + $expected = array( - "ID" => 1, - "userID" => 10, - "authorID" => 1, - "subject" => "Subject1", - "message" => "Message1", - "date" => 1252577917, - "isRead" => 1, - "isArchived" => 1 - ); - $actual = $this->model->message(1)->toArray(); - - $this->assertEquals($expected,$actual); + "ID" => 1, + "userID" => 10, + "authorID" => 1, + "subject" => "Subject1", + "message" => "Message1", + "date" => 1252577917, + "isRead" => 1, + "isArchived" => 1 + ); + $actual = $this->model->message(1)->toArray(); + + $this->assertEquals($expected, $actual); } } Modified: trunk/eStudy2Go/tests/models/MessagingOutboxTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/MessagingOutboxTest.php (original) +++ trunk/eStudy2Go/tests/models/MessagingOutboxTest.php Tue Oct 26 16:27:57 2010 @@ -1,109 +1,89 @@ <?php -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -require_once dirname(__FILE__) . '/../../application/models/MessagingOutbox.php'; +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); +require_once APPLICATION_PATH . '/models/MessagingOutbox.php'; -class MessagingOutboxTest extends Zend_Test_PHPUnit_DatabaseTestCase { - private $connectionMock; +class MessagingOutboxTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "messaging/messaging.sql"); + } + protected function setUp() { + parent::setUp(); $this->model = new Model_MessagingOutbox($this->db()); - $this->cleanUpDb(); - parent::setUp(); } - - protected function tearDown() { - parent::tearDown(); - } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE messaging_outbox;"); - } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - + protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/messagingOutboxSeed.xml'); + return $this->createXMLDataSet(__DIR__ . '/dbFiles/messagingOutboxSeed.xml'); } protected function db() { - return $this->getConnection()->getConnection(); + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } public function testShouldReturnSendMessages() { $expected = array( - array( - "ID" => 4, - "userID" => 3, - "recipientID" => 1, - "ccIDs" => "", - "subject" => "Subject4", - "message" => "Message4", - "date" => 1252577917, - "isArchived" => 1 - ), - array( - "ID" => 5, - "userID" => 3, - "recipientID" => 1, - "ccIDs" => "", - "subject" => "Subject5", - "message" => "Message5", - "date" => 1252577917, - "isArchived" => 0 - ) - ); - + array( + "ID" => 4, + "userID" => 3, + "recipientID" => 1, + "ccIDs" => "", + "subject" => "Subject4", + "message" => "Message4", + "date" => 1252577917, + "isArchived" => 1 + ), + array( + "ID" => 5, + "userID" => 3, + "recipientID" => 1, + "ccIDs" => "", + "subject" => "Subject5", + "message" => "Message5", + "date" => 1252577917, + "isArchived" => 0 + ) + ); + $actual = $this->model->sendMessages(3); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } public function testShouldReturnSelectedMessage() { $expected = array( - "ID" => 1, - "userID" => 10, - "recipientID" => 1, - "ccIDs" => "", - "subject" => "Subject1", - "message" => "Message1", - "date" => 1252577917, - "isArchived" => 0 - ); + "ID" => 1, + "userID" => 10, + "recipientID" => 1, + "ccIDs" => "", + "subject" => "Subject1", + "message" => "Message1", + "date" => 1252577917, + "isArchived" => 0 + ); $actual = $this->model->message(1)->toArray(); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } public function testShouldNotReturnDeletedMessage() { $this->model->deleteMessage(4); $actual = $this->model->message(4); - + $this->assertNull($actual); } public function testShouldReturnArchivedMessage() { $this->model->markAsArchived(1); - + $expected = array( "ID" => 1, "userID" => 10, @@ -115,7 +95,7 @@ "isArchived" => 1 ); $actual = $this->model->message(1)->toArray(); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } } Modified: trunk/eStudy2Go/tests/models/MyLinksTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/MyLinksTest.php (original) +++ trunk/eStudy2Go/tests/models/MyLinksTest.php Tue Oct 26 16:27:57 2010 @@ -1,98 +1,77 @@ <?php -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -require_once dirname(__FILE__) . '/../../application/models/Mylinks.php'; +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", dirname(__FILE__) ."/../../application"); +require_once APPLICATION_PATH . '/models/Mylinks.php'; -class MyLinksTest extends Zend_Test_PHPUnit_DatabaseTestCase { - private $connectionMock; +class MyLinksTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "common/mkf/estudy.sql"); + } + protected function setUp() { + parent::setUp(); $this->model = new Model_MyLinks($this->db()); - $this->cleanUpDb(); - parent::setUp(); } - - protected function tearDown() { - $this->cleanUpDb(); - parent::tearDown(); + + protected function getDataSet() { + return $this->createXMLDataSet(__DIR__ . '/dbFiles/myLinksSeed.xml'); } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE mylinks;"); + + protected function db() { + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(dirname(__FILE__) . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - - protected function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/dbFiles/myLinksSeed.xml'); - } - - protected function db() { - return $this->getConnection()->getConnection(); - } - + public function testShouldNotAnyLinks() { $expected = array(); - $actual = $this->model->getMylinks(4); - - $this->assertEquals($expected,$actual); + $actual = $this->model->getMylinks(4); + + $this->assertEquals($expected, $actual); } - + public function testShouldReturnUserLinks() { $expected = array( - array( - "id" => 1, - "userID" => 1, - "title" => "Testtitel1", - "address" => "http://example.com/test1", - "created" => "2009-11-13 12:00:00" - ), - array( - "id" => 2, - "userID" => 1, - "title" => "Testtitel2", - "address" => "http://example.com/test2", - "created" => "2009-11-13 13:00:00" - ) - ); - $actual = $this->model->getMylinks(1); - - $this->assertEquals($expected,$actual); + array( + "id" => 1, + "userID" => 1, + "title" => "Testtitel1", + "address" => "http://example.com/test1", + "created" => "2009-11-13 12:00:00" + ), + array( + "id" => 2, + "userID" => 1, + "title" => "Testtitel2", + "address" => "http://example.com/test2", + "created" => "2009-11-13 13:00:00" + ) + ); + $actual = $this->model->getMylinks(1); + + $this->assertEquals($expected, $actual); } - + public function testShouldNotReturnDeletedUserLinks() { $expected = array( - array( - "id" => 3, - "userID" => 2, - "title" => "Testtitel3", - "address" => "http://example.com/test3", - "created" => "2009-11-13 12:15:00" - ) - ); - + array( + "id" => 3, + "userID" => 2, + "title" => "Testtitel3", + "address" => "http://example.com/test3", + "created" => "2009-11-13 12:15:00" + ) + ); + $this->model->delete(4); $actual = $this->model->getMylinks(2); - - $this->assertEquals($expected,$actual); + + $this->assertEquals($expected, $actual); } } Modified: trunk/eStudy2Go/tests/models/NewsIndicatorTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/NewsIndicatorTest.php (original) +++ trunk/eStudy2Go/tests/models/NewsIndicatorTest.php Tue Oct 26 16:27:57 2010 @@ -1,6 +1,4 @@ <?php - -require_once "PHPUnit/Framework.php"; require_once '../../application/models/NewsIndicator.php'; Modified: trunk/eStudy2Go/tests/models/UserTest.php ============================================================================== --- trunk/eStudy2Go/tests/models/UserTest.php (original) +++ trunk/eStudy2Go/tests/models/UserTest.php Tue Oct 26 16:27:57 2010 @@ -1,108 +1,87 @@ <?php -require_once 'phar://Zend.phar/Zend/Config/Ini.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/DatabaseTestCase.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/SimpleTester.php'; -require_once 'phar://Zend.phar/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php'; +if (!defined("APPLICATION_PATH")) define("APPLICATION_PATH", __DIR__ . "/../../application"); +if (!defined("PATH_TO_ROOT")) define("PATH_TO_ROOT", __DIR__ . "/../../../web/"); -require_once __DIR__ . '/../../application/models/User.php'; +require_once PATH_TO_ROOT . "../unit-tests/database/AbstractEStudyDatabaseTest.php"; +require_once PATH_TO_ROOT . "../unit-tests/database/EstudyZendPDOAdapter.php"; -if (! defined("APPLICATION_PATH")) - define("APPLICATION_PATH", __DIR__ ."/../../application"); +require_once APPLICATION_PATH . '/models/User.php'; -class UserTest extends Zend_Test_PHPUnit_DatabaseTestCase { - - private $connectionMock; +class UserTest extends AbstractEStudyDatabaseTest { + private $model; - + + protected function beforeClass() { + $this->loadSchema(PATH_TO_ROOT . "user/user.sql"); + } + protected function setUp() { + parent::setUp(); $this->model = new Model_User($this->db()); - $this->cleanUpDb(); - parent::setUp(); } - - protected function tearDown() { - parent::tearDown(); - } - - protected function cleanUpDb() { - $this->getConnection()->getConnection()->query("TRUNCATE TABLE user;"); - } - - protected function getConnection() { - if ($this->connectionMock == null) { - $dbConfig = new Zend_Config_Ini(__DIR__ . '/../testdb.ini'); - - $connection = Zend_Db::factory($dbConfig->adapter, $dbConfig->params); - - $this->connectionMock = $this->createZendDbConnection($connection, 'zfunittests'); - Zend_Db_Table_Abstract::setDefaultAdapter($connection); - } - - return $this->connectionMock; - } - + protected function getDataSet() { return $this->createXMLDataSet(__DIR__ . '/dbFiles/userSeed.xml'); } - + protected function db() { - return $this->getConnection()->getConnection(); + return new EstudyZendPDOAdapter($this->getConnection()->getConnection()); } - + public function testShouldReturnUser() { $expected = array( - "ID" => 1, - "Vorname" => "", - "Nachname" => "", - "Login" => "root", - "ShortName" => "", - "Password" => "", - "Usergroup" => 2, - "Email" => "", - "LastUpdate" => "0000-00-00 00:00:00", - "Invisible" => 0, - "salutation" => 0, - "street" => "", - "postcode" => "", - "location" => "", - "countryID" => 0, - "gender" => 0, - "picture" => "", - "regdate" => "2010-07-27 13:23:31", - "adrshowflag" => 0, - "mailshowflag" => 0, - "picshowflag" => 1, - "hpcounter" => 1, - "university" => "", - "department" => "", - "subject" => "", - "pictitle" => "", - "sessionID" => "", - "lastlogin1" => 0, - "lastlogin2" => 0, - "lastlogout" => 0, - "lastCounter" => 0, - "styletemplate" => "", - "policy_read" => 0, - "timezone" => "", - "context_keywords" => "", - "context_news" => 1, - "welcome_note" => 1, - "style_overwrite_mode" => 0, - "num_failed_logins" => 0, - "num_bans_for_failed_login" => 0, - "num_weak_pwd_msg" => 0, - "shared_secret" => "", - "temp_session_id" => "", - "certificate" => "", - "privkey" => "", - "pm_as_email" => 0, - "useSecureEmail" => 0, - "testaccount" => 0 + "ID" => 1, + "Vorname" => "", + "Nachname" => "", + "Login" => "root", + "ShortName" => "", + "Password" => "", + "Usergroup" => 2, + "Email" => "", + "LastUpdate" => "0000-00-00 00:00:00", + "Invisible" => 0, + "salutation" => 0, + "street" => "", + "postcode" => "", + "location" => "", + "countryID" => 0, + "gender" => 0, + "picture" => "", + "regdate" => "2010-07-27 13:23:31", + "adrshowflag" => 0, + "mailshowflag" => 0, + "picshowflag" => 1, + "hpcounter" => 1, + "university" => "", + "department" => "", + "subject" => "", + "pictitle" => "", + "sessionID" => "", + "lastlogin1" => 0, + "lastlogin2" => 0, + "lastlogout" => 0, + "lastCounter" => 0, + "styletemplate" => "", + "policy_read" => 0, + "timezone" => "", + "context_keywords" => "", + "context_news" => 1, + "welcome_note" => 1, + "style_overwrite_mode" => 0, + "num_failed_logins" => 0, + "num_bans_for_failed_login" => 0, + "num_weak_pwd_msg" => 0, + "shared_secret" => "", + "temp_session_id" => "", + "certificate" => "", + "privkey" => "", + "pm_as_email" => 0, + "useSecureEmail" => 0, + "testaccount" => 0 ); - $actual = $this->model->fetchUser(1)->toArray(); - + $actual = $this->model->fetchUser(1)->toArray(); + $this->assertEquals($expected, $actual); } } Modified: trunk/unit-tests/AllDBTests.php ============================================================================== --- trunk/unit-tests/AllDBTests.php (original) +++ trunk/unit-tests/AllDBTests.php Tue Oct 26 16:27:57 2010 @@ -26,6 +26,7 @@ require_once PATH_TO_ROOT . 'lerntagebuch/tests/DiaryDatabaseTest.php'; require_once PATH_TO_ROOT . 'messaging/tests/messaging/class.messagesendertest.inc.php'; require_once PATH_TO_ROOT . 'tracking/tests/AllTests.php'; +require_once __DIR__ . "/../eStudy2Go/tests/models/AllModelDbTests.php"; class AllDBTests { @@ -36,6 +37,7 @@ $suite->addTest(Emoderation_AllPersistenceTests::suite()); $suite->addTest(Calendar_AllExportTests::suite()); $suite->addTest(Tracking_AllTests::suite()); + $suite->addTest(Estudy2Go_AllModelDbTests::suite()); // news $suite->addTestSuite("CategoryGatewayTest"); Added: trunk/unit-tests/database/EstudyZendPDOAdapter.php ============================================================================== --- trunk/unit-tests/database/EstudyZendPDOAdapter.php (added) +++ trunk/unit-tests/database/EstudyZendPDOAdapter.php Tue Oct 26 16:27:57 2010 @@ -1,0 +1,29 @@ +<?php +/*--------------------------------------------------------------------------+ +This file is part of eStudy. +- Beschreibung: Um ein bereits erstelltes PDO-Objekt mit Zend-ORM zu verbinden. ++---------------------------------------------------------------------------+ +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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ++--------------------------------------------------------------------------*/ + +require_once "Zend/Db/Adapter/Pdo/Mysql.php"; +require_once 'Zend/Db/Table/Abstract.php'; + +class EstudyZendPDOAdapter extends Zend_Db_Adapter_Pdo_Mysql { + + public function __construct(PDO $pdo) { + $this->_connection = $pdo; + $this->setProfiler(false); + } +} |