コード例 #1
0
 /**
  * @param OrmDatasource $dataSource
  * @param string $scope
  * @return int
  */
 protected function getTotalCount(OrmDatasource $dataSource, $scope)
 {
     $permission = EntityPaginationManager::getPermission($scope);
     $pager = clone $this->pager;
     $pager->setQueryBuilder($dataSource->getQueryBuilder());
     $pager->setAclPermission($permission);
     return $pager->computeNbResult();
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 /**
  * @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;
 }
コード例 #4
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Scope "wrong_scope" is not available.
  */
 public function testGetPermissionException()
 {
     EntityPaginationManager::getPermission(self::WRONG_SCOPE);
 }