Skip to content

Commit 5226204

Browse files
committed
test(mailbox): refact Mailbox test
1 parent d4516b0 commit 5226204

File tree

6 files changed

+546
-319
lines changed

6 files changed

+546
-319
lines changed

modules/core/hm-mailbox.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public function __construct($server_id, $user_config, $session, $config) {
4646
}
4747
}
4848

49+
/**
50+
* Set connection
51+
* @param object $connection The connection object to inject
52+
*/
53+
public function set_connection($connection) {
54+
$this->connection = $connection;
55+
}
56+
4957
public function connect() {
5058
if (! $this->connection) {
5159
return false;
@@ -563,6 +571,14 @@ public function search($folder, $target='ALL', $terms=array(), $sort=null, $reve
563571
if (! $this->select_folder($folder)) {
564572
return [];
565573
}
574+
575+
// Handle JMAP specifically since it's "IMAP-like" but has different method signatures
576+
if ($this->type === self::TYPE_JMAP) {
577+
// JMAP search uses IMAP-like parameters but handles sorting internally
578+
$uids = $this->connection->search($target, false, $terms, [], $exclude_deleted, $exclude_auto_bcc, $only_auto_bcc);
579+
return $uids;
580+
}
581+
566582
if ($this->is_imap()) {
567583
if ($sort) {
568584
if ($this->connection->is_supported('SORT')) {

modules/imap/hm-imap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Hm_IMAP extends Hm_IMAP_Cache {
178178
);
179179

180180
/* holds the current IMAP connection state */
181-
private $state = 'disconnected';
181+
public $state = 'disconnected';
182182

183183
/* used for message part content streaming */
184184
private $stream_size = 0;

modules/imap/hm-jmap.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,4 +1359,35 @@ private function get_raw_message_content($blob_id, $name) {
13591359
$this->api->format = 'json';
13601360
return $res;
13611361
}
1362+
1363+
/**
1364+
* Check if a feature is supported (JMAP compatibility method)
1365+
* JMAP doesn't use IMAP extensions, so most features are handled differently
1366+
*/
1367+
public function is_supported($feature) {
1368+
// TODO: Implement more features as needed, but most IMAP features don't have direct JMAP equivalents
1369+
return false;
1370+
}
1371+
1372+
/**
1373+
* Get message sort order (JMAP compatibility method)
1374+
* This provides IMAP-like interface for JMAP sorting
1375+
* JMAP doesn't have direct equivalent to IMAP SORT
1376+
* Fall back to search and let JMAP handle sorting internally
1377+
*/
1378+
public function get_message_sort_order($sort, $reverse=false, $target='ALL', $terms=array(), $exclude_deleted=true, $exclude_auto_bcc=true, $only_auto_bcc=false) {
1379+
return $this->search($target, false, $terms, [], $exclude_deleted, $exclude_auto_bcc, $only_auto_bcc);
1380+
}
1381+
1382+
/**
1383+
* Sort by fetch (JMAP compatibility method)
1384+
* JMAP doesn't need this since it handles sorting differently
1385+
*/
1386+
public function sort_by_fetch($sort, $reverse=false, $target='ALL', $uids='') {
1387+
// TODO: implement according to JMAP spec if needed
1388+
if (empty($uids)) {
1389+
return [];
1390+
}
1391+
return explode(',', $uids);
1392+
}
13621393
}

tests/phpunit/bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
/* get mock objects */
2828
require APP_PATH.'tests/phpunit/mocks.php';
2929

30+
31+
/* get the imap|jmap|ews|smtp classes */
32+
require_once APP_PATH.'modules/imap/hm-imap.php';
33+
require_once APP_PATH.'modules/imap/hm-jmap.php';
34+
require_once APP_PATH.'modules/imap/hm-ews.php';
35+
require_once APP_PATH.'modules/smtp/hm-smtp.php';
36+
require_once APP_PATH.'modules/core/hm-mailbox.php';
37+
3038
/* get the stubs */
3139
require APP_PATH.'tests/phpunit/stubs.php';
3240

0 commit comments

Comments
 (0)