/tests/unit/suites/libraries/joomla/mail/JMailTest.php

https://github.com/dextercowley/joomla-cms · PHP · 414 lines · 198 code · 37 blank · 179 comment · 1 complexity · 9684ba86f18c4969d25ca7da5d54880f MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Mail
  5. *
  6. * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. /**
  10. * Test class for JMail.
  11. * Generated by PHPUnit on 2011-10-26 at 19:32:59.
  12. *
  13. * @package Joomla.UnitTest
  14. * @subpackage Mail
  15. * @since 11.1
  16. */
  17. class JMailTest extends TestCase
  18. {
  19. /**
  20. * @var JMail
  21. */
  22. protected $object;
  23. /**
  24. * Sets up the fixture, for example, opens a network connection.
  25. * This method is called before a test is executed.
  26. *
  27. * @return void
  28. */
  29. protected function setUp()
  30. {
  31. parent::setUp();
  32. $this->object = new JMail;
  33. }
  34. /**
  35. * Tears down the fixture, for example, closes a network connection.
  36. * This method is called after a test is executed.
  37. *
  38. * @return void
  39. */
  40. protected function tearDown()
  41. {
  42. }
  43. /**
  44. * Test...
  45. *
  46. * @todo Implement testGetInstance().
  47. *
  48. * @return void
  49. */
  50. public function testGetInstance()
  51. {
  52. // Remove the following lines when you implement this test.
  53. $this->markTestIncomplete(
  54. 'This test has not been implemented yet.'
  55. );
  56. }
  57. /**
  58. * Test...
  59. *
  60. * @todo Implement testSend().
  61. *
  62. * @return void
  63. */
  64. public function testSend()
  65. {
  66. // Remove the following lines when you implement this test.
  67. $this->markTestIncomplete(
  68. 'This test has not been implemented yet.'
  69. );
  70. }
  71. /**
  72. * Test...
  73. *
  74. * @todo Implement testSetSender().
  75. *
  76. * @return void
  77. */
  78. public function testSetSender()
  79. {
  80. // Remove the following lines when you implement this test.
  81. $this->markTestIncomplete(
  82. 'This test has not been implemented yet.'
  83. );
  84. }
  85. /**
  86. * Test...
  87. *
  88. * @todo Implement testSetSubject().
  89. *
  90. * @return void
  91. */
  92. public function testSetSubject()
  93. {
  94. // Remove the following lines when you implement this test.
  95. $this->markTestIncomplete(
  96. 'This test has not been implemented yet.'
  97. );
  98. }
  99. /**
  100. * Test...
  101. *
  102. * @todo Implement testSetBody().
  103. *
  104. * @return void
  105. */
  106. public function testSetBody()
  107. {
  108. // Remove the following lines when you implement this test.
  109. $this->markTestIncomplete(
  110. 'This test has not been implemented yet.'
  111. );
  112. }
  113. /**
  114. * Provides test data for request format detection.
  115. *
  116. * @return array
  117. */
  118. public function seedTestAdd()
  119. {
  120. // Recipient, name, method
  121. return array(
  122. array('test@example.com', 'test_name', 'AddAddress', array(array('test@example.com', 'test_name'))),
  123. array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddAddress',
  124. array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
  125. array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddAddress',
  126. array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
  127. array('test@example.com', 'test_name', 'AddCC', array(array('test@example.com', 'test_name'))),
  128. array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddCC',
  129. array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
  130. array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddCC',
  131. array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
  132. array('test@example.com', 'test_name', 'AddBCC', array(array('test@example.com', 'test_name'))),
  133. array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddBCC',
  134. array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
  135. array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddBCC',
  136. array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
  137. array('test@example.com', 'test_name', 'AddReplyTo',
  138. array('test@example.com' => array('test@example.com', 'test_name'))),
  139. array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddReplyTo',
  140. array(
  141. 'test_1@example.com' => array('test_1@example.com', 'test_name'),
  142. 'test_2@example.com' => array('test_2@example.com', 'test_name')
  143. )
  144. ),
  145. array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddReplyTo',
  146. array(
  147. 'test_1@example.com' => array('test_1@example.com', 'test_name1'),
  148. 'test_2@example.com' => array('test_2@example.com', 'test_name2')
  149. )
  150. )
  151. );
  152. }
  153. /**
  154. * Tests the add method
  155. *
  156. * @param mixed $recipient Either a string or array of strings [email address(es)]
  157. * @param mixed $name Either a string or array of strings [name(s)]
  158. * @param string $method The parent method's name.
  159. * @param array $expected The expected array.
  160. *
  161. * @covers JMail::add
  162. * @dataProvider seedTestAdd
  163. *
  164. * @return void
  165. */
  166. public function testAdd($recipient, $name, $method, $expected)
  167. {
  168. TestReflection::invoke($this->object, 'add', $recipient, $name, $method);
  169. switch ($method)
  170. {
  171. case 'AddAddress':
  172. $type = 'to';
  173. break;
  174. case 'AddCC':
  175. $type = 'cc';
  176. break;
  177. case 'AddBCC':
  178. $type = 'bcc';
  179. break;
  180. case 'AddReplyTo':
  181. $type = 'ReplyTo';
  182. break;
  183. }
  184. $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, $type)));
  185. }
  186. /**
  187. * Tests the addRecipient method.
  188. *
  189. * @covers JMail::addRecipient
  190. *
  191. * @return void
  192. */
  193. public function testAddRecipient()
  194. {
  195. $recipient = 'test@example.com';
  196. $name = 'test_name';
  197. $expected = array(array('test@example.com', 'test_name'));
  198. $this->object->addRecipient($recipient, $name);
  199. $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'to')));
  200. }
  201. /**
  202. * Tests the addCC method.
  203. *
  204. * @covers JMail::addCC
  205. *
  206. * @return void
  207. */
  208. public function testAddCC()
  209. {
  210. $recipient = 'test@example.com';
  211. $name = 'test_name';
  212. $expected = array(array('test@example.com', 'test_name'));
  213. $this->object->addCC($recipient, $name);
  214. $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'cc')));
  215. }
  216. /**
  217. * Tests the addBCC method.
  218. *
  219. * @covers JMail::addBCC
  220. *
  221. * @return void
  222. */
  223. public function testAddBCC()
  224. {
  225. $recipient = 'test@example.com';
  226. $name = 'test_name';
  227. $expected = array(array('test@example.com', 'test_name'));
  228. $this->object->addBCC($recipient, $name);
  229. $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'bcc')));
  230. }
  231. /**
  232. * Test...
  233. *
  234. * @todo Implement testAddAttachment().
  235. *
  236. * @return void
  237. */
  238. public function testAddAttachment()
  239. {
  240. $attachments = array(JPATH_PLATFORM . '/joomla/mail/mail.php');
  241. $names = array('mail.php');
  242. $mail = new JMail;
  243. $mail->addAttachment($attachments, $names);
  244. $actual = $mail->GetAttachments();
  245. $actual_attachments = array();
  246. $actual_names = array();
  247. foreach ($actual as $attach)
  248. {
  249. array_push($actual_attachments, $attach[0]);
  250. array_push($actual_names, $attach[2]);
  251. }
  252. $this->assertThat($attachments, $this->equalTo($actual_attachments));
  253. $this->assertThat($names, $this->equalTo($actual_names));
  254. }
  255. /**
  256. * Tests the addReplyTo method.
  257. *
  258. * @covers JMail::addReplyTo
  259. *
  260. * @return void
  261. */
  262. public function testAddReplyTo()
  263. {
  264. $recipient = 'test@example.com';
  265. $name = 'test_name';
  266. $expected = array('test@example.com' => array('test@example.com', 'test_name'));
  267. $this->object->addReplyTo($recipient, $name);
  268. $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'ReplyTo')));
  269. }
  270. /**
  271. * Tests the IsHTML method.
  272. *
  273. * @covers JMail::IsHTML
  274. *
  275. * @return void
  276. */
  277. public function testIsHTML()
  278. {
  279. $this->object->isHtml(false);
  280. $this->assertThat('text/plain', $this->equalTo($this->object->ContentType));
  281. }
  282. /**
  283. * Test...
  284. *
  285. * @todo Implement testUseSendmail().
  286. *
  287. * @return void
  288. */
  289. public function testUseSendmail()
  290. {
  291. // Remove the following lines when you implement this test.
  292. $this->markTestIncomplete(
  293. 'This test has not been implemented yet.'
  294. );
  295. }
  296. /**
  297. * Test data for testUseSMTP method
  298. *
  299. * @return array
  300. *
  301. * @since 12.1
  302. */
  303. public function dataUseSMTP()
  304. {
  305. return array(
  306. 'SMTP without Authentication' => array(
  307. null,
  308. 'example.com',
  309. null,
  310. null,
  311. false,
  312. null,
  313. array(
  314. 'called' => 'IsSMTP',
  315. 'return' => true
  316. )
  317. )
  318. );
  319. }
  320. /**
  321. * Test for the JMail::useSMTP method.
  322. *
  323. * @param string $auth SMTP Authentication
  324. * @param string $host SMTP Host
  325. * @param string $user SMTP Username
  326. * @param string $pass SMTP Password
  327. * @param string $secure Use secure methods
  328. * @param integer $port The SMTP port
  329. * @param string $expected The expected result
  330. *
  331. * @return void
  332. *
  333. * @since 12.1
  334. *
  335. * @dataProvider dataUseSMTP
  336. */
  337. public function testUseSMTP($auth, $host, $user, $pass, $secure, $port, $expected)
  338. {
  339. $mail = $this->getMock('JMail', array('SetLanguage', 'IsSMTP', 'IsMail'));
  340. $mail->expects(
  341. $this->once()
  342. )
  343. ->method($expected['called']);
  344. $this->assertThat(
  345. $mail->useSMTP($auth, $host, $user, $pass, $secure, $port),
  346. $this->equalTo($expected['return'])
  347. );
  348. }
  349. /**
  350. * Test...
  351. *
  352. * @todo Implement testSendMail().
  353. *
  354. * @return void
  355. */
  356. public function testSendMail()
  357. {
  358. // Remove the following lines when you implement this test.
  359. $this->markTestIncomplete(
  360. 'This test has not been implemented yet.'
  361. );
  362. }
  363. /**
  364. * Test...
  365. *
  366. * @todo Implement testSendAdminMail().
  367. *
  368. * @return void
  369. */
  370. public function testSendAdminMail()
  371. {
  372. // Remove the following lines when you implement this test.
  373. $this->markTestIncomplete(
  374. 'This test has not been implemented yet.'
  375. );
  376. }
  377. }