lib/kolab_sync_data_tasks.php tests/data.php tests/data_tasks.php tests/phpunit.xml
Aleksander Machniak
machniak at kolabsys.com
Wed Jan 30 13:39:08 CET 2013
lib/kolab_sync_data_tasks.php | 74 +++++++++++++++++++++++++++++++--------
tests/data.php | 5 --
tests/data_tasks.php | 78 ++++++++++++++++++++++++++++++++++++++++++
tests/phpunit.xml | 1
4 files changed, 137 insertions(+), 21 deletions(-)
New commits:
commit 07beccb2f637d51130474771f28da026e7922e7a
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Jan 30 13:38:14 2013 +0100
Fix mapping task importance to priority and vice-versa (#1603)
diff --git a/lib/kolab_sync_data_tasks.php b/lib/kolab_sync_data_tasks.php
index 2dfc642..1635545 100644
--- a/lib/kolab_sync_data_tasks.php
+++ b/lib/kolab_sync_data_tasks.php
@@ -137,13 +137,7 @@ class kolab_sync_data_tasks extends kolab_sync_data
break;
case 'priority':
- // ActiveSync has only 3 levels of importance:
- // 0 - Low, 1 - Normal, 2 - High
- // but Kolab uses ten levels:
- // 0 - unknown and 1-9 where 1 is the highest
- if ($value) {
- $result['importance'] = $value > 5 ? 2 : 0;
- }
+ $result['importance'] = $this->prio_to_importance($value);
break;
}
@@ -196,14 +190,7 @@ class kolab_sync_data_tasks extends kolab_sync_data
break;
case 'priority':
- if ($value !== null) {
- if ($value == 1) {
- $task['priority'] = 0;
- }
- else {
- $task['priority'] = !$value ? 9 : 1;
- }
- }
+ $value = $this->importance_to_prio($value);
break;
}
@@ -221,7 +208,6 @@ class kolab_sync_data_tasks extends kolab_sync_data
return $task;
}
-
/**
* Returns filter query array according to specified ActiveSync FilterType
*
@@ -239,4 +225,60 @@ class kolab_sync_data_tasks extends kolab_sync_data
return $filter;
}
+
+ /**
+ * Convert Kolab priority into ActiveSync importance value
+ */
+ protected function prio_to_importance($value)
+ {
+ // ActiveSync has only 3 levels of importance:
+ // 0 - Low, 1 - Normal, 2 - High
+ // but Kolab uses ten levels:
+ // 0 - unknown and 1-9 where 1 is the highest
+ // Use mapping from http://msdn.microsoft.com/en-us/library/ee159635.aspx
+
+ if ($value === null) {
+ return;
+ }
+
+ switch ($value) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ return 2;
+ case 5:
+ return 1;
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ return 0;
+ }
+
+ return;
+ }
+
+ /**
+ * Convert ActiveSync importance into Kolab priority value
+ */
+ protected function importance_to_prio($value)
+ {
+ // Use mapping from http://msdn.microsoft.com/en-us/library/ee159635.aspx
+
+ if ($value === null) {
+ return;
+ }
+
+ switch ($value) {
+ case 0:
+ return 9;
+ case 1:
+ return 5;
+ case 2:
+ return 1;
+ }
+
+ return;
+ }
}
diff --git a/tests/data.php b/tests/data.php
index 0c44932..38e488a 100644
--- a/tests/data.php
+++ b/tests/data.php
@@ -2,11 +2,6 @@
class data extends PHPUnit_Framework_TestCase
{
- function setUp()
- {
- }
-
-
/**
* Test for kolab_sync_data::recurrence_to_kolab()
*/
diff --git a/tests/data_tasks.php b/tests/data_tasks.php
new file mode 100644
index 0000000..611a028
--- /dev/null
+++ b/tests/data_tasks.php
@@ -0,0 +1,78 @@
+<?php
+
+class data_tasks extends PHPUnit_Framework_TestCase
+{
+ function data_prio()
+ {
+ return array(
+ array(0, null),
+ array(1, 2),
+ array(2, 2),
+ array(3, 2),
+ array(4, 2),
+ array(5, 1),
+ array(6, 0),
+ array(7, 0),
+ array(8, 0),
+ array(9, 0),
+ // invalid input
+ array(10, null),
+ );
+ }
+
+ function data_importance()
+ {
+ return array(
+ array(0, 9),
+ array(1, 5),
+ array(2, 1),
+ // invalid input
+ array(null, null),
+ array(5, null),
+ );
+ }
+
+ /**
+ * Test for kolab_sync_data_tasks::prio_to_importance()
+ * @dataProvider data_prio()
+ */
+ function test_prio_to_importance($input, $output)
+ {
+ $data = new kolab_sync_data_tasks_test;
+ $result = $data->prio_to_importance($input);
+
+ $this->assertEquals($output, $result);
+ }
+
+ /**
+ * Test for kolab_sync_data_tasks::importance_to_prio()
+ * @dataProvider data_importance()
+ */
+ function test_importance_to_prio($input, $output)
+ {
+ $data = new kolab_sync_data_tasks_test;
+ $result = $data->importance_to_prio($input);
+
+ $this->assertEquals($output, $result);
+ }
+}
+
+/**
+ * kolab_sync_data_tasks wrapper, so we can test preotected methods too
+ */
+class kolab_sync_data_tasks_test extends kolab_sync_data_tasks
+{
+ function __construct()
+ {
+ }
+
+ public function prio_to_importance($value)
+ {
+ return parent::prio_to_importance($value);
+ }
+
+ public function importance_to_prio($value)
+ {
+ return parent::importance_to_prio($value);
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index e49675a..701ccfe 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -5,6 +5,7 @@
<testsuite name="All Tests">
<file>body_converter.php</file>
<file>data.php</file>
+ <file>data_tasks.php</file>
<file>message.php</file>
</testsuite>
</testsuites>
More information about the commits
mailing list