Esempio n. 1
0
 public function testTryToSaveInvalidDataShouldFailWithErrors()
 {
     $validatorClass = 'Magento\\MediaStorage\\Model\\File\\Validator\\AvailablePath';
     $helperClass = 'Magento\\Sitemap\\Helper\\Data';
     $validPaths = [];
     $messages = ['message1', 'message2'];
     $sessionClass = 'Magento\\Backend\\Model\\Session';
     $data = ['sitemap_filename' => 'sitemap_filename', 'sitemap_path' => '/sitemap_path'];
     $siteMapId = 1;
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->requestMock->expects($this->once())->method('getParam')->with('sitemap_id')->willReturn($siteMapId);
     $validator = $this->getMock($validatorClass, [], [], '', false);
     $validator->expects($this->once())->method('setPaths')->with($validPaths)->willReturnSelf();
     $validator->expects($this->once())->method('isValid')->with('/sitemap_path/sitemap_filename')->willReturn(false);
     $validator->expects($this->once())->method('getMessages')->willReturn($messages);
     $helper = $this->getMock($helperClass, [], [], '', false);
     $helper->expects($this->once())->method('getValidPaths')->willReturn($validPaths);
     $session = $this->getMock($sessionClass, ['setFormData'], [], '', false);
     $session->expects($this->once())->method('setFormData')->with($data)->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with($validatorClass)->willReturn($validator);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([[$helperClass, $helper], [$sessionClass, $session]]);
     $this->messageManagerMock->expects($this->at(0))->method('addError')->withConsecutive([$messages[0]], [$messages[1]])->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('adminhtml/*/edit', ['sitemap_id' => $siteMapId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->saveController->execute());
 }
Esempio n. 2
0
 public function testLoadCustomerQuoteThrowingException()
 {
     $exception = new \Exception('Message');
     $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will($this->throwException($exception));
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Load customer quote error');
     $this->object->loadCustomerQuote();
 }
 public function testLoadCustomerQuoteThrowingException()
 {
     $exception = new \Exception('Message');
     $this->checkoutSession->expects($this->once())->method('loadCustomerQuote')->will($this->throwException($exception));
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Load customer quote error');
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->object->execute($observerMock);
 }
 public function testBeforeSaveFail()
 {
     $wrongValue = '/^mozillai';
     $this->regexp->setValue($wrongValue);
     $this->messageManager->expects($this->once())->method('addNotice')->with(__('Invalid regular expression: %value', ['value' => $wrongValue]));
     $this->regexp->beforeSave();
     $this->assertNull($this->regexp->getValue());
 }
Esempio n. 5
0
 public function testDeleteActionNoId()
 {
     $this->requestMock->expects($this->once())->method('getParam')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('We can\'t find a synonym group to delete.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
Esempio n. 6
0
 /**
  * @return void
  */
 public function testAfterLogin()
 {
     $warningMessage = __('All other open sessions for this account were terminated.');
     $this->sessionsManager->expects($this->once())->method('processLogin');
     $this->sessionsManager->expects($this->once())->method('getCurrentSession')->willReturn($this->currentSession);
     $this->currentSession->expects($this->once())->method('isOtherSessionsTerminated')->willReturn(true);
     $this->messageManager->expects($this->once())->method('addWarning')->with($warningMessage);
     $this->model->afterLogin($this->authMock);
 }
Esempio n. 7
0
 /**
  * @dataProvider testPostDataProvider
  */
 public function testExecutePostValidation($postData, $exceptionExpected)
 {
     $this->_request->expects($this->any())->method('getPost')->will($this->returnValue($postData));
     if ($exceptionExpected) {
         $this->_messageManager->expects($this->once())->method('addError');
     }
     $this->_inlineTranslation->expects($this->once())->method('resume');
     $this->_inlineTranslation->expects($this->once())->method('suspend');
     $this->_controller->execute();
 }
Esempio n. 8
0
 /**
  * Test case when module is enabled in config and php extension is installed
  *
  * @return void
  */
 public function testCheckConfig()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->newRelicWrapper->expects($this->once())->method('isExtensionInstalled')->willReturn(false);
     $this->config->expects($this->once())->method('disableModule');
     $this->messageManager->expects($this->once())->method('addError');
     $this->model->execute($eventObserver);
 }
Esempio n. 9
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();
 }
 public function testExecute()
 {
     $ids = [1, 2];
     $this->request->expects($this->once())->method('getParam')->with('search')->will($this->returnValue($ids));
     $this->createQuery(0, 1);
     $this->createQuery(1, 2);
     $this->messageManager->expects($this->once())->method('addSuccess')->will($this->returnSelf());
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('search/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }
Esempio n. 11
0
 public function testExecuteRandom()
 {
     $newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
     $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
     $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
     $this->managerMock->expects($this->once())->method('addSuccessMessage');
     $this->managerMock->expects($this->once())->method('addNoticeMessage');
     $this->cacheMock->expects($this->once())->method('clean');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->model->execute();
 }
Esempio n. 12
0
 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecuteLocalizedException()
 {
     $phrase = new \Magento\Framework\Phrase('some error');
     $objectManager = new ObjectManager($this);
     $this->vault->expects($this->once())->method('processNonce')->willThrowException(new LocalizedException($phrase));
     $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'some error']);
     $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->messageManager->expects($this->once())->method('addError')->with($phrase);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\AjaxSave', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
     $this->assertSame($this->resultJson, $notification->execute());
 }
 public function testExecute()
 {
     $message = "test";
     $flagMock = $this->getMockBuilder(\Magento\CatalogRule\Model\Flag::class)->setMethods(['getState'])->disableOriginalConstructor()->getMock();
     $eventObserverMock = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)->disableOriginalConstructor()->getMock();
     $eventObserverMock->expects($this->at(0))->method('getData')->with('dirty_rules')->willReturn($flagMock);
     $flagMock->expects($this->once())->method('getState')->willReturn(1);
     $eventObserverMock->expects($this->at(1))->method('getData')->with('message')->willReturn($message);
     $this->messageManagerMock->expects($this->once())->method('addNotice')->with($message);
     $this->observer->execute($eventObserverMock);
 }
Esempio n. 14
0
 public function testEditActionBlockNoExists()
 {
     $blockId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId);
     $this->blockMock->expects($this->once())->method('load')->with($blockId);
     $this->blockMock->expects($this->once())->method('getId')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('This block no longer exists.'));
     $this->resultRedirectFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->editController->execute());
 }
Esempio n. 15
0
 public function testGetSectionData()
 {
     $msgType = 'error';
     $msgText = 'All is lost';
     $msg = $this->getMockBuilder('Magento\\Framework\\Message\\MessageInterface')->getMock();
     $messages = [$msg];
     $msg->expects($this->once())->method('getType')->willReturn($msgType);
     $msg->expects($this->once())->method('getText')->willReturn($msgText);
     $msgCollection = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->getMock();
     $this->messageManager->expects($this->once())->method('getMessages')->with(true, null)->willReturn($msgCollection);
     $msgCollection->expects($this->once())->method('getItems')->willReturn($messages);
     $this->assertEquals(['messages' => [['type' => $msgType, 'text' => $msgText]]], $this->object->getSectionData());
 }
Esempio n. 16
0
 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecuteInternalLocalizedException()
 {
     $phrase = new \Magento\Framework\Phrase('Something went wrong while processing.');
     $objectManager = new ObjectManager($this);
     $this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase));
     $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']);
     $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->messageManager->expects($this->once())->method('addError')->with($phrase);
     $this->request->expects($this->any())->method('getParam')->willReturn(true);
     /** @var \Magento\Braintree\Controller\Creditcard\Generate $controller */
     $controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
     $this->assertSame($this->resultJson, $controller->executeInternal());
 }
Esempio n. 17
0
 public function testDeleteActionThrowsException()
 {
     $errorMsg = 'Can\'t delete the page';
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock);
     $this->pageMock->expects($this->once())->method('load')->with($this->pageId);
     $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title);
     $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg)));
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg);
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
 /**
  * @return void
  */
 public function testBeforeExecute()
 {
     $logoutReasonCode = 2;
     $uri = '/uri/';
     $errorMessage = 'Error Message';
     $this->securityCookieHelperMock->expects($this->once())->method('getLogoutReasonCookie')->willReturn($logoutReasonCode);
     $this->backendControllerAuthLoginMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
     $this->requestMock->expects($this->once())->method('getUri')->willReturn($uri);
     $this->backendControllerAuthLoginMock->expects($this->once())->method('getUrl')->willReturn($uri);
     $this->adminSessionsManagerMock->expects($this->once())->method('getLogoutReasonMessageByStatus')->with($logoutReasonCode)->willReturn($errorMessage);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMessage);
     $this->securityCookieHelperMock->expects($this->once())->method('deleteLogoutReasonCookie')->willReturnSelf();
     $this->controller->beforeExecute($this->backendControllerAuthLoginMock);
 }
Esempio n. 19
0
 /**
  * @return void
  */
 public function testAroundProlongSessionIsNotActiveAndIsNotAjaxRequest()
 {
     $result = 'result';
     $errorMessage = 'Error Message';
     $proceed = function () use($result) {
         return $result;
     };
     $this->currentSessionMock->expects($this->once())->method('isLoggedInStatus')->willReturn(false);
     $this->authSessionMock->expects($this->once())->method('destroy');
     $this->requestMock->expects($this->once())->method('getParam')->with('isAjax')->willReturn(false);
     $this->adminSessionsManagerMock->expects($this->once())->method('getLogoutReasonMessage')->willReturn($errorMessage);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMessage);
     $this->model->aroundProlong($this->authSessionMock, $proceed);
 }
Esempio n. 20
0
 public function prepareMocksForTestExecute()
 {
     $postData = [1 => ['title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']];
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['isAjax', null, true], ['items', [], $postData]]);
     $this->pageRepository->expects($this->once())->method('getById')->with(1)->willReturn($this->cmsPage);
     $this->dataProcessor->expects($this->once())->method('filter')->with($postData[1])->willReturnArgument(0);
     $this->dataProcessor->expects($this->once())->method('validate')->with($postData[1])->willReturn(false);
     $this->messageManager->expects($this->once())->method('getMessages')->with(true)->willReturn($this->messageCollection);
     $this->messageCollection->expects($this->once())->method('getItems')->willReturn([$this->message]);
     $this->message->expects($this->once())->method('getText')->willReturn('Error message');
     $this->cmsPage->expects($this->atLeastOnce())->method('getId')->willReturn('1');
     $this->cmsPage->expects($this->atLeastOnce())->method('getData')->willReturn(['layout' => '1column', 'identifier' => 'test-identifier']);
     $this->cmsPage->expects($this->once())->method('setData')->with(['layout' => '1column', 'title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']);
     $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
 }
Esempio n. 21
0
 public function testExecuteWithException()
 {
     $token = 'token';
     $customerId = '11';
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['token', null, $token], ['id', null, null]]);
     $this->sessionMock->expects($this->once())->method('getRpToken')->willReturn($token);
     $this->sessionMock->expects($this->once())->method('getRpCustomerId')->willReturn($customerId);
     $this->accountManagementMock->expects($this->once())->method('validateResetPasswordLinkToken')->with($customerId, $token)->willThrowException(new \Exception('Exception.'));
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('Your password reset link has expired.'))->willReturnSelf();
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('*/*/forgotpassword', [])->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->executeInternal());
 }
Esempio n. 22
0
    /**
     * @test
     * @return void
     */
    public function testExecuteLocalizedException()
    {
        $path = 'adminhtml/*/';
        $themeId = 1;
        $this->request->expects($this->any())
            ->method('getParam')
            ->willReturnMap(
                [
                    ['id', null, $themeId],
                    ['back', false, false],
                ]
            );
        $redirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect')
            ->disableOriginalConstructor()
            ->getMock();
        $this->objectManager->expects($this->once())
            ->method('create')
            ->with('Magento\Framework\View\Design\ThemeInterface')
            ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('localized exception')));
        $this->resultFactory->expects($this->once())
            ->method('create')
            ->with(ResultFactory::TYPE_REDIRECT)
            ->willReturn($redirect);
        $redirect->expects($this->once())
            ->method('setPath')
            ->with($path)
            ->willReturnSelf();
        $this->messageManager->expects($this->once())
            ->method('addError');

        $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->controller->executeInternal());
    }
Esempio n. 23
0
 /**
  * @param array $indexerIds
  * @param \Exception $exception
  * @param array $expectsExceptionValues
  * @dataProvider executeDataProvider
  */
 public function testExecute($indexerIds, $exception, $expectsExceptionValues)
 {
     $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock);
     $this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds));
     if (!is_array($indexerIds)) {
         $this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1));
     } else {
         $this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Indexer\\IndexerRegistry')->will($this->returnValue($this->indexReg));
         $indexerInterface = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\IndexerInterface', ['setScheduled'], '', false);
         $this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface));
         if ($exception !== null) {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception));
         } else {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1));
         }
         $this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1));
         if ($exception !== null) {
             $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage());
             $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error.");
         }
     }
     $this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com");
     $this->response->expects($this->any())->method("setRedirect")->willReturn(1);
     $this->model->executeInternal();
 }
Esempio n. 24
0
 /**
  * @param bool $noDiscount
  * @param string $couponCode
  * @param string $errorMessage
  * @param string $actualCouponCode
  * @dataProvider isApplyDiscountDataProvider
  */
 public function testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
 {
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCouponCode', 'isVirtual', 'getAllItems'], [], '', false);
     $create = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', [], [], '', false);
     $paramReturnMap = [['customer_id', null, null], ['store_id', null, null], ['currency_id', null, null]];
     $this->request->expects($this->atLeastOnce())->method('getParam')->willReturnMap($paramReturnMap);
     $objectManagerParamMap = [['Magento\\Sales\\Model\\AdminOrder\\Create', $create], ['Magento\\Backend\\Model\\Session\\Quote', $this->session]];
     $this->objectManager->expects($this->atLeastOnce())->method('get')->willReturnMap($objectManagerParamMap);
     $this->eventManager->expects($this->any())->method('dispatch');
     $data = ['coupon' => ['code' => $couponCode]];
     $postReturnMap = [['order', $data], ['reset_shipping', false], ['collect_shipping_rates', false], ['sidebar', false], ['add_product', false], ['', false], ['update_items', false], ['remove_item', 1], ['from', 2], ['move_item', 1], ['to', 2], ['qty', 3], ['payment', false], [null, 'request'], ['payment', false], ['giftmessage', false], ['add_products', false], ['update_items', false]];
     $this->request->expects($this->atLeastOnce())->method('getPost')->willReturnMap($postReturnMap);
     $create->expects($this->once())->method('importPostData')->willReturnSelf();
     $create->expects($this->once())->method('initRuleData')->willReturnSelf();
     $create->expects($this->any())->method('getQuote')->willReturn($quote);
     $address = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
     $create->expects($this->once())->method('getBillingAddress')->willReturn($address);
     $quote->expects($this->any())->method('isVirtual')->willReturn(true);
     $this->request->expects($this->once())->method('has')->with('item')->willReturn(false);
     $create->expects($this->once())->method('saveQuote')->willReturnSelf();
     $this->session->expects($this->any())->method('getQuote')->willReturn($quote);
     $item = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['getNoDiscount']);
     $quote->expects($this->any())->method('getAllItems')->willReturn([$item]);
     $item->expects($this->any())->method('getNoDiscount')->willReturn($noDiscount);
     if (!$noDiscount) {
         $quote->expects($this->once())->method('getCouponCode')->willReturn($actualCouponCode);
     }
     $errorMessageManager = __($errorMessage, $couponCode);
     $this->escaper->expects($this->once())->method('escapeHtml')->with($couponCode)->willReturn($couponCode);
     $this->messageManager->expects($this->once())->method('addError')->with($errorMessageManager)->willReturnSelf();
     $this->resultForward->expects($this->once())->method('forward')->with('index')->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->processData->execute());
 }
Esempio n. 25
0
 /**
  * @return void
  */
 public function testExecuteException()
 {
     $phrase = new \Magento\Framework\Phrase('We couldn\'t logout because of an error.');
     $this->sessionsManager->expects($this->once())->method('logoutOtherUserSessions')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addException')->with(new \Exception(), $phrase);
     $this->controller->execute();
 }
Esempio n. 26
0
 public function testAdminAuthenticate()
 {
     $password = "******";
     $uid = 123;
     $authResult = true;
     $lockExpires = false;
     $userPassword = ['expires' => 1];
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock();
     /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])->getMock();
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getPassword')->willReturn($password);
     $eventMock->expects($this->once())->method('getUser')->willReturn($userMock);
     $eventMock->expects($this->once())->method('getResult')->willReturn($authResult);
     $userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires);
     $this->userMock->expects($this->once())->method('unlock');
     $this->userMock->expects($this->once())->method('getLatestPassword')->willReturn($userPassword);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getLastAddedMessage')->willReturn($this->messageInterfaceMock);
     $this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf();
     $this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired');
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false);
     $this->model->execute($eventObserverMock);
 }
Esempio n. 27
0
 public function testExecuteWithException()
 {
     $addressId = 1;
     $customerId = 2;
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address);
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->address->expects($this->once())->method('getCustomerId')->willReturn(34);
     $exception = new \Exception('Exception');
     $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.'));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
Esempio n. 28
0
 /**
  * @return void
  */
 public function testExecuteWithLocalizedException()
 {
     $errorText = new Phrase('Error');
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorText);
     $this->menuBlockMock->expects($this->once())->method('setActive')->willThrowException(new \Magento\Framework\Exception\LocalizedException($errorText));
     $this->viewed->execute();
 }
Esempio n. 29
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithException()
 {
     $productId = 11;
     $categoryId = 5;
     $sender = 'sender';
     $recipients = 'recipients';
     $formData = ['sender' => $sender, 'recipients' => $recipients];
     $redirectUrl = 'redirect_url';
     /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [])->willReturn($redirectMock);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturnMap([['id', null, $productId], ['cat_id', null, $categoryId]]);
     /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog', 'setCategory', 'getProductUrl'])->getMockForAbstractClass();
     $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock);
     $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $this->categoryRepositoryMock->expects($this->once())->method('get')->with($categoryId, null)->willThrowException(new \Magento\Framework\Exception\NoSuchEntityException(__('No Category Exception.')));
     $productMock->expects($this->never())->method('setCategory');
     $this->registryMock->expects($this->once())->method('register')->willReturnMap([['product', $productMock, false, null]]);
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($formData);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['sender', $sender], ['recipients', $recipients]]);
     $this->sendFriendMock->expects($this->once())->method('setSender')->with($sender)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setRecipients')->with($recipients)->willReturnSelf();
     $this->sendFriendMock->expects($this->once())->method('setProduct')->with($productMock)->willReturnSelf();
     $exception = new \Exception(__('Exception.'));
     $this->sendFriendMock->expects($this->once())->method('validate')->willThrowException($exception);
     $this->sendFriendMock->expects($this->never())->method('send');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Some emails were not sent.'))->willReturnSelf();
     $this->catalogSessionMock->expects($this->once())->method('setSendfriendFormData')->with($formData);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sendfriend/product/send', ['_current' => true])->willReturn($redirectUrl);
     $this->redirectMock->expects($this->once())->method('error')->with($redirectUrl)->willReturnArgument(0);
     $redirectMock->expects($this->once())->method('setUrl')->with($redirectUrl)->willReturnSelf();
     $this->assertEquals($redirectMock, $this->model->execute());
 }
Esempio n. 30
0
 public function testAfterRenderResultWithWrongArray()
 {
     $messageType = 'message1type';
     $messageText = 'message1text';
     $messages = [['type' => $messageType, 'text' => $messageText]];
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */
     $resultMock = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock();
     /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $cookieMetadataMock */
     $cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)->disableOriginalConstructor()->getMock();
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->willReturn($cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('setPublicCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode($messages), $cookieMetadataMock);
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(MessagePlugin::MESSAGES_COOKIES_NAME, \Zend_Json::encode([]))->willReturn(\Zend_Json::encode('string'));
     $this->dataMock->expects($this->any())->method('jsonDecode')->willReturnCallback(function ($data) {
         return \Zend_Json::decode($data);
     });
     $this->dataMock->expects($this->any())->method('jsonEncode')->willReturnCallback(function ($data) {
         return \Zend_Json::encode($data);
     });
     /** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */
     $messageMock = $this->getMockBuilder(MessageInterface::class)->getMock();
     $messageMock->expects($this->once())->method('getType')->willReturn($messageType);
     $this->interpretationStrategyMock->expects($this->once())->method('interpret')->with($messageMock)->willReturn($messageText);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageMock]);
     $this->managerMock->expects($this->once())->method('getMessages')->with(true, null)->willReturn($collectionMock);
     $this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock));
 }