Browse Source

more tests run

euromark 11 years ago
parent
commit
f607b997a9

+ 44 - 0
config/bootstrap.php

@@ -5,6 +5,50 @@ define('FORMAT_DB_DATETIME', 'Y-m-d H:i:s');
 define('FORMAT_DB_DATE', 'Y-m-d');
 define('FORMAT_DB_TIME', 'H:i:s');
 
+if (!defined('FORMAT_NICE_YMDHMS')) {
+	define('FORMAT_NICE_YMDHMS', 'd.m.Y, H:i:s');
+	define('FORMAT_NICE_YMDHM', 'd.m.Y, H:i');
+	define('FORMAT_NICE_YM', 'm.Y');
+	define('FORMAT_NICE_YMD', 'd.m.Y');
+	define('FORMAT_NICE_MD', 'd.m.');
+	define('FORMAT_NICE_D', 'd'); # xx
+	define('FORMAT_NICE_W_NUM', 'w'); # xx (0=sunday to 6=saturday)
+	define('FORMAT_NICE_W_ABBR', 'D'); # needs manual translation
+	define('FORMAT_NICE_W_FULL', 'l'); # needs manual translation
+	define('FORMAT_NICE_M', 'm'); # xx
+	define('FORMAT_NICE_M_ABBR', 'M'); # needs manual translation
+	define('FORMAT_NICE_M_FULL', 'F'); # needs manual translation
+	define('FORMAT_NICE_Y_ABBR', 'y'); # xx
+	define('FORMAT_NICE_Y', 'Y'); # xxxx
+	define('FORMAT_NICE_HM', 'H:i');
+	define('FORMAT_NICE_HMS', 'H:i:s');
+
+	// localDate strings
+	define('FORMAT_LOCAL_WA_YMDHMS', '%a, %d.%m.%Y, %H:%M:%S');
+	define('FORMAT_LOCAL_WF_YMDHMS', '%A, %d.%m.%Y, %H:%M:%S');
+	define('FORMAT_LOCAL_WA_YMDHM', '%a, %d.%m.%Y, %H:%M');
+	define('FORMAT_LOCAL_WF_YMDHM', '%A, %d.%m.%Y, %H:%M');
+
+	define('FORMAT_LOCAL_YMDHMS', '%d.%m.%Y, %H:%M:%S');
+	define('FORMAT_LOCAL_YMDHM', '%d.%m.%Y, %H:%M');
+	define('FORMAT_LOCAL_YMD', '%d.%m.%Y');
+	define('FORMAT_LOCAL_MD', '%d.%m.');
+	define('FORMAT_LOCAL_D', '%d'); # xx
+	define('FORMAT_LOCAL_W_NUM', '%w'); # xx (0=sunday to 6=saturday)
+	define('FORMAT_LOCAL_W_ABBR', '%a'); # needs translation
+	define('FORMAT_LOCAL_W_FULL', '%A'); # needs translation
+	define('FORMAT_LOCAL_M', '%m'); # xx
+	define('FORMAT_LOCAL_M_ABBR', '%b'); # needs translation
+	define('FORMAT_LOCAL_M_FULL', '%B'); # needs translation
+	define('FORMAT_LOCAL_Y_ABBR', '%y'); # xx
+	define('FORMAT_LOCAL_YMS_ABBR', '%d.%m.%y');
+	define('FORMAT_LOCAL_Y', '%Y'); # xxxx
+	define('FORMAT_LOCAL_H', '%H');
+	define('FORMAT_LOCAL_S', '%S');
+	define('FORMAT_LOCAL_HM', '%H:%M');
+	define('FORMAT_LOCAL_HMS', '%H:%M:%S');
+}
+
 # Make the app and l10n play nice with Windows.
 if (substr(PHP_OS, 0, 3) === 'WIN') { // || strpos(@php_uname(), 'ARCH')
 	define('WINDOWS', true);

+ 39 - 4
src/Utility/Time.php

@@ -18,7 +18,7 @@ class Time extends CakeTime {
 	 * @return bool
 	 */
 	public function hasDaylightSavingTime($timezone = null) {
-		$timezone = $this->timezone($timezone);
+		$timezone = $this->safeCreateDateTimeZone($timezone);
 		// a date outside of DST
 		$offset = $timezone->getOffset(new \DateTime('@' . mktime(0, 0, 0, 2, 1, date('Y'))));
 		$offset = $offset / HOUR;
@@ -37,7 +37,11 @@ class Time extends CakeTime {
 	 * @return int Offset in hours
 	 */
 	public function getGmtOffset($timezone = null) {
-		$timezone = $this->timezone($timezone);
+		if ($timezone) {
+			$timezone = $this->safeCreateDateTimeZone($timezone);
+		} else {
+			$timezone = $this->getTimezone();
+		}
 		$offset = $timezone->getOffset(new \DateTime('@' . time()));
 		$offset = $offset / HOUR;
 		return $offset;
@@ -336,7 +340,9 @@ class Time extends CakeTime {
 	public function incrementDate($startDate, $years = 0, $months = 0, $days = 0, $timezone = null) {
 		if (!is_object($startDate)) {
 			$startDate = new \DateTime($startDate);
-			$startDate->setTimezone($timezone ? new \DateTimeZone($timezone) : $this->timezone());
+			if ($timezone) {
+				$startDate->setTimezone($this->safeCreateDateTimeZone($timezone));
+			}
 		}
 		$startingTimeStamp = $startDate->getTimestamp();
 		// Get the month value of the given date:
@@ -414,6 +420,9 @@ class Time extends CakeTime {
 		if ($dateString === null) {
 			$dateString = time();
 		}
+		if ($options['timezone']) {
+			$options['timezone'] = static::safeCreateDateTimeZone($options['timezone']);
+		}
 		$date = new \DateTime($dateString, $options['timezone']);
 		$date = $date->format('U');
 
@@ -429,7 +438,7 @@ class Time extends CakeTime {
 			}
 		}
 
-		$date = parent::_strftime($format, $date);
+		$date = static::_strftime($format, $date);
 
 		if (!empty($options['oclock'])) {
 			switch ($format) {
@@ -446,6 +455,28 @@ class Time extends CakeTime {
 	}
 
 	/**
+	 * Multibyte wrapper for strftime.
+	 *
+	 * Handles utf8_encoding the result of strftime when necessary.
+	 *
+	 * @param string $format Format string.
+	 * @param int $date Timestamp to format.
+	 * @return string formatted string with correct encoding.
+	 */
+	protected static function _strftime($format, $date) {
+		$format = strftime($format, $date);
+		$encoding = Configure::read('App.encoding');
+
+		if (!empty($encoding) && $encoding === 'UTF-8') {
+			$valid = mb_check_encoding($format, $encoding);
+			if (!$valid) {
+				$format = utf8_encode($format);
+			}
+		}
+		return $format;
+	}
+
+	/**
 	 * Outputs Date(time) Sting nicely formatted
 	 *
 	 * Options:
@@ -468,6 +499,10 @@ class Time extends CakeTime {
 		if ($dateString === null) {
 			$dateString = time();
 		}
+
+		if ($options['timezone']) {
+			$options['timezone'] = static::safeCreateDateTimeZone($options['timezone']);
+		}
 		$date = new \DateTime($dateString, $options['timezone']);
 		$date = $date->format('U');
 		//$date = static::fromString($dateString, $options['timezone']);

+ 4 - 2
tests/TestCase/Utility/MimeTest.php

@@ -48,10 +48,12 @@ class MimeTest extends TestCase {
 
 	public function testReverseToMultiple() {
 		$res = $this->Mime->getMimeType('html', false);
-		$this->assertTrue(is_array($res) && count($res) === 2);
+		$this->assertTrue(is_array($res));
+		$this->assertSame(2, count($res));
 
 		$res = $this->Mime->getMimeType('csv', false);
-		$this->assertTrue(is_array($res) && count($res) > 2);
+		$this->assertTrue(is_array($res)); //  && count($res) > 2
+		$this->assertSame(2, count($res));
 	}
 
 	/**

+ 2 - 2
tests/TestCase/Utility/TextTest.php

@@ -47,12 +47,12 @@ TXT;
 		//pr($is);
 		$this->assertEquals($is, '0-104-32-72-0');
 
-		$is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . TB . 'x');
+		$is = $this->Text->convertToOrd('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
 		//pr($is);
 	}
 
 	public function testConvertToOrdTable() {
-		$is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . TB . 'x');
+		$is = $this->Text->convertToOrdTable('x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . PHP_EOL . 'x' . "\t" . 'x');
 		//pr($is);
 	}
 

+ 3 - 3
tests/TestCase/Utility/TimeTest.php

@@ -1042,8 +1042,8 @@ class TimeTest extends TestCase {
 	 *
 	 * @return void
 	 */
-	public function testTimezone() {
-		$timezone = $this->Time->timezone();
+	public function testGetTimezone() {
+		$timezone = $this->Time->getTimezone();
 		// usually UTC
 		$name = $timezone->getName();
 		//$this->debug($name);
@@ -1055,7 +1055,7 @@ class TimeTest extends TestCase {
 		$this->assertTrue(isset($location['latitude']));
 		$this->assertTrue(isset($location['longitude']));
 
-		$offset = $timezone->getOffset(new DateTime('@' . mktime(0, 0, 0, 1, 1, date('Y'))));
+		$offset = $timezone->getOffset(new \DateTime('@' . mktime(0, 0, 0, 1, 1, date('Y'))));
 		//$this->debug($offset);
 
 		$phpTimezone = date_default_timezone_get();