CheckmoTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\OfflinePayments\Test\Unit\Block\Info;
  7. use Magento\Framework\View\Element\Template\Context;
  8. use Magento\OfflinePayments\Block\Info\Checkmo;
  9. use Magento\Payment\Model\Info;
  10. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  11. /**
  12. * CheckmoTest contains list of test for block methods testing
  13. */
  14. class CheckmoTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var Info|MockObject
  18. */
  19. private $info;
  20. /**
  21. * @var Checkmo
  22. */
  23. private $block;
  24. /**
  25. * @inheritdoc
  26. */
  27. protected function setUp()
  28. {
  29. $context = $this->getMockBuilder(Context::class)
  30. ->disableOriginalConstructor()
  31. ->setMethods([])
  32. ->getMock();
  33. $this->info = $this->getMockBuilder(Info::class)
  34. ->disableOriginalConstructor()
  35. ->setMethods(['getAdditionalInformation'])
  36. ->getMock();
  37. $this->block = new Checkmo($context);
  38. }
  39. /**
  40. * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getPayableTo
  41. * @param array $details
  42. * @param string|null $expected
  43. * @dataProvider getPayableToDataProvider
  44. */
  45. public function testGetPayableTo($details, $expected)
  46. {
  47. $this->info->expects(static::at(0))
  48. ->method('getAdditionalInformation')
  49. ->with('payable_to')
  50. ->willReturn($details);
  51. $this->block->setData('info', $this->info);
  52. static::assertEquals($expected, $this->block->getPayableTo());
  53. }
  54. /**
  55. * Get list of variations for payable configuration option testing
  56. * @return array
  57. */
  58. public function getPayableToDataProvider()
  59. {
  60. return [
  61. ['payable_to' => 'payable', 'payable'],
  62. ['', null]
  63. ];
  64. }
  65. /**
  66. * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getMailingAddress
  67. * @param array $details
  68. * @param string|null $expected
  69. * @dataProvider getMailingAddressDataProvider
  70. */
  71. public function testGetMailingAddress($details, $expected)
  72. {
  73. $this->info->expects(static::at(1))
  74. ->method('getAdditionalInformation')
  75. ->with('mailing_address')
  76. ->willReturn($details);
  77. $this->block->setData('info', $this->info);
  78. static::assertEquals($expected, $this->block->getMailingAddress());
  79. }
  80. /**
  81. * Get list of variations for mailing address testing
  82. * @return array
  83. */
  84. public function getMailingAddressDataProvider()
  85. {
  86. return [
  87. ['mailing_address' => 'blah@blah.com', 'blah@blah.com'],
  88. ['mailing_address' => '', null]
  89. ];
  90. }
  91. /**
  92. * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getMailingAddress
  93. */
  94. public function testConvertAdditionalDataIsNeverCalled()
  95. {
  96. $mailingAddress = 'blah@blah.com';
  97. $this->info->expects(static::at(1))
  98. ->method('getAdditionalInformation')
  99. ->with('mailing_address')
  100. ->willReturn($mailingAddress);
  101. $this->block->setData('info', $this->info);
  102. // First we set the property $this->_mailingAddress
  103. $this->block->getMailingAddress();
  104. // And now we get already setted property $this->_mailingAddress
  105. static::assertEquals($mailingAddress, $this->block->getMailingAddress());
  106. }
  107. }