feat: copy the house managers of the selected houses on assignment mailings

This commit is contained in:
fromme committed 2026-11-12 12:45:53 +01:00
1 parent 2c51ddf86f
commit f22d1f1199
17 files changed
+293 -24

No files matched your search

@@ -18,6 +18,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
/**
@@ -254,6 +255,69 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->assertSame(['Anna Muster ([email protected])'], $this->colleaguesIn('[email protected]'));
}
/**
* Each house manager once per mailing, on the mail of the first recipient of their house -
* muted or not - and never one of another house or a blocked one.
*/
public function testHouseManagersAreInCcOnOneMailOfTheirHouse(): void
{
// codes of no real house: other tests leave house managers of real ones in db_test
$schwendi = $this->assignment('Schwendi', 'XQSWE');
$rotbach = $this->assignment('Rotbach', 'XQR');
$this->place($this->teamer('Anna'), $schwendi, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Cem'), $schwendi, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Dora'), $rotbach, Disposition::STATUS_CONFIRMED);
$this->houseManager('Greta', ['XQR']);
$this->houseManager('Hugo', ['XQS']);
$this->houseManager('Hanna', ['XQS'])->setMuteNotifications(true);
$this->houseManager('Paul', ['XQP']);
$this->houseManager('Dieter', ['XQS'])->setDisabledAt(new \DateTimeImmutable());
$this->login('ROLE_MANAGER');
$crawler = $this->startMailing($schwendi, $rotbach);
$this->assertStringContainsString(
'In Kopie (Hausleitung): Hugo Hausleitung, Hanna Hausleitung, Greta Hausleitung',
$crawler->filter('#mailing-assignments')->text()
);
$this->client->request('POST', self::COMPOSE_URL.'/send', [
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
]);
$this->assertEmailCount(3);
$this->assertSame(['[email protected]', '[email protected]'], $this->ccIn('[email protected]'));
$this->assertSame([], $this->ccIn('[email protected]'));
$this->assertSame(['[email protected]'], $this->ccIn('[email protected]'));
}
/**
* Placed on the travel as a teamer, or writing under the address of one, the house manager has
* the mail already.
*/
public function testAHouseManagerWhoIsARecipientIsNotInCc(): void
{
$assignment = $this->assignment('Schwendi', 'XQS');
$anna = $this->teamer('Anna');
$this->place($anna, $assignment, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Cem'), $assignment, Disposition::STATUS_CONFIRMED);
$this->houseManager('Hugo', ['XQS'])->setTeamer($anna);
$this->houseManager('Hanna', ['XQS'])->setEmail('[email protected]');
$this->login('ROLE_MANAGER');
$crawler = $this->startMailing($assignment);
$this->assertStringNotContainsString('In Kopie', $crawler->filter('#mailing-assignments')->text());
$this->client->request('POST', self::COMPOSE_URL.'/send', [
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
]);
$this->assertEmailCount(2);
$this->assertSame([], $this->ccIn('[email protected]'));
$this->assertSame([], $this->ccIn('[email protected]'));
}
public function testColleagueNamesAreEscaped(): void
{
$assignment = $this->assignment('Schwendi');
@@ -354,6 +418,22 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->fail(sprintf('No mail to %s', $to));
}
/**
* The CC addresses of the mail sent to the given address.
*
* @return string[]
*/
private function ccIn(string $to): array
{
foreach ($this->getMailerMessages() as $message) {
if ($message instanceof Email && $to === $message->getTo()[0]->getAddress()) {
return array_map(fn (Address $address) => $address->getAddress(), $message->getCc());
}
}
$this->fail(sprintf('No mail to %s', $to));
}
private function startMailing(Assignment ...$assignments): Crawler
{
$this->entityManager->flush();
@@ -399,12 +479,12 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->client->loginUser($user);
}
private function assignment(string $hotel): Assignment
private function assignment(string $hotel, string $hotelCode = 'DKI'): Assignment
{
$destination = (new Destination())
->setProduct('Davos Klosters')
->setHotel($hotel)
->setHotelCode('DKI')
->setHotelCode($hotelCode)
->setHotelBusProId(1)
->setCountry('CH')
->setDateFrom(new \DateTimeImmutable('+7 days'))
@@ -424,6 +504,25 @@ class AssignmentMailingControllerTest extends WebTestCase
return $assignment;
}
/**
* @param string[] $hotelCodes
*/
private function houseManager(string $firstName, array $hotelCodes): User
{
$user = (new User())
->setFirstName($firstName)
->setLastName('Hausleitung')
->setEmail(strtolower($firstName).'[email protected]')
->setRoles(['ROLE_HOUSE_MANAGER'])
->setHotelCodes($hotelCodes)
->setBusProAddressId(1)
->setBusProPersonId(1)
;
$this->entityManager->persist($user);
return $user;
}
private function teamer(string $firstName): Teamer
{
$teamer = (new Teamer())