[limb-svn] r6856 - in 3.x/trunk/limb/mail: . src tests tests/cases
svn at limb-project.com
svn at limb-project.com
Tue Mar 25 15:58:32 MSK 2008
Author: korchasa
Date: 2008-03-25 15:58:31 +0300 (Tue, 25 Mar 2008)
New Revision: 6856
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6856
Added:
3.x/trunk/limb/mail/tests/
3.x/trunk/limb/mail/tests/cases/
3.x/trunk/limb/mail/tests/cases/.setup.php
3.x/trunk/limb/mail/tests/cases/lmbMailerTest.class.php
Modified:
3.x/trunk/limb/mail/src/lmbMailer.class.php
Log:
-- added support of configuration by array
Modified: 3.x/trunk/limb/mail/src/lmbMailer.class.php
===================================================================
--- 3.x/trunk/limb/mail/src/lmbMailer.class.php 2008-03-25 11:38:58 UTC (rev 6855)
+++ 3.x/trunk/limb/mail/src/lmbMailer.class.php 2008-03-25 12:58:31 UTC (rev 6856)
@@ -24,25 +24,64 @@
{
protected $attachments = array();
+ protected $_config_properties_map = array(
+ 'phpmailer_dir' => 'PHPMAILER_DIR',
+ 'use_phpmail' => 'LIMB_USE_PHPMAIL',
+ 'smtp_host' => 'LIMB_SMTP_HOST',
+ 'smtp_port' => 'LIMB_SMTP_PORT',
+ 'smtp_auth' => 'LIMB_SMTP_AUTH',
+ 'smtp_user' => 'LIMB_SMTP_USER',
+ 'smtp_password' => 'LIMB_SMTP_PASSWORD'
+ );
+
+ public $phpmailer_dir;
+ public $use_phpmail;
+ public $smtp_host;
+ public $smtp_port;
+ public $smtp_auth;
+ public $smtp_user;
+ public $smtp_password;
+
+ function __construct($config = false)
+ {
+ $this->_setConfigFromDefinedContants();
+
+ if($config)
+ $this->setConfig($config);
+
+ }
+
+ protected function _setConfigFromDefinedContants()
+ {
+ foreach($this->_config_properties_map as $property_name => $define_name)
+ $this->$property_name = constant($define_name);
+ }
+
+ public function setConfig($config = array())
+ {
+ foreach($config as $property_name => $property_value)
+ $this->$property_name = $property_value;
+ }
+
protected function _createMailer()
{
- include_once(PHPMAILER_DIR . '/class.phpmailer.php');
+ include_once($this->phpmailer_dir . '/class.phpmailer.php');
$mailer = new PHPMailer();
$mailer->LE = "\r\n";
- if(LIMB_USE_PHPMAIL)
+ if($this->use_phpmail)
return $mailer;
$mailer->IsSMTP();
- $mailer->Host = LIMB_SMTP_HOST;
- $mailer->Port = LIMB_SMTP_PORT;
+ $mailer->Host = $this->smtp_host;
+ $mailer->Port = $this->smtp_port;
- if(LIMB_SMTP_AUTH == true)
+ if($this->smtp_auth == true)
{
$mailer->SMTPAuth = true;
- $mailer->Username = LIMB_SMTP_USER;
- $mailer->Password = LIMB_SMTP_PASSWORD;
+ $mailer->Username = $this->smtp_user;
+ $mailer->Password = $this->smtp_password;
}
return $mailer;
}
@@ -151,5 +190,3 @@
$attachment['type']);
}
}
-
-
Added: 3.x/trunk/limb/mail/tests/cases/.setup.php
===================================================================
--- 3.x/trunk/limb/mail/tests/cases/.setup.php (rev 0)
+++ 3.x/trunk/limb/mail/tests/cases/.setup.php 2008-03-25 12:58:31 UTC (rev 6856)
@@ -0,0 +1,8 @@
+<?php
+if(!defined('LIMB_VAR_DIR'))
+{
+ @define('LIMB_VAR_DIR', dirname(__FILE__) . '/../../../var');
+ if(!is_dir(LIMB_VAR_DIR) && !mkdir(LIMB_VAR_DIR))
+ throw new Exception("Could not create LIMB_VAR_DIR at '" . LIMB_VAR_DIR . "' during tests execution");
+}
+
Added: 3.x/trunk/limb/mail/tests/cases/lmbMailerTest.class.php
===================================================================
--- 3.x/trunk/limb/mail/tests/cases/lmbMailerTest.class.php (rev 0)
+++ 3.x/trunk/limb/mail/tests/cases/lmbMailerTest.class.php 2008-03-25 12:58:31 UTC (rev 6856)
@@ -0,0 +1,42 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class lmbMailerTest extends UnitTestCase {
+
+ function testConfiguration()
+ {
+ define('LIMB_SMTP_HOST', 'foo');
+
+ define('LIMB_SMTP_PORT', 'bar');
+ $config = array('smtp_port' => 'baz');
+
+ require_once(dirname(__FILE__).'/../../src/lmbMailer.class.php');
+
+ $mailer = new lmbMailer($config);
+ $this->assertEqual($mailer->smtp_host, 'foo');
+ $this->assertEqual($mailer->smtp_port, 'baz');
+ }
+
+ function testManualConfiguration()
+ {
+ require_once(dirname(__FILE__).'/../../src/lmbMailer.class.php');
+
+ $mailer = new lmbMailer();
+
+ $mailer->smtp_host = 'foo';
+
+ $config = array('smtp_port' => 'baz');
+ $mailer->setConfig($config);
+
+ $this->assertEqual($mailer->smtp_host, 'foo');
+ $this->assertEqual($mailer->smtp_port, 'baz');
+ }
+
+}
+?>
More information about the limb-svn
mailing list