Skip to content

Commit bbbfb09

Browse files
committed
ISSUE-345: message fixture
1 parent 915df7e commit bbbfb09

4 files changed

Lines changed: 150 additions & 11 deletions

File tree

config/repositories.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ services:
2929
PhpList\Core\Domain\Repository\Messaging\MessageRepository:
3030
parent: PhpList\Core\Domain\Repository
3131
arguments:
32-
- PPhpList\Core\Domain\Model\Messaging\Message
32+
- PhpList\Core\Domain\Model\Messaging\Message

src/Domain/Model/Messaging/Message/MessageFormat.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,36 @@ class MessageFormat
1616
private ?string $sendFormat = null;
1717

1818
#[ORM\Column(name: 'astext', type: 'integer', options: ['default' => 0])]
19-
private int $asText = 0;
19+
private int $asText;
2020

2121
#[ORM\Column(name: 'ashtml', type: 'integer', options: ['default' => 0])]
22-
private int $asHtml = 0;
23-
24-
#[ORM\Column(name: 'astextandhtml', type: 'integer', options: ['default' => 0])]
25-
private int $asTextAndHtml = 0;
22+
private int $asHtml;
2623

2724
#[ORM\Column(name: 'aspdf', type: 'integer', options: ['default' => 0])]
28-
private int $asPdf = 0;
25+
private int $asPdf;
2926

30-
#[ORM\Column(name: 'astextandpdf', type: 'integer', options: ['default' => 0])]
31-
private int $asTextAndPdf = 0;
27+
#[ORM\Column(name: 'astextandhtml', type: 'integer', options: ['default' => 0])]
28+
private int $asTextAndHtml;
3229

33-
public function __construct(bool $htmlFormatted, ?string $sendFormat = null)
34-
{
30+
#[ORM\Column(name: 'astextandpdf', type: 'integer', options: ['default' => 0])]
31+
private int $asTextAndPdf;
32+
33+
public function __construct(
34+
bool $htmlFormatted,
35+
string $sendFormat = null,
36+
int $asText = 0,
37+
int $asHtml = 0,
38+
int $asPdf = 0,
39+
int $asTextAndHtml = 0,
40+
int $asTextAndPdf = 0,
41+
) {
3542
$this->htmlFormatted = $htmlFormatted;
3643
$this->sendFormat = $sendFormat;
44+
$this->asText = $asText;
45+
$this->asHtml = $asHtml;
46+
$this->asPdf = $asPdf;
47+
$this->asTextAndHtml = $asTextAndHtml;
48+
$this->asTextAndPdf = $asTextAndPdf;
3749
}
3850

3951
public function isHtmlFormatted(): bool
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
id,uuid,subject,fromfield,tofield,replyto,message,textmessage,footer,entered,modified,embargo,repeatinterval,repeatuntil,requeueinterval,requeueuntil,status,userselection,sent,htmlformatted,sendformat,template,processed,astext,ashtml,astextandhtml,aspdf,astextandpdf,viewed,bouncecount,sendstart,rsstemplate,owner
2+
1,2df6b147-8470-45ed-8e4e-86aa01af400d,Do you want to continue receiving our messages?, My Name <my@email.com>,"","","<p>Hi [FIRST NAME%%there], remember us? You first signed up for our email newsletter on&nbsp;[ENTERED] &ndash; please click here to confirm you&#39;re happy to continue receiving our messages:</p>
3+
4+
<p><strong><a href=""[CONFIRMATIONURL]"" title=""Confirm subscription"">Continue receiving messages</a></strong>&nbsp; <u>(If you do not confirm using this link, then you won&#39;t hear from us again</u>)</p>
5+
6+
<p>While you&#39;re at it, you can also update your preferences, including your email address or other details, by clicking here:</p>
7+
8+
<p><strong><a href=""[PREFERENCESURL]"">Update preferences</a></strong></p>
9+
10+
<p>By confirming your membership and keeping your details up to date, you&#39;re helping us to manage and protect your data in accordance with best practices.</p>
11+
12+
<p>Thank you!</p>","","--
13+
14+
<div class=""footer"" style=""text-align:left; font-size: 75%;"">
15+
<p>This message was sent to [EMAIL] by [FROMEMAIL].</p>
16+
<p>To forward this message, please do not use the forward button of your email application, because this message was made specifically for you only. Instead use the <a href=""[FORWARDURL]"">forward page</a> in our newsletter system.<br/>
17+
To change your details and to choose which lists to be subscribed to, visit your personal <a href=""[PREFERENCESURL]"">preferences page</a>.<br/>
18+
Or you can <a href=""[UNSUBSCRIBEURL]"">opt-out completely</a> from all future mailings.</p>
19+
</div>
20+
21+
",2024-11-10 16:57:46,2024-11-14 08:32:15,2024-11-14 08:32:00,0,2024-11-14 08:32:00,0,2024-11-14 08:32:00,sent,,2024-11-14 08:32:15,1,invite,0,0,0,0,0,0,0,0,0,2024-11-14 08:32:15,,1
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Tests\Integration\Domain\Repository\Fixtures;
6+
7+
use DateTime;
8+
use Doctrine\Bundle\FixturesBundle\Fixture;
9+
use Doctrine\Persistence\ObjectManager;
10+
use PhpList\Core\Domain\Model\Identity\Administrator;
11+
use PhpList\Core\Domain\Model\Messaging\Message;
12+
use PhpList\Core\Domain\Model\Messaging\Message\MessageContent;
13+
use PhpList\Core\Domain\Model\Messaging\Message\MessageFormat;
14+
use PhpList\Core\Domain\Model\Messaging\Message\MessageMetadata;
15+
use PhpList\Core\Domain\Model\Messaging\Message\MessageOptions;
16+
use PhpList\Core\Domain\Model\Messaging\Message\MessageSchedule;
17+
use PhpList\Core\TestingSupport\Traits\ModelTestTrait;
18+
use RuntimeException;
19+
20+
class MessageFixture extends Fixture
21+
{
22+
use ModelTestTrait;
23+
24+
public function load(ObjectManager $manager): void
25+
{
26+
$csvFile = __DIR__ . '/Message.csv';
27+
28+
if (!file_exists($csvFile)) {
29+
throw new RuntimeException(sprintf('Fixture file "%s" not found.', $csvFile));
30+
}
31+
32+
$handle = fopen($csvFile, 'r');
33+
if ($handle === false) {
34+
throw new RuntimeException(sprintf('Could not open fixture file "%s".', $csvFile));
35+
}
36+
37+
$headers = fgetcsv($handle);
38+
$adminRepository = $manager->getRepository(Administrator::class);
39+
40+
do {
41+
$data = fgetcsv($handle);
42+
if ($data === false) {
43+
break;
44+
}
45+
$row = array_combine($headers, $data);
46+
$admin = $adminRepository->find($row['owner']);
47+
48+
$format = new MessageFormat(
49+
$row['htmlformatted'],
50+
$row['sendformat'],
51+
$row['astext'],
52+
$row['ashtml'],
53+
$row['aspdf'],
54+
$row['astextandhtml'],
55+
$row['astextandpdf']
56+
);
57+
58+
$schedule = new MessageSchedule(
59+
$row['repeatinterval'],
60+
$row['repeatuntil'],
61+
$row['requeueinterval'],
62+
$row['requeueuntil']
63+
);
64+
$metadata = new MessageMetadata(
65+
$row['status'],
66+
$row['processed'],
67+
$row['viewed'],
68+
$row['bouncecount'],
69+
$row['entered'],
70+
$row['sent']
71+
);
72+
$content = new MessageContent(
73+
$row['subject'],
74+
$row['message'],
75+
$row['textmessage'],
76+
$row['footer']
77+
);
78+
$options = new MessageOptions(
79+
$row['fromfield'],
80+
$row['tofield'],
81+
$row['replyto'],
82+
$row['embargo'],
83+
$row['userselection'],
84+
$row['template'],
85+
$row['sendstart'],
86+
$row['rsstemplate'],
87+
);
88+
89+
$message = new Message(
90+
$format,
91+
$schedule,
92+
$metadata,
93+
$content,
94+
$options,
95+
$admin,
96+
);
97+
$this->setSubjectId($message, (int)$row['id']);
98+
$this->setSubjectProperty($message, 'uuid', $row['uuid']);
99+
100+
$manager->persist($message);
101+
$this->setSubjectProperty($message, 'modificationDate', new DateTime($row['modified']));
102+
} while (true);
103+
104+
fclose($handle);
105+
}
106+
}

0 commit comments

Comments
 (0)