3 commits - lib/kolab_sync.php lib/kolab_sync_timezone_converter.php tests/phpunit.xml tests/timezone_converter.php
Aleksander Machniak
machniak at kolabsys.com
Fri May 31 12:42:46 CEST 2013
lib/kolab_sync.php | 2 +-
lib/kolab_sync_timezone_converter.php | 23 +++++++----------------
tests/phpunit.xml | 1 +
tests/timezone_converter.php | 28 ++++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 17 deletions(-)
New commits:
commit 15bd6d340decbcaddcd35d37d718c20589b34cc2
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri May 31 12:42:33 2013 +0200
Add simple test for timezone converter
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 701ccfe..ba94a37 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -7,6 +7,7 @@
<file>data.php</file>
<file>data_tasks.php</file>
<file>message.php</file>
+ <file>timezone_converter.php</file>
</testsuite>
</testsuites>
</phpunit>
diff --git a/tests/timezone_converter.php b/tests/timezone_converter.php
new file mode 100644
index 0000000..ef020ed
--- /dev/null
+++ b/tests/timezone_converter.php
@@ -0,0 +1,28 @@
+<?php
+
+class timezone_converter extends PHPUnit_Framework_TestCase
+{
+ function setUp()
+ {
+ }
+
+
+ function test_list_timezones()
+ {
+ $converter = timezone_converter_test::getInstance();
+
+ $input = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAEAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAEAAAAAAAAAxP///w==';
+ $output = $converter->getListOfTimezones($input, 'UTC');
+
+ $this->assertTrue(is_array($output));
+ }
+}
+
+class timezone_converter_test extends kolab_sync_timezone_converter
+{
+ // disable cache
+ function getCache()
+ {
+ return null;
+ }
+}
commit f83df37b89c1749be58df4745b0c659ef64eeadd
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri May 31 12:40:10 2013 +0200
Small improvements in timezone converter
diff --git a/lib/kolab_sync_timezone_converter.php b/lib/kolab_sync_timezone_converter.php
index 5bdc726..3f6a25c 100644
--- a/lib/kolab_sync_timezone_converter.php
+++ b/lib/kolab_sync_timezone_converter.php
@@ -80,11 +80,10 @@ class kolab_sync_timezone_converter
* first entry to the returned array.
*
* @param string|array $_offsets
- * @param string $_expectedTimezone Expected timezone
*
* @return array
*/
- public function getListOfTimezones($_offsets, $_expectedTimezone = null)
+ public function getListOfTimezones($_offsets)
{
if (is_string($_offsets) && isset($this->_knownTimezones[$_offsets])) {
$timezones = $this->_knownTimezones[$_offsets];
@@ -100,7 +99,6 @@ class kolab_sync_timezone_converter
}
$this->_setDefaultStartDateIfEmpty($_offsets);
- // don't use __METHOD__ ":" is not allowed as cache identifier
$cacheId = $this->_getCacheId('timezones', $_offsets);
$timezones = $this->_loadFromCache($cacheId);
@@ -109,13 +107,7 @@ class kolab_sync_timezone_converter
foreach (DateTimeZone::listIdentifiers() as $timezoneIdentifier) {
$timezone = new DateTimeZone($timezoneIdentifier);
if (false !== ($matchingTransition = $this->_checkTimezone($timezone, $_offsets))) {
- if ($timezoneIdentifier === $_expectedTimezone) {
- $timezones = array($timezoneIdentifier => $matchingTransition['abbr']);
- break;
- }
- else {
- $timezones[$timezoneIdentifier] = $matchingTransition['abbr'];
- }
+ $timezones[$timezoneIdentifier] = $matchingTransition['abbr'];
}
}
$this->_saveInCache($timezones, $cacheId);
@@ -143,13 +135,13 @@ class kolab_sync_timezone_converter
*/
public function getTimezone($_offsets, $_expectedTimezone = null)
{
- $timezones = $this->getListOfTimezones($_offsets, $_expectedTimezone);
+ $timezones = $this->getListOfTimezones($_offsets);
if ($_expectedTimezone && isset($timezones[$_expectedTimezone])) {
return $_expectedTimezone;
}
else {
- return current($timezones);
+ return key($timezones);
}
}
@@ -536,12 +528,11 @@ class kolab_sync_timezone_converter
*/
protected function _checkTimezone(DateTimeZone $timezone, $offsets)
{
-// $this->_log(__METHOD__, __LINE__, 'Checking for matches with timezone: ' . $timezone->getName());
list($standardTransition, $daylightTransition) = $this->_getTransitionsForTimezoneAndYear($timezone, $this->_startDate['year']);
if ($this->_checkTransition($standardTransition, $daylightTransition, $offsets)) {
- //$this->_log(__METHOD__, __LINE__, 'Matching timezone ' . $timezone->getName(), 7);
- //$this->_log(__METHOD__, __LINE__, 'Matching daylight transition ' . print_r($daylightTransition, 1), 7);
- //$this->_log(__METHOD__, __LINE__, 'Matching standard transition ' . print_r($standardTransition, 1), 7);
+// echo 'Matching timezone ' . $timezone->getName();
+// echo 'Matching daylight transition ' . print_r($daylightTransition, 1);
+// echo 'Matching standard transition ' . print_r($standardTransition, 1);
return $standardTransition;
}
commit e647e0dc28e37f96eb5ad1e396edce9d235a37b4
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu May 30 12:01:29 2013 +0200
Do not cache invalid authentication
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index 0aacfa9..5114170 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -184,7 +184,7 @@ class kolab_sync extends rcube
'valid' => true,
));
- if ($cache) {
+ if ($auth['valid'] && $cache) {
$cache->set($cache_key, array(
'user' => $auth['user'],
'host' => $auth['host'],
More information about the commits
mailing list