message.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. use OC\Mail\Message;
  10. use Swift_Message;
  11. class MessageTest extends TestCase {
  12. /** @var Swift_Message */
  13. private $swiftMessage;
  14. /** @var Message */
  15. private $message;
  16. /**
  17. * @return array
  18. */
  19. public function mailAddressProvider() {
  20. return array(
  21. array(array('lukas@owncloud.com' => 'Lukas Reschke'), array('lukas@owncloud.com' => 'Lukas Reschke')),
  22. array(array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@öwnclöüd.com', 'lukäs@owncloud.örg' => 'Lükäs Réschke'),
  23. array('lukas@owncloud.com' => 'Lukas Reschke', 'lukas@xn--wncld-iuae2c.com', 'lukäs@owncloud.xn--rg-eka' => 'Lükäs Réschke')),
  24. array(array('lukas@öwnclöüd.com'), array('lukas@xn--wncld-iuae2c.com'))
  25. );
  26. }
  27. function setUp() {
  28. parent::setUp();
  29. $this->swiftMessage = $this->getMockBuilder('\Swift_Message')
  30. ->disableOriginalConstructor()->getMock();
  31. $this->message = new Message($this->swiftMessage);
  32. }
  33. /**
  34. * @dataProvider mailAddressProvider
  35. */
  36. public function testConvertAddresses($unconverted, $expected) {
  37. $this->assertSame($expected, \Test_Helper::invokePrivate($this->message, 'convertAddresses', array($unconverted)));
  38. }
  39. public function testSetFrom() {
  40. $this->swiftMessage
  41. ->expects($this->once())
  42. ->method('setFrom')
  43. ->with(array('lukas@owncloud.com'));
  44. $this->message->setFrom(array('lukas@owncloud.com'));
  45. }
  46. public function testGetFrom() {
  47. $this->swiftMessage
  48. ->expects($this->once())
  49. ->method('getFrom')
  50. ->will($this->returnValue(array('lukas@owncloud.com')));
  51. $this->assertSame(array('lukas@owncloud.com'), $this->message->getFrom());
  52. }
  53. public function testSetTo() {
  54. $this->swiftMessage
  55. ->expects($this->once())
  56. ->method('setTo')
  57. ->with(array('lukas@owncloud.com'));
  58. $this->message->setTo(array('lukas@owncloud.com'));
  59. }
  60. public function testGetTo() {
  61. $this->swiftMessage
  62. ->expects($this->once())
  63. ->method('getTo')
  64. ->will($this->returnValue(array('lukas@owncloud.com')));
  65. $this->assertSame(array('lukas@owncloud.com'), $this->message->getTo());
  66. }
  67. public function testSetCc() {
  68. $this->swiftMessage
  69. ->expects($this->once())
  70. ->method('setCc')
  71. ->with(array('lukas@owncloud.com'));
  72. $this->message->setCc(array('lukas@owncloud.com'));
  73. }
  74. public function testGetCc() {
  75. $this->swiftMessage
  76. ->expects($this->once())
  77. ->method('getCc')
  78. ->will($this->returnValue(array('lukas@owncloud.com')));
  79. $this->assertSame(array('lukas@owncloud.com'), $this->message->getCc());
  80. }
  81. public function testSetBcc() {
  82. $this->swiftMessage
  83. ->expects($this->once())
  84. ->method('setBcc')
  85. ->with(array('lukas@owncloud.com'));
  86. $this->message->setBcc(array('lukas@owncloud.com'));
  87. }
  88. public function testGetBcc() {
  89. $this->swiftMessage
  90. ->expects($this->once())
  91. ->method('getBcc')
  92. ->will($this->returnValue(array('lukas@owncloud.com')));
  93. $this->assertSame(array('lukas@owncloud.com'), $this->message->getBcc());
  94. }
  95. public function testSetSubject() {
  96. $this->swiftMessage
  97. ->expects($this->once())
  98. ->method('setSubject')
  99. ->with('Fancy Subject');
  100. $this->message->setSubject('Fancy Subject');
  101. }
  102. public function testGetSubject() {
  103. $this->swiftMessage
  104. ->expects($this->once())
  105. ->method('getSubject')
  106. ->will($this->returnValue('Fancy Subject'));
  107. $this->assertSame('Fancy Subject', $this->message->getSubject());
  108. }
  109. public function testSetPlainBody() {
  110. $this->swiftMessage
  111. ->expects($this->once())
  112. ->method('setBody')
  113. ->with('Fancy Body');
  114. $this->message->setPlainBody('Fancy Body');
  115. }
  116. public function testGetPlainBody() {
  117. $this->swiftMessage
  118. ->expects($this->once())
  119. ->method('getBody')
  120. ->will($this->returnValue('Fancy Body'));
  121. $this->assertSame('Fancy Body', $this->message->getPlainBody());
  122. }
  123. public function testSetHtmlBody() {
  124. $this->swiftMessage
  125. ->expects($this->once())
  126. ->method('addPart')
  127. ->with('<blink>Fancy Body</blink>', 'text/html');
  128. $this->message->setHtmlBody('<blink>Fancy Body</blink>');
  129. }
  130. }