Skip to content

Commit

Permalink
Revert "Add auto_reset option"
Browse files Browse the repository at this point in the history
This reverts commit c3f464f.
  • Loading branch information
hlecorche committed Jul 22, 2023
1 parent c3f464f commit 3d0d5aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
12 changes: 4 additions & 8 deletions src/Crud/CrudResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(protected ContainerInterface $container)

public function getResponse(Crud $crud, array $options = []): Response
{
$options = $this->getOptions($options, true);
$options = $this->getOptions($options);
$data = $this->processCrud($crud, $options);

return $this->renderCrud($this->getTemplateName($options['template_generator'], 'index'), $data);
Expand All @@ -40,7 +40,7 @@ public function getAjaxResponse(Crud $crud, array $options = []): Response
{
$masterRequest = $this->container->get('request_stack')->getMainRequest();

$options = $this->getOptions($options, false);
$options = $this->getOptions($options);
$data = $this->processCrud($crud, $options);

$request = $this->container->get('request_stack')->getCurrentRequest();
Expand All @@ -64,7 +64,7 @@ public function getAjaxResponse(Crud $crud, array $options = []): Response

public function getCrudData(Crud $crud, array $options = []): array
{
$options = $this->getOptions($options, false);
$options = $this->getOptions($options);

return $this->processCrud($crud, $options);
}
Expand All @@ -87,9 +87,6 @@ protected function processCrud(Crud $crud, array $options): array

$request = $this->container->get('request_stack')->getCurrentRequest();

if ($options['auto_reset']) {
$crud->reset();
}
if ($request->query->has('search')) {
$crud->processSearchForm();
}
Expand All @@ -109,13 +106,12 @@ protected function processCrud(Crud $crud, array $options): array
return $data;
}

protected function getOptions(array $options, bool $autoResetDefaultValue): array
protected function getOptions(array $options): array
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
'before_build' => null,
'after_build' => null,
'auto_reset' => $autoResetDefaultValue,
]);
$resolver->setRequired([
'template_generator',
Expand Down
22 changes: 11 additions & 11 deletions tests/Functional/Controller/TestCrudControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ public function testChangePage(Client $client): Client
/**
* @depends testChangePage
*/
public function testSessionValuesAfterChangePageAndReload(Client $client): Client
public function testSessionValuesAfterChangePage(Client $client): Client
{
$client->request('GET', static::URL);

$this->assertSame([10, 3], $this->countRowsAndColumns($client->getCrawler()));
$this->assertSame([1, 2], $this->getPagination($client->getCrawler()));
$this->assertSame([1, 3], $this->countRowsAndColumns($client->getCrawler()));
$this->assertSame([2, 2], $this->getPagination($client->getCrawler()));
$this->assertSame(['last_name', Crud::DESC], $this->getSort($client->getCrawler()));
$this->assertSame('ClémentTine', $this->getFirstUsername($client->getCrawler()));
$this->assertSame('JudieCieux', $this->getFirstUsername($client->getCrawler()));
$this->checkBeforeAndAfterBuild($client->getCrawler());

return $client;
}

/**
* @depends testSessionValuesAfterChangePageAndReload
* @depends testSessionValuesAfterChangePage
*/
public function testSearch(Client $client): Client
{
Expand All @@ -200,21 +200,21 @@ public function testSearch(Client $client): Client
/**
* @depends testSearch
*/
public function testSessionValuesAfterSearchAndReload(Client $client): Client
public function testSessionValuesAfterSearch(Client $client): Client
{
$client->request('GET', static::URL);

$this->assertSame([10, 3], $this->countRowsAndColumns($client->getCrawler()));
$this->assertSame([1, 2], $this->getPagination($client->getCrawler()));
$this->assertSame([2, 3], $this->countRowsAndColumns($client->getCrawler()));
$this->assertSame([1, 1], $this->getPagination($client->getCrawler()));
$this->assertSame(['last_name', Crud::DESC], $this->getSort($client->getCrawler()));
$this->assertSame('ClémentTine', $this->getFirstUsername($client->getCrawler()));
$this->assertSame('HenriPoste', $this->getFirstUsername($client->getCrawler()));
$this->checkBeforeAndAfterBuild($client->getCrawler());

return $client;
}

/**
* @depends testSessionValuesAfterSearchAndReload
* @depends testSessionValuesAfterSearch
*/
public function testSearchWithoutFilter(Client $client): Client
{
Expand Down Expand Up @@ -409,7 +409,7 @@ public function testManualResetSort(Client $client): Client
}
$client->request('GET', $resetUrl);

$this->assertSame([5, 3], $this->countRowsAndColumns($client->getCrawler())); // Not reset display settings and search
$this->assertSame([2, 3], $this->countRowsAndColumns($client->getCrawler())); // Not reset display settings and search
$this->assertSame(['first_name', Crud::ASC], $this->getSort($client->getCrawler()));

return $client;
Expand Down

0 comments on commit 3d0d5aa

Please sign in to comment.