} $this->assertEquals(true, $exceptionThrown); // step 2: now, extend the model to add the emailAddress // field __mf_extend_model('Test_DataModel_User', 'Test_DataModel_User_EmailAddress_Ext'); // now, see if the extension works // // note: we should not have to create a new instance // of the user object! $this->assertEquals(false, $user->hasEmailAddress); $user->setEmailAddress('*****@*****.**'); $this->assertEquals(true, $user->hasEmailAddress); $this->assertEquals('*****@*****.**', $user->emailAddress); } } Testsuite_registerTests('DataModel_Tests'); class DataModel_Tests extends PHPUnit_Framework_TestCase { public function setup() { DataModel_Definitions::destroy(); $this->setupDefineModels(); } public function setupDefineModels() { $oDef = DataModel_Definitions::get('Test_DataModel_Requirement'); $oDef->addField('requirementsUid'); $oDef->addField('title'); $oDef->addField('summary'); $oDef->addField('description'); $oDef->addField('project')->setDefaultValue('MF Testing');
$e = new Exception_Technical('oh my diety: %s', array('god')); $this->fixture = new Exception_Process(500, 1, 'param 1: %s, param 2: %s', array('array 1', 'array 2'), $e); $this->type = 'ProcessException'; $this->file = basename(__FILE__); $this->line = 186; } public function testParent() { $this->assertTrue($this->fixture instanceof Exception_Process); } public function testCode() { $this->assertEquals(1, $this->fixture->getCode()); } } Testsuite_registerTests('Exception_Technical_Tests'); class Exception_Technical_Tests extends EnterpriseException_Tests { public function setup() { $e = new Exception_Technical('oh my diety: %s', array('god')); $this->fixture = new Exception_Technical('param 1: %s, param 2: %s', array('array 1', 'array 2'), $e); $this->type = 'Exception_Technical'; $this->file = basename(__FILE__); $this->line = 209; } public function testParent() { $this->assertTrue($this->fixture instanceof Exception_Technical); } }
__mf_require_once('Testsuite'); require_once APP_TOPDIR . '/mf/Datastore/Datastore.tests.inc.php'; Testsuite_registerTests('DatastorePDO_Record_Tests'); class DatastorePDO_Record_Tests extends DatastoreXXX_Record_Tests { public function setup() { // echo "\nDatastorePDO_Record_Tests::setup()\n"; createTestSqlDatabase(); defineDatastoreTestModels(); $oConn = new DatastorePDO_Connector('mysql:host=localhost;dbname=mfTest', 'root', ''); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } Testsuite_registerTests('DatastorePDO_Query_Tests'); class DatastorePDO_Query_Tests extends DatastoreXXX_Query_Tests { public function setup() { createTestSqlDatabase(); defineDatastoreTestModels(); $oConn = new DatastorePDO_Connector('mysql:host=localhost;dbname=mfTest', 'root', ''); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } function createTestSqlDatabase() { $db = mysql_connect('localhost', 'root', ''); if (!$db) {
// Released under v3 of the GNU Affero Public License // // ======================================================================== // ======================================================================== // When Who What // ------------------------------------------------------------------------ // 2009-07-26 SLH Created // ======================================================================== // // bootstrap the framework define('UNIT_TEST', true); define('APP_TOPDIR', realpath(dirname(__FILE__) . '/../../')); require_once APP_TOPDIR . '/mf/mf.inc.php'; // load additional files we explicitly require __mf_require_once('Testsuite'); Testsuite_registerTests('Debug_Timer_Tests'); class Debug_Timer_Tests extends PHPUnit_Framework_TestCase { public function setup() { $this->fixture = new Debug_Timer(); } public function testCanFormatDuration() { // perform the basic test $this->assertEquals('00.100', $this->fixture->formatDuration(0.1, 2, 3)); // now try something more challenging $this->assertEquals('01.234', $this->fixture->formatDuration(1.2345, 2, 3)); // make sure we're formatting millisecs correctly $this->assertEquals('01.002', $this->fixture->formatDuration(1.002, 2, 3)); $this->assertEquals('54.3', $this->fixture->formatDuration(54.32), 2, 1);
__mf_require_once('Testsuite'); require_once APP_TOPDIR . '/mf/Datastore/Datastore.tests.inc.php'; // define the tests Testsuite_registerTests('DatastoreMySQL_Record_Tests'); class DatastoreMySQL_Record_Tests extends DatastoreXXX_Record_Tests { public function setup() { createTestSqlDatabase(); defineDatastoreTestModels(); $oConn = new DatastoreMySQL_Connector(array('host' => 'localhost', 'db' => 'mfTest', 'user' => 'root', 'pass' => '')); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } Testsuite_registerTests('DatastoreMySQL_Query_Tests'); class DatastoreMySQL_Query_Tests extends DatastoreXXX_Query_Tests { public function setup() { createTestSqlDatabase(); defineDatastoreTestModels(); $oConn = new DatastoreMySQL_Connector(array('host' => 'localhost', 'db' => 'mfTest', 'user' => 'root', 'pass' => '')); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } // helper function to reload the database to a known state function createTestSqlDatabase() { $db = mysql_connect('localhost', 'root', '');
// Copyright (c) 2008-2010 Stuart Herbert // Released under v3 of the GNU Affero Public License // // ======================================================================== // ======================================================================== // When Who What // ------------------------------------------------------------------------ // 2009-07-07 SLH Created // ======================================================================== // bootstrap the framework define('UNIT_TEST', true); define('APP_TOPDIR', realpath(dirname(__FILE__) . '/../../')); require_once APP_TOPDIR . '/mf/mf.inc.php'; // load additional files we explicitly require __mf_require_once('Testsuite'); Testsuite_registerTests('App_Conditions_Tests'); class App_Conditions_Tests extends PHPUnit_Framework_TestCase { public function setup() { $this->fixture = new App_Conditions(); } public function testDefaultConditionIsLoggedOut() { $this->assertTrue($this->fixture['loggedOut']); $this->assertFalse($this->fixture['loggedIn']); } public function testLoggingInUpdatesLoggedOutConditionToo() { // entry conditions $this->assertTrue($this->fixture['loggedOut']);
} class Example_DefaultLayout1 extends Page_Layout { } class Example_Default_Layout2 extends Page_Layout { } class Example_Default_Layout3 extends Page_Layout { public function __construct() { $this->layoutFile = 'defaultLayout'; parent::__construct(); } } Testsuite_registerTests('Page_Layout_Tests'); class Page_Layout_Tests extends PHPUnit_Framework_TestCase { function testDefaultLayoutNamesAreSet() { // make sure that the first word is decapitalised // (small camelcase) $test1 = new Example_Layout1(); $this->assertEquals('layout1', $test1->layoutFile); // make sure that the first word is decapitalised, but // other letters are left alone $test2 = new Example_DefaultLayout1(); $this->assertEquals('defaultLayout1', $test2->layoutFile); // make sure separate words are concatenated together $test3 = new Example_Default_Layout2(); $this->assertEquals('defaultLayout2', $test3->layoutFile);
return $this->protVar; } public function setName($value) { $this->protVar = $value; } public function issetName() { return isset($this->protVar); } public function unsetFish() { $this->protVar = null; } } Testsuite_registerTests('Obj_Tests'); class Obj_Tests extends PHPUnit_Framework_TestCase { public function setup() { Obj_MixinsManager::destroy(); $this->fixture = new Test_ObjExt(); __mf_extend('Test_ObjExt', 'Test_Obj_ExtMixin'); } public function testCanGetFakeMember() { $this->assertEquals('world', $this->fixture->planet); } public function testCanSetFakeMember() { // entry conditions
// // ======================================================================== // ======================================================================== // When Who What // ------------------------------------------------------------------------ // 2007-08-11 SLH Consolidated from individual files // 2009-03-18 SLH Fixed up to use the new task-based approach // ======================================================================== // bootstrap the framework define('UNIT_TEST', true); define('APP_TOPDIR', realpath(dirname(__FILE__) . '/../../')); require_once APP_TOPDIR . '/mf/mf.inc.php'; // load additional files we explicitly require __mf_require_once('Testsuite'); Testsuite_registerTests('PHP_Array_Tests'); Testsuite_registerTests('PHP_Network_Tests'); class PHP_Network_Tests extends PHPUnit_Framework_TestCase { public $aIpAddresses = array('127.0.0.1' => 2130706433, '10.227.136.20' => 182683668); public function testCanConvertIpAddressToInt() { foreach ($this->aIpAddresses as $ipAddress => $ipInt) { $this->assertEquals($ipInt, ipAddress_to_int($ipAddress)); } } public function testCanConvertIntsToIpAddress() { foreach ($this->aIpAddresses as $ipAddress => $ipInt) { $this->assertEquals($ipAddress, int_to_ipAddress($ipInt)); } }
{ self::$eventsTriggered++; self::$data = $data; } public static function listenToTestEvent2($source, $data) { self::$eventsTriggered++; self::$data = $data; } public static function reset() { self::$eventsTriggered = 0; self::$data = array(); } } Testsuite_registerTests('Events_Tests'); class Events_Tests extends PHPUnit_Framework_TestCase { public function setup() { Events_Manager::destroy(); Test_Event_ListenerStatic::reset(); } public function testCanRegisterEvents() { // entry conditions $listeners = Events_Manager::getListeners(); $this->assertEquals(0, count($listeners)); // change state $listener = new Test_Event_ListenerObj(); Events_Manager::listensToEvents($listener);
// load additional files we explicitly require __mf_require_once('Testsuite'); require_once APP_TOPDIR . '/mf/Datastore/Datastore.tests.inc.php'; Testsuite_registerTests('DatastoreSQLite3_Record_Tests'); class DatastoreSQLite3_Record_Tests extends DatastoreXXX_Record_Tests { public function setup() { createTestSQLiteDatabase(); defineDatastoreTestModels(); $oConn = new DatastoreSQLite3_Connector('mf.sqlite'); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } Testsuite_registerTests('DatastoreSQLite3_Query_Tests'); class DatastoreSQLite3_Query_Tests extends DatastoreXXX_Query_Tests { public function setup() { createTestSQLiteDatabase(); defineDatastoreTestModels(); $oConn = new DatastoreSQLite3_Connector('mf.sqlite'); $this->db = new Datastore($oConn); defineDatastoreTestStorage_RDBMS($this->db); } } function createTestSQLiteDatabase() { if (file_exists('mf.sqlite')) { unlink('mf.sqlite');
// logged out // 2009-07-13 SLH Added tests for routing to an external URL // 2009-07-24 SLH Removed tests for shortcut function (which is now // in the XHTML module) // 2009-07-24 SLH Routing_Route::toUrl() renamed to expandUrl() // ======================================================================== // bootstrap the framework define('UNIT_TEST', true); define('APP_TOPDIR', realpath(dirname(__FILE__) . '/../../')); require_once APP_TOPDIR . '/mf/mf.inc.php'; // load additional files we explicitly require __mf_require_once('Testsuite'); if (!defined('URL_TO_TOPDIR')) { define('URL_TO_TOPDIR', 'http://www.example.com'); } Testsuite_registerTests('Routing_Tests'); class Routing_Tests extends PHPUnit_Framework_TestCase { public function setup() { // add several routes for testing purposes // // NOTE: the order that routes are defined in matters // to the Routes manager App::$routes->resetRoutes(); App::$routes->addRoute('userProfile')->withUrl('/profile/:username')->withParams(array(':username')); App::$routes->addRoute('index')->withUrl('/')->withConditions(array('loggedIn' => true))->routeToModuleAndPage('Homepage', 'indexLoggedIn'); App::$routes->addRoute('index')->withUrl('/')->withConditions(array('loggedIn' => false))->routeToModuleAndPage('Homepage', 'indexLoggedOut'); App::$routes->addRoute('showPhoto')->withUrl('/photos/:username/:photoId/show')->withParams(array(':username', ':photoId')); App::$routes->addRoute('blogArchive')->withUrl('/archive/:year/:month/:day')->withParams(array(':year' => '([0-9]{4})', ':month' => '([0-9]{2})', ':day' => '([0-9]{2})')); App::$routes->addRoute('blogArchive2')->withUrl('/archive2/:year/:month/:day')->withParams(array(':year' => true, ':month' => true, ':day' => true));