public function testHandle()
 {
     $args = $this->getMassActionArgs();
     $args->expects($this->any())->method('getData')->willReturn(['shoppingList' => 1]);
     $this->shoppingListItemHandler->expects($this->once())->method('getShoppingList')->willReturn($this->getEntity('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\ShoppingList', 1));
     $this->shoppingListItemHandler->expects($this->once())->method('createForShoppingList')->willReturn(2);
     $response = $this->handler->handle($args);
     $this->assertTrue($response->isSuccessful());
     $this->assertEquals(2, $response->getOptions()['count']);
     $this->assertEquals(self::MESSAGE, $response->getMessage());
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MassActionHandlerArgs $args)
 {
     $argsParser = new ArgsParser($args);
     $shoppingList = $this->shoppingListLineItemHandler->getShoppingList($argsParser->getShoppingListId());
     if (!$shoppingList) {
         return $this->generateResponse($args);
     }
     try {
         $addedCnt = $this->shoppingListLineItemHandler->createForShoppingList($shoppingList, $argsParser->getProductIds());
         return $this->generateResponse($args, $addedCnt, $shoppingList->getId());
     } catch (AccessDeniedException $e) {
         return $this->generateResponse($args);
     }
 }
 public function testIsAllowed()
 {
     $this->handler->expects($this->once())->method('isAllowed')->willReturn(true);
     $result = $this->processor->isAllowed();
     $this->assertInternalType('bool', $result);
     $this->assertTrue($result);
 }
 /**
  * @param array $productIds
  * @param array $productQuantities
  * @param array $expectedLineItems
  *
  * @dataProvider itemDataProvider
  */
 public function testCreateForShoppingList(array $productIds = [], array $productQuantities = [], array $expectedLineItems = [])
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|ShoppingList $shoppingList */
     $shoppingList = $this->getMock('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\ShoppingList');
     $shoppingList->expects($this->any())->method('getId')->willReturn(1);
     $accountUser = new AccountUser();
     $shoppingList->expects($this->any())->method('getAccountUser')->willReturn($accountUser);
     $this->securityFacade->expects($this->any())->method('hasLoggedUser')->willReturn(true);
     $this->securityFacade->expects($this->any())->method('isGranted')->willReturn(true);
     $this->manager->expects($this->once())->method('bulkAddLineItems')->with($this->callback(function (array $lineItems) use($expectedLineItems, $accountUser) {
         /** @var LineItem $lineItem */
         foreach ($lineItems as $key => $lineItem) {
             /** @var LineItem $expectedLineItem */
             $expectedLineItem = $expectedLineItems[$key];
             $this->assertEquals($expectedLineItem->getQuantity(), $lineItem->getQuantity());
             $this->assertEquals($accountUser, $lineItem->getAccountUser());
             $this->assertInstanceOf('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', $lineItem->getProduct());
             $this->assertInstanceOf('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', $lineItem->getUnit());
         }
         return true;
     }), $shoppingList, $this->isType('integer'));
     $this->handler->createForShoppingList($shoppingList, $productIds, $productQuantities);
 }
 /** {@inheritdoc} */
 public function isAllowed()
 {
     return $this->shoppingListLineItemHandler->isAllowed();
 }