DataTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Helper\Oauth;
  7. class DataTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Framework\App\Config\ScopeConfigInterface */
  10. protected $_scopeConfigMock;
  11. /** @var \Magento\Integration\Helper\Oauth\Data */
  12. protected $_dataHelper;
  13. protected function setUp()
  14. {
  15. $this->_scopeConfigMock = $this->getMockBuilder(
  16. \Magento\Framework\App\Config\ScopeConfigInterface::class
  17. )->disableOriginalConstructor()->getMock();
  18. $this->_dataHelper = new \Magento\Integration\Helper\Oauth\Data($this->_scopeConfigMock);
  19. }
  20. protected function tearDown()
  21. {
  22. unset($this->_scopeConfigMock);
  23. unset($this->_dataHelper);
  24. }
  25. public function testIsCleanupProbabilityZero()
  26. {
  27. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(0));
  28. $this->assertFalse($this->_dataHelper->isCleanupProbability());
  29. }
  30. public function testIsCleanupProbabilityRandomOne()
  31. {
  32. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(1));
  33. $this->assertTrue($this->_dataHelper->isCleanupProbability());
  34. }
  35. public function testGetCleanupExpirationPeriodZero()
  36. {
  37. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(0));
  38. $this->assertEquals(
  39. \Magento\Integration\Helper\Oauth\Data::CLEANUP_EXPIRATION_PERIOD_DEFAULT,
  40. $this->_dataHelper->getCleanupExpirationPeriod()
  41. );
  42. }
  43. public function testGetCleanupExpirationPeriodNonZero()
  44. {
  45. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(10));
  46. $this->assertEquals(10, $this->_dataHelper->getCleanupExpirationPeriod());
  47. }
  48. public function testConsumerPostMaxRedirectsZero()
  49. {
  50. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(0));
  51. $this->assertEquals(0, $this->_dataHelper->getConsumerPostMaxRedirects());
  52. }
  53. public function testConsumerPostMaxRedirectsNonZero()
  54. {
  55. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(10));
  56. $this->assertEquals(10, $this->_dataHelper->getConsumerPostMaxRedirects());
  57. }
  58. public function testGetConsumerPostTimeoutZero()
  59. {
  60. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(0));
  61. $this->assertEquals(
  62. \Magento\Integration\Helper\Oauth\Data::CONSUMER_POST_TIMEOUT_DEFAULT,
  63. $this->_dataHelper->getConsumerPostTimeout()
  64. );
  65. }
  66. public function testGetConsumerPostTimeoutNonZero()
  67. {
  68. $this->_scopeConfigMock->expects($this->once())->method('getValue')->will($this->returnValue(10));
  69. $this->assertEquals(10, $this->_dataHelper->getConsumerPostTimeout());
  70. }
  71. public function testGetCustomerTokenLifetimeNotEmpty()
  72. {
  73. $this->_scopeConfigMock
  74. ->expects($this->once())
  75. ->method('getValue')
  76. ->with('oauth/access_token_lifetime/customer')
  77. ->will($this->returnValue(10));
  78. $this->assertEquals(10, $this->_dataHelper->getCustomerTokenLifetime());
  79. }
  80. public function testGetCustomerTokenLifetimeEmpty()
  81. {
  82. $this->_scopeConfigMock
  83. ->expects($this->once())
  84. ->method('getValue')
  85. ->with('oauth/access_token_lifetime/customer')
  86. ->will($this->returnValue(null));
  87. $this->assertEquals(0, $this->_dataHelper->getCustomerTokenLifetime());
  88. }
  89. public function testGetAdminTokenLifetimeNotEmpty()
  90. {
  91. $this->_scopeConfigMock
  92. ->expects($this->once())
  93. ->method('getValue')
  94. ->with('oauth/access_token_lifetime/admin')
  95. ->will($this->returnValue(10));
  96. $this->assertEquals(10, $this->_dataHelper->getAdminTokenLifetime());
  97. }
  98. public function testGetAdminTokenLifetimeEmpty()
  99. {
  100. $this->_scopeConfigMock
  101. ->expects($this->once())
  102. ->method('getValue')
  103. ->with('oauth/access_token_lifetime/admin')
  104. ->will($this->returnValue(null));
  105. $this->assertEquals(0, $this->_dataHelper->getAdminTokenLifetime());
  106. }
  107. }