function it_throws_exception_when_trying_to_sort_by_a_non_sortable_field(Grid $gridDefinition) { $gridDefinition->hasField('code')->willReturn(true); $gridDefinition->hasField('name')->willReturn(true); $gridDefinition->getSorting()->willReturn(['code' => ['path' => 'code', 'direction' => 'asc']]); $gridDefinition->isSortableBy('name')->willThrow(\InvalidArgumentException::class); $this->shouldThrow(\InvalidArgumentException::class)->during('isSortedBy', ['name']); $this->shouldThrow(\InvalidArgumentException::class)->during('getSortingOrder', ['name']); }
function it_sorts_the_data_source_via_expression_builder_based_on_sorting_parameter(Grid $grid, Field $nameField, DataSourceInterface $dataSource, ExpressionBuilderInterface $expressionBuilder) { $parameters = new Parameters(['sorting' => ['name' => 'asc']]); $dataSource->getExpressionBuilder()->willReturn($expressionBuilder); $grid->getSorting()->willReturn(['code' => 'desc']); $grid->hasField('name')->willReturn(true); $grid->getField('name')->willReturn($nameField); $nameField->isSortable()->willReturn(true); $nameField->getSortable()->willReturn('translation.name'); $expressionBuilder->addOrderBy('translation.name', 'asc')->shouldBeCalled(); $this->sort($dataSource, $grid, $parameters); }
/** * @param string $fieldName * * @throws \InvalidArgumentException */ private function assertFieldExists($fieldName) { Assert::true($this->definition->hasField($fieldName), sprintf('Field "%s" does not exist.', $fieldName)); }
/** * @param string $fieldName * * @throws \InvalidArgumentException */ private function assertFieldIsSortable($fieldName) { Assert::true($this->definition->hasField($fieldName), sprintf('Field "%s" does not exist.', $fieldName)); Assert::true($this->definition->getField($fieldName)->isSortable(), sprintf('Field "%s" is not sortable.', $fieldName)); }
/** * @param string $fieldName * * @throws \InvalidArgumentException */ private function assertFieldExists($fieldName) { if (!$this->definition->hasField($fieldName)) { throw new \InvalidArgumentException(sprintf('Field "%s" does not exist.', $fieldName)); } }
function it_throws_exception_when_checking_sorting_of_non_existent_field(Grid $gridDefinition) { $gridDefinition->hasField('code')->willReturn(false); $this->shouldThrow(new \InvalidArgumentException('Field "code" does not exist.'))->during('isSortedby', ['code']); $this->shouldThrow(new \InvalidArgumentException('Field "code" does not exist.'))->during('getSortingOrder', ['code']); }