]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/Mail/mock.php
971dae6a0e0da47a839c3318cf34dc1b18142755
[quix0rs-gnu-social.git] / extlib / Mail / mock.php
1 <?php
2 //
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group                                |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license,      |
9 // | that is bundled with this package in the file LICENSE, and is        |
10 // | available at through the world-wide-web at                           |
11 // | http://www.php.net/license/2_02.txt.                                 |
12 // | If you did not receive a copy of the PHP license and are unable to   |
13 // | obtain it through the world-wide-web, please send a note to          |
14 // | license@php.net so we can mail you a copy immediately.               |
15 // +----------------------------------------------------------------------+
16 // | Author: Chuck Hagenbuch <chuck@horde.org>                            |
17 // +----------------------------------------------------------------------+
18 //
19 // $Id: mock.php,v 1.1 2007/12/08 17:57:54 chagenbu Exp $
20 //
21
22 /**
23  * Mock implementation of the PEAR Mail:: interface for testing.
24  * @access public
25  * @package Mail
26  * @version $Revision: 1.1 $
27  */
28 class Mail_mock extends Mail {
29
30     /**
31      * Array of messages that have been sent with the mock.
32      *
33      * @var array
34      * @access public
35      */
36     var $sentMessages = array();
37
38     /**
39      * Callback before sending mail.
40      *
41      * @var callback
42      */
43     var $_preSendCallback;
44
45     /**
46      * Callback after sending mai.
47      *
48      * @var callback
49      */
50     var $_postSendCallback;
51
52     /**
53      * Constructor.
54      *
55      * Instantiates a new Mail_mock:: object based on the parameters
56      * passed in. It looks for the following parameters, both optional:
57      *     preSendCallback   Called before an email would be sent.
58      *     postSendCallback  Called after an email would have been sent.
59      *
60      * @param array Hash containing any parameters.
61      * @access public
62      */
63     function Mail_mock($params)
64     {
65         if (isset($params['preSendCallback']) &&
66             is_callable($params['preSendCallback'])) {
67             $this->_preSendCallback = $params['preSendCallback'];
68         }
69
70         if (isset($params['postSendCallback']) &&
71             is_callable($params['postSendCallback'])) {
72             $this->_postSendCallback = $params['postSendCallback'];
73         }
74     }
75
76     /**
77      * Implements Mail_mock::send() function. Silently discards all
78      * mail.
79      *
80      * @param mixed $recipients Either a comma-seperated list of recipients
81      *              (RFC822 compliant), or an array of recipients,
82      *              each RFC822 valid. This may contain recipients not
83      *              specified in the headers, for Bcc:, resending
84      *              messages, etc.
85      *
86      * @param array $headers The array of headers to send with the mail, in an
87      *              associative array, where the array key is the
88      *              header name (ie, 'Subject'), and the array value
89      *              is the header value (ie, 'test'). The header
90      *              produced from those values would be 'Subject:
91      *              test'.
92      *
93      * @param string $body The full text of the message body, including any
94      *               Mime parts, etc.
95      *
96      * @return mixed Returns true on success, or a PEAR_Error
97      *               containing a descriptive error message on
98      *               failure.
99      * @access public
100      */
101     function send($recipients, $headers, $body)
102     {
103         if ($this->_preSendCallback) {
104             call_user_func_array($this->_preSendCallback,
105                                  array(&$this, $recipients, $headers, $body));
106         }
107
108         $entry = array('recipients' => $recipients, 'headers' => $headers, 'body' => $body);
109         $this->sentMessages[] = $entry;
110
111         if ($this->_postSendCallback) {
112             call_user_func_array($this->_postSendCallback,
113                                  array(&$this, $recipients, $headers, $body));
114         }
115
116         return true;
117     }
118
119 }