From: Michael M Slusarz Date: Wed, 30 Jun 2010 22:35:55 +0000 (-0600) Subject: Make quota test work again X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d67f346b2333b41b3dcea0ea21c7a3f81632ce5c;p=horde.git Make quota test work again Inject all needed dependencies into IMP_Quota drivers to accomplish this. --- diff --git a/imp/lib/Injector/Binder/Quota.php b/imp/lib/Injector/Binder/Quota.php index b2ba81c5b..5dd321381 100644 --- a/imp/lib/Injector/Binder/Quota.php +++ b/imp/lib/Injector/Binder/Quota.php @@ -30,6 +30,19 @@ class IMP_Injector_Binder_Quota implements Horde_Injector_Binder $params['password'] = $secret->read($secret->getKey('imp'), $params['password']); } + switch (Horde_String::lower($driver)) { + case 'imap': + $params['imap_ob'] = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb(); + $params['mbox'] = $GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) + ? 'INBOX' + : IMP::$mailbox; + break; + + case 'maildir': + $params['username'] = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getParam('username'); + break; + } + return IMP_Quota::factory($driver, $params); } diff --git a/imp/lib/Quota/Imap.php b/imp/lib/Quota/Imap.php index 8e0ad2a71..de52e90ae 100644 --- a/imp/lib/Quota/Imap.php +++ b/imp/lib/Quota/Imap.php @@ -15,6 +15,28 @@ class IMP_Quota_Imap extends IMP_Quota_Driver { /** + * Constructor. + * + * @param array $params Parameters: + *
+     * 'imap_ob' - (Horde_Imap_Client_Base) IMAP client object.
+     * 'mbox' - (string) IMAP mailbox to query.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(array $params = array()) + { + foreach (array('imap_ob', 'mbox') as $val) { + if (!isset($params[$val])) { + throw new InvalidArgumentException('Missing ' . $val . ' parameter'); + } + } + + parent::__construct($params); + } + + /** * Get quota information (used/allocated), in bytes. * * @return array An array with the following keys: @@ -25,7 +47,7 @@ class IMP_Quota_Imap extends IMP_Quota_Driver public function getQuota() { try { - $quota = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getQuotaRoot($GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) ? 'INBOX' : IMP::$mailbox); + $quota = $this->_params['imap_ob']->getQuotaRoot($this->_params['mbox']); } catch (Horde_Imap_Client_Exception $e) { throw new IMP_Exception(_("Unable to retrieve quota")); } diff --git a/imp/lib/Quota/Maildir.php b/imp/lib/Quota/Maildir.php index c841607f9..03aa4ec5e 100644 --- a/imp/lib/Quota/Maildir.php +++ b/imp/lib/Quota/Maildir.php @@ -28,12 +28,16 @@ class IMP_Quota_Maildir extends IMP_Quota_Driver * account name, and the actual username will be substituted in * that location. * E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/' + * DEFAULT: '' + * 'username' - (string) Username to substitute into the string. + * DEFAULT: none * */ public function __construct($params = array()) { parent::__construct(array_merge(array( - 'path' => '' + 'path' => '', + 'username' => '' ), $params)); } @@ -53,7 +57,7 @@ class IMP_Quota_Maildir extends IMP_Quota_Driver $full = $this->_params['path'] . '/maildirsize'; // Substitute the username in the string if needed. - $full = str_replace('~U', $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getParam('username'), $full); + $full = str_replace('~U', $this->_params['username'], $full); // Read in the quota file and parse it, if possible. if (!is_file($full)) { diff --git a/imp/lib/tests/quota_maildir.phpt b/imp/lib/tests/quota_maildir.phpt index 83c1586b8..ff0932ad2 100644 --- a/imp/lib/tests/quota_maildir.phpt +++ b/imp/lib/tests/quota_maildir.phpt @@ -3,15 +3,21 @@ IMP_Quota_maildir test. --FILE-- dirname(__FILE__) . '/fixtures')); +require_once dirname(__FILE__) . '/../Application.php'; +Horde_Registry::appInit('imp', array( + 'authentication' => 'none', + 'cli' => true +)); + +$quota = IMP_Quota::factory('Maildir', array( + 'path' => dirname(__FILE__) . '/fixtures' +)); + var_export($quota->getQuota()); ?> --EXPECT-- array ( - 'usage' => 550839239, 'limit' => 1000000000, + 'usage' => 550839239, )