/**
  * @param string $entityClass
  * @param int $entityId
  * @param array $filter
  *
  * @return QueryBuilder
  */
 protected function prepareQB($entityClass, $entityId, $filter)
 {
     $qb = $this->getBaseQB($entityClass, $entityId);
     $this->activityInheritanceTargetsHelper->applyInheritanceActivity($qb, $entityClass, $entityId);
     if ($this->config->get('oro_activity_list.grouping')) {
         $qb->andWhere($qb->expr()->andX('activity.head = true'));
     }
     $this->activityListFilterHelper->addFiltersToQuery($qb, $filter);
     $this->activityListAclHelper->applyAclCriteria($qb, $this->chainProvider->getProviders());
     return $qb;
 }
 /**
  * @param array $activity
  * @param int $qbCalls
  * @param int $hasModelCalls
  * @param int $hasModelCalls
  *
  * @dataProvider getInheritanceDataProvider
  */
 public function testApplyInheritanceActivity($activity, $qbCalls, $hasModelCalls, $getConfigCalls)
 {
     $config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->exactly($getConfigCalls))->method('getValues')->willReturn($activity);
     $this->configManager->expects($this->exactly($hasModelCalls))->method('hasConfigEntityModel')->with('test')->willReturn(true);
     $this->configManager->expects($this->exactly($getConfigCalls))->method('getEntityConfig')->with('activity', 'test')->willReturn($config);
     $expr = new Expr();
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->any())->method('getExpressionBuilder')->willReturn($expr);
     $qb = new QueryBuilder($em);
     $qb->select('test')->from('test', 'ttt');
     $em->expects($this->exactly($qbCalls))->method('createQueryBuilder')->willReturn($qb);
     $this->registry->expects($this->exactly($qbCalls))->method('getManagerForClass')->willReturn($em);
     $this->activityInheritanceTargetsHelper->applyInheritanceActivity($qb, 'test', 1);
 }