ApiEndpointTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Dotdigitalgroup\Email\Helper;
  3. use Magento\TestFramework\ObjectManager;
  4. /**
  5. * Class ApiEndpointTest
  6. *
  7. * @package Dotdigitalgroup\Email\Helper
  8. * @magentoDBIsolation enabled
  9. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  10. */
  11. class ApiEndpointTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @return void
  15. */
  16. public function setup()
  17. {
  18. $this->removeData();
  19. }
  20. /**
  21. * @return void
  22. */
  23. public function tearDown()
  24. {
  25. $this->removeData();
  26. }
  27. /**
  28. * @return void
  29. */
  30. public function removeData()
  31. {
  32. /** @var ObjectManager $objectManager */
  33. $objectManager = ObjectManager::getInstance();
  34. /** @var \Magento\Config\Model\ResourceModel\Config $config */
  35. $config = $objectManager->create(\Magento\Config\Model\ResourceModel\Config::class);
  36. $data = $this->dataProvider();
  37. foreach ($data as $item) {
  38. $config->deleteConfig(Config::PATH_FOR_API_ENDPOINT, $item[2], $item[0]);
  39. }
  40. }
  41. /**
  42. * @param int $website
  43. * @param string $endPoint
  44. *
  45. * @return null
  46. *
  47. * @dataProvider dataProvider
  48. */
  49. public function testFetchingApiEndpointSuccessful($website, $endPoint)
  50. {
  51. /** @var ObjectManager $objectManager */
  52. $objectManager = ObjectManager::getInstance();
  53. $property = new \stdClass();
  54. $property->name = 'ApiEndpoint';
  55. $property->value = $endPoint;
  56. $accountInfo = new \stdClass();
  57. $accountInfo->properties = [$property];
  58. $mockClient = $this->getMockBuilder(\Dotdigitalgroup\Email\Model\Apiconnector\Client::class)
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $mockClient->method('getAccountInfo')
  62. ->willReturn($accountInfo);
  63. $mockClientFactory = $this->getMockBuilder(
  64. \Dotdigitalgroup\Email\Model\Apiconnector\ClientFactory::class
  65. )
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $mockClientFactory->method('create')
  69. ->willReturn($mockClient);
  70. /** @var \Dotdigitalgroup\Email\Helper\Data $helper */
  71. $helper = new \Dotdigitalgroup\Email\Helper\Data(
  72. $objectManager->create(\Magento\Framework\App\ProductMetadata::class),
  73. $objectManager->create(\Dotdigitalgroup\Email\Model\ContactFactory::class),
  74. $objectManager->create(\Dotdigitalgroup\Email\Model\ResourceModel\Contact::class),
  75. $objectManager->create(\Dotdigitalgroup\Email\Helper\File::class),
  76. $objectManager->create(\Magento\Config\Model\ResourceModel\Config::class),
  77. $objectManager->create(\Magento\Framework\App\ResourceConnection::class),
  78. $objectManager->create(\Magento\Framework\App\Helper\Context::class),
  79. $objectManager->create(\Magento\Store\Model\StoreManagerInterface::class),
  80. $objectManager->create(\Magento\Customer\Model\CustomerFactory::class),
  81. $objectManager->create(\Magento\Framework\Module\ModuleListInterface::class),
  82. $objectManager->create(\Magento\Store\Model\Store::class),
  83. $objectManager->create(\Magento\Framework\App\Config\Storage\Writer::class),
  84. $mockClientFactory,
  85. $objectManager->create(\Dotdigitalgroup\Email\Helper\ConfigFactory::class),
  86. $objectManager->create(\Dotdigitalgroup\Email\Model\Config\Json::class),
  87. $objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTime::class),
  88. $objectManager->create(\Magento\Quote\Model\ResourceModel\Quote::class),
  89. $objectManager->create(\Magento\Quote\Model\QuoteFactory::class),
  90. $objectManager->create(\Magento\User\Model\ResourceModel\User::class),
  91. $objectManager->create(\Magento\Framework\Encryption\EncryptorInterface::class)
  92. );
  93. $apiEndpoint = $helper->getApiEndpoint($website, $mockClient);
  94. $this->assertEquals(
  95. $endPoint,
  96. $apiEndpoint
  97. );
  98. }
  99. /**
  100. * @return array
  101. */
  102. public function dataProvider()
  103. {
  104. return [
  105. [
  106. 0,
  107. 'https://r1.dummy.com',
  108. 'default'
  109. ],
  110. [
  111. 1,
  112. 'https://r1.dummy.com',
  113. 'website'
  114. ]
  115. ];
  116. }
  117. }