Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Controller/LdapDropdownController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __invoke(Request $request): Response
$this->checkFormAccessPolicies($question->getForm(), $request);

// Read others parameters
$search_text = $request->request->getString('');
$search_text = $request->request->getString('searchText', '');
$page = $request->request->getInt('page', 0);
$page_limit = $request->request->getInt('page_limit', 0);

Expand Down
58 changes: 58 additions & 0 deletions tests/Controller/LdapDropdownControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,64 @@ public function testInvalidConditonParameter(): void
]);
}

public function testSearchTextParameter(): void
{
// Arrange: create a valid form
$this->enableConfigurableItem(LdapQuestion::class);
$ldap = $this->setupAuthLdap();
$form = $this->createFormWithLdapQuestion($ldap);

// Act: execute route with searchText
$this->login('post-only');
$response = $this->renderRoute([
'condition' => $this->buildAndGetConditionUuid($form),
'page' => 1,
'page_limit' => 10,
'searchText' => 'pierre',
]);

// Assert: response should be successful
$this->assertEquals(200, $response->getStatusCode());

// Assert: response should be valid JSON
$content = $response->getContent();
$this->assertNotFalse($content);
$data = json_decode($content, true);
$this->assertIsArray($data);
$this->assertArrayHasKey('results', $data);
$this->assertArrayHasKey('count', $data);
$this->assertEquals([['id' => 'pierre', 'text' => 'pierre']], $data['results']);
}

public function testEmptySearchTextParameter(): void
{
// Arrange: create a valid form
$this->enableConfigurableItem(LdapQuestion::class);
$ldap = $this->setupAuthLdap();
$form = $this->createFormWithLdapQuestion($ldap);

// Act: execute route with empty searchText
$this->login('post-only');
$response = $this->renderRoute([
'condition' => $this->buildAndGetConditionUuid($form),
'page' => 1,
'page_limit' => 10,
'searchText' => '',
]);

// Assert: response should be successful
$this->assertEquals(200, $response->getStatusCode());

// Assert: response should be valid JSON
$content = $response->getContent();
$this->assertNotFalse($content);
$data = json_decode($content, true);
$this->assertIsArray($data);
$this->assertArrayHasKey('results', $data);
$this->assertArrayHasKey('count', $data);
$this->assertCount(10, $data['results']);
}

private function renderRoute(array $post): Response
{
$controller = new LdapDropdownController();
Expand Down