aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBennet Becker <bbecker@pks.mpg.de>2022-12-23 12:46:15 +0100
committerBennet Becker <dev@bennet.cc>2022-12-23 19:26:49 +0100
commitc1c6d215c74a8246183510b7a4e94aa07e5b82d4 (patch)
tree7fc25a1c31d848e9aef6e66b13c7ab2404833309
parent7a9f4fbbbeb413d96bf71e953886c1b6b5639bca (diff)
downloadnextcloud-server-c1c6d215c74a8246183510b7a4e94aa07e5b82d4.tar.gz
nextcloud-server-c1c6d215c74a8246183510b7a4e94aa07e5b82d4.zip
fix getAutoSubmitted return type and adding unit tests
Signed-off-by: Bennet Becker <bbecker@pks.mpg.de>
-rw-r--r--lib/private/Mail/Message.php2
-rw-r--r--tests/lib/Mail/MessageTest.php142
2 files changed, 143 insertions, 1 deletions
diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php
index c383c1b1795..d074befcae4 100644
--- a/lib/private/Mail/Message.php
+++ b/lib/private/Mail/Message.php
@@ -328,7 +328,7 @@ class Message implements IMessage {
*
* @return string
*/
- public function getAutoSubmitted(): AutoSubmittedValue {
+ public function getAutoSubmitted(): string {
$headers = $this->swiftMessage->getHeaders();
return $headers->has('Auto-Submitted') ?
diff --git a/tests/lib/Mail/MessageTest.php b/tests/lib/Mail/MessageTest.php
index bec70d1c78a..aae25497876 100644
--- a/tests/lib/Mail/MessageTest.php
+++ b/tests/lib/Mail/MessageTest.php
@@ -8,7 +8,9 @@
namespace Test\Mail;
+use Egulias\EmailValidator\EmailValidator;
use OC\Mail\Message;
+use OCP\Mail\AutoSubmittedValue;
use OCP\Mail\IEMailTemplate;
use Swift_Message;
use Test\TestCase;
@@ -263,4 +265,144 @@ class MessageTest extends TestCase {
$message->useTemplate($template);
}
+
+ public function testSetAutoSubmitted1() {
+
+ $swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $swiftMessage = $this->getMockBuilder('\Swift_Message')
+ ->disableOriginalConstructor()
+ ->disableOriginalClone()
+ ->disableArgumentCloning()
+ ->disallowMockingUnknownTypes()
+ ->getMock();
+
+
+ $swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('has')
+ ->with('Auto-Submitted');
+
+ $swiftMimeSimpleHeaderSet->expects($this->never())
+ ->method('get');
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('addTextHeader')
+ ->with('Auto-Submitted', AutoSubmittedValue::AUTO_GENERATED);
+
+ $message = new Message($swiftMessage, false);
+
+ $message->setAutoSubmitted(AutoSubmittedValue::AUTO_GENERATED);
+
+ }
+
+ public function testSetAutoSubmitted2() {
+
+ $swiftMimeHeader = $this->getMockBuilder('\Swift_Mime_Header')
+ ->disableOriginalConstructor()
+ ->addMethods(['setValue'])
+ ->getMockForAbstractClass();
+
+ $swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $swiftMessage = $this->getMockBuilder('\Swift_Message')
+ ->disableOriginalConstructor()
+ ->disableOriginalClone()
+ ->disableArgumentCloning()
+ ->disallowMockingUnknownTypes()
+ ->getMock();
+
+
+ $swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
+ $swiftMimeSimpleHeaderSet->method('get')->with("Auto-Submitted")->willReturn($swiftMimeHeader);
+
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('has')
+ ->with('Auto-Submitted')
+ ->willReturn(true);
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('get');
+
+ $swiftMimeSimpleHeaderSet->expects($this->never())
+ ->method('addTextHeader')
+ ->with('Auto-Submitted', AutoSubmittedValue::AUTO_GENERATED);
+
+ $swiftMimeHeader->expects($this->once())
+ ->method('setValue')
+ ->with(AutoSubmittedValue::AUTO_GENERATED);
+
+ $message = new Message($swiftMessage, false);
+
+ $message->setAutoSubmitted(AutoSubmittedValue::AUTO_GENERATED);
+ }
+
+ public function testGetAutoSubmitted1() {
+
+ $swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $swiftMessage = $this->getMockBuilder('\Swift_Message')
+ ->disableOriginalConstructor()
+ ->disableOriginalClone()
+ ->disableArgumentCloning()
+ ->disallowMockingUnknownTypes()
+ ->getMock();
+
+
+ $swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('has')
+ ->with('Auto-Submitted');
+
+ $swiftMimeSimpleHeaderSet->expects($this->never())
+ ->method('get');
+
+ $message = new Message($swiftMessage, false);
+
+ $this->assertSame("no", $message->getAutoSubmitted());
+ }
+ public function testGetAutoSubmitted2() {
+
+ $swiftMimeHeader = $this->getMockBuilder('\Swift_Mime_Header')
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $swiftMimeSimpleHeaderSet = $this->getMockBuilder('\Swift_Mime_SimpleHeaderSet')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $swiftMessage = $this->getMockBuilder('\Swift_Message')
+ ->disableOriginalConstructor()
+ ->disableOriginalClone()
+ ->disableArgumentCloning()
+ ->disallowMockingUnknownTypes()
+ ->getMock();
+
+
+ $swiftMessage->method('getHeaders')->willReturn($swiftMimeSimpleHeaderSet);
+ $swiftMimeHeader->method('toString')->willReturn(AutoSubmittedValue::AUTO_GENERATED);
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('has')
+ ->with('Auto-Submitted')
+ ->willReturn(true);
+
+ $swiftMimeSimpleHeaderSet->expects($this->once())
+ ->method('get')
+ ->willReturn($swiftMimeHeader);
+
+ $message = new Message($swiftMessage, false);
+
+ $this->assertSame(AutoSubmittedValue::AUTO_GENERATED, $message->getAutoSubmitted());
+
+ }
}