CustomerDataTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Block;
  7. use Magento\Customer\Block\CustomerData;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\View\Element\Template\Context;
  10. class CustomerDataTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var Context|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. private $contextMock;
  16. /**
  17. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $scopeConfigMock;
  20. protected function setUp()
  21. {
  22. $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)->getMock();
  23. $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
  24. $this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
  25. }
  26. public function testGetExpirableSectionLifetimeReturnsConfigurationValue()
  27. {
  28. $block = new CustomerData(
  29. $this->contextMock,
  30. [],
  31. []
  32. );
  33. $this->scopeConfigMock->expects($this->once())
  34. ->method('getValue')
  35. ->with('customer/online_customers/section_data_lifetime', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)
  36. ->willReturn('10');
  37. $actualResult = $block->getExpirableSectionLifetime();
  38. $this->assertSame(10, $actualResult);
  39. }
  40. public function testGetExpirableSectionNames()
  41. {
  42. $expectedResult = ['cart'];
  43. $block = new CustomerData(
  44. $this->contextMock,
  45. [],
  46. $expectedResult
  47. );
  48. $this->assertEquals($expectedResult, $block->getExpirableSectionNames());
  49. }
  50. }