/**
  * @param bool $enabled
  * @param bool $request
  * @param string $entityName
  * @param string $hash
  * @param bool $expected
  *
  * @dataProvider hasDataDataProvider
  */
 public function testHasData($enabled, $request, $entityName, $hash, $expected)
 {
     $this->setEnabled($enabled);
     if (true === $request) {
         $this->setRequest();
     }
     $this->storage->setData(self::ENTITY_NAME, self::HASH, [], 'VIEW');
     $result = $this->storage->hasData($entityName, $hash, 'VIEW');
     $this->assertSame($expected, $result);
 }
 /**
  * @param Request $request
  * @param string $scope
  * @return bool
  */
 public function collect(Request $request, $scope)
 {
     if (!$this->paginationManager->isEnabled()) {
         return false;
     }
     $isDataCollected = false;
     $gridNames = array_keys($request->query->get('grid', []));
     foreach ($gridNames as $gridName) {
         // datagrid manager automatically extracts all required parameters from request
         $dataGrid = $this->datagridManager->getDatagridByRequestParams($gridName);
         if (!$this->paginationManager->isDatagridApplicable($dataGrid)) {
             continue;
         }
         $dataSource = $dataGrid->getDatasource();
         $dataGrid->getAcceptor()->acceptDatasource($dataSource);
         $entityName = $this->getEntityName($dataSource);
         $stateHash = $this->generateStateHash($dataGrid);
         // if entities are not in storage
         if (!$this->storage->hasData($entityName, $stateHash, $scope)) {
             $entitiesLimit = $this->getEntitiesLimit();
             $totalCount = $this->getTotalCount($dataSource, $scope);
             // if grid contains allowed number of entities
             if ($totalCount <= $entitiesLimit) {
                 // collect and set entity IDs
                 $entityIds = $this->getAllEntityIds($dataSource, $scope, $entitiesLimit);
                 $this->storage->setData($entityName, $stateHash, $entityIds, $scope);
             } else {
                 // set empty array as a sign that data is collected, but pagination itself must be disabled
                 $this->storage->setData($entityName, $stateHash, [], $scope);
             }
         }
         $isDataCollected = true;
     }
     return $isDataCollected;
 }