当前位置: 首页>>代码示例>>PHP>>正文


PHP Message\Manager类代码示例

本文整理汇总了PHP中Magento\Framework\Message\Manager的典型用法代码示例。如果您正苦于以下问题:PHP Manager类的具体用法?PHP Manager怎么用?PHP Manager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: afterDispatch

 /**
  * Set Cookie for msg box when it displays first
  *
  * @param \Magento\Framework\App\FrontController $subject
  * @param \Magento\Framework\App\ResponseInterface $response
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\ResponseInterface $response)
 {
     if ($this->request->isPost() && $this->messageManager->hasMessages()) {
         $this->cookie->set(self::COOKIE_NAME, 1, self::COOKIE_PERIOD, '/');
     }
     return $response;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:16,代码来源:MessageBox.php

示例2: testExecuteNotPost

 public function testExecuteNotPost()
 {
     $this->validatorMock->expects($this->once())->method('validate')->willReturn(false);
     $this->request->expects($this->once())->method('isPost')->willReturn(false);
     $this->messageManager->expects($this->once())->method('addError')->with('You have not canceled the item.');
     $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->assertEquals($this->resultRedirect, $this->controller->execute());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:8,代码来源:CancelTest.php

示例3: afterDispatch

 /**
  * Set Cookie for msg box when it displays first
  *
  * @param FrontController $subject
  * @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result
  *
  * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDispatch(FrontController $subject, $result)
 {
     if ($this->request->isPost() && $this->messageManager->hasMessages()) {
         $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false);
         $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata);
     }
     return $result;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:MessageBox.php

示例4: testExecute

 public function testExecute()
 {
     $path = '*/*';
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('We updated lifetime statistic.'));
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Resource\\Report\\Order')->willReturn($this->order);
     $this->resultRedirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->refreshStatisticsController->execute());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:9,代码来源:RefreshStatisticsTest.php

示例5: testAfterDispatch

 /**
  * @param bool $isPost
  * @param int $numOfCalls
  * @dataProvider afterDispatchTestDataProvider
  */
 public function testAfterDispatch($isPost, $numOfCalls)
 {
     $this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     $this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->will($this->returnValue($this->publicCookieMetadataMock));
     $this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock);
     $this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:MessageBoxTest.php

示例6: testExecuteLoadShipmentFail

 /**
  * Run test execute method (fail load shipment model)
  */
 public function testExecuteLoadShipmentFail()
 {
     $this->shipmentLoaderMock->expects($this->once())->method('load')->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message')));
     $this->messageManagerMock->expects($this->once())->method('addError')->will($this->returnSelf());
     $this->redirectSection();
     $this->assertNull($this->controller->execute());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:PrintLabelTest.php

示例7: testEmail

    public function testEmail()
    {
        $cmId = 10000031;
        $cmManagement = 'Magento\Sales\Api\CreditmemoManagementInterface';
        $cmManagementMock = $this->getMock($cmManagement, [], [], '', false);
        $this->prepareRedirect($cmId);

        $this->request->expects($this->once())
            ->method('getParam')
            ->with('creditmemo_id')
            ->willReturn($cmId);
        $this->objectManager->expects($this->once())
            ->method('create')
            ->with($cmManagement)
            ->willReturn($cmManagementMock);
        $cmManagementMock->expects($this->once())
            ->method('notify')
            ->willReturn(true);
        $this->messageManager->expects($this->once())
            ->method('addSuccess')
            ->with('You sent the message.');

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->creditmemoEmail->executeInternal()
        );
        $this->assertEquals($this->response, $this->creditmemoEmail->getResponse());
    }
开发者ID:nblair,项目名称:magescotch,代码行数:28,代码来源:EmailTest.php

示例8: testEditPostActionWithoutErrors

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testEditPostActionWithoutErrors()
 {
     $customerId = 24;
     $address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
     $loadedCustomer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], 'loadedCustomer', false);
     $loadedCustomer->expects($this->once())->method('getAddresses')->willReturn([$address, $address]);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->redirectResultMock);
     $this->formKeyValidator->expects($this->once())->method('validate')->willReturn(true);
     $this->request->expects($this->once())->method('isPost')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->customerExtractor->expects($this->once())->method('extract')->willReturn($this->customer);
     $this->customer->expects($this->once())->method('setId')->with($customerId);
     $this->customer->expects($this->once())->method('getAddresses')->willReturn(null);
     $this->customerRepository->expects($this->exactly(2))->method('getById')->with($customerId)->willReturn($loadedCustomer);
     $this->customer->expects($this->once())->method('setAddresses')->with([$address, $address]);
     $this->request->expects($this->once())->method('getParam')->with('change_password')->willReturn(true);
     $this->request->expects($this->at(2))->method('getPost')->with('current_password', null)->willReturn(123);
     $this->request->expects($this->at(3))->method('getPost')->with('password', null)->willReturn(321);
     $this->request->expects($this->at(4))->method('getPost')->with('password_confirmation', null)->willReturn(321);
     $this->customerAccountManagement->expects($this->once())->method('changePassword');
     $this->customerRepository->expects($this->once())->method('save');
     $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', [], [], '', false);
     $messageCollection->expects($this->once())->method('getCount')->willReturn(0);
     $this->messageManager->expects($this->once())->method('getMessages')->willReturn($messageCollection);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You saved the account information.');
     $this->redirectResultMock->expects($this->once())->method('setPath')->with('customer/account')->willReturn('http://test.com/customer/account/edit');
     $this->assertSame($this->redirectResultMock, $this->getController()->execute());
 }
开发者ID:nja78,项目名称:magento2,代码行数:31,代码来源:EditPostTest.php

示例9: testEmail

 public function testEmail()
 {
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipment = ['items' => []];
     $orderShipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', '__wakeup'], [], '', false);
     $shipmentNotifierClassName = 'Magento\\Shipping\\Model\\ShipmentNotifier';
     $shipmentNotifier = $this->getMock($shipmentNotifierClassName, ['notify', '__wakeup'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]]));
     $this->shipmentLoader->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoader->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoader->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoader->expects($this->once())->method('setTracking')->with($tracking);
     $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($orderShipment));
     $orderShipment->expects($this->once())->method('save')->will($this->returnSelf());
     $this->objectManager->expects($this->once())->method('create')->with($shipmentNotifierClassName)->will($this->returnValue($shipmentNotifier));
     $shipmentNotifier->expects($this->once())->method('notify')->with($orderShipment)->will($this->returnValue(true));
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the shipment.');
     $path = '*/*/view';
     $arguments = ['shipment_id' => $shipmentId];
     $this->prepareRedirect($path, $arguments, 0);
     $this->shipmentEmail->execute();
     $this->assertEquals($this->response, $this->shipmentEmail->getResponse());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:25,代码来源:EmailTest.php

示例10: testExecuteAddSuccessCriticalException

 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:39,代码来源:UpdateItemOptionsTest.php

示例11: testEmailNoOrderId

    public function testEmailNoOrderId()
    {
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('order_id')
            ->will($this->returnValue(null));
        $this->orderRepositoryMock->expects($this->once())
            ->method('get')
            ->with(null)
            ->willThrowException(
                new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist'))
            );
        $this->messageManager->expects($this->once())
            ->method('addError')
            ->with('This order no longer exists.');

        $this->actionFlag->expects($this->once())
            ->method('set')
            ->with('', 'no-dispatch', true)
            ->will($this->returnValue(true));
        $this->resultRedirect->expects($this->once())
            ->method('setPath')
            ->with('sales/*/')
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->orderEmail->executeInternal()
        );
    }
开发者ID:nblair,项目名称:magescotch,代码行数:30,代码来源:EmailTest.php

示例12: testAddMessages

 public function testAddMessages()
 {
     $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', ['getItems', 'addMessage'], [], '', false);
     $this->session->expects($this->any())->method('getData')->will($this->returnValue($messageCollection));
     $this->eventManager->expects($this->once())->method('dispatch')->with('session_abstract_add_message');
     $messageCollection->expects($this->once())->method('addMessage')->with($this->messageMock);
     $this->model->addMessages([$this->messageMock]);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:8,代码来源:ManagerTest.php

示例13: testExecuteWithException

 public function testExecuteWithException()
 {
     $customersIds = [10, 11, 12];
     $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->willThrowException(new \Exception('Some message.'));
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Some message.');
     $this->massAction->execute();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:8,代码来源:MassAssignGroupTest.php

示例14: testExecuteUpdateAction

 public function testExecuteUpdateAction()
 {
     $orderId = 30;
     $action = 'update';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId);
     $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
     $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('update');
     $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true);
     $this->messageManagerMock->expects($this->once())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf();
     $result = $this->reviewPayment->execute();
     $this->assertEquals($this->resultRedirectMock, $result);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:ReviewPaymentTest.php

示例15: testExecuteUpdateAction

 public function testExecuteUpdateAction()
 {
     $orderId = 30;
     $action = 'update';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getId')->willReturn($orderId);
     $this->orderMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock);
     $this->orderMock->expects($this->once())->method('save')->willReturnSelf();
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The payment update has been made.');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('update');
     $result = $this->reviewPayment->execute();
     $this->assertEquals($this->resultRedirectMock, $result);
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:18,代码来源:ReviewPaymentTest.php


注:本文中的Magento\Framework\Message\Manager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。