/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
- <?php
- /**
- * @package Joomla.UnitTest
- * @subpackage Mail
- *
- * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
- /**
- * Test class for JMail.
- * Generated by PHPUnit on 2011-10-26 at 19:32:59.
- *
- * @package Joomla.UnitTest
- * @subpackage Mail
- * @since 11.1
- */
- class JMailTest extends TestCase
- {
- /**
- * @var JMail
- */
- protected $object;
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- *
- * @return void
- */
- protected function setUp()
- {
- parent::setUp();
- $this->object = new JMail;
- }
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- *
- * @return void
- */
- protected function tearDown()
- {
- }
- /**
- * Test...
- *
- * @todo Implement testGetInstance().
- *
- * @return void
- */
- public function testGetInstance()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSend().
- *
- * @return void
- */
- public function testSend()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSetSender().
- *
- * @return void
- */
- public function testSetSender()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSetSubject().
- *
- * @return void
- */
- public function testSetSubject()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSetBody().
- *
- * @return void
- */
- public function testSetBody()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Provides test data for request format detection.
- *
- * @return array
- */
- public function seedTestAdd()
- {
- // Recipient, name, method
- return array(
- array('test@example.com', 'test_name', 'AddAddress', array(array('test@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddAddress',
- array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddAddress',
- array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
- array('test@example.com', 'test_name', 'AddCC', array(array('test@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddCC',
- array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddCC',
- array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
- array('test@example.com', 'test_name', 'AddBCC', array(array('test@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddBCC',
- array(array('test_1@example.com', 'test_name'), array('test_2@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddBCC',
- array(array('test_1@example.com', 'test_name1'), array('test_2@example.com', 'test_name2'))),
- array('test@example.com', 'test_name', 'AddReplyTo',
- array('test@example.com' => array('test@example.com', 'test_name'))),
- array(array('test_1@example.com', 'test_2@example.com'), 'test_name', 'AddReplyTo',
- array(
- 'test_1@example.com' => array('test_1@example.com', 'test_name'),
- 'test_2@example.com' => array('test_2@example.com', 'test_name')
- )
- ),
- array(array('test_1@example.com', 'test_2@example.com'), array('test_name1', 'test_name2'), 'AddReplyTo',
- array(
- 'test_1@example.com' => array('test_1@example.com', 'test_name1'),
- 'test_2@example.com' => array('test_2@example.com', 'test_name2')
- )
- )
- );
- }
- /**
- * Tests the add method
- *
- * @param mixed $recipient Either a string or array of strings [email address(es)]
- * @param mixed $name Either a string or array of strings [name(s)]
- * @param string $method The parent method's name.
- * @param array $expected The expected array.
- *
- * @covers JMail::add
- * @dataProvider seedTestAdd
- *
- * @return void
- */
- public function testAdd($recipient, $name, $method, $expected)
- {
- TestReflection::invoke($this->object, 'add', $recipient, $name, $method);
- switch ($method)
- {
- case 'AddAddress':
- $type = 'to';
- break;
- case 'AddCC':
- $type = 'cc';
- break;
- case 'AddBCC':
- $type = 'bcc';
- break;
- case 'AddReplyTo':
- $type = 'ReplyTo';
- break;
- }
- $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, $type)));
- }
- /**
- * Tests the addRecipient method.
- *
- * @covers JMail::addRecipient
- *
- * @return void
- */
- public function testAddRecipient()
- {
- $recipient = 'test@example.com';
- $name = 'test_name';
- $expected = array(array('test@example.com', 'test_name'));
- $this->object->addRecipient($recipient, $name);
- $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'to')));
- }
- /**
- * Tests the addCC method.
- *
- * @covers JMail::addCC
- *
- * @return void
- */
- public function testAddCC()
- {
- $recipient = 'test@example.com';
- $name = 'test_name';
- $expected = array(array('test@example.com', 'test_name'));
- $this->object->addCC($recipient, $name);
- $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'cc')));
- }
- /**
- * Tests the addBCC method.
- *
- * @covers JMail::addBCC
- *
- * @return void
- */
- public function testAddBCC()
- {
- $recipient = 'test@example.com';
- $name = 'test_name';
- $expected = array(array('test@example.com', 'test_name'));
- $this->object->addBCC($recipient, $name);
- $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'bcc')));
- }
- /**
- * Test...
- *
- * @todo Implement testAddAttachment().
- *
- * @return void
- */
- public function testAddAttachment()
- {
- $attachments = array(JPATH_PLATFORM . '/joomla/mail/mail.php');
- $names = array('mail.php');
- $mail = new JMail;
- $mail->addAttachment($attachments, $names);
- $actual = $mail->GetAttachments();
- $actual_attachments = array();
- $actual_names = array();
- foreach ($actual as $attach)
- {
- array_push($actual_attachments, $attach[0]);
- array_push($actual_names, $attach[2]);
- }
- $this->assertThat($attachments, $this->equalTo($actual_attachments));
- $this->assertThat($names, $this->equalTo($actual_names));
- }
- /**
- * Tests the addReplyTo method.
- *
- * @covers JMail::addReplyTo
- *
- * @return void
- */
- public function testAddReplyTo()
- {
- $recipient = 'test@example.com';
- $name = 'test_name';
- $expected = array('test@example.com' => array('test@example.com', 'test_name'));
- $this->object->addReplyTo($recipient, $name);
- $this->assertThat($expected, $this->equalTo(TestReflection::getValue($this->object, 'ReplyTo')));
- }
- /**
- * Tests the IsHTML method.
- *
- * @covers JMail::IsHTML
- *
- * @return void
- */
- public function testIsHTML()
- {
- $this->object->isHtml(false);
- $this->assertThat('text/plain', $this->equalTo($this->object->ContentType));
- }
- /**
- * Test...
- *
- * @todo Implement testUseSendmail().
- *
- * @return void
- */
- public function testUseSendmail()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test data for testUseSMTP method
- *
- * @return array
- *
- * @since 12.1
- */
- public function dataUseSMTP()
- {
- return array(
- 'SMTP without Authentication' => array(
- null,
- 'example.com',
- null,
- null,
- false,
- null,
- array(
- 'called' => 'IsSMTP',
- 'return' => true
- )
- )
- );
- }
- /**
- * Test for the JMail::useSMTP method.
- *
- * @param string $auth SMTP Authentication
- * @param string $host SMTP Host
- * @param string $user SMTP Username
- * @param string $pass SMTP Password
- * @param string $secure Use secure methods
- * @param integer $port The SMTP port
- * @param string $expected The expected result
- *
- * @return void
- *
- * @since 12.1
- *
- * @dataProvider dataUseSMTP
- */
- public function testUseSMTP($auth, $host, $user, $pass, $secure, $port, $expected)
- {
- $mail = $this->getMock('JMail', array('SetLanguage', 'IsSMTP', 'IsMail'));
- $mail->expects(
- $this->once()
- )
- ->method($expected['called']);
- $this->assertThat(
- $mail->useSMTP($auth, $host, $user, $pass, $secure, $port),
- $this->equalTo($expected['return'])
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSendMail().
- *
- * @return void
- */
- public function testSendMail()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- /**
- * Test...
- *
- * @todo Implement testSendAdminMail().
- *
- * @return void
- */
- public function testSendAdminMail()
- {
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete(
- 'This test has not been implemented yet.'
- );
- }
- }