Skip to content
Snippets Groups Projects
Commit e174df14 authored by Demian Katz's avatar Demian Katz
Browse files

Only simulate emailing during tests.

parent 7a50e09a
No related merge requests found
...@@ -407,6 +407,9 @@ port = 25 ...@@ -407,6 +407,9 @@ port = 25
; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol ; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol
; based on the configured port is chosen (587 -> tls, 487 -> ssl). ; based on the configured port is chosen (587 -> tls, 487 -> ssl).
;secure = tls ;secure = tls
; Uncomment this setting to disable outbound mail but simulate success; this
; is useful for interface testing but should never be used in production!
;testOnly = true
; If set to false, users can send anonymous emails; otherwise, they must log in first ; If set to false, users can send anonymous emails; otherwise, they must log in first
require_login = true require_login = true
; Should we put the logged-in user's address in the "from" field by default? ; Should we put the logged-in user's address in the "from" field by default?
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki * @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/ */
namespace VuFind\Mailer; namespace VuFind\Mailer;
use Zend\Mail\Transport\InMemory;
use Zend\Mail\Transport\Smtp, Zend\Mail\Transport\SmtpOptions; use Zend\Mail\Transport\Smtp, Zend\Mail\Transport\SmtpOptions;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
...@@ -43,16 +44,18 @@ use Zend\ServiceManager\ServiceLocatorInterface; ...@@ -43,16 +44,18 @@ use Zend\ServiceManager\ServiceLocatorInterface;
class Factory implements \Zend\ServiceManager\FactoryInterface class Factory implements \Zend\ServiceManager\FactoryInterface
{ {
/** /**
* Create service * Build the mail transport object.
* *
* @param ServiceLocatorInterface $sm Service manager * @param \Zend\Config\Config $config Configuration
* *
* @return mixed * @return InMemory|Smtp
*/ */
public function createService(ServiceLocatorInterface $sm) protected function getTransport($config)
{ {
// Load configurations: // In test mode? Return fake object:
$config = $sm->get('VuFind\Config')->get('config'); if (isset($config->Mail->testOnly) && $config->Mail->testOnly) {
return new InMemory();
}
// Create mail transport: // Create mail transport:
$settings = [ $settings = [
...@@ -76,10 +79,22 @@ class Factory implements \Zend\ServiceManager\FactoryInterface ...@@ -76,10 +79,22 @@ class Factory implements \Zend\ServiceManager\FactoryInterface
} }
} }
} }
$transport = new Smtp(); return new Smtp(new SmtpOptions($settings));
$transport->setOptions(new SmtpOptions($settings)); }
/**
* Create service
*
* @param ServiceLocatorInterface $sm Service manager
*
* @return mixed
*/
public function createService(ServiceLocatorInterface $sm)
{
// Load configurations:
$config = $sm->get('VuFind\Config')->get('config');
// Create service: // Create service:
return new \VuFind\Mailer\Mailer($transport); return new \VuFind\Mailer\Mailer($this->getTransport($config));
} }
} }
...@@ -242,7 +242,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase ...@@ -242,7 +242,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase
{ {
// Change the theme: // Change the theme:
$this->changeConfigs( $this->changeConfigs(
['config' => ['Site' => ['theme' => 'bootstrap3']]] [
'config' => [
'Site' => ['theme' => 'bootstrap3'],
'Mail' => ['testOnly' => 1],
]
]
); );
// Go to a record view // Go to a record view
...@@ -295,7 +300,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase ...@@ -295,7 +300,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase
{ {
// Change the theme: // Change the theme:
$this->changeConfigs( $this->changeConfigs(
['config' => ['Site' => ['theme' => 'bootstrap3']]] [
'config' => [
'Site' => ['theme' => 'bootstrap3'],
'Mail' => ['testOnly' => 1],
]
]
); );
// Go to a record view // Go to a record view
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment