public function testGetFailedMessage() { $message = 'test message'; $this->router->expects($this->never())->method($this->anything()); $this->translator->expects($this->once())->method('trans')->willReturn($message); $this->assertEquals($message, $this->generator->getFailedMessage()); }
/** * @param Request $request * @param bool $isFailedMessage */ protected function assertFlashMessage(Request $request, $isFailedMessage = false) { $message = 'test message'; $this->messageGenerator->expects($this->once())->method($isFailedMessage ? 'getFailedMessage' : 'getSuccessMessage')->willReturn($message); $flashBag = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface'); $flashBag->expects($this->once())->method('add')->with($isFailedMessage ? 'error' : 'success', $message)->willReturn($flashBag); /** @var \PHPUnit_Framework_MockObject_MockObject|Session $session */ $session = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock(); $session->expects($this->once())->method('getFlashBag')->willReturn($flashBag); $request->setSession($session); }
/** {@inheritdoc} */ public function process(array $data, Request $request) { if (empty($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY]) || !is_array($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY])) { return; } $data = $data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY]; $shoppingListId = (int) $request->get(sprintf('%s[%s]', QuickAddType::NAME, QuickAddType::ADDITIONAL_FIELD_NAME), null, true); $shoppingList = $this->shoppingListLineItemHandler->getShoppingList($shoppingListId); $productSkus = ArrayUtils::arrayColumn($data, 'productSku'); $productIds = $this->getProductRepository()->getProductsIdsBySku($productSkus); $productSkuQuantities = array_combine($productSkus, ArrayUtils::arrayColumn($data, 'productQuantity')); $productIdsQuantities = array_combine($productIds, $productSkuQuantities); /** @var Session $session */ $session = $request->getSession(); $flashBag = $session->getFlashBag(); try { $entitiesCount = $this->shoppingListLineItemHandler->createForShoppingList($shoppingList, array_values($productIds), $productIdsQuantities); $flashBag->add('success', $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount)); } catch (AccessDeniedException $e) { $flashBag->add('error', $this->messageGenerator->getFailedMessage()); } }
/** * @param MassActionHandlerArgs $args * @param int $entitiesCount * @param int|null $shoppingListId * * @return MassActionResponse */ protected function generateResponse(MassActionHandlerArgs $args, $entitiesCount = 0, $shoppingListId = null) { $transChoiceKey = $args->getMassAction()->getOptions()->offsetGetByPath('[messages][success]', 'orob2b.shoppinglist.actions.add_success_message'); return new MassActionResponse($entitiesCount > 0, $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount, $transChoiceKey), ['count' => $entitiesCount]); }