ViewTest.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Test for \Magento\Paypal\Block\Billing\Agreement\View
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Paypal\Block\Billing\Agreement;
  9. use Magento\TestFramework\Helper\Bootstrap;
  10. class ViewTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  11. {
  12. /** @var \Magento\Paypal\Block\Billing\Agreement\View */
  13. protected $_block;
  14. protected function setUp()
  15. {
  16. $this->_block = Bootstrap::getObjectManager()->create(\Magento\Paypal\Block\Billing\Agreement\View::class);
  17. parent::setUp();
  18. }
  19. /**
  20. * Test getting orders associated with specified billing agreement.
  21. *
  22. * Create two identical orders, associate one of them with billing agreement and invoke testGetRelatedOrders()
  23. *
  24. * @magentoDataFixture Magento/Customer/_files/customer.php
  25. * @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
  26. * @magentoDataFixture Magento/Sales/_files/order.php
  27. * @magentoDbIsolation enabled
  28. * @magentoAppIsolation enabled
  29. */
  30. public function testGetRelatedOrders()
  31. {
  32. /** Customer ID declared in the fixture */
  33. $customerId = 1;
  34. /** Assign first order to the active customer */
  35. /** @var \Magento\Sales\Model\Order $orderA */
  36. $orderA = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
  37. $orderA->loadByIncrementId('100000001');
  38. $orderA->setCustomerIsGuest(false)->setCustomerId($customerId)->save();
  39. /** @var \Magento\Customer\Model\Session $customerSession */
  40. $customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
  41. $customerSession->setCustomerId($customerId);
  42. /** Assign second order to the active customer */
  43. $orderB = clone $orderA;
  44. $orderB->setId(
  45. null
  46. )->setIncrementId(
  47. '100000002'
  48. )->setCustomerIsGuest(
  49. false
  50. )->setCustomerId(
  51. $customerId
  52. )->save();
  53. /** @var \Magento\Customer\Model\Session $customerSession */
  54. $customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
  55. $customerSession->setCustomerId($customerId);
  56. /** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
  57. $billingAgreementCollection = Bootstrap::getObjectManager()->create(
  58. \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
  59. );
  60. /** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
  61. $billingAgreement = $billingAgreementCollection->getFirstItem();
  62. $billingAgreement->addOrderRelation($orderA->getId())->save();
  63. $registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
  64. $registry->register('current_billing_agreement', $billingAgreement);
  65. $relatedOrders = $this->_block->getRelatedOrders();
  66. $this->assertEquals(1, $relatedOrders->count(), "Only one order must be returned.");
  67. $this->assertEquals(
  68. $orderA->getId(),
  69. $relatedOrders->getFirstItem()->getId(),
  70. "Invalid order returned as associated with billing agreement."
  71. );
  72. }
  73. }