InstantPurchaseTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\InstantPurchase\CustomerData;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. use PHPUnit\Framework\TestCase;
  10. use Magento\Customer\Model\Session;
  11. /**
  12. * @magentoAppIsolation enabled
  13. */
  14. class InstantPurchaseTest extends TestCase
  15. {
  16. /**
  17. * @var ObjectManagerInterface
  18. */
  19. private $objectManager;
  20. public function setUp()
  21. {
  22. $this->objectManager = Bootstrap::getObjectManager();
  23. }
  24. /**
  25. * @magentoDataFixture Magento/Customer/_files/customer.php
  26. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  27. * @magentoDataFixture Magento/InstantPurchase/_files/fake_payment_token.php
  28. */
  29. public function testDefaultFormatterIsAppliedWhenBasicIntegration()
  30. {
  31. /** @var Session $customerSession */
  32. $customerSession = $this->objectManager->get(Session::class);
  33. $customerSession->loginById(1);
  34. /** @var InstantPurchase $customerDataSectionSource */
  35. $customerDataSectionSource = $this->objectManager->get(InstantPurchase::class);
  36. $data = $customerDataSectionSource->getSectionData();
  37. $this->assertEquals(
  38. 'Fake Payment Method Vault',
  39. $data['paymentToken']['summary'],
  40. 'Basic implementation returns provider title.'
  41. );
  42. }
  43. /**
  44. * @magentoDataFixture Magento/Customer/_files/customer.php
  45. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  46. * @magentoDataFixture Magento/InstantPurchase/_files/fake_payment_token.php
  47. * @magentoConfigFixture current_store payment/fake_vault/instant_purchase/tokenFormat StubFormatter
  48. */
  49. public function testCustomFormatterIsAppliedWhenComplexIntegration()
  50. {
  51. $this->objectManager->configure([
  52. 'StubFormatter' => [
  53. 'type' => StubPaymentTokenFormatter::class,
  54. ],
  55. ]);
  56. /** @var Session $customerSession */
  57. $customerSession = $this->objectManager->get(Session::class);
  58. $customerSession->loginById(1);
  59. /** @var InstantPurchase $customerDataSectionSource */
  60. $customerDataSectionSource = $this->objectManager->get(InstantPurchase::class);
  61. $data = $customerDataSectionSource->getSectionData();
  62. $this->assertEquals(
  63. StubPaymentTokenFormatter::VALUE,
  64. $data['paymentToken']['summary'],
  65. 'Complex implementation returns custom string.'
  66. );
  67. }
  68. }