/** * @param OrmResultAfter $event */ public function onResultAfter(OrmResultAfter $event) { if (!$this->paginationManager->isEnabled()) { return; } $dataGrid = $event->getDatagrid(); if (!$this->paginationManager->isDatagridApplicable($dataGrid)) { return; } // clear all data as long as we can't guarantee that storage data is valid $entityName = $this->getEntityName($dataGrid); $this->storage->clearData($entityName); }
/** * @param bool $expected * @param bool $isOrmDatasource * @param bool|null $entityPagination * @dataProvider isDatagridApplicableDataProvider */ public function testIsDatagridApplicable($expected, $isOrmDatasource, $entityPagination) { if ($isOrmDatasource) { $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock(); } else { $dataSource = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\DatasourceInterface'); } $config = ['options' => ['entity_pagination' => $entityPagination]]; $configObject = DatagridConfiguration::create($config); $dataGrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface'); $dataGrid->expects($this->any())->method('getDatasource')->will($this->returnValue($dataSource)); $dataGrid->expects($this->any())->method('getConfig')->will($this->returnValue($configObject)); $this->assertSame($expected, $this->entityPaginationManager->isDatagridApplicable($dataGrid)); }
/** * @return int */ protected function getEntitiesLimit() { return $this->paginationManager->getLimit(); }
/** * @param object $entity * @param string $resultType * @param string $scope * @return NavigationResult */ protected function getResult($entity, $resultType, $scope = EntityPaginationManager::VIEW_SCOPE) { $result = new NavigationResult(); if ($this->storage->isEnvironmentValid() && $this->storage->isEntityInStorage($entity, $scope)) { $entityName = ClassUtils::getClass($entity); if ($this->isIdentifierMatched($entity, $resultType, $scope)) { do { $identifier = $this->getProcessedIdentifier($entity, $resultType, $scope); if (!$identifier) { break; } $navigationEntity = $this->doctrineHelper->getEntity($entityName, $identifier); $permission = EntityPaginationManager::getPermission($scope); if (!$navigationEntity) { $this->storage->unsetIdentifier($identifier, $entity, $scope); $result->setAvailable(false); } elseif (!$this->securityFacade->isGranted($permission, $navigationEntity)) { $this->storage->unsetIdentifier($identifier, $entity, $scope); $result->setAccessible(false); } } while (!$navigationEntity || !$this->securityFacade->isGranted($permission, $navigationEntity)); $result->setId($identifier); } } return $result; }
/** * @param bool $isApplicable * @param array $state * @param string $scope * @param array $entityIds * @param int $entitiesLimit * @return \PHPUnit_Framework_MockObject_MockObject */ protected function buildDataGrid($isApplicable = false, array $state = [], $scope = EntityPaginationManager::VIEW_SCOPE, array $entityIds = [], $entitiesLimit = 0) { $metadata = ['state' => $state]; $metadataObject = MetadataObject::create($metadata); $permission = EntityPaginationManager::getPermission($scope); $identifierField = 'id'; $this->paginationManager->expects($this->any())->method('isDatagridApplicable')->will($this->returnValue($isApplicable)); $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $queryBuilder->expects($this->any())->method('getRootEntities')->will($this->returnValue([self::ENTITY_NAME])); $queryBuilder->expects($this->any())->method('setFirstResult')->with(0); $queryBuilder->expects($this->any())->method('setMaxResults')->with($entitiesLimit); $entities = []; foreach ($entityIds as $id) { $entities[] = [$identifierField => $id]; } $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['execute'])->getMockForAbstractClass(); $query->expects($this->any())->method('execute')->will($this->returnValue($entities)); $this->aclHelper->expects($this->any())->method('apply')->with($queryBuilder, $permission)->will($this->returnValue($query)); $this->doctrineHelper->expects($this->any())->method('getEntityMetadata')->with(self::ENTITY_NAME)->will($this->returnValue(new ClassMetadata(self::ENTITY_NAME))); $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifierFieldName')->with(self::ENTITY_NAME)->will($this->returnValue($identifierField)); $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock(); $dataSource->expects($this->any())->method('getQueryBuilder')->will($this->returnValue($queryBuilder)); $acceptor = $this->getMock('Oro\\Bundle\\DataGridBundle\\Extension\\Acceptor'); if ($isApplicable) { $acceptor->expects($this->once())->method('acceptDatasource')->with($dataSource); } $dataGrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface'); $dataGrid->expects($this->any())->method('getMetadata')->will($this->returnValue($metadataObject)); $dataGrid->expects($this->any())->method('getAcceptor')->will($this->returnValue($acceptor)); $dataGrid->expects($this->any())->method('getDatasource')->will($this->returnValue($dataSource)); $this->pager->expects($this->any())->method('setQueryBuilder')->with($queryBuilder); $this->pager->expects($this->any())->method('setAclPermission')->with($permission); $this->pager->expects($this->any())->method('computeNbResult')->will($this->returnValue(count($entityIds))); $this->datagridManager->expects($this->once())->method('getDatagridByRequestParams')->with(self::GRID_NAME)->will($this->returnValue($dataGrid)); return $dataGrid; }