Esempio n. 1
0
 public function testSaveActionWithException()
 {
     $this->formKeyValidatorMock->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
     $this->customerRepositoryMock->expects($this->any())->method('getById')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customerId', 'value' => 'value']))));
     $this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'customer/account/', []);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Something went wrong while saving your subscription.');
     $this->action->execute();
 }
Esempio n. 2
0
 /**
  * Initialize dependencies.
  *
  * @param \Magento\Framework\App\Action\Context $context
  * @param \Magento\Customer\Model\Session $customerSession
  * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param CustomerRepository $customerRepository
  * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
  */
 public function __construct(\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Store\Model\StoreManagerInterface $storeManager, CustomerRepository $customerRepository, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory)
 {
     $this->storeManager = $storeManager;
     $this->formKeyValidator = $formKeyValidator;
     $this->customerRepository = $customerRepository;
     $this->subscriberFactory = $subscriberFactory;
     parent::__construct($context, $customerSession);
 }