CaseInfoTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Signifyd\Block\Adminhtml;
  7. use Magento\Framework\App\RequestInterface;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Framework\View\Element\Template\Context;
  10. use Magento\Sales\Model\Order;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. class CaseInfoTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @var Order
  20. */
  21. private $order;
  22. /**
  23. * @var \Magento\Framework\View\LayoutFactory
  24. */
  25. protected $layoutFactory;
  26. /**
  27. * @inheritdoc
  28. */
  29. protected function setUp()
  30. {
  31. $this->objectManager = Bootstrap::getObjectManager();
  32. $this->order = $this->objectManager->create(Order::class);
  33. $this->layoutFactory = $this->objectManager->get(\Magento\Framework\View\LayoutFactory::class);
  34. }
  35. /**
  36. * Checks that block has contents when case entity for order is exists
  37. * even if Signifyd module is inactive.
  38. *
  39. * @magentoConfigFixture current_store fraud_protection/signifyd/active 0
  40. * @magentoDataFixture Magento/Signifyd/_files/case.php
  41. * @magentoAppArea adminhtml
  42. */
  43. public function testModuleIsInactive()
  44. {
  45. $this->order->loadByIncrementId('100000001');
  46. self::assertNotEmpty($this->getBlock()->toHtml());
  47. }
  48. /**
  49. * Checks that block does not give contents
  50. * if there is no case entity created for order.
  51. *
  52. * @covers \Magento\Signifyd\Block\Adminhtml\CaseInfo::getCaseEntity
  53. * @magentoConfigFixture current_store fraud_protection/signifyd/active 1
  54. * @magentoDataFixture Magento/Signifyd/_files/order_with_customer_and_two_simple_products.php
  55. * @magentoAppArea adminhtml
  56. */
  57. public function testCaseEntityNotExists()
  58. {
  59. $this->order->loadByIncrementId('100000001');
  60. self::assertEmpty($this->getBlock()->toHtml());
  61. }
  62. /**
  63. * Checks that:
  64. * - block give contents
  65. * - block contents guarantee decision field
  66. *
  67. * @covers \Magento\Signifyd\Block\Adminhtml\CaseInfo::getScoreClass
  68. * @magentoConfigFixture current_store fraud_protection/signifyd/active 1
  69. * @magentoDataFixture Magento/Signifyd/_files/case.php
  70. * @magentoAppArea adminhtml
  71. */
  72. public function testCaseEntityExists()
  73. {
  74. $this->order->loadByIncrementId('100000001');
  75. $block = $this->getBlock();
  76. self::assertNotEmpty($block->toHtml());
  77. self::assertContains((string) $block->getCaseGuaranteeDisposition(), $block->toHtml());
  78. }
  79. /**
  80. * Gets block.
  81. *
  82. * @return CaseInfo
  83. */
  84. private function getBlock()
  85. {
  86. $layout = $this->layoutFactory->create();
  87. $layout->addContainer('order_additional_info', 'Container');
  88. /** @var CaseInfo $block */
  89. $block = $layout->addBlock(CaseInfo::class, 'order_case_info', 'order_additional_info');
  90. $block->setAttribute('context', $this->getContext());
  91. $block->setTemplate('Magento_Signifyd::case_info.phtml');
  92. return $block;
  93. }
  94. /**
  95. * Creates template context with necessary order id param.
  96. *
  97. * @return Context
  98. */
  99. private function getContext()
  100. {
  101. /** @var RequestInterface $request */
  102. $request = $this->objectManager->get(RequestInterface::class);
  103. $request->setParams(['order_id' => $this->order->getEntityId()]);
  104. return $this->objectManager->create(Context::class, ['request' => $request]);
  105. }
  106. }