AnalyticsTokenTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model;
  7. use Magento\Analytics\Model\AnalyticsToken;
  8. use Magento\Framework\App\Config\ReinitableConfigInterface;
  9. use Magento\Framework\App\Config\ScopeConfigInterface;
  10. use Magento\Framework\App\Config\Storage\WriterInterface;
  11. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  12. class AnalyticsTokenTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $reinitableConfigMock;
  18. /**
  19. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $configMock;
  22. /**
  23. * @var WriterInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $configWriterMock;
  26. /**
  27. * @var ObjectManagerHelper
  28. */
  29. private $objectManagerHelper;
  30. /**
  31. * @var AnalyticsToken
  32. */
  33. private $tokenModel;
  34. /**
  35. * @var string
  36. */
  37. private $tokenPath = 'analytics/general/token';
  38. /**
  39. * @return void
  40. */
  41. protected function setUp()
  42. {
  43. $this->reinitableConfigMock = $this->getMockBuilder(ReinitableConfigInterface::class)
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->configWriterMock = $this->getMockBuilder(WriterInterface::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->objectManagerHelper = new ObjectManagerHelper($this);
  53. $this->tokenModel = $this->objectManagerHelper->getObject(
  54. AnalyticsToken::class,
  55. [
  56. 'reinitableConfig' => $this->reinitableConfigMock,
  57. 'config' => $this->configMock,
  58. 'configWriter' => $this->configWriterMock,
  59. 'tokenPath' => $this->tokenPath,
  60. ]
  61. );
  62. }
  63. /**
  64. * @return void
  65. */
  66. public function testStoreToken()
  67. {
  68. $value = 'jjjj0000';
  69. $this->configWriterMock
  70. ->expects($this->once())
  71. ->method('save')
  72. ->with($this->tokenPath, $value);
  73. $this->reinitableConfigMock
  74. ->expects($this->once())
  75. ->method('reinit')
  76. ->willReturnSelf();
  77. $this->assertTrue($this->tokenModel->storeToken($value));
  78. }
  79. /**
  80. * @return void
  81. */
  82. public function testGetToken()
  83. {
  84. $value = 'jjjj0000';
  85. $this->configMock
  86. ->expects($this->once())
  87. ->method('getValue')
  88. ->with($this->tokenPath)
  89. ->willReturn($value);
  90. $this->assertSame($value, $this->tokenModel->getToken());
  91. }
  92. /**
  93. * @return void
  94. */
  95. public function testIsTokenExist()
  96. {
  97. $this->assertFalse($this->tokenModel->isTokenExist());
  98. $this->configMock
  99. ->expects($this->once())
  100. ->method('getValue')
  101. ->with($this->tokenPath)
  102. ->willReturn('0000');
  103. $this->assertTrue($this->tokenModel->isTokenExist());
  104. }
  105. }