SuccessTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Multishipping\Test\Unit\Block\Checkout;
  8. use Magento\Multishipping\Block\Checkout\Success;
  9. class SuccessTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var Success
  13. */
  14. protected $model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $sessionMock;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $contextMock;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $storeManagerMock;
  27. protected function setUp()
  28. {
  29. $this->sessionMock = $this->createPartialMock(
  30. \Magento\Framework\Session\SessionManagerInterface::class,
  31. [
  32. 'getOrderIds',
  33. 'start',
  34. 'writeClose',
  35. 'isSessionExists',
  36. 'getSessionId',
  37. 'getName',
  38. 'setName',
  39. 'destroy',
  40. 'clearStorage',
  41. 'getCookieDomain',
  42. 'getCookiePath',
  43. 'getCookieLifetime',
  44. 'setSessionId',
  45. 'regenerateId',
  46. 'expireSessionCookie',
  47. 'getSessionIdForHost',
  48. 'isValidForHost',
  49. 'isValidForPath',
  50. '__wakeup'
  51. ]
  52. );
  53. $this->contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  54. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  55. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  56. $this->contextMock->expects($this->once())->method('getSession')->will($this->returnValue($this->sessionMock));
  57. $this->contextMock->expects($this->once())
  58. ->method('getStoreManager')->will($this->returnValue($this->storeManagerMock));
  59. $this->model = $objectManager->getObject(
  60. \Magento\Multishipping\Block\Checkout\Success::class,
  61. [
  62. 'context' => $this->contextMock
  63. ]
  64. );
  65. }
  66. public function testGetOrderIdsWithoutId()
  67. {
  68. $this->sessionMock->method('getOrderIds')->willReturn(null);
  69. $this->assertFalse($this->model->getOrderIds());
  70. }
  71. public function testGetOrderIdsWithEmptyIdsArray()
  72. {
  73. $this->sessionMock->method('getOrderIds')->willReturn([]);
  74. $this->assertFalse($this->model->getOrderIds());
  75. }
  76. public function testGetOrderIds()
  77. {
  78. $ids = [100, 102, 103];
  79. $this->sessionMock->method('getOrderIds')->willReturn($ids);
  80. $this->assertEquals($ids, $this->model->getOrderIds());
  81. }
  82. public function testGetContinueUrl()
  83. {
  84. $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
  85. $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
  86. $storeMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('Expected Result'));
  87. $this->assertEquals('Expected Result', $this->model->getContinueUrl());
  88. }
  89. }