BannersTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Bml;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class BannersTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @param int $publisherId
  12. * @param int $display
  13. * @param int $position
  14. * @param int $configPosition
  15. * @param bool $isEmptyHtml
  16. * @param string $methodWppBml
  17. * @param string $methodWppPeBml
  18. * @dataProvider testToHtmlDataProvider
  19. * @magentoAppIsolation enabled
  20. * @magentoAppArea frontend
  21. */
  22. public function testToHtml(
  23. $publisherId,
  24. $display,
  25. $position,
  26. $configPosition,
  27. $isEmptyHtml,
  28. $methodWppBml,
  29. $methodWppPeBml
  30. ) {
  31. /** @var \Magento\Paypal\Model\Config|\PHPUnit_Framework_MockObject_MockObject $paypalConfig */
  32. $paypalConfig = $this->createMock(\Magento\Paypal\Model\Config::class);
  33. $paypalConfig->expects($this->any())->method('getBmlPublisherId')->will($this->returnValue($publisherId));
  34. $paypalConfig->expects($this->any())->method('getBmlDisplay')->will($this->returnValue($display));
  35. $paypalConfig->expects($this->any())->method('getBmlPosition')->will($this->returnValue($configPosition));
  36. $paypalConfig->expects($this->any())
  37. ->method('isMethodAvailable')
  38. ->willReturnMap(
  39. [
  40. [
  41. $methodWppBml,
  42. true,
  43. ],
  44. [
  45. $methodWppPeBml,
  46. true,
  47. ],
  48. ]
  49. );
  50. /** @var \Magento\Framework\View\LayoutInterface $layout */
  51. $layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
  52. $block = $layout->createBlock(
  53. \Magento\Paypal\Block\Bml\Banners::class,
  54. '',
  55. [
  56. 'paypalConfig' => $paypalConfig,
  57. 'data' => ['position' => $position]
  58. ]
  59. );
  60. $block->setTemplate('bml.phtml');
  61. $html = $block->toHtml();
  62. if ($isEmptyHtml) {
  63. $this->assertEmpty($html);
  64. } else {
  65. $this->assertContains('data-pp-pubid="' . $block->getPublisherId() . '"', $html);
  66. $this->assertContains('data-pp-placementtype="' . $block->getSize() . '"', $html);
  67. }
  68. }
  69. /**
  70. * @return array
  71. */
  72. public function testToHtmlDataProvider()
  73. {
  74. return [
  75. [
  76. 'publisherId' => 1,
  77. 'display' => 1,
  78. 'position' => 100,
  79. 'configPosition' => 100,
  80. 'isEmptyHtml' => false,
  81. 'methodWppBml' => 'paypal_express_bml',
  82. 'methodWppPeBml' => 'payflow_express_bml',
  83. ],
  84. [
  85. 'publisherId' => 0,
  86. 'display' => 1,
  87. 'position' => 100,
  88. 'configPosition' => 100,
  89. 'isEmptyHtml' => true,
  90. 'methodWppBml' => 'paypal_express_bml',
  91. 'methodWppPeBml' => 'payflow_express_bml',
  92. ],
  93. [
  94. 'publisherId' => 1,
  95. 'display' => 0,
  96. 'position' => 100,
  97. 'configPosition' => 100,
  98. 'isEmptyHtml' => true,
  99. 'methodWppBml' => 'paypal_express_bml',
  100. 'methodWppPeBml' => 'payflow_express_bml',
  101. ],
  102. [
  103. 'publisherId' => 1,
  104. 'display' => 0,
  105. 'position' => 10,
  106. 'configPosition' => 100,
  107. 'isEmptyHtml' => true,
  108. 'methodWppBml' => 'paypal_express_bml',
  109. 'methodWppPeBml' => 'payflow_express_bml',
  110. ]
  111. ];
  112. }
  113. }