ShippingTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Block\Cart;
  7. class ShippingTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Checkout\Block\Cart\Shipping
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $context;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerSession;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $checkoutSession;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $configProvider;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $layoutProcessor;
  33. /**
  34. * @var \PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $storeManager;
  37. /**
  38. * @var array
  39. */
  40. protected $layout;
  41. /**
  42. * @var \PHPUnit_Framework_MockObject_MockObject
  43. */
  44. private $serializer;
  45. protected function setUp()
  46. {
  47. $this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  48. $this->customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
  49. $this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
  50. $this->configProvider = $this->createMock(\Magento\Checkout\Model\CompositeConfigProvider::class);
  51. $this->layoutProcessor = $this->createMock(\Magento\Checkout\Block\Checkout\LayoutProcessorInterface::class);
  52. $this->layout = [
  53. 'components' => [
  54. 'firstComponent' => ['param' => 'value'],
  55. 'secondComponent' => ['param' => 'value'],
  56. ]
  57. ];
  58. $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  59. $this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
  60. $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
  61. $this->model = new \Magento\Checkout\Block\Cart\Shipping(
  62. $this->context,
  63. $this->customerSession,
  64. $this->checkoutSession,
  65. $this->configProvider,
  66. [$this->layoutProcessor],
  67. ['jsLayout' => $this->layout],
  68. $this->serializer
  69. );
  70. }
  71. public function testGetCheckoutConfig()
  72. {
  73. $config = ['param' => 'value'];
  74. $this->configProvider->expects($this->once())->method('getConfig')->willReturn($config);
  75. $this->assertEquals($config, $this->model->getCheckoutConfig());
  76. }
  77. public function testGetJsLayout()
  78. {
  79. $layoutProcessed = $this->layout;
  80. $layoutProcessed['components']['thirdComponent'] = ['param' => 'value'];
  81. $jsonLayoutProcessed = json_encode($layoutProcessed);
  82. $this->layoutProcessor->expects($this->once())
  83. ->method('process')
  84. ->with($this->layout)
  85. ->willReturn($layoutProcessed);
  86. $this->assertEquals(
  87. $jsonLayoutProcessed,
  88. $this->model->getJsLayout()
  89. );
  90. }
  91. public function testGetBaseUrl()
  92. {
  93. $baseUrl = 'baseUrl';
  94. $storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getBaseUrl']);
  95. $storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
  96. $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
  97. $this->assertEquals($baseUrl, $this->model->getBaseUrl());
  98. }
  99. public function testGetSerializedCheckoutConfig()
  100. {
  101. $checkoutConfig = ['checkout', 'config'];
  102. $this->configProvider->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
  103. $this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig());
  104. }
  105. }