Пример #1
0
 public function testInstantiateDaoWithoutConfigFile() {
     $this->removeConfigFile();
     Config::destroyInstance();
     $cfg_values = array("table_prefix"=>"tu_", "db_host"=>"localhost");
     $config = Config::getInstance($cfg_values);
     $test_dao = new TestMySQLDAO($cfg_values);
     $users = $test_dao->getUserCount(0, 'mary');
     $this->assertIsA($users, "array");
     $this->assertEqual(count($users), 2);
     $this->assertEqual($users[0]['user_name'], 'mary');
     $this->assertEqual($users[1]['user_name'], 'sweetmary');
     $this->restoreConfigFile();
 }
Пример #2
0
 public static function destroyPDO()
 {
     self::$PDO = null;
 }
Пример #3
0
 public function testCompareMySQLAndPHPTimezoneOffsets()
 {
     if (!$this->isTimeZoneSupported()) {
         return;
     }
     // These tests will only be run if the time_zone tables are populated in MySQL.
     // See http://dev.mysql.com/doc/refman/5.1/en/mysql-tzinfo-to-sql.html
     $config = Config::getInstance();
     // set timezones the same for MySQL and PHP
     $config->setValue('timezone', 'America/Los_Angeles');
     date_default_timezone_set('America/Los_Angeles');
     $timezone = $config->getValue('timezone');
     TestMySQLDAO::destroyPDO();
     $testdao = DAOFactory::getDAO('TestDAO');
     // test time outside of daylight saving time
     $stmt = TestMySQLDAO::$PDO->query('SELECT UNIX_TIMESTAMP("2011-01-01 00:00:00") AS time');
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $mysql_time = $row['time'];
     $php_time = strtotime('2011-01-01 00:00:00');
     $this->assertEqual($mysql_time, $php_time);
     // test time during daylight saving time
     $stmt = TestMySQLDAO::$PDO->query('SELECT UNIX_TIMESTAMP("2011-09-01 00:00:00") AS time');
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $mysql_time = $row['time'];
     $php_time = strtotime('2011-09-01 00:00:00');
     $this->assertEqual($mysql_time, $php_time);
 }
Пример #4
0
 public function testCompareTimezoneOffsets()
 {
     $config = Config::getInstance();
     $config->setValue('timezone', 'Europe/London');
     $timezone = $config->getValue('timezone');
     $time = new DateTime("now", new DateTimeZone($timezone));
     $tz_config = $time->format('P');
     //destroy the existing PDO connection which gets established in setUp to start with a clean slate
     TestMySQLDAO::destroyPDO();
     // this should return the same timezone offset as the config value
     $test_dao = new TestMySQLDAO();
     $tz_server = $test_dao->getTimezoneOffset();
     $this->assertEqual($tz_config, $tz_server['tz_offset']);
     Config::destroyInstance();
 }