Skip to content

Commit

Permalink
change based on comments #3580
Browse files Browse the repository at this point in the history
  • Loading branch information
numew committed Jan 21, 2025
1 parent 079bc4a commit 2eeec1e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Entity\Enum\OccupantLink;
use App\Entity\Enum\QualificationStatus;
use App\Entity\File;
use App\Entity\Suivi;
use App\Service\Files\ImageBase64Encoder;
use App\Service\Notification\NotificationCounter;
use App\Service\Signalement\Qualification\QualificationStatusService;
Expand Down Expand Up @@ -154,6 +155,7 @@ public function getFunctions(): array
new TwigFunction('show_email_alert', [$this, 'showEmailAlert']),
new TwigFunction('user_avatar_or_placeholder', [UserAvatar::class, 'userAvatarOrPlaceholder'], ['is_safe' => ['html']]),
new TwigFunction('singular_or_plural', [$this, 'displaySingularOrPlural']),
new TwigFunction('transform_suivi_description', [$this, 'transformSuiviDescription']),
];
}

Expand Down Expand Up @@ -182,4 +184,14 @@ public function displaySingularOrPlural(?int $count, string $strIfSingular, stri

return $count.' '.$strIfSingular;
}

public function transformSuiviDescription(Suivi $suivi): string
{
$content = $suivi->getDescription();
$content = str_replace('&t=___TOKEN___', '/'.$suivi->getSignalement()->getUuid(), $content);
$content = str_replace('?t=___TOKEN___', '/'.$suivi->getSignalement()->getUuid(), $content);
$content = str_replace('?folder=_up', '/'.$suivi->getSignalement()->getUuid().'?variant=resize', $content);

return $content;
}
}
32 changes: 25 additions & 7 deletions tests/Functional/Manager/SuiviManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SuiviManagerTest extends KernelTestCase
private UrlGeneratorInterface $urlGenerator;
private DesordreCritereRepository $desordreCritereRepository;
private HtmlSanitizerInterface $htmlSanitizerInterface;
private SuiviManager $suiviManager;

protected function setUp(): void
{
Expand All @@ -35,12 +36,8 @@ protected function setUp(): void
$this->security = static::getContainer()->get(Security::class);
$this->urlGenerator = static::getContainer()->get(UrlGeneratorInterface::class);
$this->desordreCritereRepository = static::getContainer()->get(DesordreCritereRepository::class);
$this->htmlSanitizerInterface = static::getContainer()->get(HtmlSanitizerInterface::class);
}

public function testCreateSuivi(): void
{
$suiviManager = new SuiviManager(
$this->htmlSanitizerInterface = self::getContainer()->get('html_sanitizer.sanitizer.app.message_sanitizer');
$this->suiviManager = new SuiviManager(
$this->managerRegistry,
$this->urlGenerator,
$this->signalementUpdatedListener,
Expand All @@ -49,7 +46,10 @@ public function testCreateSuivi(): void
$this->htmlSanitizerInterface,
Suivi::class,
);
}

public function testCreateSuivi(): void
{
/** @var Signalement $signalement */
$signalement = $this->managerRegistry->getRepository(Signalement::class)->findOneBy(
['reference' => self::REF_SIGNALEMENT]
Expand All @@ -65,7 +65,7 @@ public function testCreateSuivi(): void
'motif_cloture' => MotifCloture::tryFrom('NON_DECENCE'),
'subject' => 'test',
];
$suivi = $suiviManager->createSuivi(
$suivi = $this->suiviManager->createSuivi(
user : $user,
signalement : $signalement,
description : SuiviManager::buildDescriptionClotureSignalement($params),
Expand All @@ -84,4 +84,22 @@ public function testCreateSuivi(): void
$this->assertTrue($suivi->getIsSanitized());
$this->assertInstanceOf(UserInterface::class, $suivi->getCreatedBy());
}

public function testCreateSuiviWithImageBase64(): void
{
/** @var Signalement $signalement */
$signalement = $this->managerRegistry->getRepository(Signalement::class)->findOneBy(
['reference' => self::REF_SIGNALEMENT]
);

$desc = 'Salut ma poule <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=">';
$descSanitized = 'Salut ma poule ';

$suivi = $this->suiviManager->createSuivi(
signalement : $signalement,
description : $desc,
type : Suivi::TYPE_USAGER
);
$this->assertEquals($descSanitized, $suivi->getDescription());
}
}

0 comments on commit 2eeec1e

Please sign in to comment.