|
5 | 5 | namespace PhpList\Core\Tests\Unit\Domain\Messaging\Service\Manager; |
6 | 6 |
|
7 | 7 | use DateTime; |
| 8 | +use InvalidArgumentException; |
8 | 9 | use PhpList\Core\Domain\Identity\Model\Administrator; |
| 10 | +use PhpList\Core\Domain\Messaging\Model\ListMessage; |
9 | 11 | use PhpList\Core\Domain\Messaging\Model\Dto\CreateMessageDto; |
10 | 12 | use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageContentDto; |
11 | 13 | use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageFormatDto; |
|
22 | 24 | use PhpList\Core\Domain\Messaging\Repository\MessageRepository; |
23 | 25 | use PhpList\Core\Domain\Messaging\Service\Builder\MessageBuilder; |
24 | 26 | use PhpList\Core\Domain\Messaging\Service\Manager\MessageManager; |
| 27 | +use PhpList\Core\Domain\Subscription\Model\SubscriberList; |
25 | 28 | use PHPUnit\Framework\TestCase; |
26 | 29 |
|
27 | 30 | class MessageManagerTest extends TestCase |
@@ -176,4 +179,63 @@ public function testUpdateMessageReturnsUpdatedMessage(): void |
176 | 179 | $this->assertSame('Updated Subject', $message->getContent()->getSubject()); |
177 | 180 | $this->assertSame(Message\MessageStatus::Draft, $message->getMetadata()->getStatus()); |
178 | 181 | } |
| 182 | + |
| 183 | + public function testUpdateStatusThrowsWhenSubmittedWithoutListMessage(): void |
| 184 | + { |
| 185 | + $messageRepository = $this->createMock(MessageRepository::class); |
| 186 | + $messageBuilder = $this->createMock(MessageBuilder::class); |
| 187 | + $manager = new MessageManager($messageRepository, $messageBuilder); |
| 188 | + |
| 189 | + $message = new Message( |
| 190 | + format: new MessageFormat(true, 'html'), |
| 191 | + schedule: new MessageSchedule( |
| 192 | + repeatInterval: 0, |
| 193 | + repeatUntil: null, |
| 194 | + requeueInterval: 0, |
| 195 | + requeueUntil: null, |
| 196 | + embargo: new DateTime('2025-04-17T09:00:00+00:00') |
| 197 | + ), |
| 198 | + metadata: new MessageMetadata(Message\MessageStatus::Draft), |
| 199 | + content: new MessageContent('Subject', 'Body text', 'Short text', 'Footer'), |
| 200 | + options: new MessageOptions('from@example.com', 'to@example.com', 'reply@example.com', 'all-users'), |
| 201 | + owner: null |
| 202 | + ); |
| 203 | + |
| 204 | + $this->expectException(InvalidArgumentException::class); |
| 205 | + $this->expectExceptionMessage('Cannot set status to submitted'); |
| 206 | + |
| 207 | + $manager->updateStatus($message, Message\MessageStatus::Submitted); |
| 208 | + } |
| 209 | + |
| 210 | + public function testUpdateStatusSetsSubmittedWhenRequiredFieldsAndListArePresent(): void |
| 211 | + { |
| 212 | + $messageRepository = $this->createMock(MessageRepository::class); |
| 213 | + $messageBuilder = $this->createMock(MessageBuilder::class); |
| 214 | + $manager = new MessageManager($messageRepository, $messageBuilder); |
| 215 | + |
| 216 | + $message = new Message( |
| 217 | + format: new MessageFormat(true, 'html'), |
| 218 | + schedule: new MessageSchedule( |
| 219 | + repeatInterval: 0, |
| 220 | + repeatUntil: null, |
| 221 | + requeueInterval: 0, |
| 222 | + requeueUntil: null, |
| 223 | + embargo: new DateTime('2025-04-17T09:00:00+00:00') |
| 224 | + ), |
| 225 | + metadata: new MessageMetadata(Message\MessageStatus::Draft), |
| 226 | + content: new MessageContent('Subject', 'Body text', 'Short text', 'Footer'), |
| 227 | + options: new MessageOptions('from@example.com', 'to@example.com', 'reply@example.com', 'all-users'), |
| 228 | + owner: null |
| 229 | + ); |
| 230 | + |
| 231 | + $listMessage = new ListMessage(); |
| 232 | + $listMessage->setMessage($message); |
| 233 | + $listMessage->setList($this->createMock(SubscriberList::class)); |
| 234 | + $message->getListMessages()->add($listMessage); |
| 235 | + |
| 236 | + $updated = $manager->updateStatus($message, Message\MessageStatus::Submitted); |
| 237 | + |
| 238 | + $this->assertSame($message, $updated); |
| 239 | + $this->assertSame(Message\MessageStatus::Submitted, $message->getMetadata()->getStatus()); |
| 240 | + } |
179 | 241 | } |
0 commit comments