Skip to content

Commit

Permalink
Merge branch 'main' into develop #2534
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed May 7, 2024
2 parents 414732c + 637f0cf commit 4c6a342
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/Controller/BailleurController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ public function index(
private function sanitizeBailleurs(array $bailleurs, string $name): ArrayCollection
{
return (new ArrayCollection($bailleurs))
->filter(fn ($bailleurItem) => str_contains(
strtolower($this->sanitizeName($bailleurItem->getName())),
strtolower($name)))
/* @var Bailleur $bailleurItem */
->filter(function ($bailleurItem) use ($name) {
if (str_starts_with($bailleurItem->getName(), Bailleur::BAILLEUR_RADIE)) {
$terms = explode(' ', $name);

return str_contains(strtolower($this->sanitizeName($bailleurItem->getName())), $terms[0]);
}

return true;
})
->map(fn ($bailleurItem) => $bailleurItem->setName($this->sanitizeName($bailleurItem->getName())));
}

Expand Down
15 changes: 14 additions & 1 deletion tests/Functional/Controller/BailleurControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function testSearchBailleursSanitized(): void

$this->client->request('GET', $route);
$response = json_decode($this->client->getResponse()->getContent(), true);

foreach ($response as $item) {
$this->assertStringContainsString('ra', strtolower($item['name']));
$this->assertStringNotContainsString(Bailleur::BAILLEUR_RADIE, strtolower($item['name']));
Expand All @@ -70,4 +69,18 @@ public function testSearchBailleursRadies(): void
$this->assertStringContainsString(Bailleur::BAILLEUR_RADIE, $item['name']);
}
}

public function testSearchTermsSanitized(): void
{
$routeFirst = $this->router->generate('app_bailleur', ['name' => 'habitat 13', 'postcode' => 13002, 'sanitize' => true]);

$this->client->request('GET', $routeFirst);
$responseFirst = json_decode($this->client->getResponse()->getContent(), true);

$routeSecond = $this->router->generate('app_bailleur', ['name' => '13 habitat', 'postcode' => 13002, 'sanitize' => true]);
$this->client->request('GET', $routeSecond);
$responseSecond = json_decode($this->client->getResponse()->getContent(), true);

$this->assertEquals($responseFirst, $responseSecond);
}
}

0 comments on commit 4c6a342

Please sign in to comment.