[BUGFIX] Fix the unit tests to work with PHPUnit 3.6
[Packages/TYPO3.CMS.git] / tests / t3lib / utility / t3lib_utility_mailTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the t3lib_utility_Mail class.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 *
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class t3lib_utility_mailTest extends tx_phpunit_testcase {
34 /**
35 * backed-up TYPO3_CONF_VARS SC_OPTIONS
36 *
37 * @var array
38 */
39 private $scOptionsBackup = array();
40
41 /**
42 * backed-up T3_VAR callUserFunction
43 *
44 * @var array
45 */
46 private $callUserFunctionBackup = array();
47
48 public function setUp() {
49 $this->scOptionsBackup = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'];
50 $this->callUserFunctionBackup = $GLOBALS['T3_VAR']['callUserFunction'];
51 }
52
53 public function tearDown() {
54 t3lib_div::purgeInstances();
55 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'] = $this->scOptionsBackup;
56 $GLOBALS['T3_VAR']['callUserFunction'] = $this->callUserFunctionBackup;
57 }
58
59
60 //////////////////////////
61 // Tests concerning mail
62 //////////////////////////
63
64 /**
65 * @test
66 */
67 public function mailCallsHook() {
68 $to = 'john@example.com';
69 $subject = 'Good news everybody!';
70 $messageBody = 'The hooks works!';
71 $additionalHeaders = 'Reply-to: jane@example.com';
72 $additionalParameters = '-f postmaster@example.com';
73
74 $mockMailer = $this->getMock('mockMailer', array('mail'));
75 $mockMailer->expects($this->once())->method('mail')
76 ->with(
77 array(
78 'to' => $to,
79 'subject' => $subject,
80 'messageBody' => $messageBody,
81 'additionalHeaders' => $additionalHeaders,
82 'additionalParameters' => $additionalParameters,
83 ),
84 FALSE
85 );
86 $GLOBALS['T3_VAR']['callUserFunction']['mockMailer->mail']
87 = array('obj' => $mockMailer, 'method' => 'mail');
88
89 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']
90 ['t3lib/utility/class.t3lib_utility_mail.php']
91 ['substituteMailDelivery'] = array('mockMailer->mail');
92
93 t3lib_utility_Mail::mail(
94 $to, $subject, $messageBody, $additionalHeaders,
95 $additionalParameters
96 );
97 }
98 }
99 ?>