Skip to content

Commit

Permalink
bug #223 [Sorting] Allow for sorting on disabled, declared fields (to…
Browse files Browse the repository at this point in the history
… preserve bc) (lchrusciel)

This PR was merged into the 1.10 branch.

Discussion
----------



Commits
-------

15dd9c1 [Sorting] Allow for sorting on disabled, declared fields (to preserve bc)
  • Loading branch information
Zales0123 authored Mar 15, 2022
2 parents 52df113 + 15dd9c1 commit f567be2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/Bundle/Tests/Functional/SortingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public function it_returns_correct_amount_of_sorted_authors_by_book_title_with_u
self::assertCount(10, $this->getItemsFromCurrentResponse());
}

/** @test */
public function it_allows_for_sorting_by_disabled_field(): void
{
$this->client->request('GET', '/authors/?sorting[id]=asc');

self::assertCount(10, $this->getItemsFromCurrentResponse());
}

private function getItemsFromCurrentResponse(): array
{
return json_decode($this->client->getResponse()->getContent(), true)['_embedded']['items'];
Expand Down
Binary file modified src/Bundle/test/config/db.sql
Binary file not shown.
5 changes: 5 additions & 0 deletions src/Bundle/test/config/sylius/grids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ sylius_grid:
sorting:
name: asc
fields:
id:
type: string
label: ID
sortable: ~
enabled: false
name:
type: string
label: Name
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Sorting/Sorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(?SortingParametersValidatorInterface $sortingValidat

public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters): void
{
$enabledFields = $grid->getEnabledFields();
$enabledFields = $grid->getFields();

$expressionBuilder = $dataSource->getExpressionBuilder();

Expand Down
4 changes: 2 additions & 2 deletions src/Component/spec/Sorting/SorterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function it_sorts_the_data_source_via_expression_builder_based_on_the_grid_defin
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder);

$grid->getSorting()->willReturn(['name' => 'desc']);
$grid->getEnabledFields()->willReturn(['name'=> $field, 'code' => $anotherField]);
$grid->getFields()->willReturn(['name'=> $field, 'code' => $anotherField]);

$sortingValidator->validateSortingParameters(['name' => 'desc'], ['name' => $field , 'code' => $anotherField])->shouldBeCalled();
$fieldValidator->validateFieldName('name', ['name' => $field , 'code' => $anotherField])->shouldBeCalled();
Expand Down Expand Up @@ -78,7 +78,7 @@ function it_sorts_the_data_source_via_expression_builder_based_on_sorting_parame
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder);

$grid->getSorting()->willReturn(['code' => 'asc']);
$grid->getEnabledFields()->willReturn(['name' => $field , 'code' => $anotherField]);
$grid->getFields()->willReturn(['name' => $field , 'code' => $anotherField]);

$sortingValidator->validateSortingParameters(['name' => 'asc'], ['name' => $field , 'code' => $anotherField])->shouldBeCalled();
$fieldValidator->validateFieldName('name', ['name' => $field , 'code' => $anotherField])->shouldBeCalled();
Expand Down

0 comments on commit f567be2

Please sign in to comment.