IndexTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Controller\Cart;
  7. use Magento\Checkout\Controller\Cart\Index;
  8. /**
  9. * Class IndexTest
  10. *
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class IndexTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Index
  17. */
  18. protected $controller;
  19. /**
  20. * @var \Magento\Checkout\Model\Session | \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $checkoutSession;
  23. /**
  24. * @var \Magento\Framework\App\Request\Http | \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $request;
  27. /**
  28. * @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. protected $response;
  31. /**
  32. * @var \Magento\Quote\Model\Quote | \PHPUnit_Framework_MockObject_MockObject
  33. */
  34. protected $quote;
  35. /**
  36. * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject
  37. */
  38. protected $eventManager;
  39. /**
  40. * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject
  41. */
  42. protected $objectManagerMock;
  43. /**
  44. * @var \PHPUnit_Framework_MockObject_MockObject
  45. */
  46. protected $cart;
  47. /**
  48. * @var \PHPUnit_Framework_MockObject_MockObject
  49. */
  50. protected $scopeConfig;
  51. /**
  52. * @var \PHPUnit_Framework_MockObject_MockObject
  53. */
  54. protected $messageManager;
  55. /**
  56. * @var \PHPUnit_Framework_MockObject_MockObject
  57. */
  58. protected $resultPageFactory;
  59. /**
  60. * @return void
  61. */
  62. protected function setUp()
  63. {
  64. $this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
  65. $this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
  66. $this->quote = $this->createMock(\Magento\Quote\Model\Quote::class);
  67. $this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
  68. $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
  69. $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManager\ObjectManager::class);
  70. $this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
  71. ->disableOriginalConstructor()
  72. ->getMock();
  73. $context = $this->createMock(\Magento\Framework\App\Action\Context::class);
  74. $context->expects($this->once())
  75. ->method('getObjectManager')
  76. ->willReturn($this->objectManagerMock);
  77. $context->expects($this->once())
  78. ->method('getRequest')
  79. ->willReturn($this->request);
  80. $context->expects($this->once())
  81. ->method('getResponse')
  82. ->willReturn($this->response);
  83. $context->expects($this->once())
  84. ->method('getEventManager')
  85. ->willReturn($this->eventManager);
  86. $context->expects($this->once())
  87. ->method('getMessageManager')
  88. ->willReturn($this->messageManager);
  89. $this->cart = $this->getMockBuilder(\Magento\Checkout\Model\Cart::class)
  90. ->disableOriginalConstructor()
  91. ->getMock();
  92. $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
  93. ->disableOriginalConstructor()
  94. ->getMock();
  95. $this->resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
  96. ->disableOriginalConstructor()
  97. ->setMethods(['create'])
  98. ->getMock();
  99. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  100. $this->controller = $objectManagerHelper->getObject(
  101. \Magento\Checkout\Controller\Cart\Index::class,
  102. [
  103. 'context' => $context,
  104. 'checkoutSession' => $this->checkoutSession,
  105. 'cart' => $this->cart,
  106. 'scopeConfig' => $this->scopeConfig,
  107. 'resultPageFactory' => $this->resultPageFactory
  108. ]
  109. );
  110. }
  111. /**
  112. * @return void
  113. */
  114. public function testExecuteWithMessages()
  115. {
  116. $title = $this->getMockBuilder(\Magento\Framework\View\Page\Title::class)
  117. ->disableOriginalConstructor()
  118. ->getMock();
  119. $title->expects($this->once())
  120. ->method('set')
  121. ->with('Shopping Cart');
  122. $config = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
  123. ->disableOriginalConstructor()
  124. ->getMock();
  125. $config->expects($this->once())
  126. ->method('getTitle')
  127. ->willReturn($title);
  128. $page = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
  129. ->disableOriginalConstructor()
  130. ->getMock();
  131. $page->expects($this->once())
  132. ->method('getConfig')
  133. ->willReturn($config);
  134. $this->resultPageFactory->expects($this->once())
  135. ->method('create')
  136. ->willReturn($page);
  137. $result = $this->controller->execute();
  138. $this->assertInstanceOf(\Magento\Framework\View\Result\Page::class, $result);
  139. }
  140. }