/**
  * @param BuildBefore $event
  * @param string      $entityName
  *
  * @return bool
  */
 protected function isApplicable(BuildBefore $event, $entityName)
 {
     if (empty($entityName)) {
         return false;
     }
     try {
         $isEntity = $this->entityClassResolver->isEntity($entityName);
     } catch (\Exception $e) {
         $isEntity = false;
     }
     $existingConfig = $event->getConfig()->offsetGetByPath(sprintf(self::ACTION_CONFIGURATION_KEY, MassUpdateActionHandler::ACTION_NAME), false);
     return empty($existingConfig) && $isEntity && $this->actionHandler->isMassActionEnabled($entityName);
 }
 /**
  * @param string     $entityName
  * @param bool       $isEntity
  * @param bool       $isException
  * @param bool       $isAlreadyConfigured
  * @param bool       $isActionEnabled
  * @param array|null $expected
  *
  * @dataProvider onBuildBeforeProvider
  */
 public function testOnBuildBefore($entityName, $isEntity, $isException, $isAlreadyConfigured, $isActionEnabled, $expected = null)
 {
     $datagrid = $this->getDatagrid($entityName, $isAlreadyConfigured);
     // prepare mocks
     if ($isException) {
         $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->throwException(new \ReflectionException("Not valid class")));
     } else {
         $this->classResolverMock->expects($this->once())->method('isEntity')->with($entityName)->will($this->returnValue($isEntity));
         if ($isEntity && !$isAlreadyConfigured && $isActionEnabled) {
             $this->doctrineHelperMock->expects($this->once())->method('getSingleEntityIdentifierFieldName')->will($this->returnValue('id'));
         }
         $isEmptyAndEnabled = !$isAlreadyConfigured && $isEntity;
         $this->handlerMock->expects($isEmptyAndEnabled ? $this->once() : $this->never())->method('isMassActionEnabled')->with($entityName)->will($this->returnValue($isActionEnabled));
     }
     $event = new BuildBefore($datagrid, $datagrid->getConfig());
     $this->listener->onBuildBefore($event);
     $this->assertEquals($expected, $event->getConfig()->offsetGetByPath(sprintf(GridListener::ACTION_CONFIGURATION_KEY, MassUpdateActionHandler::ACTION_NAME)), 'Failed asserting that mass action config added by listener');
 }
 public function testHandleUpdateNotAllowed()
 {
     $massActionMock = $this->getMock(MassActionInterface::class);
     $datagridMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $iteratorMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\IterableResultInterface');
     $entityName = 'Test\\EntityName';
     $hasConfig = true;
     $isEnabled = true;
     $isGranted = false;
     $data = [];
     $this->actionRepoMock->expects($this->once())->method('getEntityName')->with($datagridMock)->will($this->returnValue($entityName));
     $this->configMock->expects($this->once())->method('hasConfig')->with($entityName)->will($this->returnValue($hasConfig));
     $this->configMock->expects($this->once())->method('getConfig')->with($entityName)->will($this->returnValue(new Config(new EntityConfigId('extend', $entityName), ['update_mass_action_enabled' => $isEnabled])));
     $this->securityMock->expects($this->once())->method('isGranted')->with('EDIT', 'entity:' . $entityName)->will($this->returnValue($isGranted));
     $this->actionRepoMock->expects($this->never())->method('batchUpdate');
     $this->transMock->expects($this->once())->method('trans')->will($this->returnValue(uniqid()));
     $options = ActionConfiguration::create(['success_message' => '', 'error_message' => '']);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     $this->transMock->expects($this->once())->method('trans')->with('', ['%error%' => 'Action not configured or not allowed']);
     $this->loggerMock->expects($this->once())->method('debug');
     $actionResponse = $this->handler->handle(new MassActionHandlerArgs($massActionMock, $datagridMock, $iteratorMock, $data));
     $this->assertFalse($actionResponse->isSuccessful());
 }