Ejemplo n.º 1
0
 /**
  * @param string $fieldName
  *
  * @return bool
  */
 public function isSortedBy($fieldName)
 {
     $this->assertFieldExists($fieldName);
     Assert::true($this->definition->isSortableBy($fieldName), sprintf('Field "%s" is not sortable.', $fieldName));
     if ($this->parameters->has('sorting')) {
         return array_key_exists($fieldName, $this->parameters->get('sorting'));
     }
     $sortingDefinition = $this->getDefinition()->getSorting();
     $sortedFields = array_keys($sortingDefinition);
     return $fieldName === array_shift($sortedFields);
 }
Ejemplo n.º 2
0
 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']);
 }